use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.
the class CustomConnectorHandlerTest method shouldCreateNewConnectorsBasedOnConnectorTemplates.
@Test
public void shouldCreateNewConnectorsBasedOnConnectorTemplates() {
final Map<String, ConfigurationProperty> properties = new HashMap<>();
properties.put("prop1", new ConfigurationProperty.Builder().build());
final Map<String, ConfigurationProperty> connectorProperties = new HashMap<>();
connectorProperties.put("prop2", new ConfigurationProperty.Builder().build());
connectorProperties.put("prop3", new ConfigurationProperty.Builder().build());
final ConnectorGroup group = new ConnectorGroup.Builder().name("connector template group").build();
final ConnectorTemplate connectorTemplate = //
new ConnectorTemplate.Builder().id(//
"connector-template-id").name(//
"connector template").properties(properties).connectorProperties(//
connectorProperties).connectorGroup(//
group).build();
final ConnectorAction action = new ConnectorAction.Builder().name("action").build();
when(dataManager.fetch(ConnectorTemplate.class, "connector-template-id")).thenReturn(connectorTemplate);
when(dataManager.create(any(Connector.class))).thenAnswer(invocation -> invocation.getArgumentAt(0, Connector.class));
when(applicationContext.getBean("connector-template-id", ConnectorGenerator.class)).thenReturn(new ConnectorGenerator() {
@Override
public Connector generate(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
return new Connector.Builder().createFrom(baseConnectorFrom(connectorTemplate, connectorSettings)).putAllProperties(connectorProperties).putConfiguredProperty("prop1", "value1").addAction(action).build();
}
@Override
public ConnectorSummary info(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
return null;
}
});
final Connector created = //
new CustomConnectorHandler(dataManager, applicationContext, iconDao).create(//
new ConnectorSettings.Builder().connectorTemplateId(//
"connector-template-id").name(//
"new connector").description(//
"new connector description").icon(//
"new connector icon").putConfiguredProperty("prop1", //
"value1").putConfiguredProperty("unknown-prop", //
"unknown-value").build());
final Connector expected = //
new Connector.Builder().id(//
created.getId()).name(//
"new connector").description(//
"new connector description").icon(//
"new connector icon").connectorGroup(//
group).properties(//
connectorProperties).putConfiguredProperty("prop1", //
"value1").addAction(//
action).build();
assertThat(created).isEqualTo(expected);
}
use of io.syndesis.common.model.action.ConnectorAction 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.action.ConnectorAction 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.action.ConnectorAction in project syndesis by syndesisio.
the class GenerateMapperInspectionsMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
final Resource resource = new Resource();
resource.setDirectory(outputDir.getCanonicalPath());
project.addResource(resource);
final Set<File> generated = new HashSet<>();
final ReadApiClientData reader = new ReadApiClientData();
final List<ModelData<?>> modelList = reader.readDataFromFile("io/syndesis/server/dao/deployment.json");
for (final ModelData<?> model : modelList) {
if (model.getKind() == Kind.Connector) {
final Connector connector = (Connector) model.getData();
for (final ConnectorAction action : connector.getActions()) {
process(generated, connector, action, action.getInputDataShape());
process(generated, connector, action, action.getOutputDataShape());
}
}
}
} catch (final IOException e) {
throw new MojoFailureException(e.getMessage(), e);
}
}
use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.
the class EndpointStepHandler method handle.
@SuppressWarnings({ "unchecked", "PMD" })
@Override
public Optional<ProcessorDefinition> handle(Step step, ProcessorDefinition route, IntegrationRouteBuilder builder, final String stepIndex) {
// Model
final Connection connection = step.getConnection().get();
final Connector connector = connection.getConnector().get();
final ConnectorAction action = step.getActionAs(ConnectorAction.class).get();
final ConnectorDescriptor descriptor = action.getDescriptor();
// Camel
final String componentScheme = action.getDescriptor().getCamelConnectorPrefix();
final Map<String, String> configuredProperties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties());
final Map<String, String> properties = CollectionsUtils.aggregate(connector.filterEndpointProperties(configuredProperties), action.filterEndpointProperties(configuredProperties));
properties.entrySet().stream().filter(Predicates.or(connector::isEndpointProperty, action::isEndpointProperty)).filter(Predicates.or(connector::isSecret, action::isSecret)).forEach(e -> e.setValue(String.format("{{%s-%s.%s}}", componentScheme, stepIndex, e.getKey())));
// raw values.
properties.entrySet().stream().filter(Predicates.or(connector::isRaw, action::isRaw)).forEach(e -> e.setValue(String.format("RAW(%s)", e.getValue())));
// any configuredProperties on action descriptor are considered
properties.putAll(descriptor.getConfiguredProperties());
String uri = String.format("%s-%s", componentScheme, stepIndex);
if (ObjectHelper.isNotEmpty(uri) && ObjectHelper.isNotEmpty(properties)) {
try {
uri = URISupport.appendParametersToURI(uri, Map.class.cast(properties));
} catch (UnsupportedEncodingException | URISyntaxException e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
if (route == null) {
route = builder.from(uri);
} else {
route = route.to(uri);
}
return Optional.ofNullable(route);
}
Aggregations