private IntegrationDeploymentState getCurrentStateInitialize() { return IntegrationDeployment.super.getCurrentState(); }
private boolean stale(StateChangeHandler handler, IntegrationDeployment integrationDeployment) { if (integrationDeployment == null || handler == null) { return true; } IntegrationDeploymentState desiredState = integrationDeployment.getTargetState(); return desiredState.equals(integrationDeployment.getCurrentState()); }
/** * Re-conciliates the state of the deployment between the database and Openshift. * This is mostly needed for cases where an active integration has been tampered with external tools. * For example: Deleted or Scaled down DeploymentConfig. */ private IntegrationDeployment reconcileDeployment(IntegrationDeployment integrationDeployment) { IntegrationDeploymentState actualState = determineState(integrationDeployment); LOG.debug("Actual state: {}, Persisted state: {}, Desired state: {}", actualState, integrationDeployment.getCurrentState(), integrationDeployment.getTargetState()); //We also need to compare with current state to make sure we only call the unpublished() once. Calling it multiple times, might loose the steps perfromed, causing an infinite loop. if (actualState == IntegrationDeploymentState.Unpublished && actualState != integrationDeployment.getCurrentState()) { return integrationDeployment.unpublished(); } else { return integrationDeployment.withCurrentState(actualState); } } }
@Override public void run() { LOGGER.debug("Processing states for integration deployments."); try { final ListResult<IntegrationDeployment> deployments = dataManager.fetchAll(IntegrationDeployment.class); for (IntegrationDeployment deployment : deployments) { final IntegrationDeploymentState currentState = deployment.getCurrentState(); final List<StateHandler> handlers = this.stateHandlers.getOrDefault(currentState, Collections.emptyList()); if (!handlers.isEmpty()) { for (StateHandler handler : handlers) { try { handler.accept(deployment); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex) { if (LOGGER.isErrorEnabled()) { final String msg = String.format("Error handling state [%s] with handler [%s]", currentState, handler.getDescription()); LOGGER.error(msg, ex); } } } } } } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex) { LOGGER.error("Error while iterating integration deployments.", ex); } }
/** * Counts active integrations (in DB) of the owner of the specified integration. * * @param deployment The specified IntegrationDeployment. * @return The number of integrations (excluding the current). */ private int countActiveIntegrationsOfSameUserAs(IntegrationDeployment deployment) { Integration integration = deployment.getSpec(); String integrationId = integration.getId().orElseThrow(() -> new IllegalStateException("Couldn't find the id of the integration.")); String username = deployment.getUserId().orElseThrow(() -> new IllegalStateException("Couldn't find the user of the integration")); return (int) dataManager.fetchAll(IntegrationDeployment.class).getItems() .stream() .filter(i -> !i.getIntegrationId().get().equals(integrationId)) //The "current" integration will already be in the database. .filter(i -> IntegrationDeploymentState.Published == i.getCurrentState()) .filter(i -> i.getUserId().map(username::equals).orElse(Boolean.FALSE)) .count(); }
private void checkIntegrationStatus(IntegrationDeployment integrationDeployment) { if (integrationDeployment == null) { return; } IntegrationDeployment reconciled = reconcileDeployment(integrationDeployment); IntegrationDeploymentState desiredState = reconciled.getTargetState(); IntegrationDeploymentState currentState = reconciled.getCurrentState(); if (!currentState.equals(desiredState)) { reconciled.getId().ifPresent(integrationDeploymentId -> { StateChangeHandler statusChangeHandler = handlers.get(desiredState); if (statusChangeHandler != null) { LOG.info("Integration {} : Desired status \"{}\" != current status \"{}\" --> calling status change handler", integrationDeploymentId, desiredState.toString(), currentState); callStateChangeHandler(statusChangeHandler, reconciled); } }); } else if (reconciled.getCurrentState() != integrationDeployment.getCurrentState()) { dataManager.update(reconciled); scheduledChecks.remove(getIntegrationMarkerKey(reconciled)); } else { scheduledChecks.remove(getIntegrationMarkerKey(reconciled)); } }
private Collection<? extends LeveledMessage> computeDeploymentDifferences(Integration integration, Collection<IntegrationDeployment> allDeployments) { List<IntegrationDeployment> deployments = allDeployments.stream() .filter(d -> d.getIntegrationId().equals(integration.getId())) .filter(d -> d.getCurrentState().equals(IntegrationDeploymentState.Published)) .collect(Collectors.toList());