Search in sources :

Example 1 with Scheduler

use of io.syndesis.common.model.integration.Scheduler 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)

Example 2 with Scheduler

use of io.syndesis.common.model.integration.Scheduler in project syndesis by syndesisio.

the class IntegrationSchedulerTest method integrationSchedulerTest.

@Test
public void integrationSchedulerTest() throws Exception {
    final CamelContext context = new SpringCamelContext(applicationContext);
    try {
        final RouteBuilder routes = new IntegrationRouteBuilder("", Collections.emptyList()) {

            @Override
            protected Integration loadIntegration() throws IOException {
                Integration integration = newIntegration(new Step.Builder().id("step-1").stepKind(StepKind.endpoint).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().componentScheme("log").putConfiguredProperty("loggerName", "timer").build()).build()).build(), new Step.Builder().id("step-2").stepKind(StepKind.endpoint).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().componentScheme("mock").putConfiguredProperty("name", "timer").build()).build()).build());
                return new Integration.Builder().createFrom(integration).scheduler(new Scheduler.Builder().type(Scheduler.Type.timer).expression("1s").build()).build();
            }
        };
        // Set up the camel context
        context.addRoutes(routes);
        context.start();
        dumpRoutes(context);
        RouteDefinition routeDefinition = context.getRouteDefinition("test-integration");
        assertThat(routeDefinition).isNotNull();
        assertThat(routeDefinition).hasFieldOrPropertyWithValue("id", "test-integration");
        assertThat(routeDefinition.getInputs()).hasSize(1);
        assertThat(routeDefinition.getInputs().get(0).getEndpointUri()).isEqualTo("timer:integration?period=1s");
        assertThat(routeDefinition.getOutputs()).hasSize(4);
        assertThat(routeDefinition.getOutputs().get(0)).hasFieldOrPropertyWithValue("endpointUri", "log:timer");
        assertThat(routeDefinition.getOutputs().get(1)).isInstanceOf(ProcessDefinition.class);
        assertThat(routeDefinition.getOutputs().get(2)).hasFieldOrPropertyWithValue("endpointUri", "mock:timer");
        assertThat(routeDefinition.getOutputs().get(3)).isInstanceOf(ProcessDefinition.class);
        assertThat(routeDefinition.getInputs().get(0)).hasFieldOrPropertyWithValue("id", "integration-scheduler");
        assertThat(routeDefinition.getOutputs().get(0)).hasFieldOrPropertyWithValue("id", "step-1");
        assertThat(routeDefinition.getOutputs().get(1)).hasFieldOrPropertyWithValue("id", "step-1-capture");
        assertThat(routeDefinition.getOutputs().get(2)).hasFieldOrPropertyWithValue("id", "step-2");
        assertThat(routeDefinition.getOutputs().get(3)).hasFieldOrPropertyWithValue("id", "step-2-capture");
    } finally {
        context.stop();
    }
}
Also used : SpringCamelContext(org.apache.camel.spring.SpringCamelContext) CamelContext(org.apache.camel.CamelContext) Integration(io.syndesis.common.model.integration.Integration) RouteBuilder(org.apache.camel.builder.RouteBuilder) Scheduler(io.syndesis.common.model.integration.Scheduler) RouteBuilder(org.apache.camel.builder.RouteBuilder) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Step(io.syndesis.common.model.integration.Step) RouteDefinition(org.apache.camel.model.RouteDefinition) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Scheduler (io.syndesis.common.model.integration.Scheduler)2 RouteDefinition (org.apache.camel.model.RouteDefinition)2 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)1 Integration (io.syndesis.common.model.integration.Integration)1 Step (io.syndesis.common.model.integration.Step)1 HashMap (java.util.HashMap)1 CamelContext (org.apache.camel.CamelContext)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 RuntimeCamelCatalog (org.apache.camel.runtimecatalog.RuntimeCamelCatalog)1 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1