Search in sources :

Example 36 with Connection

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

the class IntegrationUpdateHandler method compute.

@SuppressWarnings({ "PMD.ExcessiveMethodLength", "PMD.NPathComplexity" })
@Override
protected List<IntegrationBulletinBoard> compute(final ChangeEvent event) {
    final List<IntegrationBulletinBoard> boards = new ArrayList<>();
    final DataManager dataManager = getDataManager();
    /*
         * Assemble all the artifact collections that are going to be checked in
         * the data manager. This does it once rather than repeatedly in the
         * various loops since getting stuff from the DataManager is quite
         * expensive and slow.
         *
         * see #3717
         */
    final List<Integration> integrations = dataManager.fetchAll(Integration.class).getItems();
    final List<IntegrationDeployment> deployments = dataManager.fetchAll(IntegrationDeployment.class).getItems();
    final Set<Integration> deployedIintegrations = deployments.stream().map(d -> d.getSpec()).collect(Collectors.toSet());
    final List<Connection> connections = dataManager.fetchAll(Connection.class).getItems();
    final Collection<Integration> allIntegrations = new ArrayList<>(integrations.size() + deployedIintegrations.size());
    allIntegrations.addAll(integrations);
    allIntegrations.addAll(deployedIintegrations);
    final List<LeveledMessage> messages = new ArrayList<>();
    for (final Integration integration : integrations) {
        final String id = integration.getId().get();
        final IntegrationBulletinBoard board = dataManager.fetchByPropertyValue(IntegrationBulletinBoard.class, "targetResourceId", id).orElse(null);
        final IntegrationBulletinBoard.Builder builder;
        if (board != null) {
            builder = new IntegrationBulletinBoard.Builder().createFrom(board);
        } else {
            builder = new IntegrationBulletinBoard.Builder().id(KeyGenerator.createKey()).targetResourceId(id).createdAt(System.currentTimeMillis());
        }
        // reuse messages
        messages.clear();
        final List<Flow> flows = integration.getFlows();
        for (int f = 0; f < flows.size(); f++) {
            final Flow flow = flows.get(f);
            final String flowId = flow.getId().orElse("flow-" + f);
            final List<Step> steps = flow.getSteps();
            // to the resources the properties apply to
            for (int s = 0; s < steps.size(); s++) {
                final Step step = steps.get(s);
                final String stepId = step.getId().orElse("step-" + s);
                final Supplier<LeveledMessage.Builder> supplier = () -> new LeveledMessage.Builder().putMetadata("flow", flowId).putMetadata("step", stepId);
                if (!step.getAction().isPresent()) {
                    continue;
                }
                // **********************
                // Integration
                // **********************
                final TargetWithDomain<Integration> intTarget = new IntegrationWithDomain(integration, allIntegrations);
                messages.addAll(computeValidatorMessages(supplier, intTarget));
                // **********************
                // Extension Action
                // **********************
                step.getAction().filter(StepAction.class::isInstance).map(StepAction.class::cast).ifPresent(action -> {
                    if (!step.getExtension().isPresent()) {
                        return;
                    }
                    final Extension extension = step.getExtension().get();
                    // When an extension is updated a new entity is written
                    // to the db
                    // so we can't simply lookup by ID but whe need to
                    // search for the
                    // latest installed extension.
                    // 
                    // This fetchIdsByPropertyValue is not really optimized
                    // as it
                    // ends up in multiple statements sent to the db, we
                    // maybe need
                    // to have a better support for this use-case.
                    final Set<String> ids = dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", extension.getExtensionId(), "status", Extension.Status.Installed.name());
                    // has been deleted.
                    if (ids.size() == 0) {
                        messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS004).build());
                        return;
                    }
                    // phase
                    if (ids.size() > 1) {
                        messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS010).build());
                        return;
                    }
                    final Extension newExtension = dataManager.fetch(Extension.class, ids.iterator().next());
                    if (newExtension == null) {
                        messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS004).build());
                    } else {
                        final Action newAction = newExtension.findActionById(action.getId().get()).orElse(null);
                        if (newAction == null) {
                            messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS005).build());
                        } else {
                            messages.addAll(computePropertiesDiffMessages(supplier, action.getProperties(), newAction.getProperties()));
                            messages.addAll(computeMissingMandatoryPropertiesMessages(supplier, newAction.getProperties(), step.getConfiguredProperties()));
                            messages.addAll(computeSecretsUpdateMessages(supplier, newAction.getProperties(), step.getConfiguredProperties()));
                        }
                    }
                });
                // **********************
                // Connector Action
                // **********************
                step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).ifPresent(action -> {
                    if (!step.getConnection().isPresent()) {
                        return;
                    }
                    final Connection connection = step.getConnection().get();
                    final Connection dbConnection = getDataManager().fetch(Connection.class, connection.getId().get());
                    if (dbConnection != null && Kind.Integration.equals(event.getKind().map(Kind::from).orElse(null))) {
                        /*
                             * An integration event will create, delete or
                             * update it. This has an impact on associated
                             * connections in that their augmented properties,
                             * ie. those appended by the {@link
                             * ConnectionHandler#augmentedWithUsage}, eg. uses,
                             * need to be re-synced by clients. In order to do
                             * that, a change event must be broadcast to all
                             * clients and a call to update() provides such an
                             * event.
                             *
                             * see #4008
                             */
                        dataManager.update(dbConnection);
                    }
                    if (connection.getId().isPresent() && (!connection.getConnector().isPresent() || !connection.getConnector().get().getTags().contains("dynamic"))) {
                        // 
                        // Compare the connection in the draft integration's
                        // step
                        // with the connection from the data manager and log
                        // the
                        // result using the given message codes
                        // 
                        compareConnection(connection, dbConnection, messages, supplier, LeveledMessage.Code.SYNDESIS009, LeveledMessage.Code.SYNDESIS011);
                    }
                    final Connector newConnector = dataManager.fetch(Connector.class, connection.getConnectorId());
                    if (newConnector == null) {
                        messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS003).build());
                    } else {
                        final Action newAction = newConnector.findActionById(action.getId().get()).orElse(null);
                        if (newAction == null) {
                            messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS005).build());
                        } else {
                            final Map<String, String> configuredProperties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties());
                            final ConnectionWithDomain connTarget = new ConnectionWithDomain(connection, connections);
                            messages.addAll(computeValidatorMessages(supplier, connTarget));
                            messages.addAll(computePropertiesDiffMessages(supplier, action.getProperties(), newAction.getProperties()));
                            messages.addAll(computeMissingMandatoryPropertiesMessages(supplier, newAction.getProperties(), configuredProperties));
                            messages.addAll(computeSecretsUpdateMessages(supplier, newAction.getProperties(), configuredProperties));
                        }
                    }
                });
            }
        }
        // **********************
        // Integration Deployments
        // **********************
        messages.addAll(computeDeploymentDifferences(integration, deployments));
        builder.errors(countMessagesWithLevel(LeveledMessage.Level.ERROR, messages));
        builder.warnings(countMessagesWithLevel(LeveledMessage.Level.WARN, messages));
        builder.notices(countMessagesWithLevel(LeveledMessage.Level.INFO, messages));
        builder.putMetadata("integration-id", id);
        builder.putMetadata("integration-version", Integer.toString(integration.getVersion()));
        builder.messages(messages);
        final IntegrationBulletinBoard updated = builder.build();
        if (!updated.equals(board)) {
            boards.add(builder.updatedAt(System.currentTimeMillis()).build());
        }
        // reuse messages
        messages.clear();
    }
    return boards;
}
Also used : ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Arrays(java.util.Arrays) Action(io.syndesis.common.model.action.Action) KeyGenerator(io.syndesis.common.util.KeyGenerator) Step(io.syndesis.common.model.integration.Step) Kind(io.syndesis.common.model.Kind) IntegrationBulletinBoard(io.syndesis.common.model.bulletin.IntegrationBulletinBoard) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Equivalencer(io.syndesis.common.model.support.Equivalencer) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) CollectionsUtils(io.syndesis.common.util.CollectionsUtils) DataManager(io.syndesis.server.dao.manager.DataManager) Integration(io.syndesis.common.model.integration.Integration) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage) StepAction(io.syndesis.common.model.action.StepAction) Collection(java.util.Collection) Set(java.util.Set) Validator(javax.validation.Validator) Connector(io.syndesis.common.model.connection.Connector) Extension(io.syndesis.common.model.extension.Extension) Collectors(java.util.stream.Collectors) Flow(io.syndesis.common.model.integration.Flow) List(java.util.List) TargetWithDomain(io.syndesis.common.model.validation.TargetWithDomain) IntegrationWithDomain(io.syndesis.common.model.validation.integration.IntegrationWithDomain) Optional(java.util.Optional) IntegrationDeploymentState(io.syndesis.common.model.integration.IntegrationDeploymentState) ChangeEvent(io.syndesis.common.model.ChangeEvent) ConnectionWithDomain(io.syndesis.common.model.validation.connection.ConnectionWithDomain) Collections(java.util.Collections) Connector(io.syndesis.common.model.connection.Connector) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Action(io.syndesis.common.model.action.Action) StepAction(io.syndesis.common.model.action.StepAction) IntegrationBulletinBoard(io.syndesis.common.model.bulletin.IntegrationBulletinBoard) ArrayList(java.util.ArrayList) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Step(io.syndesis.common.model.integration.Step) ConnectionWithDomain(io.syndesis.common.model.validation.connection.ConnectionWithDomain) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Integration(io.syndesis.common.model.integration.Integration) Connection(io.syndesis.common.model.connection.Connection) DataManager(io.syndesis.server.dao.manager.DataManager) IntegrationWithDomain(io.syndesis.common.model.validation.integration.IntegrationWithDomain) Flow(io.syndesis.common.model.integration.Flow) Extension(io.syndesis.common.model.extension.Extension) StepAction(io.syndesis.common.model.action.StepAction) LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage)

