This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
The following commit(s) were added to refs/heads/master by this push: new fbc5a2a Refactor health support new b99a93a Merge pull request #249 from lburgazzoli/health-refactor fbc5a2a is described below commit fbc5a2a10c9854f2557d2e8e9dc1e1a348e2daa1 Author: lburgazzoli <lburgazz...@gmail.com> AuthorDate: Mon Mar 2 16:30:44 2020 +0100 Refactor health support --- .../camel-k-runtime-health}/pom.xml | 39 +++- .../camel/k/health/HealthContextCustomizer.java | 159 +++++++++++++++ .../services/org/apache/camel/k/customizer/health | 0 .../camel/k/health/HealthCustomizerTest.java | 82 ++++++++ .../src/test/resources/log4j2-test.xml | 5 +- .../camel-k-runtime-inspector}/pom.xml | 43 ++-- .../k/inspector/InspectorContextCustomizer.java | 22 +-- .../camel/k/inspector/InspectorCustomizer.java | 15 +- .../camel/k/inspector/InspectorEndpoint.java | 220 +++++++++++++++++++++ .../org/apache/camel/k/customizer/inspector | 2 +- .../camel/k/inspector/InspectorCustomizerTest.java | 74 +++++++ .../src/test/resources/log4j2-test.xml | 2 +- .../camel-k-runtime-main}/pom.xml | 2 +- .../java/org/apache/camel/k/main/Application.java | 0 .../apache/camel/k/main/ApplicationRuntime.java | 0 .../apache/camel/k/main/ApplicationSupport.java | 0 .../src/main/resources/log4j2.properties | 0 .../test/java/org/apache/camel/k/main/MyBean.java | 0 .../org/apache/camel/k/main/PropertiesTest.java | 0 .../java/org/apache/camel/k/main/RuntimeTest.java | 0 .../org/apache/camel/k/main/TestCustomizer.java | 0 .../services/org/apache/camel/k/customizer/test | 0 .../src/test/resources/MyRoutesConfig.java | 0 .../src/test/resources/MyRoutesWithBeans.java | 0 .../src/test/resources/conf.d/001/conf.properties | 0 .../src/test/resources/conf.d/002/conf.properties | 0 .../src/test/resources/conf.properties | 0 .../src/test/resources/log4j2-test.xml | 0 .../src/test/resources/my-resource.txt | 0 .../camel-k-runtime-main}/src/test/resources/r1.js | 0 .../src/test/resources/r2.mytype | 0 .../src/test/resources/rests.xml | 0 .../src/test/resources/routes-with-expression.xml | 0 .../src/test/resources/routes.xml | 0 .../log4j2-test.xml => camel-k-main/pom.xml | 32 +-- camel-k-runtime-bom/pom.xml | 2 +- .../camel/k/health/HealthContextCustomizer.java | 51 ----- .../org/apache/camel/k/health/HealthEndpoint.java | 63 ------ .../camel/k/health/HealthCustomizerTest.java | 51 ----- .../apache/camel/k/servlet/ServletEndpoint.java | 87 -------- .../camel/k/servlet/ServletRegistration.java | 82 -------- .../ServletRegistrationContextCustomizer.java | 68 ------- .../apache/camel/k/customizer/servletregistration | 18 -- .../camel/k/servlet/ServletCustomizerTest.java | 50 ----- .../servlet/ServletRegistrationCustomizerTest.java | 50 ----- .../camel-k-runtime-example-health/README.adoc | 15 +- examples/camel-k-runtime-example-health/pom.xml | 6 +- .../src/main/resources/application.properties | 4 +- .../src/main/resources/routes.groovy | 3 +- .../camel-k-runtime-example-servlet/README.adoc | 14 -- examples/camel-k-runtime-example-servlet/pom.xml | 84 -------- .../src/main/resources/application.properties | 35 ---- examples/camel-k-runtime-example-yaml/pom.xml | 4 - examples/pom.xml | 1 - pom.xml | 11 +- .../src/it/generate-catalog-main/pom.xml | 2 +- .../src/it/generate-catalog-main/verify.groovy | 12 +- .../src/it/generate-catalog-quarkus/pom.xml | 2 +- .../src/it/generate-catalog-quarkus/verify.groovy | 10 +- .../camel/k/tooling/maven/GenerateCatalogMojo.java | 20 +- .../{crd/RuntimeSpec.java => CamelCapability.java} | 25 +-- .../k/tooling/maven/model/crd/RuntimeSpec.java | 6 + .../maven/processors/CatalogProcessor3x.java | 2 +- .../maven/processors/CatalogProcessor3Test.java | 2 +- 64 files changed, 728 insertions(+), 749 deletions(-) diff --git a/camel-k-runtime-health/pom.xml b/camel-k-main/camel-k-runtime-health/pom.xml similarity index 75% rename from camel-k-runtime-health/pom.xml rename to camel-k-main/camel-k-runtime-health/pom.xml index fc7d405..3024878 100644 --- a/camel-k-runtime-health/pom.xml +++ b/camel-k-main/camel-k-runtime-health/pom.xml @@ -20,7 +20,7 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-parent</artifactId> + <artifactId>camel-k-main</artifactId> <version>1.1.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> @@ -45,7 +45,13 @@ </dependency> <dependency> <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-servlet</artifactId> + <artifactId>camel-k-runtime-inspector</artifactId> + </dependency> + + <dependency> + <groupId>io.vertx</groupId> + <artifactId>vertx-web</artifactId> + <version>${vertx.version}</version> </dependency> <!-- ****************************** --> @@ -59,6 +65,16 @@ <artifactId>camel-test</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-direct</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-mock</artifactId> + <scope>test</scope> + </dependency> <dependency> <groupId>org.junit.jupiter</groupId> @@ -73,11 +89,24 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-params</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + + <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>${assertj.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <version>${rest-assured.version}</version> + <scope>test</scope> + </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> @@ -91,6 +120,12 @@ <version>${log4j2.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-jcl</artifactId> + <version>${log4j2.version}</version> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/camel-k-main/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthContextCustomizer.java b/camel-k-main/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthContextCustomizer.java new file mode 100644 index 0000000..8d70f10 --- /dev/null +++ b/camel-k-main/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthContextCustomizer.java @@ -0,0 +1,159 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.k.health; + +import java.util.Collection; +import java.util.Map; + +import io.vertx.core.http.HttpMethod; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import org.apache.camel.CamelContext; +import org.apache.camel.Ordered; +import org.apache.camel.health.HealthCheck; +import org.apache.camel.health.HealthCheckFilter; +import org.apache.camel.health.HealthCheckHelper; +import org.apache.camel.health.HealthCheckRegistry; +import org.apache.camel.impl.health.AbstractHealthCheck; +import org.apache.camel.impl.health.ContextHealthCheck; +import org.apache.camel.impl.health.RoutesHealthCheckRepository; +import org.apache.camel.k.ContextCustomizer; +import org.apache.camel.k.inspector.InspectorCustomizer; + +public class HealthContextCustomizer implements ContextCustomizer { + public static final String DEFAULT_PATH = "/health"; + + private String path; + private String healthGroupFilterExclude; + private boolean includeRoutes; + private boolean includeContext; + + public HealthContextCustomizer() { + this.path = DEFAULT_PATH; + this.includeRoutes = true; + this.includeContext = true; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getHealthGroupFilterExclude() { + return healthGroupFilterExclude; + } + + public void setHealthGroupFilterExclude(String healthGroupFilterExclude) { + this.healthGroupFilterExclude = healthGroupFilterExclude; + } + + public boolean isIncludeRoutes() { + return includeRoutes; + } + + public void setIncludeRoutes(boolean includeRoutes) { + this.includeRoutes = includeRoutes; + } + + public boolean isIncludeContext() { + return includeContext; + } + + public void setIncludeContext(boolean includeContext) { + this.includeContext = includeContext; + } + + @Override + public int getOrder() { + return Ordered.HIGHEST; + } + + @Override + public void apply(CamelContext camelContext) { + try { + HealthCheckRegistry reg = HealthCheckRegistry.get(camelContext); + if (includeRoutes) { + reg.addRepository(new RoutesHealthCheckRepository()); + } + if (includeContext) { + ContextHealthCheck contextHealthCheck = new ContextHealthCheck(); + contextHealthCheck.getConfiguration().setEnabled(true); + + reg.register(contextHealthCheck); + } + + camelContext.addService(reg); + } catch (Exception e) { + throw new RuntimeException(e); + } + + camelContext.getRegistry().bind( + "health-route", + customizer(camelContext) + ); + } + + private InspectorCustomizer customizer(CamelContext camelContext) { + return router -> router.route(HttpMethod.GET, path).handler(routingContext -> { + int code = 200; + + Collection<HealthCheck.Result> results = HealthCheckHelper.invoke( + camelContext, + (HealthCheckFilter) check -> check.getGroup() != null && check.getGroup().equals(getHealthGroupFilterExclude())); + + JsonObject response = new JsonObject(); + response.put("status", "UP"); + + JsonArray checks = new JsonArray(); + + for (HealthCheck.Result result: results) { + Map<String, Object> details = result.getDetails(); + boolean enabled = true; + + if (details.containsKey(AbstractHealthCheck.CHECK_ENABLED)) { + enabled = (boolean) details.get(AbstractHealthCheck.CHECK_ENABLED); + } + + if (enabled) { + JsonObject check = new JsonObject(); + check.put("name", result.getCheck().getId()); + check.put("status", result.getState().name()); + + if (result.getState() == HealthCheck.State.DOWN) { + response.put("status", "DOWN"); + code = 503; + } + + checks.add(check); + } + } + + if (!checks.isEmpty()) { + response.put("checks", checks); + } + + routingContext.response() + .putHeader("content-type", "application/json") + .setStatusCode(code) + .end(Json.encodePrettily(response)); + }); + } +} diff --git a/camel-k-runtime-health/src/main/resources/META-INF/services/org/apache/camel/k/customizer/health b/camel-k-main/camel-k-runtime-health/src/main/resources/META-INF/services/org/apache/camel/k/customizer/health similarity index 100% rename from camel-k-runtime-health/src/main/resources/META-INF/services/org/apache/camel/k/customizer/health rename to camel-k-main/camel-k-runtime-health/src/main/resources/META-INF/services/org/apache/camel/k/customizer/health diff --git a/camel-k-main/camel-k-runtime-health/src/test/java/org/apache/camel/k/health/HealthCustomizerTest.java b/camel-k-main/camel-k-runtime-health/src/test/java/org/apache/camel/k/health/HealthCustomizerTest.java new file mode 100644 index 0000000..1a7fb06 --- /dev/null +++ b/camel-k-main/camel-k-runtime-health/src/test/java/org/apache/camel/k/health/HealthCustomizerTest.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.k.health; + +import java.net.URL; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.k.Runtime; +import org.apache.camel.k.inspector.InspectorContextCustomizer; +import org.apache.camel.test.AvailablePortFinder; +import org.apache.camel.util.ObjectHelper; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItems; + +public class HealthCustomizerTest { + + @ParameterizedTest + @ValueSource(strings = { "", "/test", "/test/nested" }) + public void testHealthConfigurer(String path) throws Exception { + Runtime runtime = Runtime.on(new DefaultCamelContext()); + runtime.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .routeId("my-route") + .to("mock:end"); + } + }); + + HealthContextCustomizer healthCustomizer = new HealthContextCustomizer(); + healthCustomizer.apply(runtime.getCamelContext()); + + InspectorContextCustomizer inspectorCustomizer = new InspectorContextCustomizer(); + inspectorCustomizer.setBindPort(AvailablePortFinder.getNextAvailable()); + + String url; + if (ObjectHelper.isEmpty(path)) { + url = "http://localhost:" + inspectorCustomizer.getBindPort() + HealthContextCustomizer.DEFAULT_PATH; + } else { + inspectorCustomizer.setPath(path); + + url = "http://localhost:" + inspectorCustomizer.getBindPort() + path + HealthContextCustomizer.DEFAULT_PATH; + } + + inspectorCustomizer.apply(runtime.getCamelContext()); + + try { + runtime.getCamelContext().start(); + + when() + .get(new URL(url)) + .then() + .statusCode(200) + .body( + "status", equalTo("UP"), + "checks.name", hasItems("context", "route:my-route"), + "checks.status", hasItems("UP", "UP") + ); + } finally { + runtime.stop(); + } + } +} diff --git a/camel-k-runtime-health/src/test/resources/log4j2-test.xml b/camel-k-main/camel-k-runtime-health/src/test/resources/log4j2-test.xml similarity index 88% copy from camel-k-runtime-health/src/test/resources/log4j2-test.xml copy to camel-k-main/camel-k-runtime-health/src/test/resources/log4j2-test.xml index 48bdd0c..0f393ea 100644 --- a/camel-k-runtime-health/src/test/resources/log4j2-test.xml +++ b/camel-k-main/camel-k-runtime-health/src/test/resources/log4j2-test.xml @@ -26,10 +26,9 @@ </Appenders> <Loggers> - <Logger name="io.netty" level="INFO"/> - <Logger name="io.netty.handler.logging" level="DEBUG"/> + <Logger name="io.vertx" level="INFO"/> <Root level="INFO"> - <!--<AppenderRef ref="STDOUT"/>--> + <!-- <AppenderRef ref="STDOUT"/> --> <AppenderRef ref="NONE"/> </Root> </Loggers> diff --git a/camel-k-runtime-servlet/pom.xml b/camel-k-main/camel-k-runtime-inspector/pom.xml similarity index 82% rename from camel-k-runtime-servlet/pom.xml rename to camel-k-main/camel-k-runtime-inspector/pom.xml index f506317..9b3a8c7 100644 --- a/camel-k-runtime-servlet/pom.xml +++ b/camel-k-main/camel-k-runtime-inspector/pom.xml @@ -20,12 +20,12 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-parent</artifactId> + <artifactId>camel-k-main</artifactId> <version>1.1.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> - <artifactId>camel-k-runtime-servlet</artifactId> + <artifactId>camel-k-runtime-inspector</artifactId> <dependencies> @@ -40,27 +40,14 @@ <artifactId>camel-core-engine</artifactId> </dependency> <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-servlet</artifactId> - </dependency> - <dependency> <groupId>org.apache.camel.k</groupId> <artifactId>camel-k-runtime-core</artifactId> </dependency> - <!-- - the following dependencies should be kept in sync with the version - used by camel - --> - <dependency> - <groupId>io.undertow</groupId> - <artifactId>undertow-core</artifactId> - <version>${undertow.version}</version> - </dependency> <dependency> - <groupId>io.undertow</groupId> - <artifactId>undertow-servlet</artifactId> - <version>1.4.26.Final</version> + <groupId>io.vertx</groupId> + <artifactId>vertx-web</artifactId> + <version>${vertx.version}</version> </dependency> <!-- ****************************** --> @@ -88,6 +75,13 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-params</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + + <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>${assertj.version}</version> @@ -95,6 +89,13 @@ </dependency> <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <version>${rest-assured.version}</version> + <scope>test</scope> + </dependency> + + <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>${log4j2.version}</version> @@ -106,6 +107,12 @@ <version>${log4j2.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-jcl</artifactId> + <version>${log4j2.version}</version> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletContextCustomizer.java b/camel-k-main/camel-k-runtime-inspector/src/main/java/org/apache/camel/k/inspector/InspectorContextCustomizer.java similarity index 85% rename from camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletContextCustomizer.java rename to camel-k-main/camel-k-runtime-inspector/src/main/java/org/apache/camel/k/inspector/InspectorContextCustomizer.java index 9986889..5bcc396 100644 --- a/camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletContextCustomizer.java +++ b/camel-k-main/camel-k-runtime-inspector/src/main/java/org/apache/camel/k/inspector/InspectorContextCustomizer.java @@ -14,23 +14,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.k.servlet; +package org.apache.camel.k.inspector; import org.apache.camel.CamelContext; import org.apache.camel.Ordered; import org.apache.camel.k.ContextCustomizer; -public class ServletContextCustomizer implements ContextCustomizer { +public class InspectorContextCustomizer implements ContextCustomizer { public static final String DEFAULT_BIND_HOST = "0.0.0.0"; - public static final int DEFAULT_BIND_PORT = 8080; + public static final int DEFAULT_BIND_PORT = 8081; public static final String DEFAULT_PATH = "/"; private String bindHost; private int bindPort; private String path; - private ServletEndpoint endpoint; + private InspectorEndpoint endpoint; - public ServletContextCustomizer() { + public InspectorContextCustomizer() { this.bindHost = DEFAULT_BIND_HOST; this.bindPort = DEFAULT_BIND_PORT; this.path = DEFAULT_PATH; @@ -61,8 +61,13 @@ public class ServletContextCustomizer implements ContextCustomizer { } @Override + public int getOrder() { + return Ordered.LOWEST; + } + + @Override public void apply(CamelContext camelContext) { - endpoint = new ServletEndpoint(camelContext, bindHost, bindPort, path); + endpoint = new InspectorEndpoint(camelContext, bindHost, bindPort, path); try { camelContext.addService(endpoint, true, true); @@ -70,9 +75,4 @@ public class ServletContextCustomizer implements ContextCustomizer { throw new RuntimeException(e); } } - - @Override - public int getOrder() { - return Ordered.LOWEST; - } } diff --git a/examples/camel-k-runtime-example-servlet/src/main/resources/routes.groovy b/camel-k-main/camel-k-runtime-inspector/src/main/java/org/apache/camel/k/inspector/InspectorCustomizer.java similarity index 71% rename from examples/camel-k-runtime-example-servlet/src/main/resources/routes.groovy rename to camel-k-main/camel-k-runtime-inspector/src/main/java/org/apache/camel/k/inspector/InspectorCustomizer.java index 452b215..06b4cbb 100644 --- a/examples/camel-k-runtime-example-servlet/src/main/resources/routes.groovy +++ b/camel-k-main/camel-k-runtime-inspector/src/main/java/org/apache/camel/k/inspector/InspectorCustomizer.java @@ -14,7 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package org.apache.camel.k.inspector; -from('servlet:/test') - .convertBodyTo(String.class) - .to('log:info') \ No newline at end of file +import java.util.function.Consumer; + +import io.vertx.ext.web.Router; + +/** + * Marker interface to easily lookup Vertx customizer from the + * camel {@link org.apache.camel.spi.Registry}. + */ +@FunctionalInterface +public interface InspectorCustomizer extends Consumer<Router> { +} diff --git a/camel-k-main/camel-k-runtime-inspector/src/main/java/org/apache/camel/k/inspector/InspectorEndpoint.java b/camel-k-main/camel-k-runtime-inspector/src/main/java/org/apache/camel/k/inspector/InspectorEndpoint.java new file mode 100644 index 0000000..71eafde --- /dev/null +++ b/camel-k-main/camel-k-runtime-inspector/src/main/java/org/apache/camel/k/inspector/InspectorEndpoint.java @@ -0,0 +1,220 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.k.inspector; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +import io.vertx.core.Vertx; +import io.vertx.core.VertxOptions; +import io.vertx.core.http.HttpServer; +import io.vertx.ext.web.Router; +import org.apache.camel.CamelContext; +import org.apache.camel.support.CamelContextHelper; +import org.apache.camel.support.service.ServiceSupport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class InspectorEndpoint extends ServiceSupport { + private static final Logger LOGGER = LoggerFactory.getLogger(InspectorEndpoint.class); + + private final CamelContext context; + private final String bindHost; + private final int bindPort; + private final String path; + + private Vertx vertx; + private boolean localVertx; + private ExecutorService executor; + private HttpServerWrapper vertxHttpServer; + + public InspectorEndpoint(CamelContext context, String bindHost, int bindPort, String path) { + this.context = context; + this.bindHost = bindHost; + this.bindPort = bindPort; + this.path = path; + } + + @Override + protected void doStart() throws Exception { + this.executor = context.getExecutorServiceManager().newSingleThreadExecutor(this, "main-actuator"); + this.vertx = CamelContextHelper.findByType(context, Vertx.class); + + if (this.vertx != null) { + LOGGER.info("Found Vert.x instance in registry: {}", this.vertx); + } else { + VertxOptions options = CamelContextHelper.findByType(context, VertxOptions.class); + if (options == null) { + options = new VertxOptions(); + } + + LOGGER.info("Creating new Vert.x instance"); + + this.vertx = Vertx.vertx(options); + this.localVertx = true; + } + + vertxHttpServer = new HttpServerWrapper(); + vertxHttpServer.start(); + } + + @Override + protected void doStop() throws Exception { + if (this.vertxHttpServer != null) { + vertxHttpServer.stop(); + } + + if (this.vertx != null && this.localVertx) { + Future<?> future = this.executor.submit( + () -> { + CountDownLatch latch = new CountDownLatch(1); + + this.vertx.close(result -> { + try { + if (result.failed()) { + LOGGER.warn("Failed to close Vert.x reason: {}", + result.cause().getMessage() + ); + + throw new RuntimeException(result.cause()); + } + + LOGGER.info("Vert.x stopped"); + } finally { + latch.countDown(); + } + }); + + try { + latch.await(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + ); + + try { + future.get(); + } finally { + this.vertx = null; + this.localVertx = false; + } + } + + if (this.executor != null) { + context.getExecutorServiceManager().shutdownNow(this.executor); + } + } + + private final class HttpServerWrapper extends ServiceSupport { + private HttpServer server; + + @Override + protected void doStart() throws Exception { + startAsync().toCompletableFuture().join(); + } + + @Override + protected void doStop() throws Exception { + try { + if (server != null) { + stopAsync().toCompletableFuture().join(); + } + } finally { + this.server = null; + } + } + + private CompletionStage<Void> startAsync() { + final Router router = Router.router(vertx); + final Router subRouter = Router.router(vertx); + + context.getRegistry().findByType(InspectorCustomizer.class).forEach(customizer -> { + LOGGER.debug("InspectorCustomizer: {}", customizer); + customizer.accept(subRouter); + }); + + router.mountSubRouter(path, subRouter); + + server = vertx.createHttpServer(); + return CompletableFuture.runAsync( + () -> { + CountDownLatch latch = new CountDownLatch(1); + + server.requestHandler(router).listen(bindPort, bindHost, result -> { + try { + if (result.failed()) { + LOGGER.warn("Failed to start Vert.x HttpServer on {}:{}, reason: {}", + bindHost, + bindPort, + result.cause().getMessage() + ); + + throw new RuntimeException(result.cause()); + } + + LOGGER.info("Vert.x HttpServer started on {}:{}", bindHost, bindPort); + } finally { + latch.countDown(); + } + }); + + try { + latch.await(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }, + executor + ); + } + + protected CompletionStage<Void> stopAsync() { + return CompletableFuture.runAsync( + () -> { + CountDownLatch latch = new CountDownLatch(1); + + server.close(result -> { + try { + if (result.failed()) { + LOGGER.warn("Failed to close Vert.x HttpServer reason: {}", + result.cause().getMessage() + ); + + throw new RuntimeException(result.cause()); + } + + LOGGER.info("Vert.x HttpServer stopped"); + } finally { + latch.countDown(); + } + }); + + try { + latch.await(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }, + executor + ); + } + } +} diff --git a/camel-k-runtime-servlet/src/main/resources/META-INF/services/org/apache/camel/k/customizer/servlet b/camel-k-main/camel-k-runtime-inspector/src/main/resources/META-INF/services/org/apache/camel/k/customizer/inspector similarity index 92% rename from camel-k-runtime-servlet/src/main/resources/META-INF/services/org/apache/camel/k/customizer/servlet rename to camel-k-main/camel-k-runtime-inspector/src/main/resources/META-INF/services/org/apache/camel/k/customizer/inspector index 46bb724..6fa86ed 100644 --- a/camel-k-runtime-servlet/src/main/resources/META-INF/services/org/apache/camel/k/customizer/servlet +++ b/camel-k-main/camel-k-runtime-inspector/src/main/resources/META-INF/services/org/apache/camel/k/customizer/inspector @@ -15,4 +15,4 @@ # limitations under the License. # -class=org.apache.camel.k.servlet.ServletContextCustomizer +class=org.apache.camel.k.inspector.InspectorContextCustomizer diff --git a/camel-k-main/camel-k-runtime-inspector/src/test/java/org/apache/camel/k/inspector/InspectorCustomizerTest.java b/camel-k-main/camel-k-runtime-inspector/src/test/java/org/apache/camel/k/inspector/InspectorCustomizerTest.java new file mode 100644 index 0000000..d103b1f --- /dev/null +++ b/camel-k-main/camel-k-runtime-inspector/src/test/java/org/apache/camel/k/inspector/InspectorCustomizerTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (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.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.k.inspector; + +import java.net.URL; + +import io.vertx.core.http.HttpMethod; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonObject; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.k.Runtime; +import org.apache.camel.test.AvailablePortFinder; +import org.apache.camel.util.ObjectHelper; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.Matchers.equalTo; + +public class InspectorCustomizerTest { + + @ParameterizedTest + @ValueSource(strings = { "", "/test", "/test/nested" }) + public void testInspectorConfigurer(String path) throws Exception { + Runtime runtime = Runtime.on(new DefaultCamelContext()); + + runtime.getRegistry().bind("my-customizer", (InspectorCustomizer) router -> + router.route(HttpMethod.GET, "/my/path") + .handler(routingContext -> { + JsonObject response = new JsonObject(); + response.put("status", "UP"); + + routingContext.response() + .putHeader("content-type", "application/json") + .setStatusCode(200) + .end(Json.encodePrettily(response)); + }) + ); + + InspectorContextCustomizer inspectorCustomizer = new InspectorContextCustomizer(); + inspectorCustomizer.setBindPort(AvailablePortFinder.getNextAvailable()); + + String url; + if (ObjectHelper.isEmpty(path)) { + url = "http://localhost:" + inspectorCustomizer.getBindPort() + "/my/path"; + } else { + inspectorCustomizer.setPath(path); + + url = "http://localhost:" + inspectorCustomizer.getBindPort() + path + "/my/path"; + } + + inspectorCustomizer.apply(runtime.getCamelContext()); + + when() + .get(new URL(url)) + .then() + .statusCode(200) + .body("status", equalTo("UP")); + } +} diff --git a/camel-k-runtime-servlet/src/test/resources/log4j2-test.xml b/camel-k-main/camel-k-runtime-inspector/src/test/resources/log4j2-test.xml similarity index 95% rename from camel-k-runtime-servlet/src/test/resources/log4j2-test.xml rename to camel-k-main/camel-k-runtime-inspector/src/test/resources/log4j2-test.xml index 384e622..d0ac3a4 100644 --- a/camel-k-runtime-servlet/src/test/resources/log4j2-test.xml +++ b/camel-k-main/camel-k-runtime-inspector/src/test/resources/log4j2-test.xml @@ -26,7 +26,7 @@ </Appenders> <Loggers> - <Logger name="io.undertow" level="INFO"/> + <Logger name="io.vertx" level="INFO"/> <Root level="INFO"> <!--<AppenderRef ref="STDOUT"/>--> <AppenderRef ref="NONE"/> diff --git a/camel-k-runtime-main/pom.xml b/camel-k-main/camel-k-runtime-main/pom.xml similarity index 99% rename from camel-k-runtime-main/pom.xml rename to camel-k-main/camel-k-runtime-main/pom.xml index 2ae7c16..4b32b82 100644 --- a/camel-k-runtime-main/pom.xml +++ b/camel-k-main/camel-k-runtime-main/pom.xml @@ -20,7 +20,7 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-parent</artifactId> + <artifactId>camel-k-main</artifactId> <version>1.1.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> diff --git a/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/Application.java b/camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/Application.java similarity index 100% rename from camel-k-runtime-main/src/main/java/org/apache/camel/k/main/Application.java rename to camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/Application.java diff --git a/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java b/camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java similarity index 100% rename from camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java rename to camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationRuntime.java diff --git a/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationSupport.java b/camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationSupport.java similarity index 100% rename from camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationSupport.java rename to camel-k-main/camel-k-runtime-main/src/main/java/org/apache/camel/k/main/ApplicationSupport.java diff --git a/camel-k-runtime-main/src/main/resources/log4j2.properties b/camel-k-main/camel-k-runtime-main/src/main/resources/log4j2.properties similarity index 100% rename from camel-k-runtime-main/src/main/resources/log4j2.properties rename to camel-k-main/camel-k-runtime-main/src/main/resources/log4j2.properties diff --git a/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/MyBean.java b/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/MyBean.java similarity index 100% rename from camel-k-runtime-main/src/test/java/org/apache/camel/k/main/MyBean.java rename to camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/MyBean.java diff --git a/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/PropertiesTest.java b/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/PropertiesTest.java similarity index 100% rename from camel-k-runtime-main/src/test/java/org/apache/camel/k/main/PropertiesTest.java rename to camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/PropertiesTest.java diff --git a/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java b/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java similarity index 100% rename from camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java rename to camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/RuntimeTest.java diff --git a/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/TestCustomizer.java b/camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/TestCustomizer.java similarity index 100% rename from camel-k-runtime-main/src/test/java/org/apache/camel/k/main/TestCustomizer.java rename to camel-k-main/camel-k-runtime-main/src/test/java/org/apache/camel/k/main/TestCustomizer.java diff --git a/camel-k-runtime-main/src/test/resources/META-INF/services/org/apache/camel/k/customizer/test b/camel-k-main/camel-k-runtime-main/src/test/resources/META-INF/services/org/apache/camel/k/customizer/test similarity index 100% rename from camel-k-runtime-main/src/test/resources/META-INF/services/org/apache/camel/k/customizer/test rename to camel-k-main/camel-k-runtime-main/src/test/resources/META-INF/services/org/apache/camel/k/customizer/test diff --git a/camel-k-runtime-main/src/test/resources/MyRoutesConfig.java b/camel-k-main/camel-k-runtime-main/src/test/resources/MyRoutesConfig.java similarity index 100% rename from camel-k-runtime-main/src/test/resources/MyRoutesConfig.java rename to camel-k-main/camel-k-runtime-main/src/test/resources/MyRoutesConfig.java diff --git a/camel-k-runtime-main/src/test/resources/MyRoutesWithBeans.java b/camel-k-main/camel-k-runtime-main/src/test/resources/MyRoutesWithBeans.java similarity index 100% rename from camel-k-runtime-main/src/test/resources/MyRoutesWithBeans.java rename to camel-k-main/camel-k-runtime-main/src/test/resources/MyRoutesWithBeans.java diff --git a/camel-k-runtime-main/src/test/resources/conf.d/001/conf.properties b/camel-k-main/camel-k-runtime-main/src/test/resources/conf.d/001/conf.properties similarity index 100% rename from camel-k-runtime-main/src/test/resources/conf.d/001/conf.properties rename to camel-k-main/camel-k-runtime-main/src/test/resources/conf.d/001/conf.properties diff --git a/camel-k-runtime-main/src/test/resources/conf.d/002/conf.properties b/camel-k-main/camel-k-runtime-main/src/test/resources/conf.d/002/conf.properties similarity index 100% rename from camel-k-runtime-main/src/test/resources/conf.d/002/conf.properties rename to camel-k-main/camel-k-runtime-main/src/test/resources/conf.d/002/conf.properties diff --git a/camel-k-runtime-main/src/test/resources/conf.properties b/camel-k-main/camel-k-runtime-main/src/test/resources/conf.properties similarity index 100% rename from camel-k-runtime-main/src/test/resources/conf.properties rename to camel-k-main/camel-k-runtime-main/src/test/resources/conf.properties diff --git a/camel-k-runtime-main/src/test/resources/log4j2-test.xml b/camel-k-main/camel-k-runtime-main/src/test/resources/log4j2-test.xml similarity index 100% rename from camel-k-runtime-main/src/test/resources/log4j2-test.xml rename to camel-k-main/camel-k-runtime-main/src/test/resources/log4j2-test.xml diff --git a/camel-k-runtime-main/src/test/resources/my-resource.txt b/camel-k-main/camel-k-runtime-main/src/test/resources/my-resource.txt similarity index 100% rename from camel-k-runtime-main/src/test/resources/my-resource.txt rename to camel-k-main/camel-k-runtime-main/src/test/resources/my-resource.txt diff --git a/camel-k-runtime-main/src/test/resources/r1.js b/camel-k-main/camel-k-runtime-main/src/test/resources/r1.js similarity index 100% rename from camel-k-runtime-main/src/test/resources/r1.js rename to camel-k-main/camel-k-runtime-main/src/test/resources/r1.js diff --git a/camel-k-runtime-main/src/test/resources/r2.mytype b/camel-k-main/camel-k-runtime-main/src/test/resources/r2.mytype similarity index 100% rename from camel-k-runtime-main/src/test/resources/r2.mytype rename to camel-k-main/camel-k-runtime-main/src/test/resources/r2.mytype diff --git a/camel-k-runtime-main/src/test/resources/rests.xml b/camel-k-main/camel-k-runtime-main/src/test/resources/rests.xml similarity index 100% rename from camel-k-runtime-main/src/test/resources/rests.xml rename to camel-k-main/camel-k-runtime-main/src/test/resources/rests.xml diff --git a/camel-k-runtime-main/src/test/resources/routes-with-expression.xml b/camel-k-main/camel-k-runtime-main/src/test/resources/routes-with-expression.xml similarity index 100% rename from camel-k-runtime-main/src/test/resources/routes-with-expression.xml rename to camel-k-main/camel-k-runtime-main/src/test/resources/routes-with-expression.xml diff --git a/camel-k-runtime-main/src/test/resources/routes.xml b/camel-k-main/camel-k-runtime-main/src/test/resources/routes.xml similarity index 100% rename from camel-k-runtime-main/src/test/resources/routes.xml rename to camel-k-main/camel-k-runtime-main/src/test/resources/routes.xml diff --git a/camel-k-runtime-health/src/test/resources/log4j2-test.xml b/camel-k-main/pom.xml similarity index 55% rename from camel-k-runtime-health/src/test/resources/log4j2-test.xml rename to camel-k-main/pom.xml index 48bdd0c..083386d 100644 --- a/camel-k-runtime-health/src/test/resources/log4j2-test.xml +++ b/camel-k-main/pom.xml @@ -17,21 +17,21 @@ limitations under the License. --> -<Configuration status="INFO"> - <Appenders> - <Console name="STDOUT" target="SYSTEM_OUT"> - <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|%t|%c - %msg%n"/> - </Console> - <Null name="NONE"/> - </Appenders> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>org.apache.camel.k</groupId> + <artifactId>camel-k-runtime-parent</artifactId> + <version>1.1.1-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <packaging>pom</packaging> - <Loggers> - <Logger name="io.netty" level="INFO"/> - <Logger name="io.netty.handler.logging" level="DEBUG"/> - <Root level="INFO"> - <!--<AppenderRef ref="STDOUT"/>--> - <AppenderRef ref="NONE"/> - </Root> - </Loggers> + <artifactId>camel-k-main</artifactId> -</Configuration> \ No newline at end of file + <modules> + <module>camel-k-runtime-main</module> + <module>camel-k-runtime-health</module> + <module>camel-k-runtime-inspector</module> + </modules> + +</project> diff --git a/camel-k-runtime-bom/pom.xml b/camel-k-runtime-bom/pom.xml index 067a260..bace3f9 100644 --- a/camel-k-runtime-bom/pom.xml +++ b/camel-k-runtime-bom/pom.xml @@ -135,7 +135,7 @@ </dependency> <dependency> <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-servlet</artifactId> + <artifactId>camel-k-runtime-inspector</artifactId> <version>${project.version}</version> </dependency> <dependency> diff --git a/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthContextCustomizer.java b/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthContextCustomizer.java deleted file mode 100644 index cab06e3..0000000 --- a/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthContextCustomizer.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.health; - -import org.apache.camel.CamelContext; -import org.apache.camel.k.ContextCustomizer; -import org.apache.camel.k.servlet.ServletRegistration; - -public class HealthContextCustomizer implements ContextCustomizer { - public static final String DEFAULT_PATH = "/health"; - - private String path; - - public HealthContextCustomizer() { - this.path = DEFAULT_PATH; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - @Override - public void apply(CamelContext camelContext) { - camelContext.getRegistry().bind( - "health-servlet", - new ServletRegistration( - "HealthServlet", - new HealthEndpoint(camelContext), - path - ) - ); - } -} diff --git a/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthEndpoint.java b/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthEndpoint.java deleted file mode 100644 index 62172b4..0000000 --- a/camel-k-runtime-health/src/main/java/org/apache/camel/k/health/HealthEndpoint.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.health; - -import java.io.IOException; -import java.io.PrintWriter; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.camel.CamelContext; -import org.apache.camel.ServiceStatus; - -public class HealthEndpoint extends HttpServlet { - private final CamelContext context; - - public HealthEndpoint(CamelContext context) { - this.context = context; - } - - @Override - protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { - if (context.getStatus() == ServiceStatus.Started) { - resp.setContentType("text/plain"); - resp.setContentLength(2); - resp.setStatus(HttpServletResponse.SC_OK); - - try (PrintWriter writer = resp.getWriter()) { - writer.write("OK"); - } - - } else { - resp.setContentType("text/plain"); - resp.setContentLength(2); - resp.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); - - try (PrintWriter writer = resp.getWriter()) { - writer.write("KO"); - } - } - } - - @Override - protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { - doGet(req, resp); - } -} diff --git a/camel-k-runtime-health/src/test/java/org/apache/camel/k/health/HealthCustomizerTest.java b/camel-k-runtime-health/src/test/java/org/apache/camel/k/health/HealthCustomizerTest.java deleted file mode 100644 index 5946a96..0000000 --- a/camel-k-runtime-health/src/test/java/org/apache/camel/k/health/HealthCustomizerTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.health; - -import io.undertow.servlet.Servlets; -import io.undertow.servlet.api.DeploymentManager; -import io.undertow.servlet.core.ManagedServlet; -import io.undertow.servlet.core.ManagedServlets; -import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.k.Runtime; -import org.apache.camel.k.servlet.ServletContextCustomizer; -import org.apache.camel.test.AvailablePortFinder; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class HealthCustomizerTest { - - @Test - public void testServletConfigurer() { - Runtime runtime = Runtime.on(new DefaultCamelContext()); - - HealthContextCustomizer healthCustomizer = new HealthContextCustomizer(); - healthCustomizer.apply(runtime.getCamelContext()); - - ServletContextCustomizer servletCustomizer = new ServletContextCustomizer(); - servletCustomizer.setBindPort(AvailablePortFinder.getNextAvailable()); - servletCustomizer.apply(runtime.getCamelContext()); - - DeploymentManager manager = Servlets.defaultContainer().getDeploymentByPath("/"); - ManagedServlets managedServlets = manager.getDeployment().getServlets(); - ManagedServlet servlet = managedServlets.getManagedServlet("HealthServlet"); - - assertThat(servlet).isNotNull(); - assertThat(servlet.getServletInfo().getMappings()).contains("/health"); - } -} diff --git a/camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletEndpoint.java b/camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletEndpoint.java deleted file mode 100644 index afff9a1..0000000 --- a/camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletEndpoint.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.servlet; - -import javax.servlet.http.HttpServlet; - -import io.undertow.Handlers; -import io.undertow.Undertow; -import io.undertow.server.handlers.PathHandler; -import io.undertow.servlet.Servlets; -import io.undertow.servlet.api.DeploymentInfo; -import io.undertow.servlet.api.DeploymentManager; -import io.undertow.servlet.util.ImmediateInstanceHandle; -import org.apache.camel.CamelContext; -import org.apache.camel.support.service.ServiceSupport; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ServletEndpoint extends ServiceSupport { - private static final Logger LOGGER = LoggerFactory.getLogger(ServletEndpoint.class); - - private final CamelContext context; - private final String bindHost; - private final int bindPort; - private final String path; - - private Undertow server; - private DeploymentManager manager; - - public ServletEndpoint(CamelContext context, String bindHost, int bindPort, String path) { - this.context = context; - this.bindHost = bindHost; - this.bindPort = bindPort; - this.path = path; - } - - @SuppressWarnings("unchecked") - @Override - protected void doStart() throws Exception { - DeploymentInfo servletBuilder = Servlets.deployment() - .setClassLoader(ServletEndpoint.class.getClassLoader()) - .setContextPath(path) - .setDeploymentName("camel-k.war"); - - context.getRegistry().findByType(ServletRegistration.class) - .forEach(r -> { - LOGGER.info("Registering servlet: {}", r); - - servletBuilder.addServlet( - Servlets.servlet(r.getName(), HttpServlet.class, () -> new ImmediateInstanceHandle(r.getServlet())).addMappings(r.getMappings()) - ); - } - ); - - this.manager = Servlets.defaultContainer().addDeployment(servletBuilder); - this.manager.deploy(); - - PathHandler path = Handlers.path(Handlers.redirect(this.path)).addPrefixPath(this.path, manager.start()); - - LOGGER.info("Starting servlet engine on {}:{}{}", this.bindHost, this.bindPort, this.path); - - this.server = Undertow.builder().addHttpListener(this.bindPort, this.bindHost).setHandler(path).build(); - this.server.start(); - } - - @Override - protected void doStop() throws Exception { - if (this.server != null) { - LOGGER.info("Stopping servlet engine"); - this.server.stop(); - } - } -} diff --git a/camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletRegistration.java b/camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletRegistration.java deleted file mode 100644 index 2a3f06e..0000000 --- a/camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletRegistration.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.servlet; - -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.Set; - -import javax.servlet.Servlet; - -/** - * An helper class used to register servlets. - * - * <pre>{@code - * public class WebhookCustomizer implements ContextCustomizer { - * {@literal @}Override - * public void apply(CamelContext camelContext, Runtime.Registry registry) { - * registry.bind( - * "webhook-servlet", - * new ServletRegistration("CamelServlet", new CamelHttpTransportServlet(), "/webhook/*") - * ); - * } - * } - * }</pre> - */ -public final class ServletRegistration { - private final Servlet servlet; - private final String name; - private final Set<String> mappings; - - public ServletRegistration(String name, Servlet servlet, Collection<String> mappings) { - this.name = name; - this.servlet = servlet; - this.mappings = new LinkedHashSet<>(); - this.mappings.addAll(mappings); - } - - public ServletRegistration(String name, Servlet servlet, String... mappings) { - this.name = name; - this.servlet = servlet; - this.mappings = new LinkedHashSet<>(); - - for (String mapping: mappings) { - this.mappings.add(mapping); - } - } - - public String getName() { - return name; - } - - public Servlet getServlet() { - return servlet; - } - - public Collection<String> getMappings() { - return mappings; - } - - @Override - public String toString() { - return "ServletRegistration{" - + "servlet=" + servlet - + ", name='" + name + '\'' - + ", mappings=" + mappings - + '}'; - } -} diff --git a/camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletRegistrationContextCustomizer.java b/camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletRegistrationContextCustomizer.java deleted file mode 100644 index 274964c..0000000 --- a/camel-k-runtime-servlet/src/main/java/org/apache/camel/k/servlet/ServletRegistrationContextCustomizer.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.servlet; - -import org.apache.camel.CamelContext; -import org.apache.camel.Ordered; -import org.apache.camel.component.servlet.CamelHttpTransportServlet; -import org.apache.camel.k.ContextCustomizer; - -public class ServletRegistrationContextCustomizer implements ContextCustomizer { - public static final String DEFAULT_PATH = "/camel/*"; - public static final String DEFAULT_CAMEL_SERVLET_NAME = "CamelServlet"; - - private String path; - private String camelServletName; - - public ServletRegistrationContextCustomizer() { - this(DEFAULT_PATH, DEFAULT_CAMEL_SERVLET_NAME); - } - - public ServletRegistrationContextCustomizer(String path, String camelServletName) { - this.path = path; - this.camelServletName = camelServletName; - } - - @Override - public void apply(CamelContext camelContext) { - camelContext.getRegistry().bind( - camelServletName, - new ServletRegistration(camelServletName, new CamelHttpTransportServlet(), path) - ); - } - - @Override - public int getOrder() { - return Ordered.HIGHEST; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public String getCamelServletName() { - return camelServletName; - } - - public void setCamelServletName(String camelServletName) { - this.camelServletName = camelServletName; - } -} \ No newline at end of file diff --git a/camel-k-runtime-servlet/src/main/resources/META-INF/services/org/apache/camel/k/customizer/servletregistration b/camel-k-runtime-servlet/src/main/resources/META-INF/services/org/apache/camel/k/customizer/servletregistration deleted file mode 100644 index 018dda8..0000000 --- a/camel-k-runtime-servlet/src/main/resources/META-INF/services/org/apache/camel/k/customizer/servletregistration +++ /dev/null @@ -1,18 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (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.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -class=org.apache.camel.k.servlet.ServletRegistrationContextCustomizer diff --git a/camel-k-runtime-servlet/src/test/java/org/apache/camel/k/servlet/ServletCustomizerTest.java b/camel-k-runtime-servlet/src/test/java/org/apache/camel/k/servlet/ServletCustomizerTest.java deleted file mode 100644 index 0cc7ca7..0000000 --- a/camel-k-runtime-servlet/src/test/java/org/apache/camel/k/servlet/ServletCustomizerTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.servlet; - -import io.undertow.servlet.Servlets; -import io.undertow.servlet.api.DeploymentManager; -import io.undertow.servlet.core.ManagedServlet; -import io.undertow.servlet.core.ManagedServlets; -import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.k.Runtime; -import org.apache.camel.test.AvailablePortFinder; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ServletCustomizerTest { - - @Test - public void testServletConfigurer() { - Runtime runtime = Runtime.on(new DefaultCamelContext()); - - ServletRegistrationContextCustomizer servletRegistrationCustomizer = new ServletRegistrationContextCustomizer("/webhook/*", "webhook-servlet"); - servletRegistrationCustomizer.apply(runtime.getCamelContext()); - - ServletContextCustomizer servletCustomizer = new ServletContextCustomizer(); - servletCustomizer.setBindPort(AvailablePortFinder.getNextAvailable()); - servletCustomizer.apply(runtime.getCamelContext()); - - DeploymentManager manager = Servlets.defaultContainer().getDeploymentByPath("/"); - ManagedServlets managedServlets = manager.getDeployment().getServlets(); - ManagedServlet servlet = managedServlets.getManagedServlet("webhook-servlet"); - - assertThat(servlet).isNotNull(); - assertThat(servlet.getServletInfo().getMappings()).contains("/webhook/*"); - } -} diff --git a/camel-k-runtime-servlet/src/test/java/org/apache/camel/k/servlet/ServletRegistrationCustomizerTest.java b/camel-k-runtime-servlet/src/test/java/org/apache/camel/k/servlet/ServletRegistrationCustomizerTest.java deleted file mode 100644 index 2c3eea9..0000000 --- a/camel-k-runtime-servlet/src/test/java/org/apache/camel/k/servlet/ServletRegistrationCustomizerTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.k.servlet; - -import io.undertow.servlet.Servlets; -import io.undertow.servlet.api.DeploymentManager; -import io.undertow.servlet.core.ManagedServlet; -import io.undertow.servlet.core.ManagedServlets; -import org.apache.camel.impl.DefaultCamelContext; -import org.apache.camel.k.Runtime; -import org.apache.camel.test.AvailablePortFinder; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ServletRegistrationCustomizerTest { - - @Test - public void testServletRegistrationConfigurer() { - Runtime runtime = Runtime.on(new DefaultCamelContext()); - - ServletRegistrationContextCustomizer servletRegistrationCustomizer = new ServletRegistrationContextCustomizer(); - servletRegistrationCustomizer.apply(runtime.getCamelContext()); - - ServletContextCustomizer servletCustomizer = new ServletContextCustomizer(); - servletCustomizer.setBindPort(AvailablePortFinder.getNextAvailable()); - servletCustomizer.apply(runtime.getCamelContext()); - - DeploymentManager manager = Servlets.defaultContainer().getDeploymentByPath("/"); - ManagedServlets managedServlets = manager.getDeployment().getServlets(); - ManagedServlet servlet = managedServlets.getManagedServlet("CamelServlet"); - - assertThat(servlet).isNotNull(); - assertThat(servlet.getServletInfo().getMappings()).contains("/camel/*"); - } -} diff --git a/examples/camel-k-runtime-example-health/README.adoc b/examples/camel-k-runtime-example-health/README.adoc index dbecf56..1c19469 100644 --- a/examples/camel-k-runtime-example-health/README.adoc +++ b/examples/camel-k-runtime-example-health/README.adoc @@ -9,6 +9,17 @@ mvn clean exec:java ``` while it is running (from another terminal) you can access the rest camel route exposed through the servlet with: ```bash -curl http://localhost:8080/health +curl http://localhost:8082/health ``` -if the camel context has started properly that should get `OK`. +if the camel context has started properly that should get: +```json +{ + "checks": [ + { + "name": "route:my-route", + "status": "UP" + } + ], + "status": "UP" +} +``` \ No newline at end of file diff --git a/examples/camel-k-runtime-example-health/pom.xml b/examples/camel-k-runtime-example-health/pom.xml index 11a570a..15f2a2f 100644 --- a/examples/camel-k-runtime-example-health/pom.xml +++ b/examples/camel-k-runtime-example-health/pom.xml @@ -38,11 +38,11 @@ </dependency> <dependency> <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-servlet</artifactId> + <artifactId>camel-k-runtime-health</artifactId> </dependency> <dependency> - <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-health</artifactId> + <groupId>org.apache.camel</groupId> + <artifactId>camel-netty-http</artifactId> </dependency> <dependency> <groupId>org.apache.camel</groupId> diff --git a/examples/camel-k-runtime-example-health/src/main/resources/application.properties b/examples/camel-k-runtime-example-health/src/main/resources/application.properties index 2e302fb..cf08a83 100644 --- a/examples/camel-k-runtime-example-health/src/main/resources/application.properties +++ b/examples/camel-k-runtime-example-health/src/main/resources/application.properties @@ -30,6 +30,6 @@ camel.main.stream-caching-spool-directory = ${java.io.tmpdir}/camel-k # # Camel K # -customizer.servlet.enabled = true -customizer.servletregistration.enabled = true +customizer.inspector.enabled = true +customizer.inspector.bind-port = 8082 customizer.health.enabled = true \ No newline at end of file diff --git a/examples/camel-k-runtime-example-health/src/main/resources/routes.groovy b/examples/camel-k-runtime-example-health/src/main/resources/routes.groovy index 452b215..a1818bd 100644 --- a/examples/camel-k-runtime-example-health/src/main/resources/routes.groovy +++ b/examples/camel-k-runtime-example-health/src/main/resources/routes.groovy @@ -15,6 +15,7 @@ * limitations under the License. */ -from('servlet:/test') +from('netty-http:http:0.0.0.0:8080//test') + .routeId('my-route') .convertBodyTo(String.class) .to('log:info') \ No newline at end of file diff --git a/examples/camel-k-runtime-example-servlet/README.adoc b/examples/camel-k-runtime-example-servlet/README.adoc deleted file mode 100644 index 601c3be..0000000 --- a/examples/camel-k-runtime-example-servlet/README.adoc +++ /dev/null @@ -1,14 +0,0 @@ -Servlet Apache Camel K Runtime example -====================================== - -This repository contains an Apache Camel-K Runtime application that use camel servlet. - -In order to run it: -```bash -mvn clean exec:java -``` -while it is running (from another terminal) you can access the rest camel route exposed through the servlet with: -```bash -curl http://localhost:8080/mypath/test -``` -that should log and empty exchange in the running application console logs. diff --git a/examples/camel-k-runtime-example-servlet/pom.xml b/examples/camel-k-runtime-example-servlet/pom.xml deleted file mode 100644 index dc7c790..0000000 --- a/examples/camel-k-runtime-example-servlet/pom.xml +++ /dev/null @@ -1,84 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (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.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-examples</artifactId> - <version>1.1.1-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <artifactId>camel-k-runtime-example-servlet</artifactId> - - <dependencies> - - <!-- ****************************** --> - <!-- --> - <!-- RUNTIME --> - <!-- --> - <!-- ****************************** --> - - <dependency> - <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-main</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-loader-groovy</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-servlet</artifactId> - </dependency> - </dependencies> - - <build> - <defaultGoal>exec:java</defaultGoal> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>${exec-maven-plugin.version}</version> - <executions> - <execution> - <goals> - <goal>java</goal> - </goals> - </execution> - </executions> - <configuration> - <mainClass>org.apache.camel.k.main.Application</mainClass> - <classpathScope>runtime</classpathScope> - <systemProperties> - <systemProperty> - <key>camel.k.conf</key> - <value>${project.basedir}/src/main/resources/application.properties</value> - </systemProperty> - <systemProperty> - <key>camel.k.routes</key> - <value>file:${project.basedir}/src/main/resources/routes.groovy</value> - </systemProperty> - </systemProperties> - </configuration> - </plugin> - </plugins> - </build> - -</project> diff --git a/examples/camel-k-runtime-example-servlet/src/main/resources/application.properties b/examples/camel-k-runtime-example-servlet/src/main/resources/application.properties deleted file mode 100644 index 08f0a0c..0000000 --- a/examples/camel-k-runtime-example-servlet/src/main/resources/application.properties +++ /dev/null @@ -1,35 +0,0 @@ -## --------------------------------------------------------------------------- -## Licensed to the Apache Software Foundation (ASF) under one or more -## contributor license agreements. See the NOTICE file distributed with -## this work for additional information regarding copyright ownership. -## The ASF licenses this file to You under the Apache License, Version 2.0 -## (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.apache.org/licenses/LICENSE-2.0 -## -## Unless required by applicable law or agreed to in writing, software -## distributed under the License is distributed on an "AS IS" BASIS, -## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -## See the License for the specific language governing permissions and -## limitations under the License. -## --------------------------------------------------------------------------- - -# -# Logging -# -logging.level.org.apache.camel.k = DEBUG - -# -# camel - main -# -camel.main.name = camel-k -camel.main.stream-caching-enabled = true -camel.main.stream-caching-spool-directory = ${java.io.tmpdir}/camel-k - -# -# Camel K -# -customizer.servletregistration.enabled = true -customizer.servletregistration.path = /mypath/* -customizer.servlet.enabled = true diff --git a/examples/camel-k-runtime-example-yaml/pom.xml b/examples/camel-k-runtime-example-yaml/pom.xml index 526385a..ae92d71 100644 --- a/examples/camel-k-runtime-example-yaml/pom.xml +++ b/examples/camel-k-runtime-example-yaml/pom.xml @@ -34,10 +34,6 @@ </dependency> <dependency> <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-servlet</artifactId> - </dependency> - <dependency> - <groupId>org.apache.camel.k</groupId> <artifactId>camel-k-loader-yaml</artifactId> </dependency> <dependency> diff --git a/examples/pom.xml b/examples/pom.xml index aaa22eb..040a6a0 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -33,7 +33,6 @@ </properties> <modules> - <module>camel-k-runtime-example-servlet</module> <module>camel-k-runtime-example-health</module> <module>camel-k-runtime-example-yaml</module> <module>camel-k-runtime-example-knative</module> diff --git a/pom.xml b/pom.xml index c087ff5..2381a0d 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,7 @@ <jandex.version>2.1.2.Final</jandex.version> <javapoet.version>1.11.1</javapoet.version> <auto-service.version>1.0-rc6</auto-service.version> + <rest-assured.version>4.2.0</rest-assured.version> <gmavenplus-plugin.version>1.7.1</gmavenplus-plugin.version> <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version> <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version> @@ -205,7 +206,7 @@ <module>camel-knative</module> <module>camel-k-runtime-core</module> - <module>camel-k-runtime-main</module> + <module>camel-k-main</module> <module>camel-k-quarkus</module> <module>camel-k-loader-groovy</module> @@ -216,15 +217,13 @@ <module>camel-k-loader-java</module> <module>camel-k-loader-knative</module> - <module>camel-k-runtime-bom</module> - <module>camel-k-runtime-cron</module> - <module>camel-k-runtime-health</module> <module>camel-k-runtime-knative</module> <module>camel-k-runtime-master</module> - <module>camel-k-runtime-servlet</module> <module>camel-k-runtime-webhook</module> + <module>camel-k-runtime-bom</module> + <module>examples</module> <module>distribution</module> </modules> @@ -320,7 +319,7 @@ </dependency> <dependency> <groupId>org.apache.camel.k</groupId> - <artifactId>camel-k-runtime-servlet</artifactId> + <artifactId>camel-k-runtime-inspector</artifactId> <version>${project.version}</version> </dependency> <dependency> diff --git a/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/pom.xml b/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/pom.xml index 61dd65b..1b4b08e 100644 --- a/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/pom.xml +++ b/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/pom.xml @@ -32,7 +32,7 @@ <catalog.runtime>main</catalog.runtime> <catalog.file>catalog.yaml</catalog.file> - <runtime.version>1.1.0-SNAPSHOT</runtime.version> + <runtime.version>1.1.1-SNAPSHOT</runtime.version> </properties> <build> diff --git a/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/verify.groovy b/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/verify.groovy index 835a5cf..78c9221 100644 --- a/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/verify.groovy +++ b/tooling/camel-k-maven-plugin/src/it/generate-catalog-main/verify.groovy @@ -14,11 +14,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -def runtimeVersion = '1.1.0-SNAPSHOT' +def runtimeVersion = '1.1.1-SNAPSHOT' def source = new File(basedir, "catalog.yaml") def catalog = new org.yaml.snakeyaml.Yaml().load(new FileInputStream(source)) assert catalog.spec.runtime.version == runtimeVersion assert catalog.spec.runtime.applicationClass == 'org.apache.camel.k.main.Application' -assert catalog.metadata.labels['camel.apache.org/runtime.version'] == runtimeVersion \ No newline at end of file + +assert catalog.spec.runtime.capabilities['health'].dependencies[0].groupId == 'org.apache.camel.k' +assert catalog.spec.runtime.capabilities['health'].dependencies[0].artifactId == 'camel-k-runtime-health' +assert catalog.spec.runtime.capabilities['rest'].dependencies[0].groupId == 'org.apache.camel' +assert catalog.spec.runtime.capabilities['rest'].dependencies[0].artifactId == 'camel-rest' +assert catalog.spec.runtime.capabilities['rest'].dependencies[1].groupId == 'org.apache.camel' +assert catalog.spec.runtime.capabilities['rest'].dependencies[1].artifactId == 'camel-undertow' + +assert catalog.metadata.labels['camel.apache.org/runtime.version'] == runtimeVersion diff --git a/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/pom.xml b/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/pom.xml index 39b467f..5a2a129 100644 --- a/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/pom.xml +++ b/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/pom.xml @@ -32,7 +32,7 @@ <catalog.runtime>quarkus</catalog.runtime> <catalog.file>catalog.yaml</catalog.file> - <runtime.version>1.1.0-SNAPSHOT</runtime.version> + <runtime.version>1.1.1-SNAPSHOT</runtime.version> </properties> <build> diff --git a/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/verify.groovy b/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/verify.groovy index 4ca1d1b..5e10855 100644 --- a/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/verify.groovy +++ b/tooling/camel-k-maven-plugin/src/it/generate-catalog-quarkus/verify.groovy @@ -14,11 +14,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -def runtimeVersion = '1.1.0-SNAPSHOT' +def runtimeVersion = '1.1.1-SNAPSHOT' def source = new File(basedir, "catalog.yaml") def catalog = new org.yaml.snakeyaml.Yaml().load(new FileInputStream(source)) assert catalog.spec.runtime.version == runtimeVersion assert catalog.spec.runtime.applicationClass == 'io.quarkus.runner.GeneratedMain' + +assert catalog.spec.runtime.capabilities['health'].dependencies[0].groupId == 'org.apache.camel.quarkus' +assert catalog.spec.runtime.capabilities['health'].dependencies[0].artifactId == 'camel-quarkus-microprofile-health' +assert catalog.spec.runtime.capabilities['rest'].dependencies[0].groupId == 'org.apache.camel.quarkus' +assert catalog.spec.runtime.capabilities['rest'].dependencies[0].artifactId == 'camel-quarkus-rest' +assert catalog.spec.runtime.capabilities['rest'].dependencies[1].groupId == 'org.apache.camel.quarkus' +assert catalog.spec.runtime.capabilities['rest'].dependencies[1].artifactId == 'camel-quarkus-platform-http' + assert catalog.metadata.labels['camel.apache.org/runtime.version'] == runtimeVersion \ No newline at end of file diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java index cd62f2e..9a37a02 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateCatalogMojo.java @@ -38,6 +38,7 @@ import org.apache.camel.catalog.DefaultCamelCatalog; import org.apache.camel.catalog.DefaultRuntimeProvider; import org.apache.camel.catalog.quarkus.QuarkusRuntimeProvider; import org.apache.camel.impl.engine.AbstractCamelContext; +import org.apache.camel.k.tooling.maven.model.CamelCapability; import org.apache.camel.k.tooling.maven.model.CatalogProcessor; import org.apache.camel.k.tooling.maven.model.crd.CamelCatalog; import org.apache.camel.k.tooling.maven.model.crd.CamelCatalogSpec; @@ -85,7 +86,6 @@ public class GenerateCatalogMojo extends AbstractMojo { if (Files.notExists(output.getParent())) { Files.createDirectories(output.getParent()); } - if (Files.exists(output)) { Files.delete(output); } @@ -123,11 +123,29 @@ public class GenerateCatalogMojo extends AbstractMojo { catalog.setRuntimeProvider(new DefaultRuntimeProvider()); runtimeSpec.applicationClass("org.apache.camel.k.main.Application"); runtimeSpec.addDependency("org.apache.camel.k", "camel-k-runtime-main"); + runtimeSpec.putCapability( + "health", + CamelCapability.forArtifact("org.apache.camel.k", "camel-k-runtime-health")); + runtimeSpec.putCapability( + "rest", + new CamelCapability.Builder() + .addDependency("org.apache.camel", "camel-rest") + .addDependency("org.apache.camel", "camel-undertow") + .build()); break; case "quarkus": catalog.setRuntimeProvider(new QuarkusRuntimeProvider()); runtimeSpec.applicationClass("io.quarkus.runner.GeneratedMain"); runtimeSpec.addDependency("org.apache.camel.k", "camel-k-runtime-quarkus"); + runtimeSpec.putCapability( + "health", + CamelCapability.forArtifact("org.apache.camel.quarkus", "camel-quarkus-microprofile-health")); + runtimeSpec.putCapability( + "rest", + new CamelCapability.Builder() + .addDependency("org.apache.camel.quarkus", "camel-quarkus-rest") + .addDependency("org.apache.camel.quarkus", "camel-quarkus-platform-http") + .build()); break; default: throw new IllegalArgumentException("catalog.runtime parameter value [" + runtime + "] is not supported!"); diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeSpec.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelCapability.java similarity index 74% copy from tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeSpec.java copy to tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelCapability.java index ee1b3f7..3c44274 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeSpec.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelCapability.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.k.tooling.maven.model.crd; +package org.apache.camel.k.tooling.maven.model; import java.util.Collections; import java.util.Map; @@ -22,29 +22,30 @@ import java.util.Set; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import org.apache.camel.k.tooling.maven.model.MavenArtifact; import org.immutables.value.Value; @Value.Immutable @Value.Style(depluralize = true) -@JsonDeserialize(builder = RuntimeSpec.Builder.class) -@JsonPropertyOrder({ "version", "runtimeVersion", "artifacts" }) -public interface RuntimeSpec { - String getVersion(); - String getProvider(); - String getApplicationClass(); +@JsonDeserialize(builder = CamelCapability.Builder.class) +@JsonPropertyOrder({"groupId", "artifactId", "version"}) +public interface CamelCapability { + @Value.Auxiliary + @Value.Default + default Set<Artifact> getDependencies() { + return Collections.emptySet(); + } + @Value.Auxiliary @Value.Default default Map<String, String> getMetadata() { return Collections.emptyMap(); } - @Value.Default - default Set<MavenArtifact> getDependencies() { - return Collections.emptySet(); + static CamelCapability forArtifact(String groupId, String artifactId) { + return new Builder().addDependency(groupId, artifactId).build(); } - class Builder extends ImmutableRuntimeSpec.Builder { + class Builder extends ImmutableCamelCapability.Builder { public Builder addDependency(String groupId, String artifactId) { addDependencies(MavenArtifact.from(groupId, artifactId)); return this; diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeSpec.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeSpec.java index ee1b3f7..06f5986 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeSpec.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/crd/RuntimeSpec.java @@ -22,6 +22,7 @@ import java.util.Set; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.apache.camel.k.tooling.maven.model.CamelCapability; import org.apache.camel.k.tooling.maven.model.MavenArtifact; import org.immutables.value.Value; @@ -44,6 +45,11 @@ public interface RuntimeSpec { return Collections.emptySet(); } + @Value.Default + default Map<String, CamelCapability> getCapabilities() { + return Collections.emptyMap(); + } + class Builder extends ImmutableRuntimeSpec.Builder { public Builder addDependency(String groupId, String artifactId) { addDependencies(MavenArtifact.from(groupId, artifactId)); diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java index 0fe6453..3b183b8 100644 --- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java @@ -132,7 +132,7 @@ public class CatalogProcessor3x implements CatalogProcessor { specBuilder.putArtifact( new CamelArtifact.Builder() .groupId("org.apache.camel.k") - .artifactId("camel-k-runtime-servlet") + .artifactId("camel-k-runtime-inspector") .build() ); specBuilder.putArtifact( diff --git a/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java b/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java index 18e9388..82e99a5 100644 --- a/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java +++ b/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java @@ -82,7 +82,7 @@ public class CatalogProcessor3Test extends AbstractCatalogProcessorTest { Map<String, CamelArtifact> artifactMap = spec.getArtifacts(); assertThat(artifactMap).containsKeys("camel-k-runtime-health"); - assertThat(artifactMap).containsKeys("camel-k-runtime-servlet"); + assertThat(artifactMap).containsKeys("camel-k-runtime-inspector"); assertThat(artifactMap).containsKeys("camel-k-runtime-webhook"); assertThat(artifactMap.get("camel-k-runtime-knative")).satisfies(a -> {