Search in sources :

Example 26 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class Credentials method apply.

public Connection apply(final Connection updatedConnection, final CredentialFlowState flowState) {
    final CredentialProvider credentialProvider = providerFrom(flowState);
    final Connection withDerivedFlag = new Connection.Builder().createFrom(updatedConnection).isDerived(true).build();
    final Connection appliedConnection = credentialProvider.applyTo(withDerivedFlag, flowState);
    final Map<String, String> configuredProperties = appliedConnection.getConfiguredProperties();
    final Map<String, ConfigurationProperty> properties = updatedConnection.getConnector().orElseGet(() -> dataManager.fetch(Connector.class, updatedConnection.getConnectorId())).getProperties();
    final Map<String, String> encryptedConfiguredProperties = encryptionComponent.encryptPropertyValues(configuredProperties, properties);
    return new Connection.Builder().createFrom(appliedConnection).configuredProperties(encryptedConfiguredProperties).build();
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connection(io.syndesis.common.model.connection.Connection)

Example 27 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class IntegrationResourceManager method sanitize.

@SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION")
@SuppressWarnings("PMD.ExcessiveMethodLength")
default Integration sanitize(Integration integration) {
    // Always sanitize the integration name
    String sanitizeIntegrationName = sanitize(integration.getName());
    if (integration.getFlows().isEmpty()) {
        return new Integration.Builder().createFrom(integration).name(sanitizeIntegrationName).build();
    }
    final List<Flow> replacementFlows = new ArrayList<>(integration.getFlows());
    final ListIterator<Flow> flows = replacementFlows.listIterator();
    while (flows.hasNext()) {
        final Flow flow = flows.next();
        if (flow.getSteps().isEmpty()) {
            continue;
        }
        final List<Step> replacementSteps = new ArrayList<>(flow.getSteps());
        final ListIterator<Step> steps = replacementSteps.listIterator();
        while (steps.hasNext()) {
            final Step source = steps.next();
            Step replacement = source;
            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 = 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
                    replacement = new Step.Builder().createFrom(source).connection(newConnection).build();
                }
                // Prune Connector, nix actions. The action in use is on the Step
                Connector prunedConnector = new Connector.Builder().createFrom(replacement.getConnection().get().getConnector().get()).actions(new ArrayList<>()).icon(null).build();
                // Replace with the new 'pruned' connector
                Connection prunedConnection = new Connection.Builder().createFrom(connection).connector(prunedConnector).icon(null).build();
                // Replace with the new 'pruned' step
                replacement = new Step.Builder().createFrom(source).connection(prunedConnection).build();
            }
            // 
            // If a template step then update it to ensure it
            // has the correct dependencies
            // 
            steps.set(TemplateStepLanguage.updateStep(replacement));
        }
        final Flow.Builder replacementFlowBuilder = flow.builder().createFrom(flow).steps(replacementSteps);
        flows.set(replacementFlowBuilder.build());
        // is fully implemented and schedule options are set on integration.
        if (!flow.getScheduler().isPresent()) {
            final Step firstStep = replacementSteps.get(0);
            final Map<String, String> properties = new HashMap<>(firstStep.getConfiguredProperties());
            String type = properties.remove("schedulerType");
            final String expr = properties.remove("schedulerExpression");
            if (StringUtils.isNotEmpty(expr)) {
                if (StringUtils.isEmpty(type)) {
                    type = "timer";
                }
                final Scheduler scheduler = new Scheduler.Builder().type(Scheduler.Type.valueOf(type)).expression(expr).build();
                final Flow replacementFlow = replacementFlowBuilder.scheduler(scheduler).build();
                flows.set(replacementFlow);
            }
            // Replace first step so underlying connector won't fail uri param
            // validation if schedule options were set.
            steps.set(new Step.Builder().createFrom(firstStep).configuredProperties(properties).build());
        }
    }
    return new Integration.Builder().createFrom(integration).name(sanitizeIntegrationName).flows(replacementFlows).build();
}
Also used : Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) HashMap(java.util.HashMap) Scheduler(io.syndesis.common.model.integration.Scheduler) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) Flow(io.syndesis.common.model.integration.Flow) SuppressFBWarnings(io.syndesis.common.util.SuppressFBWarnings)

