Search in sources :

Example 1 with Ordered

use of org.apache.camel.Ordered in project camel-quarkus by apache.

the class KameletProcessor method configureTemplates.

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelContextCustomizerBuildItem configureTemplates(List<KameletResolverBuildItem> resolvers, KameletConfiguration configuration, KameletRecorder recorder) throws Exception {
    List<RouteTemplateDefinition> definitions = new ArrayList<>();
    List<KameletResolver> kameletResolvers = resolvers.stream().map(KameletResolverBuildItem::getResolver).sorted(Comparator.comparingInt(Ordered::getOrder)).collect(Collectors.toList());
    CamelContext context = new DefaultCamelContext();
    ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
    for (String id : configuration.identifiers.orElse(Collections.emptyList())) {
        for (KameletResolver resolver : kameletResolvers) {
            final Optional<Resource> resource = resolver.resolve(id, ecc);
            if (!resource.isPresent()) {
                continue;
            }
            Collection<RoutesBuilder> rbs = ecc.getRoutesLoader().findRoutesBuilders(resource.get());
            for (RoutesBuilder rb : rbs) {
                RouteBuilder routeBuilder = (RouteBuilder) rb;
                routeBuilder.configure();
                if (routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() == 0) {
                    throw new IllegalStateException("No kamelet template was created for " + "kamelet:" + id + ". It might be that the kamelet was malformed?");
                } else if (routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() > 1) {
                    throw new IllegalStateException("A kamelet is not supposed to create more than one route (" + "kamelet:" + id + "," + "routes: " + routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() + ")");
                }
                definitions.add(routeBuilder.getRouteTemplateCollection().getRouteTemplates().get(0));
            }
        }
    }
    return new CamelContextCustomizerBuildItem(recorder.createTemplateLoaderCustomizer(definitions));
}
Also used : CamelContext(org.apache.camel.CamelContext) ExtendedCamelContext(org.apache.camel.ExtendedCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) ArrayList(java.util.ArrayList) Ordered(org.apache.camel.Ordered) Resource(org.apache.camel.spi.Resource) RouteTemplateDefinition(org.apache.camel.model.RouteTemplateDefinition) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContextCustomizerBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem) ExtendedCamelContext(org.apache.camel.ExtendedCamelContext) RoutesBuilder(org.apache.camel.RoutesBuilder) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)1 Record (io.quarkus.deployment.annotations.Record)1 ArrayList (java.util.ArrayList)1 CamelContext (org.apache.camel.CamelContext)1 ExtendedCamelContext (org.apache.camel.ExtendedCamelContext)1 Ordered (org.apache.camel.Ordered)1 RoutesBuilder (org.apache.camel.RoutesBuilder)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 RouteTemplateDefinition (org.apache.camel.model.RouteTemplateDefinition)1 CamelContextCustomizerBuildItem (org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem)1 Resource (org.apache.camel.spi.Resource)1