Search in sources :

Example 6 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class ActionComparatorTest method shouldOrderActionsBasedOnTagsAndName.

@Test
public void shouldOrderActionsBasedOnTagsAndName() {
    final ConnectorAction a = new ConnectorAction.Builder().name("a").addTag("a").build();
    final ConnectorAction b = new ConnectorAction.Builder().name("b").addTag("b").build();
    final ConnectorAction c = new ConnectorAction.Builder().name("c").addTag("b").build();
    final ConnectorAction noTagsA = new ConnectorAction.Builder().name("a").build();
    final ConnectorAction noTagsB = new ConnectorAction.Builder().name("b").build();
    final ConnectorAction noTagsNoName = new ConnectorAction.Builder().build();
    final List<ConnectorAction> actions = new ArrayList<>(Arrays.asList(c, noTagsA, a, noTagsB, b, noTagsNoName));
    Collections.shuffle(actions);
    actions.sort(ActionComparator.INSTANCE);
    assertThat(actions).containsExactly(a, b, c, noTagsA, noTagsB, noTagsNoName);
}
Also used : ArrayList(java.util.ArrayList) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test)

Example 7 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class ActionComparatorTest method shouldOrderActionsBasedOnTags.

@Test
public void shouldOrderActionsBasedOnTags() {
    final ConnectorAction a = new ConnectorAction.Builder().addTag("a").build();
    final ConnectorAction b = new ConnectorAction.Builder().addTag("b").build();
    final ConnectorAction c = new ConnectorAction.Builder().addTag("c").build();
    final ConnectorAction noTags = new ConnectorAction.Builder().build();
    final List<ConnectorAction> actions = new ArrayList<>(Arrays.asList(c, noTags, a, b));
    Collections.shuffle(actions);
    actions.sort(ActionComparator.INSTANCE);
    assertThat(actions).containsExactly(a, b, c, noTags);
}
Also used : ArrayList(java.util.ArrayList) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test)

Example 8 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class ProjectGenerator method generateApplicationProperties.

@SuppressWarnings("PMD")
@Override
public Properties generateApplicationProperties(final Integration integrationDefinition) {
    final Integration integration = sanitize(integrationDefinition, resourceManager);
    final Properties properties = new Properties();
    final List<? extends Step> steps = integration.getSteps();
    for (int i = 0; i < steps.size(); i++) {
        final Step step = steps.get(i);
        // Check if a step is of supported type.
        if (StepKind.endpoint != step.getStepKind()) {
            continue;
        }
        // Check if a step has the required options
        if (step.getAction().filter(ConnectorAction.class::isInstance).isPresent() && step.getConnection().isPresent()) {
            final String index = Integer.toString(i + 1);
            final Connection connection = step.getConnection().get();
            final ConnectorAction action = ConnectorAction.class.cast(step.getAction().get());
            final ConnectorDescriptor descriptor = action.getDescriptor();
            final Connector connector = resourceManager.loadConnector(connection).orElseThrow(() -> new IllegalArgumentException("No connector with id: " + connection.getConnectorId()));
            if (connector.getComponentScheme().isPresent() || descriptor.getComponentScheme().isPresent()) {
                // Grab the component scheme from the component descriptor or
                // from the connector
                final String componentScheme = Optionals.first(descriptor.getComponentScheme(), connector.getComponentScheme()).get();
                final Map<String, ConfigurationProperty> configurationProperties = CollectionsUtils.aggregate(connector.getProperties(), action.getProperties());
                // Workaround for https://github.com/syndesisio/syndesis/issues/1713
                for (Map.Entry<String, ConfigurationProperty> entry : configurationProperties.entrySet()) {
                    if (entry.getValue() != null && entry.getValue().getDefaultValue() != null && !entry.getValue().getDefaultValue().isEmpty()) {
                        if (connector.isSecret(entry.getKey()) || action.isSecret(entry.getKey())) {
                            addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue().getDefaultValue());
                        }
                    }
                }
                for (Map.Entry<String, String> entry : connection.getConfiguredProperties().entrySet()) {
                    if (connector.isSecret(entry) || action.isSecret(entry)) {
                        addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue());
                    }
                }
                for (Map.Entry<String, String> entry : step.getConfiguredProperties().entrySet()) {
                    if (connector.isSecret(entry) || action.isSecret(entry)) {
                        addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue());
                    }
                }
            } else {
                // The component scheme is defined as camel connector prefix
                // for 'old' style connectors.
                final String componentScheme = descriptor.getCamelConnectorPrefix();
                // endpoint secrets
                Stream.of(connector, connection, step).filter(WithConfiguredProperties.class::isInstance).map(WithConfiguredProperties.class::cast).map(WithConfiguredProperties::getConfiguredProperties).flatMap(map -> map.entrySet().stream()).filter(Predicates.or(connector::isEndpointProperty, action::isEndpointProperty)).filter(Predicates.or(connector::isSecret, action::isSecret)).forEach(e -> {
                    addDecryptedKeyProperty(properties, index, componentScheme, e.getKey(), e.getValue());
                });
                // Component properties triggers connectors aliasing so we
                // can have multiple instances of the same connectors
                Stream.of(connector, connection, step).filter(WithConfiguredProperties.class::isInstance).map(WithConfiguredProperties.class::cast).map(WithConfiguredProperties::getConfiguredProperties).flatMap(map -> map.entrySet().stream()).filter(Predicates.or(connector::isComponentProperty, action::isComponentProperty)).forEach(e -> {
                    String propKeyPrefix = String.format("%s.configurations.%s", componentScheme, componentScheme);
                    addDecryptedKeyProperty(properties, index, propKeyPrefix, e.getKey(), e.getValue());
                });
            }
        }
    }
    return properties;
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ProjectGeneratorHelper.sanitize(io.syndesis.integration.project.generator.ProjectGeneratorHelper.sanitize) ProjectGeneratorHelper.mandatoryDecrypt(io.syndesis.integration.project.generator.ProjectGeneratorHelper.mandatoryDecrypt) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) ProjectGeneratorHelper.addTarEntry(io.syndesis.integration.project.generator.ProjectGeneratorHelper.addTarEntry) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) MavenProperties(io.syndesis.common.util.MavenProperties) StringUtils(org.apache.commons.lang3.StringUtils) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) WithConfiguredProperties(io.syndesis.common.model.WithConfiguredProperties) PipedInputStream(java.io.PipedInputStream) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) Integration(io.syndesis.common.model.integration.Integration) DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Set(java.util.Set) Connector(io.syndesis.common.model.connection.Connector) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) ProjectGeneratorHelper.addResource(io.syndesis.integration.project.generator.ProjectGeneratorHelper.addResource) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Stream(java.util.stream.Stream) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) MavenGav(io.syndesis.integration.project.generator.mvn.MavenGav) PomContext(io.syndesis.integration.project.generator.mvn.PomContext) Step(io.syndesis.common.model.integration.Step) Mustache(com.github.mustachejava.Mustache) Names(io.syndesis.common.util.Names) TreeSet(java.util.TreeSet) MustacheFactory(com.github.mustachejava.MustacheFactory) CollectionsUtils(io.syndesis.common.util.CollectionsUtils) StepKind(io.syndesis.common.model.integration.StepKind) Optionals(io.syndesis.common.util.Optionals) ExecutorService(java.util.concurrent.ExecutorService) OutputStream(java.io.OutputStream) Properties(java.util.Properties) Logger(org.slf4j.Logger) Files(java.nio.file.Files) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) Predicates(io.syndesis.common.util.Predicates) IOException(java.io.IOException) PipedOutputStream(java.io.PipedOutputStream) Dependency(io.syndesis.common.model.Dependency) ProjectGeneratorHelper.compile(io.syndesis.integration.project.generator.ProjectGeneratorHelper.compile) Paths(java.nio.file.Paths) IntegrationResourceManager(io.syndesis.integration.api.IntegrationResourceManager) Json(io.syndesis.common.util.Json) InputStream(java.io.InputStream) Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) WithConfiguredProperties(io.syndesis.common.model.WithConfiguredProperties) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) MavenProperties(io.syndesis.common.util.MavenProperties) WithConfiguredProperties(io.syndesis.common.model.WithConfiguredProperties) Properties(java.util.Properties) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Map(java.util.Map)