Example 28 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class ProjectGenerator method addPropertiesFrom.

private static void addPropertiesFrom(final Properties properties, final Integration integration, final IntegrationResourceManager resourceManager) {
    final List<Flow> flows = integration.getFlows();
    for (int flowIndex = 0; flowIndex < flows.size(); flowIndex++) {
        final Flow flow = flows.get(flowIndex);
        final List<Step> steps = flow.getSteps();
        for (int stepIndex = 0; stepIndex < steps.size(); stepIndex++) {
            final Step step = steps.get(stepIndex);
            // Check if a step is of supported type.
            if (StepKind.endpoint != step.getStepKind()) {
                continue;
            }
            final Optional<Action> maybeAction = step.getAction();
            final boolean isConnectorAction = maybeAction.map(a -> a instanceof ConnectorAction).orElse(Boolean.FALSE);
            final boolean usesConnection = step.getConnection().isPresent();
            // Check if a step has the required options
            if (!isConnectorAction || !usesConnection) {
                continue;
            }
            final Connection connection = step.getConnection().get();
            final Connector connector = resourceManager.loadConnector(connection).orElseThrow(() -> new IllegalArgumentException("No connector with id: " + connection.getConnectorId()));
            final ConnectorAction action = (ConnectorAction) maybeAction.get();
            final ConnectorDescriptor actionDescriptor = action.getDescriptor();
            final Optional<String> maybeComponentScheme = Optionals.first(actionDescriptor.getComponentScheme(), connector.getComponentScheme());
            boolean hasComponentScheme = maybeComponentScheme.isPresent();
            if (!hasComponentScheme) {
                throw new UnsupportedOperationException("Old style of connectors from camel-connector are not supported anymore, please be sure that integration json satisfy connector.getComponentScheme().isPresent() || descriptor.getComponentScheme().isPresent()");
            }
            // Grab the component scheme from the component descriptor or
            // from the connector
            final String componentScheme = maybeComponentScheme.get();
            final Map<String, ConfigurationProperty> configurationProperties = CollectionsUtils.aggregate(connector.getProperties(), action.getProperties());
            // https://github.com/syndesisio/syndesis/issues/1713
            for (Map.Entry<String, ConfigurationProperty> entry : configurationProperties.entrySet()) {
                final String propertyName = entry.getKey();
                final ConfigurationProperty configurationProperty = entry.getValue();
                final String defaultValue = Objects.toString(configurationProperty.getDefaultValue(), null);
                boolean isSecret = connector.isSecret(propertyName) || action.isSecret(propertyName);
                if (Strings.isEmptyOrBlank(defaultValue) && isSecret) {
                    addDecryptedKeyProperty(resourceManager, properties, flowIndex, stepIndex, componentScheme, propertyName, defaultValue);
                }
            }
            addConfiguredPropertiesFrom(connector, action, connection, resourceManager, properties, flowIndex, stepIndex, componentScheme);
            addConfiguredPropertiesFrom(connector, action, step, resourceManager, properties, flowIndex, stepIndex, componentScheme);
        }
    }
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) OpenApi(io.syndesis.common.model.openapi.OpenApi) IntegrationErrorHandler(io.syndesis.integration.api.IntegrationErrorHandler) 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) JsonUtils(io.syndesis.common.util.json.JsonUtils) 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) Library(io.apicurio.datamodels.Library) Set(java.util.Set) Connector(io.syndesis.common.model.connection.Connector) Collectors(java.util.stream.Collectors) Flow(io.syndesis.common.model.integration.Flow) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) ProjectGeneratorHelper.addResource(io.syndesis.integration.project.generator.ProjectGeneratorHelper.addResource) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Optional(java.util.Optional) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) MavenGav(io.syndesis.integration.project.generator.mvn.MavenGav) PomContext(io.syndesis.integration.project.generator.mvn.PomContext) Action(io.syndesis.common.model.action.Action) Step(io.syndesis.common.model.integration.Step) ResourceIdentifier(io.syndesis.common.model.ResourceIdentifier) Kind(io.syndesis.common.model.Kind) RestDslGenerator(org.apache.camel.generator.openapi.RestDslGenerator) 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) Document(io.apicurio.datamodels.core.models.Document) 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) 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) OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) InputStream(java.io.InputStream) Strings(io.syndesis.common.util.Strings) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Action(io.syndesis.common.model.action.Action) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) Flow(io.syndesis.common.model.integration.Flow) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Map(java.util.Map)

