Search in sources :

Example 1 with RuntimeCamelCatalog

use of org.apache.camel.runtimecatalog.RuntimeCamelCatalog in project syndesis by syndesisio.

the class SimpleEndpointStepHandler method handle.

@SuppressWarnings({ "unchecked", "PMD" })
@Override
public Optional<ProcessorDefinition> handle(Step step, ProcessorDefinition route, IntegrationRouteBuilder builder, final String index) {
    // Model
    final ConnectorAction action = step.getActionAs(ConnectorAction.class).get();
    final ConnectorDescriptor descriptor = action.getDescriptor();
    // Camel
    final String componentScheme = action.getDescriptor().getComponentScheme().get();
    final Map<String, String> configuredProperties = step.getConfiguredProperties();
    final Map<String, String> properties = action.filterEndpointProperties(configuredProperties);
    properties.entrySet().stream().filter(action::isEndpointProperty).filter(action::isSecret).forEach(e -> e.setValue(String.format("{{%s-%s.%s}}", componentScheme, index, e.getKey())));
    // raw values.
    properties.entrySet().stream().filter(action::isRaw).forEach(e -> e.setValue(String.format("RAW(%s)", e.getValue())));
    // any configuredProperties on action descriptor are considered
    properties.putAll(descriptor.getConfiguredProperties());
    try {
        final RuntimeCamelCatalog catalog = builder.getContext().getRuntimeCamelCatalog();
        final String uri = catalog.asEndpointUri(componentScheme, Map.class.cast(properties), false);
        if (route == null) {
            route = builder.from(uri);
        } else {
            route = route.to(uri);
        }
    } catch (URISyntaxException e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
    return Optional.ofNullable(route);
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) URISyntaxException(java.net.URISyntaxException) RuntimeCamelCatalog(org.apache.camel.runtimecatalog.RuntimeCamelCatalog) Map(java.util.Map)

Example 2 with RuntimeCamelCatalog

use of org.apache.camel.runtimecatalog.RuntimeCamelCatalog in project syndesis by syndesisio.

the class IntegrationRouteBuilder method configureRouteScheduler.

/**
 * If the integration has a scheduler, start the route with a timer or quartz2
 * endpoint.
 */
private ProcessorDefinition configureRouteScheduler(Integration integration) throws URISyntaxException {
    if (integration.getScheduler().isPresent()) {
        Scheduler scheduler = integration.getScheduler().get();
        // later on.
        if (scheduler.isTimer()) {
            Map<String, String> properties = new HashMap<>();
            properties.put("timerName", "integration");
            properties.put("period", scheduler.getExpression());
            final RuntimeCamelCatalog catalog = getContext().getRuntimeCamelCatalog();
            final String uri = catalog.asEndpointUri("timer", properties, false);
            RouteDefinition route = this.from(uri);
            route.getInputs().get(0).setId("integration-scheduler");
            integration.getId().ifPresent(route::setId);
            return route;
        } else {
            throw new IllegalArgumentException("Unsupported scheduler type: " + scheduler.getType());
        }
    }
    return null;
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) HashMap(java.util.HashMap) Scheduler(io.syndesis.common.model.integration.Scheduler) RuntimeCamelCatalog(org.apache.camel.runtimecatalog.RuntimeCamelCatalog)

Aggregations

RuntimeCamelCatalog (org.apache.camel.runtimecatalog.RuntimeCamelCatalog)2 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)1 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)1 Scheduler (io.syndesis.common.model.integration.Scheduler)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RouteDefinition (org.apache.camel.model.RouteDefinition)1