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 fc7d4050b..30248787f 100644 --- a/camel-k-runtime-health/pom.xml +++ b/camel-k-main/camel-k-runtime-health/pom.xml @@ -20,7 +20,7 @@ org.apache.camel.k - camel-k-runtime-parent + camel-k-main 1.1.1-SNAPSHOT 4.0.0 @@ -45,7 +45,13 @@ org.apache.camel.k - camel-k-runtime-servlet + camel-k-runtime-inspector + + + + io.vertx + vertx-web + ${vertx.version} @@ -59,6 +65,16 @@ camel-test test + + org.apache.camel + camel-direct + test + + + org.apache.camel + camel-mock + test + org.junit.jupiter @@ -72,12 +88,25 @@ ${junit.version} test + + org.junit.jupiter + junit-jupiter-params + ${junit.version} + test + + org.assertj assertj-core ${assertj.version} test + + io.rest-assured + rest-assured + ${rest-assured.version} + test + org.apache.logging.log4j @@ -91,6 +120,12 @@ ${log4j2.version} test + + org.apache.logging.log4j + log4j-jcl + ${log4j2.version} + test + 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 000000000..8d70f1049 --- /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 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 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 000000000..1a7fb069a --- /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 89% rename from camel-k-runtime-health/src/test/resources/log4j2-test.xml rename to camel-k-main/camel-k-runtime-health/src/test/resources/log4j2-test.xml index 48bdd0c49..0f393eaed 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 @@ - - + - + 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 f506317e4..9b3a8c79a 100644 --- a/camel-k-runtime-servlet/pom.xml +++ b/camel-k-main/camel-k-runtime-inspector/pom.xml @@ -20,12 +20,12 @@ org.apache.camel.k - camel-k-runtime-parent + camel-k-main 1.1.1-SNAPSHOT 4.0.0 - camel-k-runtime-servlet + camel-k-runtime-inspector @@ -39,28 +39,15 @@ org.apache.camel camel-core-engine - - org.apache.camel - camel-servlet - org.apache.camel.k camel-k-runtime-core - - - io.undertow - undertow-core - ${undertow.version} - - io.undertow - undertow-servlet - 1.4.26.Final + io.vertx + vertx-web + ${vertx.version} @@ -87,6 +74,13 @@ ${junit.version} test + + org.junit.jupiter + junit-jupiter-params + ${junit.version} + test + + org.assertj assertj-core @@ -94,6 +88,13 @@ test + + io.rest-assured + rest-assured + ${rest-assured.version} + test + + org.apache.logging.log4j log4j-core @@ -106,6 +107,12 @@ ${log4j2.version} test + + org.apache.logging.log4j + log4j-jcl + ${log4j2.version} + test + 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 998688908..5bcc396d6 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; @@ -60,9 +60,14 @@ public void setPath(String path) { this.path = path; } + @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 void apply(CamelContext camelContext) { 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 452b215bd..06b4cbb48 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 { +} 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 000000000..71eafde95 --- /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 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 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 46bb724bf..6fa86edb1 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 000000000..d103b1f00 --- /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 96% 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 384e62214..d0ac3a469 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 @@ - + 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 2ae7c16ab..4b32b825c 100644 --- a/camel-k-runtime-main/pom.xml +++ b/camel-k-main/camel-k-runtime-main/pom.xml @@ -20,7 +20,7 @@ org.apache.camel.k - camel-k-runtime-parent + camel-k-main 1.1.1-SNAPSHOT 4.0.0 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-main/pom.xml b/camel-k-main/pom.xml new file mode 100644 index 000000000..083386d16 --- /dev/null +++ b/camel-k-main/pom.xml @@ -0,0 +1,37 @@ + + + + + org.apache.camel.k + camel-k-runtime-parent + 1.1.1-SNAPSHOT + + 4.0.0 + pom + + camel-k-main + + + camel-k-runtime-main + camel-k-runtime-health + camel-k-runtime-inspector + + + diff --git a/camel-k-runtime-bom/pom.xml b/camel-k-runtime-bom/pom.xml index 067a26000..bace3f94d 100644 --- a/camel-k-runtime-bom/pom.xml +++ b/camel-k-runtime-bom/pom.xml @@ -135,7 +135,7 @@ org.apache.camel.k - camel-k-runtime-servlet + camel-k-runtime-inspector ${project.version} 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 cab06e31f..000000000 --- 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 62172b448..000000000 --- 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 5946a96ae..000000000 --- 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 afff9a145..000000000 --- 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 2a3f06ea2..000000000 --- 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. - * - *
{@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/*")
- *         );
- *     }
- * }
- * }
- */ -public final class ServletRegistration { - private final Servlet servlet; - private final String name; - private final Set mappings; - - public ServletRegistration(String name, Servlet servlet, Collection 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 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 274964c73..000000000 --- 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 018dda838..000000000 --- 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 0cc7ca75b..000000000 --- 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 2c3eea963..000000000 --- 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 dbecf5668..1c19469c6 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 11a570a2e..15f2a2f70 100644 --- a/examples/camel-k-runtime-example-health/pom.xml +++ b/examples/camel-k-runtime-example-health/pom.xml @@ -38,11 +38,11 @@
org.apache.camel.k - camel-k-runtime-servlet + camel-k-runtime-health - org.apache.camel.k - camel-k-runtime-health + org.apache.camel + camel-netty-http org.apache.camel 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 2e302fbcf..cf08a8322 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 452b215bd..a1818bd12 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 601c3be39..000000000 --- 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 dc7c79072..000000000 --- a/examples/camel-k-runtime-example-servlet/pom.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - org.apache.camel.k - camel-k-runtime-examples - 1.1.1-SNAPSHOT - - 4.0.0 - - camel-k-runtime-example-servlet - - - - - - - - - - - org.apache.camel.k - camel-k-runtime-main - - - org.apache.camel.k - camel-k-loader-groovy - - - org.apache.camel.k - camel-k-runtime-servlet - - - - - exec:java - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - java - - - - - org.apache.camel.k.main.Application - runtime - - - camel.k.conf - ${project.basedir}/src/main/resources/application.properties - - - camel.k.routes - file:${project.basedir}/src/main/resources/routes.groovy - - - - - - - - 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 08f0a0ce8..000000000 --- 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 526385a93..ae92d7188 100644 --- a/examples/camel-k-runtime-example-yaml/pom.xml +++ b/examples/camel-k-runtime-example-yaml/pom.xml @@ -32,10 +32,6 @@ org.apache.camel.k camel-k-runtime-main - - org.apache.camel.k - camel-k-runtime-servlet - org.apache.camel.k camel-k-loader-yaml diff --git a/examples/pom.xml b/examples/pom.xml index aaa22ebb6..040a6a0aa 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -33,7 +33,6 @@ - camel-k-runtime-example-servlet camel-k-runtime-example-health camel-k-runtime-example-yaml camel-k-runtime-example-knative diff --git a/pom.xml b/pom.xml index c087ff5b8..2381a0d25 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,7 @@ 2.1.2.Final 1.11.1 1.0-rc6 + 4.2.0 1.7.1 3.8.1 2.22.2 @@ -205,7 +206,7 @@ camel-knative camel-k-runtime-core - camel-k-runtime-main + camel-k-main camel-k-quarkus camel-k-loader-groovy @@ -216,15 +217,13 @@ camel-k-loader-java camel-k-loader-knative - camel-k-runtime-bom - camel-k-runtime-cron - camel-k-runtime-health camel-k-runtime-knative camel-k-runtime-master - camel-k-runtime-servlet camel-k-runtime-webhook + camel-k-runtime-bom + examples distribution @@ -320,7 +319,7 @@ org.apache.camel.k - camel-k-runtime-servlet + camel-k-runtime-inspector ${project.version} 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 61dd65bac..1b4b08e5e 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 @@ main catalog.yaml - 1.1.0-SNAPSHOT + 1.1.1-SNAPSHOT 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 835a5cf03..78c92213a 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 39b467f4b..5a2a12949 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 @@ quarkus catalog.yaml - 1.1.0-SNAPSHOT + 1.1.1-SNAPSHOT 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 4ca1d1b37..5e108556a 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 cd62f2e9e..9a37a02f9 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.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 void execute() throws MojoExecutionException, MojoFailureException { if (Files.notExists(output.getParent())) { Files.createDirectories(output.getParent()); } - if (Files.exists(output)) { Files.delete(output); } @@ -123,11 +123,29 @@ public void execute() throws MojoExecutionException, MojoFailureException { 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/CamelCapability.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelCapability.java new file mode 100644 index 000000000..3c44274f7 --- /dev/null +++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/model/CamelCapability.java @@ -0,0 +1,54 @@ +/* + * 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.tooling.maven.model; + +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +@Value.Immutable +@Value.Style(depluralize = true) +@JsonDeserialize(builder = CamelCapability.Builder.class) +@JsonPropertyOrder({"groupId", "artifactId", "version"}) +public interface CamelCapability { + @Value.Auxiliary + @Value.Default + default Set getDependencies() { + return Collections.emptySet(); + } + + @Value.Auxiliary + @Value.Default + default Map getMetadata() { + return Collections.emptyMap(); + } + + static CamelCapability forArtifact(String groupId, String artifactId) { + return new Builder().addDependency(groupId, artifactId).build(); + } + + 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 ee1b3f752..06f5986d0 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 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 @@ default Set getDependencies() { return Collections.emptySet(); } + @Value.Default + default Map 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 0fe6453fe..3b183b84c 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 void process(MavenProject project, CamelCatalog catalog, CamelCatalogSpec 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 18e9388dc..82e99a5f0 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 void testArtifactsEnrichment() { Map 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 -> {