Skip to content

Commit

Permalink
Upgrade to Camel 3.3.0 and camel-quarkus 1.0.0.CR1 #338
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Jun 3, 2020
1 parent 64a20ec commit 00888b7
Show file tree
Hide file tree
Showing 41 changed files with 593 additions and 1,379 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
native-image-project:
- :camel-k-quarkus-core-it
- :camel-k-quarkus-cron-it
- :camel-k-quarkus-knative-it
- :camel-k-quarkus-loader-xml-it
- :camel-k-quarkus-loader-yaml-it
- :camel-k-runtime-example-quarkus-xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void testLoaders(String location, Class<? extends SourceLoader> type) thr

List<RouteDefinition> routes = builder.getRouteCollection().getRoutes();
assertThat(routes).hasSize(1);
assertThat(routes.get(0).getInput().getEndpointUri()).isEqualTo("timer:tick");
assertThat(routes.get(0).getInput().getEndpointUri()).matches("timer:/*tick");
assertThat(routes.get(0).getOutputs().get(0)).isInstanceOf(ToDefinition.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testLoaders(String location, Class<? extends SourceLoader> type) thr

List<RouteDefinition> routes = builder.getRouteCollection().getRoutes();
assertThat(routes).hasSize(1);
assertThat(routes.get(0).getInput().getEndpointUri()).isEqualTo("timer:tick");
assertThat(routes.get(0).getInput().getEndpointUri()).matches("timer:/*tick");
assertThat(routes.get(0).getOutputs().get(0)).isInstanceOf(ToDefinition.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class LoaderTest {

@Test
fun `load routes`() {
var runtime = TestRuntime()
var source = Sources.fromURI("classpath:routes.kts")
val runtime = TestRuntime()
val source = Sources.fromURI("classpath:routes.kts")
val loader = RoutesConfigurer.load(runtime, source)

assertThat(loader).isInstanceOf(KotlinSourceLoader::class.java)
assertThat(runtime.builders).hasSize(1)
assertThat(runtime.builders[0]).isInstanceOf(RouteBuilder::class.java)

var builder = runtime.builders[0] as RouteBuilder
val builder = runtime.builders[0] as RouteBuilder
builder.context = runtime.camelContext
builder.configure()

Expand All @@ -54,23 +54,23 @@ class LoaderTest {

@Test
fun `load routes with endpoint dsl`() {
var runtime = TestRuntime()
var source = Sources.fromURI("classpath:routes-with-endpoint-dsl.kts")
val runtime = TestRuntime()
val source = Sources.fromURI("classpath:routes-with-endpoint-dsl.kts")
val loader = RoutesConfigurer.load(runtime, source)

assertThat(loader).isInstanceOf(KotlinSourceLoader::class.java)
assertThat(runtime.builders).hasSize(1)
assertThat(runtime.builders[0]).isInstanceOf(RouteBuilder::class.java)

var builder = runtime.builders[0] as RouteBuilder
val builder = runtime.builders[0] as RouteBuilder
builder.context = runtime.camelContext
builder.configure()

val routes = builder.routeCollection.routes
assertThat(routes).hasSize(1)
assertThat(routes[0].input.endpointUri).isEqualTo("timer:tick?period=1s")
assertThat(routes[0].input.endpointUri).isEqualTo("timer://tick?period=1s")
assertThat(routes[0].outputs[0]).isInstanceOfSatisfying(ToDefinition::class.java) {
assertThat(it.endpointUri).isEqualTo("log:info")
assertThat(it.endpointUri).isEqualTo("log://info")
}
}

Expand Down
1 change: 1 addition & 0 deletions camel-k-loader-yaml/camel-k-loader-yaml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<blacklistedDefinitions>
<blacklistedDefinition>org.apache.camel.model.Resilience4jConfigurationDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.HystrixConfigurationDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.FaultToleranceConfigurationDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.OnFallbackDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.InOnlyDefinition</blacklistedDefinition>
<blacklistedDefinition>org.apache.camel.model.InOutDefinition</blacklistedDefinition>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.vertx.ext.web.Route;
import org.apache.camel.CamelContext;
import org.apache.camel.Ordered;
import org.apache.camel.component.platform.http.vertx.VertxPlatformHttpRouter;
import org.apache.camel.health.HealthCheck;
import org.apache.camel.health.HealthCheckFilter;
import org.apache.camel.health.HealthCheckHelper;
Expand All @@ -35,7 +36,6 @@
import org.apache.camel.impl.health.RoutesHealthCheckRepository;
import org.apache.camel.k.ContextCustomizer;
import org.apache.camel.k.annotation.Customizer;
import org.apache.camel.k.http.PlatformHttp;

@Customizer("health")
public class HealthContextCustomizer implements ContextCustomizer {
Expand Down Expand Up @@ -111,16 +111,17 @@ public void apply(CamelContext camelContext) {
// add health route
addRoute(
camelContext,
PlatformHttp.lookup(camelContext)
VertxPlatformHttpRouter.lookup(camelContext)
);
}

private Route addRoute(CamelContext camelContext, PlatformHttp platformHttp) {
Route route = platformHttp.router().route(HttpMethod.GET, path);
private Route addRoute(CamelContext camelContext, VertxPlatformHttpRouter router) {
Route route = router.route(HttpMethod.GET, path);

// add global handlers first i.e. body handler
platformHttp.handlers().forEach(route::handler);
// add body handler
route.handler(router.bodyHandler());

// add health endpoint handler
route.handler(routingContext -> {
int code = 200;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public ApplicationRuntime() {
this.main = new MainAdapter();
this.main.configure().setXmlRoutes("false");
this.main.configure().setXmlRests("false");
this.main.setDefaultPropertyPlaceholderLocation("false");
this.main.setRoutesCollector(new NoRoutesCollector());
this.main.addMainListener(new MainListenerAdapter());
}
Expand All @@ -76,12 +77,12 @@ public void stop() throws Exception {

@Override
public void addRoutes(RoutesBuilder builder) {
this.main.addRoutesBuilder(builder);
this.main.configure().addRoutesBuilder(builder);
}

@Override
public void addConfiguration(Object configuration) {
this.main.addConfiguration(configuration);
this.main.configure().addConfiguration(configuration);
}

@Override
Expand Down Expand Up @@ -130,16 +131,24 @@ public void addListener(Phase phase, ThrowingConsumer<Runtime, Exception> consum

private final class MainListenerAdapter implements org.apache.camel.main.MainListener {
@Override
public void beforeConfigure(BaseMainSupport main) {
public void beforeInitialize(BaseMainSupport main) {
invokeListeners(Phase.ConfigureProperties);
}

@Override
public void beforeConfigure(BaseMainSupport main) {
invokeListeners(Phase.ConfigureRoutes);
}

@Override
public void configure(CamelContext context) {
public void afterConfigure(BaseMainSupport main) {
invokeListeners(Phase.ConfigureContext);
}

@Override
public void configure(CamelContext context) {
}

@Override
public void beforeStart(BaseMainSupport main) {
invokeListeners(Phase.Starting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.apache.camel.k.Constants;
import org.apache.camel.k.Runtime;
import org.apache.camel.k.core.quarkus.RuntimeRecorder;
import org.apache.camel.quarkus.core.deployment.CamelMainListenerBuildItem;
import org.apache.camel.quarkus.core.deployment.CamelServicePatternBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelMainListenerBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem;
import org.apache.camel.spi.HasId;
import org.apache.camel.spi.StreamCachingStrategy;
import org.jboss.jandex.IndexView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,22 @@ public void setListeners(List<Runtime.Listener> listeners) {
}

@Override
public void beforeConfigure(BaseMainSupport main) {
public void beforeInitialize(BaseMainSupport main) {
invokeListeners(listeners, on(main), Runtime.Phase.ConfigureProperties);
}

@Override
public void beforeConfigure(BaseMainSupport main) {
invokeListeners(listeners, on(main), Runtime.Phase.ConfigureRoutes);
}

@Override
public void afterConfigure(BaseMainSupport main) {
invokeListeners(listeners, on(main), Runtime.Phase.ConfigureContext);
}

@Override
public void configure(CamelContext context) {
invokeListeners(listeners, on(context), Runtime.Phase.ConfigureContext);
}

@Override
Expand Down Expand Up @@ -118,22 +126,22 @@ public CamelContext getCamelContext() {

@Override
public void addRoutes(RoutesBuilder builder) {
main.addRoutesBuilder(builder);
main.configure().addRoutesBuilder(builder);
}

@Override
public void addConfiguration(Object configuration) {
main.addConfiguration(configuration);
main.configure().addConfiguration(configuration);
}

@Override
public void setInitialProperties(Properties properties) {
main.getCamelContext().getPropertiesComponent().setInitialProperties(properties);
main.setInitialProperties(properties);
}

@Override
public void setProperties(Properties properties) {
main.getCamelContext().getPropertiesComponent().setOverrideProperties(properties);
main.setOverrideProperties(properties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,36 @@
*/
package org.apache.camel.k.quarkus.knative.deployment;

import io.quarkus.deployment.annotations.BuildProducer;
import java.util.List;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.vertx.core.deployment.CoreVertxBuildItem;
import io.quarkus.vertx.http.deployment.BodyHandlerBuildItem;
import io.quarkus.vertx.http.deployment.VertxWebRouterBuildItem;
import org.apache.camel.component.knative.KnativeComponent;
import org.apache.camel.component.knative.KnativeConstants;
import org.apache.camel.component.knative.spi.KnativeEnvironment;
import org.apache.camel.k.quarkus.knative.KnativeRecorder;
import org.apache.camel.quarkus.core.deployment.CamelRuntimeBeanBuildItem;
import org.apache.camel.quarkus.core.deployment.CamelServiceFilter;
import org.apache.camel.quarkus.core.deployment.CamelServiceFilterBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBeanBuildItem;
import org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilter;
import org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilterBuildItem;

public class DeploymentProcessor {
@BuildStep
void servicesFilters(BuildProducer<CamelServiceFilterBuildItem> serviceFilter) {
serviceFilter.produce(
new CamelServiceFilterBuildItem(CamelServiceFilter.forComponent("knative"))
List<ReflectiveClassBuildItem> reflectiveClasses() {
return List.of(
new ReflectiveClassBuildItem(true, false, KnativeEnvironment.class),
new ReflectiveClassBuildItem(true, false, KnativeEnvironment.KnativeServiceDefinition.class)
);
serviceFilter.produce(
}

@BuildStep
List<CamelServiceFilterBuildItem> servicesFilters() {
return List.of(
new CamelServiceFilterBuildItem(CamelServiceFilter.forComponent(KnativeConstants.SCHEME)),
new CamelServiceFilterBuildItem(CamelServiceFilter.forPathEndingWith(CamelServiceFilter.CAMEL_SERVICE_BASE_PATH + "/knative/transport/http"))
);
}
Expand All @@ -50,18 +59,12 @@ CamelRuntimeBeanBuildItem knativeComponent(
BodyHandlerBuildItem bodyHandlerBuildItem) {

return new CamelRuntimeBeanBuildItem(
"knative",
"org.apache.camel.component.knative.KnativeComponent",
KnativeConstants.SCHEME,
KnativeComponent.class.getName(),
recorder.createKnativeComponent(
vertx.getVertx(),
router.getRouter(),
bodyHandlerBuildItem.getHandler())
);
}

@BuildStep
void registerReflectiveClasses(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, KnativeEnvironment.class));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, KnativeEnvironment.KnativeServiceDefinition.class));
}
}
Loading

0 comments on commit 00888b7

Please sign in to comment.