Example 9 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class SqlConnectorTestSupport method newSqlEndpointStep.

protected Step newSqlEndpointStep(String actionId, Consumer<Step.Builder> stepConsumer, Consumer<ConnectorDescriptor.Builder> descriptorConsumer) {
    final Connector connector = getResourceManager().mandatoryLoadConnector("sql");
    final ConnectorAction action = getResourceManager().mandatoryLookupAction(connector, actionId);
    final ConnectorDescriptor.Builder descriptorBuilder = new ConnectorDescriptor.Builder().createFrom(action.getDescriptor());
    descriptorConsumer.accept(descriptorBuilder);
    final Step.Builder builder = new Step.Builder().stepKind(StepKind.endpoint).action(new ConnectorAction.Builder().createFrom(action).descriptor(descriptorBuilder.build()).build()).connection(new io.syndesis.common.model.connection.Connection.Builder().connector(connector).putConfiguredProperty("user", db.properties.getProperty("sql-connector.user")).putConfiguredProperty("password", db.properties.getProperty("sql-connector.password")).putConfiguredProperty("url", db.properties.getProperty("sql-connector.url")).build());
    stepConsumer.accept(builder);
    return builder.build();
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Step(io.syndesis.common.model.integration.Step)

Example 10 with ConnectorAction

use of io.syndesis.common.model.action.ConnectorAction in project syndesis by syndesisio.

the class SqlConnectorTestSupport method newSqlEndpointStep.

// **************************
// Helpers
// **************************
protected Step newSqlEndpointStep(String actionId, Consumer<Step.Builder> consumer) {
    final Connector connector = getResourceManager().mandatoryLoadConnector("sql");
    final ConnectorAction action = getResourceManager().mandatoryLookupAction(connector, actionId);
    final Step.Builder builder = new Step.Builder().stepKind(StepKind.endpoint).action(action).connection(new io.syndesis.common.model.connection.Connection.Builder().connector(connector).putConfiguredProperty("user", db.properties.getProperty("sql-connector.user")).putConfiguredProperty("password", db.properties.getProperty("sql-connector.password")).putConfiguredProperty("url", db.properties.getProperty("sql-connector.url")).build());
    consumer.accept(builder);
    return builder.build();
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Step(io.syndesis.common.model.integration.Step)

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