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;
}
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();
}
}
Aggregations