Example 37 with Connection

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

the class IntegrationUpdateHandler method computeDeploymentDifferences.

private Collection<? extends LeveledMessage> computeDeploymentDifferences(final Integration integration, final Collection<IntegrationDeployment> allDeployments) {
    final List<IntegrationDeployment> deployments = allDeployments.stream().filter(d -> d.getIntegrationId().equals(integration.getId())).filter(d -> d.getCurrentState().equals(IntegrationDeploymentState.Published)).collect(Collectors.toList());
    if (deployments.isEmpty()) {
        // Nothing to do as no deployments have been published
        return Collections.emptyList();
    }
    final List<LeveledMessage> messages = new ArrayList<>();
    for (final IntegrationDeployment deployment : deployments) {
        final Supplier<LeveledMessage.Builder> supplier = () -> new LeveledMessage.Builder().putMetadata("deployment", deployment.getId().get());
        final Integration deployedInteg = deployment.getSpec();
        // **********************
        // Draft Integration
        // **********************
        final Equivalencer equiv = new Equivalencer();
        if (!equiv.equivalent(integration, deployedInteg)) {
            final String message = equiv.failureMessage();
            messages.add(supplier.get().code(LeveledMessage.Code.SYNDESIS012).level(LeveledMessage.Level.WARN).detail(message).build());
            // 
            continue;
        }
        for (final Step deployedStep : deployedInteg.getSteps()) {
            deployedStep.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).ifPresent(action -> {
                if (!deployedStep.getConnection().isPresent()) {
                    return;
                }
                // 
                // Compare the connection in the deployed integration's
                // step
                // with the connection from the data manager and log the
                // result using the given message codes
                // 
                final Connection connection = deployedStep.getConnection().get();
                final Connection dbConnection = getDataManager().fetch(Connection.class, connection.getId().get());
                compareConnection(connection, dbConnection, messages, supplier, LeveledMessage.Code.SYNDESIS009, LeveledMessage.Code.SYNDESIS012);
            });
        }
    }
    return Collections.unmodifiableList(messages);
}
Also used : ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Arrays(java.util.Arrays) Action(io.syndesis.common.model.action.Action) KeyGenerator(io.syndesis.common.util.KeyGenerator) Step(io.syndesis.common.model.integration.Step) Kind(io.syndesis.common.model.Kind) IntegrationBulletinBoard(io.syndesis.common.model.bulletin.IntegrationBulletinBoard) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Equivalencer(io.syndesis.common.model.support.Equivalencer) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) CollectionsUtils(io.syndesis.common.util.CollectionsUtils) DataManager(io.syndesis.server.dao.manager.DataManager) Integration(io.syndesis.common.model.integration.Integration) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage) StepAction(io.syndesis.common.model.action.StepAction) Collection(java.util.Collection) Set(java.util.Set) Validator(javax.validation.Validator) Connector(io.syndesis.common.model.connection.Connector) Extension(io.syndesis.common.model.extension.Extension) Collectors(java.util.stream.Collectors) Flow(io.syndesis.common.model.integration.Flow) List(java.util.List) TargetWithDomain(io.syndesis.common.model.validation.TargetWithDomain) IntegrationWithDomain(io.syndesis.common.model.validation.integration.IntegrationWithDomain) Optional(java.util.Optional) IntegrationDeploymentState(io.syndesis.common.model.integration.IntegrationDeploymentState) ChangeEvent(io.syndesis.common.model.ChangeEvent) ConnectionWithDomain(io.syndesis.common.model.validation.connection.ConnectionWithDomain) Collections(java.util.Collections) Integration(io.syndesis.common.model.integration.Integration) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Equivalencer(io.syndesis.common.model.support.Equivalencer) Step(io.syndesis.common.model.integration.Step) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage)

