@Test public void shouldComputeStaleIntegrationAndDeployment() { final IntegrationUpdateHandler updateHandler = new IntegrationUpdateHandler(dataManager, null, validator); ChangeEvent event = getEventFromChangedIntegration(false); List<IntegrationBulletinBoard> boards = updateHandler.compute(event); assertFalse(boards.isEmpty()); assertEquals(1, boards.size()); IntegrationBulletinBoard board = boards.get(0); List<LeveledMessage> messages = board.getMessages(); assertFalse(messages.isEmpty()); assertEquals(1, messages.size()); messages.forEach(message -> { switch (message.getCode()) { case SYNDESIS011: Optional<String> detail = message.getDetail(); assertTrue(detail.isPresent()); String msg = detail.get(); assertEquals( "Reason: 'name' is different" + NEW_LINE + TAB + "=> 'SQL Connector'" + NEW_LINE + TAB + "=> 'SQL Connector_new'" + NEW_LINE + "Context: Connection('PostgresDB') / Connector('SQL Connector')" + NEW_LINE, msg); break; case SYNDESIS012: break; default: fail("Expecting syndesis codes 11 & 12 only"); } }); }
@SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.NPathComplexity"}) @Override protected List<IntegrationBulletinBoard> compute(final ChangeEvent event) { final List<IntegrationBulletinBoard> boards = new ArrayList<>(); final DataManager dataManager = getDataManager(); 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()); } 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(); 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; } final TargetWithDomain<Integration> intTarget = new IntegrationWithDomain(integration, allIntegrations); messages.addAll(computeValidatorMessages(supplier, intTarget)); step.getAction().filter(StepAction.class::isInstance).map(StepAction.class::cast).ifPresent(action -> { if (!step.getExtension().isPresent()) { return; } final Extension extension = step.getExtension().get(); final Set<String> ids = dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", extension.getExtensionId(), "status", Extension.Status.Installed.name()); if (ids.size() == 0) { messages.add( supplier.get() .level(LeveledMessage.Level.WARN) .code(LeveledMessage.Code.SYNDESIS004) .build()); return; } 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())); } } }); 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))) { dataManager.update(dbConnection); } if (connection.getId().isPresent() && (!connection.getConnector().isPresent() || !connection.getConnector().get().getTags().contains("dynamic"))) { 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)); } } }); } } 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()); } messages.clear(); } return boards; }
IntegrationUpdateHandler extends AbstractResourceUpdateHandler<IntegrationBulletinBoard> { @SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.NPathComplexity"}) @Override protected List<IntegrationBulletinBoard> compute(final ChangeEvent event) { final List<IntegrationBulletinBoard> boards = new ArrayList<>(); final DataManager dataManager = getDataManager(); 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()); } 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(); 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; } final TargetWithDomain<Integration> intTarget = new IntegrationWithDomain(integration, allIntegrations); messages.addAll(computeValidatorMessages(supplier, intTarget)); step.getAction().filter(StepAction.class::isInstance).map(StepAction.class::cast).ifPresent(action -> { if (!step.getExtension().isPresent()) { return; } final Extension extension = step.getExtension().get(); final Set<String> ids = dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", extension.getExtensionId(), "status", Extension.Status.Installed.name()); if (ids.size() == 0) { messages.add( supplier.get() .level(LeveledMessage.Level.WARN) .code(LeveledMessage.Code.SYNDESIS004) .build()); return; } 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())); } } }); 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))) { dataManager.update(dbConnection); } if (connection.getId().isPresent() && (!connection.getConnector().isPresent() || !connection.getConnector().get().getTags().contains("dynamic"))) { 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)); } } }); } } 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()); } messages.clear(); } return boards; } }
IntegrationUpdateHandler extends AbstractResourceUpdateHandler<IntegrationBulletinBoard> { @SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.NPathComplexity"}) @Override protected List<IntegrationBulletinBoard> compute(final ChangeEvent event) { final List<IntegrationBulletinBoard> boards = new ArrayList<>(); final DataManager dataManager = getDataManager(); 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()); } 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(); 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; } final TargetWithDomain<Integration> intTarget = new IntegrationWithDomain(integration, allIntegrations); messages.addAll(computeValidatorMessages(supplier, intTarget)); step.getAction().filter(StepAction.class::isInstance).map(StepAction.class::cast).ifPresent(action -> { if (!step.getExtension().isPresent()) { return; } final Extension extension = step.getExtension().get(); final Set<String> ids = dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", extension.getExtensionId(), "status", Extension.Status.Installed.name()); if (ids.size() == 0) { messages.add( supplier.get() .level(LeveledMessage.Level.WARN) .code(LeveledMessage.Code.SYNDESIS004) .build()); return; } 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())); } } }); 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))) { dataManager.update(dbConnection); } if (connection.getId().isPresent() && (!connection.getConnector().isPresent() || !connection.getConnector().get().getTags().contains("dynamic"))) { 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)); } } }); } } 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()); } messages.clear(); } return boards; } IntegrationUpdateHandler(final DataManager dataManager, final EncryptionComponent encryptionComponent, final Validator validator); }
IntegrationUpdateHandler extends AbstractResourceUpdateHandler<IntegrationBulletinBoard> { @SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.NPathComplexity"}) @Override protected List<IntegrationBulletinBoard> compute(final ChangeEvent event) { final List<IntegrationBulletinBoard> boards = new ArrayList<>(); final DataManager dataManager = getDataManager(); 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()); } 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(); 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; } final TargetWithDomain<Integration> intTarget = new IntegrationWithDomain(integration, allIntegrations); messages.addAll(computeValidatorMessages(supplier, intTarget)); step.getAction().filter(StepAction.class::isInstance).map(StepAction.class::cast).ifPresent(action -> { if (!step.getExtension().isPresent()) { return; } final Extension extension = step.getExtension().get(); final Set<String> ids = dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", extension.getExtensionId(), "status", Extension.Status.Installed.name()); if (ids.size() == 0) { messages.add( supplier.get() .level(LeveledMessage.Level.WARN) .code(LeveledMessage.Code.SYNDESIS004) .build()); return; } 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())); } } }); 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))) { dataManager.update(dbConnection); } if (connection.getId().isPresent() && (!connection.getConnector().isPresent() || !connection.getConnector().get().getTags().contains("dynamic"))) { 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)); } } }); } } 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()); } messages.clear(); } return boards; } IntegrationUpdateHandler(final DataManager dataManager, final EncryptionComponent encryptionComponent, final Validator validator); @Override boolean canHandle(final ChangeEvent event); }
IntegrationUpdateHandler extends AbstractResourceUpdateHandler<IntegrationBulletinBoard> { @SuppressWarnings({"PMD.ExcessiveMethodLength", "PMD.NPathComplexity"}) @Override protected List<IntegrationBulletinBoard> compute(final ChangeEvent event) { final List<IntegrationBulletinBoard> boards = new ArrayList<>(); final DataManager dataManager = getDataManager(); 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()); } 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(); 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; } final TargetWithDomain<Integration> intTarget = new IntegrationWithDomain(integration, allIntegrations); messages.addAll(computeValidatorMessages(supplier, intTarget)); step.getAction().filter(StepAction.class::isInstance).map(StepAction.class::cast).ifPresent(action -> { if (!step.getExtension().isPresent()) { return; } final Extension extension = step.getExtension().get(); final Set<String> ids = dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", extension.getExtensionId(), "status", Extension.Status.Installed.name()); if (ids.size() == 0) { messages.add( supplier.get() .level(LeveledMessage.Level.WARN) .code(LeveledMessage.Code.SYNDESIS004) .build()); return; } 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())); } } }); 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))) { dataManager.update(dbConnection); } if (connection.getId().isPresent() && (!connection.getConnector().isPresent() || !connection.getConnector().get().getTags().contains("dynamic"))) { 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)); } } }); } } 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()); } messages.clear(); } return boards; } IntegrationUpdateHandler(final DataManager dataManager, final EncryptionComponent encryptionComponent, final Validator validator); @Override boolean canHandle(final ChangeEvent event);  }