Example 29 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class ProjectGeneratorTest method testGenerateProject.

// ***************************
// Tests
// ***************************
@Test
public void testGenerateProject() throws Exception {
    TestResourceManager resourceManager = new TestResourceManager();
    Integration integration = resourceManager.newIntegration(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id("timer-connection").connector(TestConstants.TIMER_CONNECTOR).build()).putConfiguredProperty("period", "5000").action(TestConstants.PERIODIC_TIMER_ACTION).build(), new Step.Builder().stepKind(StepKind.mapper).putConfiguredProperty("atlasmapping", "{}").build(), new Step.Builder().stepKind(StepKind.ruleFilter).putConfiguredProperty("predicate", "AND").putConfiguredProperty("rules", "[{ \"path\": \"in.header.counter\", \"op\": \">\", \"value\": \"10\" }]").build(), new Step.Builder().stepKind(StepKind.extension).extension(new Extension.Builder().id("my-extension-1").extensionId("my-extension-1").addDependency(Dependency.maven("org.slf4j:slf4j-api:1.7.11")).addDependency(Dependency.maven("org.slf4j:slf4j-simple:1.7.11")).addDependency(Dependency.maven("org.apache.camel:camel-spring-boot-starter:2.10.0")).build()).putConfiguredProperty("key-1", "val-1").putConfiguredProperty("key-2", "val-2").action(new StepAction.Builder().id("my-extension-1-action-1").addTag("expose").descriptor(new StepDescriptor.Builder().kind(StepAction.Kind.ENDPOINT).entrypoint("direct:extension").build()).build()).build(), new Step.Builder().stepKind(StepKind.extension).extension(new Extension.Builder().id("my-extension-2").extensionId("my-extension-2").build()).putConfiguredProperty("key-1", "val-1").putConfiguredProperty("key-2", "val-2").action(new StepAction.Builder().id("my-extension-1-action-1").addTag("expose").descriptor(new StepDescriptor.Builder().kind(StepAction.Kind.BEAN).entrypoint("com.example.MyExtension::action").build()).build()).build(), new Step.Builder().stepKind(StepKind.extension).extension(new Extension.Builder().id("my-extension-3").extensionId("my-extension-3").build()).putConfiguredProperty("key-1", "val-1").putConfiguredProperty("key-2", "val-2").action(new StepAction.Builder().id("my-extension-2-action-1").descriptor(new StepDescriptor.Builder().kind(StepAction.Kind.STEP).entrypoint("com.example.MyStep").build()).build()).build(), new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().id("http-connection").connector(TestConstants.HTTP_CONNECTOR).build()).putConfiguredProperty("httpUri", "http://localhost:8080/hello").putConfiguredProperty("username", "admin").putConfiguredProperty("password", "admin").putConfiguredProperty("token", "mytoken").action(TestConstants.HTTP_GET_ACTION).build());
    ProjectGeneratorConfiguration configuration = new ProjectGeneratorConfiguration();
    configuration.getTemplates().setOverridePath(this.basePath);
    configuration.getTemplates().getAdditionalResources().addAll(this.additionalResources);
    configuration.setSecretMaskingEnabled(true);
    Path runtimeDir = generate(integration, configuration, resourceManager);
    assertFileContents(configuration, runtimeDir.resolve("pom.xml"), "pom.xml");
    assertFileContentsJson(configuration, runtimeDir.resolve("src/main/resources/syndesis/integration/integration.json"), "integration.json");
    assertFileContents(configuration, runtimeDir.resolve("src/main/resources/application.properties"), "application.properties");
    assertFileContents(configuration, runtimeDir.resolve("src/main/resources/loader.properties"), "loader.properties");
    assertFileContents(configuration, runtimeDir.resolve(".s2i/bin/assemble"), "assemble");
    assertFileContents(configuration, runtimeDir.resolve("prometheus-config.yml"), "prometheus-config.yml");
    assertThat(runtimeDir.resolve("extensions/my-extension-1.jar")).exists();
    assertThat(runtimeDir.resolve("extensions/my-extension-2.jar")).exists();
    assertThat(runtimeDir.resolve("extensions/my-extension-3.jar")).exists();
    assertThat(runtimeDir.resolve("src/main/resources/mapping-flow-0-step-1.json")).exists();
    // lets validate configuration when activity tracing is enabled.
    try (Stream<Path> stream = Files.walk(testFolder.getRoot().toPath().resolve("integration-project"))) {
        stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
    }
    configuration.setActivityTracing(true);
    runtimeDir = generate(integration, configuration, resourceManager);
    assertFileContents(configuration, runtimeDir.resolve("src/main/resources/application.properties"), "application-tracing.properties");
    assertThat(errors).isEmpty();
}
Also used : Path(java.nio.file.Path) Integration(io.syndesis.common.model.integration.Integration) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) Extension(io.syndesis.common.model.extension.Extension) StepAction(io.syndesis.common.model.action.StepAction) File(java.io.File) Test(org.junit.Test)

