Search in sources :

Example 6 with DataManager

use of io.syndesis.server.dao.manager.DataManager 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 7 with DataManager

use of io.syndesis.server.dao.manager.DataManager in project syndesis by syndesisio.

the class IntegrationHandlerTest method setUp.

@Before
public void setUp() {
    DataManager manager = mock(DataManager.class);
    Validator validator = mock(Validator.class);
    openShiftService = mock(OpenShiftService.class);
    inspectors = mock(Inspectors.class);
    handler = new IntegrationHandler(manager, openShiftService, validator, inspectors, new EncryptionComponent(null));
}
Also used : IntegrationHandler(io.syndesis.server.endpoint.v1.handler.integration.IntegrationHandler) Inspectors(io.syndesis.server.inspector.Inspectors) OpenShiftService(io.syndesis.server.openshift.OpenShiftService) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) DataManager(io.syndesis.server.dao.manager.DataManager) Validator(javax.validation.Validator) Before(org.junit.Before)

Example 8 with DataManager

use of io.syndesis.server.dao.manager.DataManager in project syndesis by syndesisio.

the class IntegrationHandler method toCurrentConnection.

public Connection toCurrentConnection(Connection c) {
    final DataManager dataManager = getDataManager();
    final Connection connection = dataManager.fetch(Connection.class, c.getId().get());
    final Connector connector = dataManager.fetch(Connector.class, connection.getConnectorId());
    return new Connection.Builder().createFrom(connection).connector(connector).build();
}
Also used : Connector(io.syndesis.common.model.connection.Connector) Connection(io.syndesis.common.model.connection.Connection) DataManager(io.syndesis.server.dao.manager.DataManager)

Example 9 with DataManager

use of io.syndesis.server.dao.manager.DataManager in project syndesis by syndesisio.

the class IntegrationHandler method get.

@Override
public IntegrationOverview get(String id) {
    final DataManager dataManager = getDataManager();
    final Integration integration = dataManager.fetch(Integration.class, id);
    if (integration == null) {
        throw new EntityNotFoundException();
    }
    if (integration.isDeleted()) {
        // Cause that test, is using NoopHandlerProvider, so that means no controllers.
        throw new EntityNotFoundException(String.format("Integration %s has been deleted", integration.getId()));
    }
    return toCurrentIntegrationOverview(integration);
}
Also used : Integration(io.syndesis.common.model.integration.Integration) DataManager(io.syndesis.server.dao.manager.DataManager) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 10 with DataManager

use of io.syndesis.server.dao.manager.DataManager in project syndesis by syndesisio.

the class DataManagerTest method setup.

@Before
public void setup() {
    cacheManager = new LRUCacheManager(100);
    EncryptionComponent encryptionComponent = new EncryptionComponent(null);
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    // Create Data Manager
    dataManager = new DataManager(cacheManager, Collections.emptyList(), null, encryptionComponent, resourceLoader);
    dataManager.init();
    dataManager.resetDeploymentData();
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) DataManager(io.syndesis.server.dao.manager.DataManager) LRUCacheManager(io.syndesis.common.util.cache.LRUCacheManager) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Before(org.junit.Before)

Aggregations

DataManager (io.syndesis.server.dao.manager.DataManager)15 Connector (io.syndesis.common.model.connection.Connector)6 Connection (io.syndesis.common.model.connection.Connection)5 ConnectionBulletinBoard (io.syndesis.common.model.bulletin.ConnectionBulletinBoard)4 EncryptionComponent (io.syndesis.server.dao.manager.EncryptionComponent)4 ArrayList (java.util.ArrayList)4 LeveledMessage (io.syndesis.common.model.bulletin.LeveledMessage)3 Integration (io.syndesis.common.model.integration.Integration)3 EntityNotFoundException (javax.persistence.EntityNotFoundException)3 Before (org.junit.Before)3 Test (org.junit.Test)3 IntegrationBulletinBoard (io.syndesis.common.model.bulletin.IntegrationBulletinBoard)2 ConnectionOverview (io.syndesis.common.model.connection.ConnectionOverview)2 Extension (io.syndesis.common.model.extension.Extension)2 LRUCacheManager (io.syndesis.common.util.cache.LRUCacheManager)2 Validator (javax.validation.Validator)2 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)2 ResourceLoader (org.springframework.core.io.ResourceLoader)2 ChangeEvent (io.syndesis.common.model.ChangeEvent)1 Kind (io.syndesis.common.model.Kind)1