Skip to content

Commit 629c12f

Browse files
csvirimetacosm
authored andcommitted
fix: wip
1 parent 814c707 commit 629c12f

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/polling/PerResourcePollingEventSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void run() {
117117
res.ifPresentOrElse(r -> pollForResource(r),
118118
() -> log.warn("No resource in cache for resource ID: {}", resourceID));
119119
}
120-
}, period, period);
120+
}, 0, period);
121121
}
122122
}
123123

sample-operators/mysql-schema/src/main/java/io/javaoperatorsdk/operator/sample/MySQLSchemaReconciler.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.sql.SQLException;
88
import java.sql.Statement;
99
import java.util.Base64;
10+
import java.util.Optional;
1011

1112
import org.apache.commons.lang3.RandomStringUtils;
1213
import org.slf4j.Logger;
@@ -20,7 +21,8 @@
2021
import static java.lang.String.format;
2122

2223
@ControllerConfiguration
23-
public class MySQLSchemaReconciler implements Reconciler<MySQLSchema> {
24+
public class MySQLSchemaReconciler
25+
implements Reconciler<MySQLSchema>, ErrorStatusHandler<MySQLSchema> {
2426
static final String USERNAME_FORMAT = "%s-user";
2527
static final String SECRET_FORMAT = "%s-secret";
2628

@@ -87,7 +89,6 @@ public UpdateControl<MySQLSchema> reconcile(MySQLSchema schema,
8789
return UpdateControl.noUpdate();
8890
} catch (SQLException e) {
8991
log.error("Error while creating Schema", e);
90-
9192
SchemaStatus status = new SchemaStatus();
9293
status.setUrl(null);
9394
status.setUserName(null);
@@ -99,6 +100,13 @@ public UpdateControl<MySQLSchema> reconcile(MySQLSchema schema,
99100
}
100101
}
101102

103+
@Override
104+
public Optional<MySQLSchema> updateErrorStatus(MySQLSchema resource, RetryInfo retryInfo,
105+
RuntimeException e) {
106+
107+
return Optional.empty();
108+
}
109+
102110
@Override
103111
public DeleteControl cleanup(MySQLSchema schema, Context context) {
104112
log.info("Execution deleteResource for: {}", schema.getMetadata().getName());
@@ -140,18 +148,20 @@ private Connection getConnection() throws SQLException {
140148
String connectionString =
141149
format("jdbc:mysql://%1$s:%2$s", mysqlDbConfig.getHost(), mysqlDbConfig.getPort());
142150

143-
log.info("Connecting to '{}' with user '{}'", connectionString, mysqlDbConfig.getUser());
151+
log.debug("Connecting to '{}' with user '{}'", connectionString, mysqlDbConfig.getUser());
144152
return DriverManager.getConnection(connectionString, mysqlDbConfig.getUser(),
145153
mysqlDbConfig.getPassword());
146154
}
147155

148156
private boolean schemaExists(Connection connection, String schemaName) throws SQLException {
149157
try (PreparedStatement ps =
150158
connection.prepareStatement(
151-
"SELECT schema_name FROM information_schema.schemata WHERE schema_name = ?")) {
159+
"SELECT * FROM information_schema.schemata WHERE schema_name = ?")) {
152160
ps.setString(1, schemaName);
153161
try (ResultSet resultSet = ps.executeQuery()) {
154-
return resultSet.next();
162+
// CATALOG_NAME, SCHEMA_NAME, DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME, SQL_PATH
163+
var exists = resultSet.next();
164+
return exists;
155165
}
156166
}
157167
}

0 commit comments

Comments
 (0)