Search in sources :

Example 11 with ConnectorAction

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);
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) HashMap(java.util.HashMap) ConnectorGenerator(io.syndesis.server.connector.generator.ConnectorGenerator) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorGroup(io.syndesis.common.model.connection.ConnectorGroup) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test)

Example 12 with ConnectorAction

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");
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) MavenProperties(io.syndesis.common.util.MavenProperties) Properties(java.util.Properties) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test)

Example 13 with ConnectorAction

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();
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Step(io.syndesis.common.model.integration.Step) Split(io.syndesis.common.model.Split) SplitStepHandler(io.syndesis.integration.runtime.handlers.SplitStepHandler)

Example 14 with ConnectorAction

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);
    }
}
Also used : ModelData(io.syndesis.common.model.ModelData) Connector(io.syndesis.common.model.connection.Connector) Resource(org.apache.maven.model.Resource) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) IOException(java.io.IOException) File(java.io.File) HashSet(java.util.HashSet) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData)

Example 15 with ConnectorAction

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);
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Connection(io.syndesis.common.model.connection.Connection) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) URISyntaxException(java.net.URISyntaxException)

Aggregations

ConnectorAction (io.syndesis.common.model.action.ConnectorAction)21 Connector (io.syndesis.common.model.connection.Connector)16 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)11 Step (io.syndesis.common.model.integration.Step)8 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)5 Connection (io.syndesis.common.model.connection.Connection)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 DataShape (io.syndesis.common.model.DataShape)4 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Test (org.junit.Test)3 ConnectorSettings (io.syndesis.common.model.connection.ConnectorSettings)2 Integration (io.syndesis.common.model.integration.Integration)2 MavenProperties (io.syndesis.common.util.MavenProperties)2 IntegrationProjectGenerator (io.syndesis.integration.api.IntegrationProjectGenerator)2 ComponentProxyComponent (io.syndesis.integration.component.proxy.ComponentProxyComponent)2 File (java.io.File)2