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