Example 30 with Connection

use of io.syndesis.common.model.connection.Connection in project syndesis by syndesisio.

the class ConnectionHandler method list.

@Override
public ListResult<ConnectionOverview> list(int page, int perPage) {
    DataManager dataManager = getDataManager();
    final ListResult<Connection> connectionResults = dataManager.fetchAll(Connection.class, new PaginationFilter<>(new PaginationOptionsFromQueryParams(page, perPage)));
    final List<Connection> connections = connectionResults.getItems();
    final List<ConnectionOverview> overviews = new ArrayList<>(connectionResults.getTotalCount());
    for (Connection connection : connections) {
        final String id = connection.getId().get();
        final ConnectionOverview.Builder builder = new ConnectionOverview.Builder().createFrom(connection);
        // set the connector
        DataManagerSupport.fetch(dataManager, Connector.class, connection.getConnectorId()).ifPresent(builder::connector);
        // set the board
        DataManagerSupport.fetchBoard(dataManager, ConnectionBulletinBoard.class, id).ifPresent(builder::board);
        overviews.add(builder.build());
    }
    return ListResult.of(overviews);
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectionOverview(io.syndesis.common.model.connection.ConnectionOverview) Connection(io.syndesis.common.model.connection.Connection) ArrayList(java.util.ArrayList) DataManager(io.syndesis.server.dao.manager.DataManager) PaginationOptionsFromQueryParams(io.syndesis.server.endpoint.v1.operations.PaginationOptionsFromQueryParams) ConnectionBulletinBoard(io.syndesis.common.model.bulletin.ConnectionBulletinBoard)

Aggregations

Connection (io.syndesis.common.model.connection.Connection)111 Connector (io.syndesis.common.model.connection.Connector)65 Test (org.junit.Test)48 Step (io.syndesis.common.model.integration.Step)40 Integration (io.syndesis.common.model.integration.Integration)38 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)26 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)26 List (java.util.List)24 HashMap (java.util.HashMap)21 Action (io.syndesis.common.model.action.Action)18 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)18 ArrayList (java.util.ArrayList)17 Map (java.util.Map)16 IOException (java.io.IOException)14 InputStream (java.io.InputStream)14 IntegrationDeployment (io.syndesis.common.model.integration.IntegrationDeployment)13 StepDefinition (io.syndesis.qe.bdd.entities.StepDefinition)12 DataManager (io.syndesis.server.dao.manager.DataManager)11 Given (cucumber.api.java.en.Given)10 Flow (io.syndesis.common.model.integration.Flow)10