Search in sources :

Example 11 with IntegrationDeployment

use of io.syndesis.common.model.integration.IntegrationDeployment in project syndesis by syndesisio.

the class IntegrationController method callStateChangeHandler.

void callStateChangeHandler(StateChangeHandler handler, String integrationDeploymentId) {
    executor.execute(() -> {
        IntegrationDeployment integrationDeployment = dataManager.fetch(IntegrationDeployment.class, integrationDeploymentId);
        String checkKey = getIntegrationMarkerKey(integrationDeployment);
        scheduledChecks.add(checkKey);
        if (stale(handler, integrationDeployment)) {
            scheduledChecks.remove(checkKey);
            return;
        }
        try {
            final String integrationId = integrationDeployment.getIntegrationId().get();
            LOG.info("Integration {} : Start processing integration: {}, version: {} with handler:{}", integrationId, integrationId, integrationDeployment.getVersion(), handler.getClass().getSimpleName());
            handler.execute(integrationDeployment, update -> {
                if (LOG.isInfoEnabled()) {
                    LOG.info("{} : Setting status to {}{}", getLabel(integrationDeployment), update.getState(), Optional.ofNullable(update.getStatusMessage()).map(x -> " (" + x + ")").orElse(""));
                }
                // handler.execute might block for while so refresh our copy of the integration
                // data before we update the current status
                IntegrationDeployment current = dataManager.fetch(IntegrationDeployment.class, integrationDeploymentId);
                dataManager.update(current.builder().statusMessage(Optional.ofNullable(update.getStatusMessage())).currentState(update.getState()).stepsDone(update.getStepsPerformed()).updatedAt(System.currentTimeMillis()).build());
            });
        } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
            LOG.error("Error while processing integration status for integration {}", integrationDeploymentId, e);
            // Something went wrong.. lets note it.
            IntegrationDeployment current = dataManager.fetch(IntegrationDeployment.class, integrationDeploymentId);
            dataManager.update(new IntegrationDeployment.Builder().createFrom(current).currentState(IntegrationDeploymentState.Error).statusMessage(Exceptions.toString(e)).updatedAt(System.currentTimeMillis()).build());
        } finally {
            // Add a next check for the next interval
            reschedule(integrationDeploymentId);
        }
    });
}
Also used : IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) IOException(java.io.IOException)

Aggregations

IntegrationDeployment (io.syndesis.common.model.integration.IntegrationDeployment)11 DataManager (io.syndesis.server.dao.manager.DataManager)6 Integration (io.syndesis.common.model.integration.Integration)5 IntegrationDeploymentState (io.syndesis.common.model.integration.IntegrationDeploymentState)5 OpenShiftService (io.syndesis.server.openshift.OpenShiftService)5 IOException (java.io.IOException)5 Set (java.util.Set)5 Labels (io.syndesis.common.util.Labels)4 SyndesisServerException (io.syndesis.common.util.SyndesisServerException)4 IntegrationProjectGenerator (io.syndesis.integration.api.IntegrationProjectGenerator)4 ControllersConfigurationProperties (io.syndesis.server.controller.ControllersConfigurationProperties)4 StateChangeHandler (io.syndesis.server.controller.StateChangeHandler)4 StateUpdate (io.syndesis.server.controller.StateUpdate)4 DeploymentData (io.syndesis.server.openshift.DeploymentData)4 InputStream (java.io.InputStream)4 StringWriter (java.io.StringWriter)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Properties (java.util.Properties)4