Example 38 with Connection

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

the class ConnectionsGeneralSteps method createTwitterConnection.

@Given("^create the TW connection using \"([^\"]*)\" template")
public void createTwitterConnection(String twitterTemplate) {
    final Connector twitterConnector = connectorsEndpoint.get("twitter");
    final Account twitterAccount = accountsDirectory.getAccount(twitterTemplate).get();
    log.info("Template name:  {}", twitterTemplate);
    final Connection twitterConnection = new Connection.Builder().connector(twitterConnector).connectorId(getConnectorId(twitterConnector)).id(RestConstants.getInstance().getTWITTER_CONNECTION_ID()).name("New Fuse QE twitter listen").configuredProperties(TestUtils.map("accessToken", twitterAccount.getProperty("accessToken"), "accessTokenSecret", twitterAccount.getProperty("accessTokenSecret"), "consumerKey", twitterAccount.getProperty("consumerKey"), "consumerSecret", twitterAccount.getProperty("consumerSecret"))).icon("fa-twitter").tags(Arrays.asList("twitter")).build();
    log.info("Creating twitter connection {}", twitterConnection.getName());
    connectionsEndpoint.create(twitterConnection);
}
Also used : Connector(io.syndesis.common.model.connection.Connector) Account(io.syndesis.qe.accounts.Account) S3BucketNameBuilder(io.syndesis.qe.utils.S3BucketNameBuilder) Connection(io.syndesis.common.model.connection.Connection) Given(cucumber.api.java.en.Given)

