use of io.syndesis.common.model.integration.Step in project syndesis by syndesisio.
the class ProjectGeneratorHelper method sanitize.
public static Integration sanitize(Integration integration, IntegrationResourceManager resourceManager) {
final List<Step> steps = new ArrayList<>(integration.getSteps());
if (steps.isEmpty()) {
return integration;
}
for (int i = 0; i < steps.size(); i++) {
final Step source = steps.get(i);
if (source.getConnection().isPresent()) {
final Connection connection = source.getConnection().get();
// If connector is not set, fetch it from data source and update connection
if (!connection.getConnector().isPresent()) {
Connector connector = resourceManager.loadConnector(connection.getConnectorId()).orElseThrow(() -> new IllegalArgumentException("Unable to fetch connector: " + connection.getConnectorId()));
// Add missing connector to connection.
Connection newConnection = new Connection.Builder().createFrom(connection).connector(connector).build();
// Replace with the new 'sanitized' step
steps.set(i, new Step.Builder().createFrom(source).connection(newConnection).build());
}
}
}
final Integration.Builder builder = new Integration.Builder().createFrom(integration);
// is fully implemented and schedule options are set on integration.
if (!integration.getScheduler().isPresent()) {
Map<String, String> properties = new HashMap<>(steps.get(0).getConfiguredProperties());
String type = properties.remove("schedulerType");
String expr = properties.remove("schedulerExpression");
if (StringUtils.isNotEmpty(expr)) {
if (StringUtils.isEmpty(type)) {
type = "timer";
}
builder.scheduler(new Scheduler.Builder().type(Scheduler.Type.valueOf(type)).expression(expr).build());
}
// Replace first step so underlying connector won't fail uri param
// validation if schedule options were set.
steps.set(0, new Step.Builder().createFrom(steps.get(0)).configuredProperties(properties).build());
}
return builder.steps(steps).build();
}
use of io.syndesis.common.model.integration.Step in project syndesis by syndesisio.
the class ProjectGeneratorTest method testGenerateApplicationProperties.
@Test
public void testGenerateApplicationProperties() throws IOException {
// ******************
// OLD STYLE
// ******************
final ConnectorAction oldAction = new ConnectorAction.Builder().id(KeyGenerator.createKey()).descriptor(new ConnectorDescriptor.Builder().connectorId("old").camelConnectorPrefix("old").build()).build();
final Connector oldConnector = new Connector.Builder().id("old").addAction(oldAction).putProperty("username", new ConfigurationProperty.Builder().componentProperty(false).secret(true).build()).putProperty("password", new ConfigurationProperty.Builder().componentProperty(false).secret(true).build()).putProperty("token", new ConfigurationProperty.Builder().componentProperty(true).secret(true).build()).build();
// ******************
// NEW STYLE
// ******************
final ConnectorAction newAction = new ConnectorAction.Builder().id(KeyGenerator.createKey()).descriptor(new ConnectorDescriptor.Builder().connectorId("new").componentScheme("http4").build()).build();
final Connector newConnector = new Connector.Builder().id("new").addAction(oldAction).putProperty("username", new ConfigurationProperty.Builder().componentProperty(false).secret(true).build()).putProperty("password", new ConfigurationProperty.Builder().componentProperty(false).secret(true).build()).putProperty("token", new ConfigurationProperty.Builder().componentProperty(true).secret(true).build()).build();
// ******************
// Integration
// ******************
Step s1 = new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id(KeyGenerator.createKey()).connector(oldConnector).build()).putConfiguredProperty("username", "my-username-1").putConfiguredProperty("password", "my-password-1").putConfiguredProperty("token", "my-token-1").action(oldAction).build();
Step s2 = new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id(KeyGenerator.createKey()).connector(newConnector).build()).putConfiguredProperty("username", "my-username-2").putConfiguredProperty("password", "my-password-2").putConfiguredProperty("token", "my-token-2").action(newAction).build();
TestResourceManager resourceManager = new TestResourceManager();
ProjectGeneratorConfiguration configuration = new ProjectGeneratorConfiguration();
ProjectGenerator generator = new ProjectGenerator(configuration, resourceManager, getMavenProperties());
Integration integration = resourceManager.newIntegration(s1, s2);
Properties properties = generator.generateApplicationProperties(integration);
assertThat(properties.size()).isEqualTo(6);
assertThat(properties.getProperty("old.configurations.old-1.token")).isEqualTo("my-token-1");
assertThat(properties.getProperty("old-1.username")).isEqualTo("my-username-1");
assertThat(properties.getProperty("old-1.password")).isEqualTo("my-password-1");
assertThat(properties.getProperty("http4-2.token")).isEqualTo("my-token-2");
assertThat(properties.getProperty("http4-2.username")).isEqualTo("my-username-2");
assertThat(properties.getProperty("http4-2.password")).isEqualTo("my-password-2");
}
use of io.syndesis.common.model.integration.Step in project syndesis by syndesisio.
the class IntegrationRouteBuilder method handleConnectorSplit.
private Optional<ProcessorDefinition> handleConnectorSplit(Step step, ProcessorDefinition route, String index) {
if (step.getAction().filter(ConnectorAction.class::isInstance).isPresent()) {
final ConnectorAction action = step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).get();
final ConnectorDescriptor descriptor = action.getDescriptor();
if (descriptor.getSplit().isPresent()) {
final Split split = descriptor.getSplit().get();
final Step.Builder splitBuilder = new Step.Builder().stepKind(StepKind.split);
split.getLanguage().ifPresent(s -> splitBuilder.putConfiguredProperty("language", s));
split.getExpression().ifPresent(s -> splitBuilder.putConfiguredProperty("expression", s));
return new SplitStepHandler().handle(splitBuilder.build(), route, this, index);
}
}
return Optional.empty();
}
use of io.syndesis.common.model.integration.Step in project syndesis by syndesisio.
the class Application method generateIntegrationProject.
private void generateIntegrationProject(File project) throws IOException {
final ReadApiClientData reader = new ReadApiClientData();
final ArrayList<Step> steps = new ArrayList<>();
String deploymentText;
try (InputStream is = resourceLoader.getResource("io/syndesis/server/dao/deployment.json").getInputStream()) {
deploymentText = reader.from(is);
}
final List<ModelData<?>> modelList = reader.readDataFromString(deploymentText);
for (final ModelData<?> model : modelList) {
if (model.getKind() == Kind.Connector) {
final Connector connector = (Connector) model.getData();
for (final Action action : connector.getActions()) {
steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connector(connector).connectorId(connector.getId().get()).build()).action(action).build());
}
}
if (model.getKind() == Kind.ConnectorTemplate) {
final ConnectorTemplate template = (ConnectorTemplate) model.getData();
steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connectorId("connector-" + template.getId()).build()).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().camelConnectorGAV(template.getCamelConnectorGAV()).camelConnectorPrefix(template.getCamelConnectorPrefix()).build()).build()).build());
}
}
try {
final ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
final Resource[] resources = resolver.getResources("classpath:/META-INF/syndesis/connector/*.json");
if (resources != null) {
for (Resource resource : resources) {
Connector connector = Json.reader().forType(Connector.class).readValue(resource.getInputStream());
if (connector != null) {
for (final Action action : connector.getActions()) {
steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connector(connector).connectorId(connector.getId().get()).build()).action(action).build());
}
}
}
}
} catch (FileNotFoundException ignored) {
// ignore
}
Integration integration = new Integration.Builder().id("Integration").name("Integration").description("This integration is used to prime the .m2 repo").steps(steps).build();
generate(integration, project);
}
use of io.syndesis.common.model.integration.Step 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