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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations