Search in sources :

Example 1 with LeveledMessage

use of io.syndesis.common.model.bulletin.LeveledMessage in project syndesis by syndesisio.

the class IntegrationUpdateHandler method compute.

@SuppressWarnings({ "PMD.ExcessiveMethodLength", "PMD.NPathComplexity" })
@Override
protected List<IntegrationBulletinBoard> compute(ChangeEvent event) {
    final List<IntegrationBulletinBoard> boards = new ArrayList<>();
    final DataManager dataManager = getDataManager();
    final List<Integration> integrations = dataManager.fetchAll(Integration.class).getItems();
    final List<LeveledMessage> messages = new ArrayList<>();
    for (int i = 0; i < integrations.size(); i++) {
        final Integration integration = integrations.get(i);
        final List<Step> steps = integration.getSteps();
        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).updatedAt(System.currentTimeMillis());
        } else {
            builder = new IntegrationBulletinBoard.Builder().id(KeyGenerator.createKey()).targetResourceId(id).createdAt(System.currentTimeMillis());
        }
        // reuse messages
        messages.clear();
        // to the resources the properties apply to
        for (int s = 0; s < steps.size(); s++) {
            final int index = s;
            final Step step = steps.get(s);
            final Supplier<LeveledMessage.Builder> supplier = () -> new LeveledMessage.Builder().putMetadata("step", step.getId().orElse("step-" + index));
            if (!step.getAction().isPresent()) {
                continue;
            }
            // **********************
            // Integration
            // **********************
            messages.addAll(computeValidatorMessages(supplier, integration));
            // **********************
            // Extension
            // **********************
            step.getAction().filter(StepAction.class::isInstance).map(StepAction.class::cast).ifPresent(action -> {
                Extension extension = step.getExtension().orElse(null);
                if (extension == null) {
                    return;
                }
                // 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.
                Set<String> ids = dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", extension.getExtensionId(), "status", Extension.Status.Installed.name());
                if (ids.size() != 1) {
                    return;
                }
                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 {
                    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
            // **********************
            step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).ifPresent(action -> {
                Connection connection = step.getConnection().orElse(null);
                if (connection == null) {
                    return;
                }
                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 {
                    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 {
                        Map<String, String> configuredProperties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties());
                        messages.addAll(computeValidatorMessages(supplier, connection));
                        messages.addAll(computePropertiesDiffMessages(supplier, action.getProperties(), newAction.getProperties()));
                        messages.addAll(computeMissingMandatoryPropertiesMessages(supplier, newAction.getProperties(), configuredProperties));
                        messages.addAll(computeSecretsUpdateMessages(supplier, newAction.getProperties(), configuredProperties));
                    }
                }
            });
        }
        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);
        boards.add(builder.build());
    }
    return boards;
}
Also used : Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) 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) Connection(io.syndesis.common.model.connection.Connection) DataManager(io.syndesis.server.dao.manager.DataManager) Step(io.syndesis.common.model.integration.Step) Extension(io.syndesis.common.model.extension.Extension) StepAction(io.syndesis.common.model.action.StepAction) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage)

Example 2 with LeveledMessage

use of io.syndesis.common.model.bulletin.LeveledMessage in project syndesis by syndesisio.

the class AbstractResourceUpdateHandler method computePropertiesDiffMessages.

// *********************
// Simple Bulletin
// *********************
protected List<LeveledMessage> computePropertiesDiffMessages(Supplier<LeveledMessage.Builder> supplier, Map<String, ConfigurationProperty> left, Map<String, ConfigurationProperty> right) {
    final List<LeveledMessage> messages = new ArrayList<>();
    final MapDifference<String, ConfigurationProperty> diff = Maps.difference(left, right);
    for (Map.Entry<String, MapDifference.ValueDifference<ConfigurationProperty>> entry : diff.entriesDiffering().entrySet()) {
        final MapDifference.ValueDifference<ConfigurationProperty> value = entry.getValue();
        final ConfigurationProperty leftValue = value.leftValue();
        final ConfigurationProperty rightValue = value.rightValue();
        // Special handling because of dynamic metadata
        if (!equals(leftValue, rightValue)) {
            messages.add(supplier.get().level(LeveledMessage.Level.INFO).code(LeveledMessage.Code.SYNDESIS001).build());
            break;
        }
    }
    if (!diff.entriesOnlyOnLeft().isEmpty() || !diff.entriesOnlyOnRight().isEmpty()) {
        messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS002).build());
    }
    return messages;
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) MapDifference(com.google.common.collect.MapDifference) ArrayList(java.util.ArrayList) Map(java.util.Map) LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage)

Example 3 with LeveledMessage

use of io.syndesis.common.model.bulletin.LeveledMessage in project syndesis by syndesisio.

the class ConnectionUpdateHandler method computeBoard.

private ConnectionBulletinBoard computeBoard(Connection connection, Connector oldConnector, Connector newConnector) {
    final DataManager dataManager = getDataManager();
    final String id = connection.getId().get();
    final ConnectionBulletinBoard board = dataManager.fetchByPropertyValue(ConnectionBulletinBoard.class, "targetResourceId", id).orElse(null);
    final ConnectionBulletinBoard.Builder builder;
    if (board != null) {
        builder = new ConnectionBulletinBoard.Builder().createFrom(board).updatedAt(System.currentTimeMillis());
    } else {
        builder = new ConnectionBulletinBoard.Builder().id(KeyGenerator.createKey()).targetResourceId(id).createdAt(System.currentTimeMillis());
    }
    List<LeveledMessage> messages = new ArrayList<>();
    messages.addAll(computeValidatorMessages(LeveledMessage.Builder::new, connection));
    messages.addAll(computePropertiesDiffMessages(LeveledMessage.Builder::new, oldConnector.getProperties(), newConnector.getProperties()));
    messages.addAll(computeMissingMandatoryPropertiesMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties()));
    messages.addAll(computeSecretsUpdateMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties()));
    builder.errors(countMessagesWithLevel(LeveledMessage.Level.ERROR, messages));
    builder.warnings(countMessagesWithLevel(LeveledMessage.Level.WARN, messages));
    builder.notices(countMessagesWithLevel(LeveledMessage.Level.INFO, messages));
    builder.putMetadata("connector-id", newConnector.getId().get());
    builder.putMetadata("connector-version-latest", Integer.toString(newConnector.getVersion()));
    builder.putMetadata("connector-version-connection", Integer.toString(oldConnector.getVersion()));
    builder.messages(messages);
    return builder.build();
}
Also used : ArrayList(java.util.ArrayList) DataManager(io.syndesis.server.dao.manager.DataManager) ConnectionBulletinBoard(io.syndesis.common.model.bulletin.ConnectionBulletinBoard) LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage)

Aggregations

LeveledMessage (io.syndesis.common.model.bulletin.LeveledMessage)3 ArrayList (java.util.ArrayList)3 DataManager (io.syndesis.server.dao.manager.DataManager)2 MapDifference (com.google.common.collect.MapDifference)1 Action (io.syndesis.common.model.action.Action)1 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)1 StepAction (io.syndesis.common.model.action.StepAction)1 ConnectionBulletinBoard (io.syndesis.common.model.bulletin.ConnectionBulletinBoard)1 IntegrationBulletinBoard (io.syndesis.common.model.bulletin.IntegrationBulletinBoard)1 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)1 Connection (io.syndesis.common.model.connection.Connection)1 Connector (io.syndesis.common.model.connection.Connector)1 Extension (io.syndesis.common.model.extension.Extension)1 Integration (io.syndesis.common.model.integration.Integration)1 Step (io.syndesis.common.model.integration.Step)1 Map (java.util.Map)1