Example 39 with Connection

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

the class ConnectionsGeneralSteps method createFtpConnection.

@Given("^create the FTP connection using \"([^\"]*)\" template")
public void createFtpConnection(String ftpTemplate) {
    connectionsEndpoint.list().forEach(c -> log.info(c.getName()));
    final Connector ftpConnector = connectorsEndpoint.get("ftp");
    final Account ftpAccount = accountsDirectory.getAccount(ftpTemplate).get();
    log.info("Template name:  {}", ftpTemplate);
    final Connection ftpConnection = new Connection.Builder().connector(ftpConnector).connectorId(getConnectorId(ftpConnector)).id(RestConstants.getInstance().getFTP_CONNECTION_ID()).name("New Fuse QE FTP").configuredProperties(TestUtils.map(// "disconnect", ftpAccount.getProperty("disconnect"),
    "host", ftpAccount.getProperty("host"), // "password", ftpAccount.getProperty("password"),
    "port", ftpAccount.getProperty("port"))).icon("fa-ftp").tags(Arrays.asList("ftp")).build();
    log.info("Creating ftp connection {}", ftpConnection.getName());
    connectionsEndpoint.create(ftpConnection);
}
Also used : Connector(io.syndesis.common.model.connection.Connector) Account(io.syndesis.qe.accounts.Account) S3BucketNameBuilder(io.syndesis.qe.utils.S3BucketNameBuilder) Connection(io.syndesis.common.model.connection.Connection) Given(cucumber.api.java.en.Given)

Example 40 with Connection

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

the class ConnectionsGeneralSteps method createSalesforceConnection.

@Given("^create SF connection")
public void createSalesforceConnection() {
    final Account salesforceAccount = accountsDirectory.getAccount("salesforce").get();
    final Connector salesforceConnector = connectorsEndpoint.get("salesforce");
    final Connection salesforceConnection = new Connection.Builder().connector(salesforceConnector).connectorId(getConnectorId(salesforceConnector)).id(RestConstants.getInstance().getSALESFORCE_CONNECTION_ID()).icon("fa-puzzle-piece").name("New Fuse QE salesforce").configuredProperties(TestUtils.map("clientId", salesforceAccount.getProperty("clientId"), "clientSecret", salesforceAccount.getProperty("clientSecret"), "loginUrl", salesforceAccount.getProperty("loginUrl"), "userName", salesforceAccount.getProperty("userName"), "password", salesforceAccount.getProperty("password"))).tags(Arrays.asList("salesforce")).build();
    log.info("Creating salesforce connection {}", salesforceConnection.getName());
    connectionsEndpoint.create(salesforceConnection);
}
Also used : Account(io.syndesis.qe.accounts.Account) Connector(io.syndesis.common.model.connection.Connector) S3BucketNameBuilder(io.syndesis.qe.utils.S3BucketNameBuilder) Connection(io.syndesis.common.model.connection.Connection) Given(cucumber.api.java.en.Given)

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