Skip to content

Commit

Permalink
update to quarkus 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Nov 3, 2019
1 parent 0aae73b commit f3795a7
Show file tree
Hide file tree
Showing 36 changed files with 276 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class IntegrationTest extends Specification {

def setup() {
this.context = new DefaultCamelContext()
this.runtime = Runtime.of(context)
this.runtime = Runtime.on(context)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class IntegrationTest {
@BeforeEach
public void setUp() {
this.context = new DefaultCamelContext();
this.runtime = Runtime.of(context);
this.runtime = Runtime.on(context);
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class IntegrationTest {
@Test
fun `load integration with rest`() {
val context = DefaultCamelContext()
val runtime = Runtime.of(context)
val runtime = Runtime.on(context)

forRoutes("classpath:routes-with-rest.kts").accept(Runtime.Phase.ConfigureRoutes, runtime)

Expand Down Expand Up @@ -74,7 +74,7 @@ class IntegrationTest {
@Test
fun `load integration with beans`() {
val context = DefaultCamelContext()
val runtime = Runtime.of(context)
val runtime = Runtime.on(context)

forRoutes("classpath:routes-with-beans.kts").accept(Runtime.Phase.ConfigureRoutes, runtime)

Expand All @@ -89,7 +89,7 @@ class IntegrationTest {
@Test
fun `load integration with components configuration`() {
val context = DefaultCamelContext()
val runtime = Runtime.of(context)
val runtime = Runtime.on(context)

forRoutes("classpath:routes-with-components-configuration.kts").accept(Runtime.Phase.ConfigureRoutes, runtime)

Expand All @@ -107,7 +107,7 @@ class IntegrationTest {
@Test
fun `load integration with languages configuration`() {
val context = DefaultCamelContext()
val runtime = Runtime.of(context)
val runtime = Runtime.on(context)

forRoutes("classpath:routes-with-languages-configuration.kts").accept(Runtime.Phase.ConfigureRoutes, runtime)

Expand All @@ -123,7 +123,7 @@ class IntegrationTest {
@Test
fun `load integration with dataformats configuration`() {
val context = DefaultCamelContext()
val runtime = Runtime.of(context)
val runtime = Runtime.on(context)

forRoutes("classpath:routes-with-dataformats-configuration.kts").accept(Runtime.Phase.ConfigureRoutes, runtime)

Expand All @@ -139,7 +139,7 @@ class IntegrationTest {
@Test
fun `load integration with error handler`() {
val context = DefaultCamelContext()
val runtime = Runtime.of(context)
val runtime = Runtime.on(context)

forRoutes("classpath:routes-with-error-handler.kts").accept(Runtime.Phase.ConfigureRoutes, runtime)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.substrate.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.substrate.ServiceProviderBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import org.apache.camel.k.Runtime;
import org.apache.camel.k.core.quarkus.RuntimeListenerAdapter;
import org.apache.camel.k.core.quarkus.RuntimeRecorder;
import org.apache.camel.quarkus.core.deployment.CamelMainListenerBuildItem;
import org.apache.camel.spi.HasId;
Expand Down Expand Up @@ -96,7 +95,7 @@ void registerStreamCachingClasses(
);
}

@Record(ExecutionTime.RUNTIME_INIT)
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelMainListenerBuildItem registerListener(RuntimeRecorder recorder) {
List<Runtime.Listener> listeners = new ArrayList<>();
Expand All @@ -107,16 +106,13 @@ CamelMainListenerBuildItem registerListener(RuntimeRecorder recorder) {
id = id + ".";
}

// TODO: this has to be done on quarkus side
// TODO: this has to be done at runtime
//PropertiesSupport.bindProperties(getCamelContext(), listener, id);
}

listeners.add(listener);
});

RuntimeListenerAdapter adapter = new RuntimeListenerAdapter();
adapter.setListeners(listeners);

return new CamelMainListenerBuildItem(adapter);
return new CamelMainListenerBuildItem(recorder.createMainListener(listeners));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
package org.apache.camel.k.core.quarkus.deployment;

import io.quarkus.test.junit.SubstrateTest;
import io.quarkus.test.junit.NativeImageTest;

@SubstrateTest
@NativeImageTest
public class ExtensionIT extends ExtensionTest {
}
18 changes: 18 additions & 0 deletions camel-k-quarkus/camel-k-quarkus-core/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,32 @@
<artifactId>camel-k-quarkus-core</artifactId>

<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-support</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core-engine</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-runtime-core</artifactId>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.xml.bind</groupId>
<artifactId>jboss-jaxb-api_2.3_spec</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,121 +49,61 @@ public List<Runtime.Listener> getListeners() {

@Override
public void beforeStart(BaseMainSupport main) {
final Runtime runtime = new Runtime() {
@Override
public CamelContext getCamelContext() {
return main.getCamelContext();
}

@Override
public void addRoutes(RoutesBuilder builder) {
try {
// TODO: the before start event is fired in the wrong
// phase in camek-quarkus so routes have to be
// added directly to the registry, eplace with:
// main.addRoutesBuilder(builder)
// when fixed.
main.getCamelContext().addRoutes(builder);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};

invokeListeners(runtime, Runtime.Phase.Starting);
invokeListeners(runtime, Runtime.Phase.ConfigureRoutes);
invokeListeners(listeners, on(main), Runtime.Phase.Starting);
invokeListeners(listeners, on(main), Runtime.Phase.ConfigureRoutes);
}

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

@Override
public void afterStart(BaseMainSupport main) {
final Runtime runtime = new Runtime() {
@Override
public CamelContext getCamelContext() {
return main.getCamelContext();
}

@Override
public void addRoutes(RoutesBuilder builder) {
try {
// TODO: the before start event is fired in the wrong
// phase in camek-quarkus so routes have to be
// added directly to the registry, eplace with:
// main.addRoutesBuilder(builder)
// when fixed.
main.getCamelContext().addRoutes(builder);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};

invokeListeners(runtime, Runtime.Phase.Started);
invokeListeners(listeners, on(main), Runtime.Phase.Started);
}

@Override
public void beforeStop(BaseMainSupport main) {
final Runtime runtime = new Runtime() {
@Override
public CamelContext getCamelContext() {
return main.getCamelContext();
}
invokeListeners(listeners, on(main), Runtime.Phase.Stopping);
}

@Override
public void addRoutes(RoutesBuilder builder) {
try {
// TODO: the before start event is fired in the wrong
// phase in camek-quarkus so routes have to be
// added directly to the registry, eplace with:
// main.addRoutesBuilder(builder)
// when fixed.
main.getCamelContext().addRoutes(builder);
} catch (Exception e) {
throw new RuntimeException(e);
@Override
public void afterStop(BaseMainSupport main) {
invokeListeners(listeners, on(main), Runtime.Phase.Stopped);
}

// ************************
//
// Helpers
//
// ************************

private static void invokeListeners(List<Runtime.Listener> listeners, Runtime runtime, Runtime.Phase phase) {
listeners.stream()
.sorted(Comparator.comparingInt(Runtime.Listener::getOrder))
.forEach(l -> {
if (l.accept(phase, runtime)) {
LOGGER.info("Listener {} executed in phase {}", l, phase);
}
}
};
});
}

invokeListeners(runtime, Runtime.Phase.Stopping);
private static Runtime on(CamelContext context) {
return Runtime.on(context);
}

@Override
public void afterStop(BaseMainSupport main) {
final Runtime runtime = new Runtime() {
private static Runtime on(BaseMainSupport main) {
return new Runtime() {
@Override
public CamelContext getCamelContext() {
return main.getCamelContext();
}

@Override
public void addRoutes(RoutesBuilder builder) {
try {
// TODO: the before start event is fired in the wrong
// phase in camek-quarkus so routes have to be
// added directly to the registry, eplace with:
// main.addRoutesBuilder(builder)
// when fixed.
main.getCamelContext().addRoutes(builder);
} catch (Exception e) {
throw new RuntimeException(e);
}
main.addRoutesBuilder(builder);
}
};

invokeListeners(runtime, Runtime.Phase.Stopped);
}

private void invokeListeners(Runtime runtime, Runtime.Phase phase) {
listeners.stream()
.sorted(Comparator.comparingInt(Runtime.Listener::getOrder))
.forEach(l -> {
if (l.accept(phase, runtime)) {
LOGGER.info("Listener {} executed in phase {}", l, phase);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@
*/
package org.apache.camel.k.core.quarkus;

import java.util.List;

import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import org.apache.camel.k.Runtime;
import org.apache.camel.main.MainListener;

@Recorder
public class RuntimeRecorder {
public RuntimeValue<MainListener> createMainListener(List<Runtime.Listener> listeners) {
RuntimeListenerAdapter adapter = new RuntimeListenerAdapter();
adapter.setListeners(listeners);

return new RuntimeValue<>(adapter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,38 @@

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.substrate.ReflectiveClassBuildItem;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.vertx.deployment.VertxBuildItem;
import org.apache.camel.component.knative.KnativeComponent;
import org.apache.camel.component.knative.spi.KnativeEnvironment;
import org.apache.camel.k.quarkus.knative.KnativeRecorder;
import org.apache.camel.quarkus.core.CamelServiceFilter;
import org.apache.camel.quarkus.core.deployment.CamelRuntimeBeanBuildItem;
import org.apache.camel.quarkus.core.deployment.CamelServiceFilterBuildItem;

public class DeploymentProcessor {
@BuildStep
void servicesFilters(BuildProducer<CamelServiceFilterBuildItem> serviceFilter) {
serviceFilter.produce(
new CamelServiceFilterBuildItem(CamelServiceFilter.forComponent("knative"))
);
serviceFilter.produce(
new CamelServiceFilterBuildItem(CamelServiceFilter.forPathEndingWith(CamelServiceFilter.CAMEL_SERVICE_BASE_PATH + "/knative/transport/http"))
);
}

@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
CamelRuntimeBeanBuildItem knativeComponent(KnativeRecorder recorder, VertxBuildItem vertx) {
return new CamelRuntimeBeanBuildItem(
"knative",
KnativeComponent.class,
recorder.createKnativeComponent(vertx.getVertx())
);
}

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

0 comments on commit f3795a7

Please sign in to comment.