-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support checking preconditions before starting core app (#9026)
* feat: support checking preconditions before starting core app This patch changes up the precondition checker a bit so that it runs before the main KsqlRestApplication. This way, preconditions can look out for critical config properties to arrive, before they are handled by the actuall application. Detailed changes: - Run the precondition checker as a separate Executable implementation before running KsqlRestApplication. The precondition checker waits for any preconditions to pass, and while this is ongoing it runs a simple server that responds to all requests (other than the health probes) with a 503. - Change the precondition interface to accept a properties loader so that precondition checkers can wait on the arrival of dynamic properties. - Support multiple properties files as args (which are then overlaid) * feedback * tests pass
- Loading branch information
Showing
22 changed files
with
1,232 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
ksqldb-rest-app/src/main/java/io/confluent/ksql/api/server/PreconditionVerticle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.api.server; | ||
|
||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import io.confluent.ksql.api.util.ApiServerUtils; | ||
import io.confluent.ksql.rest.server.state.ServerState; | ||
import io.vertx.core.AbstractVerticle; | ||
import io.vertx.core.Promise; | ||
import io.vertx.core.http.HttpMethod; | ||
import io.vertx.core.http.HttpServer; | ||
import io.vertx.core.http.HttpServerOptions; | ||
import io.vertx.ext.web.Router; | ||
import java.util.Objects; | ||
|
||
/** | ||
* The server deploys multiple server verticles. This is where the HTTP2 requests are handled. The | ||
* actual implementation of the endpoints is provided by an implementation of {@code Endpoints}. | ||
*/ | ||
public class PreconditionVerticle extends AbstractVerticle { | ||
private final HttpServerOptions httpServerOptions; | ||
private final ServerState serverState; | ||
private HttpServer httpServer; | ||
|
||
@SuppressFBWarnings(value = "EI_EXPOSE_REP2") | ||
public PreconditionVerticle( | ||
final HttpServerOptions httpServerOptions, | ||
final ServerState serverState | ||
) { | ||
this.httpServerOptions = Objects.requireNonNull(httpServerOptions); | ||
this.serverState = Objects.requireNonNull(serverState, "serverState"); | ||
} | ||
|
||
@Override | ||
public void start(final Promise<Void> startPromise) { | ||
httpServer = vertx.createHttpServer(httpServerOptions).requestHandler(setupRouter()) | ||
.exceptionHandler(ApiServerUtils::unhandledExceptionHandler); | ||
httpServer.listen(ar -> { | ||
if (ar.succeeded()) { | ||
startPromise.complete(); | ||
} else { | ||
startPromise.fail(ar.cause()); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void stop(final Promise<Void> stopPromise) { | ||
if (httpServer == null) { | ||
stopPromise.complete(); | ||
} else { | ||
httpServer.close(stopPromise.future()); | ||
} | ||
} | ||
|
||
private Router setupRouter() { | ||
final Router router = Router.router(vertx); | ||
router.route(HttpMethod.GET, "/chc/ready").handler(ApiServerUtils::chcHandler); | ||
router.route(HttpMethod.GET, "/chc/live").handler(ApiServerUtils::chcHandler); | ||
router.route().handler(new ServerStateHandler(serverState)); | ||
router.route().failureHandler(new FailureHandler()); | ||
return router; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.