@Autowired public IntegrationController(DataManager dataManager, EventBus eventBus, StateChangeHandlerProvider handlerFactory) { this.dataManager = dataManager; this.eventBus = eventBus; for (StateChangeHandler handler : handlerFactory.getStatusChangeHandlers()) { for (IntegrationDeploymentState state : handler.getTriggerStates()) { this.handlers.put(state, handler); } } }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { try { Thread.sleep(waitMillis); return new StateUpdate(state); } catch (InterruptedException e) { return null; } } }
default void execute(IntegrationDeployment integrationDeployment, Consumer<StateUpdate>updates) { StateUpdate update = execute(integrationDeployment); if( update!=null ) { updates.accept(update); } } }
@Override public StateUpdate execute(final IntegrationDeployment integrationDeployment) { final int maxIntegrationsPerUser = properties.getMaxIntegrationsPerUser(); if (maxIntegrationsPerUser != ControllersConfigurationProperties.UNLIMITED) { int userIntegrations = countActiveIntegrationsOfSameUserAs(integrationDeployment); if (userIntegrations >= maxIntegrationsPerUser) { return new StateUpdate(IntegrationDeploymentState.Unpublished, "User has currently " + userIntegrations + " integrations, while the maximum allowed number is " + maxIntegrationsPerUser + "."); final int maxDeploymentsPerUser = properties.getMaxDeploymentsPerUser(); if (maxDeploymentsPerUser != ControllersConfigurationProperties.UNLIMITED) { int userDeployments = countDeployments(integrationDeployment); if (userDeployments >= maxDeploymentsPerUser) { return new StateUpdate(IntegrationDeploymentState.Unpublished, "User has currently " + userDeployments + " deployments, while the maximum allowed number is " + maxDeploymentsPerUser + "."); logInfo(integrationDeployment, "Build started: {}, isRunning: {}, Deployment ready: {}", isBuildStarted(integrationDeployment), isRunning(integrationDeployment), isReady(integrationDeployment)); BuildStepPerformer stepPerformer = new BuildStepPerformer(integrationDeployment); logInfo(integrationDeployment, "Steps performed so far: " + stepPerformer.getStepsPerformed()); if (isBuildFailed(integrationDeployment)){ return new StateUpdate(IntegrationDeploymentState.Error, stepPerformer.getStepsPerformed(), "Error"); final Integration integration = integrationOf(integrationDeployment); try { setVersion(integrationDeployment); deactivatePreviousDeployments(integrationDeployment);
@Override public StateUpdate execute(IntegrationDeployment integrationDeploymentDefinition) { final IntegrationDeployment integrationDeployment = IntegrationSupport.sanitize(integrationDeploymentDefinition, dataManager, encryptionComponent); final Integration integration = integrationOf(integrationDeployment); final int maxIntegrationsPerUser = properties.getMaxIntegrationsPerUser(); if (maxIntegrationsPerUser != ControllersConfigurationProperties.UNLIMITED) { int userIntegrations = countActiveIntegrationsOfSameUserAs(integration); if (userIntegrations >= maxIntegrationsPerUser) { return new StateUpdate(IntegrationDeploymentState.Inactive, "User has currently " + userIntegrations + " integrations, while the maximum allowed number is " + maxIntegrationsPerUser + "."); final int maxDeploymentsPerUser = properties.getMaxDeploymentsPerUser(); if (maxDeploymentsPerUser != ControllersConfigurationProperties.UNLIMITED) { int userDeployments = countDeployments(integration); if (userDeployments >= maxDeploymentsPerUser) { return new StateUpdate(IntegrationDeploymentState.Inactive, "User has currently " + userDeployments + " deployments, while the maximum allowed number is " + maxDeploymentsPerUser + "."); logInfo(integrationDeployment, "Build started: {}, isRunning: {}, Deployment ready: {}", isBuildStarted(integrationDeployment), isRunning(integrationDeployment), isReady(integrationDeployment)); BuildStepPerformer stepPerformer = new BuildStepPerformer(integrationDeployment); logInfo(integrationDeployment, "Steps performed so far: " + stepPerformer.getStepsPerformed()); try { deactivatePreviousDeployments(integrationDeployment); DeploymentData deploymentData = createDeploymentData(integration, integrationDeployment); stepPerformer.perform("build", this::build, deploymentData); stepPerformer.perform("deploy", this::deploy, deploymentData);
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; 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("")); .statusMessage(Optional.ofNullable(update.getStatusMessage())) .currentState(update.getState()) .stepsDone(update.getStepsPerformed()) .updatedAt(System.currentTimeMillis()) .build()); reschedule(integrationDeploymentId);
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { IntegrationDeploymentState currentState = !openShiftService().exists(integrationDeployment.getName()) || openShiftService().delete(integrationDeployment.getName()) ? IntegrationDeploymentState.Undeployed : IntegrationDeploymentState.Pending; logInfo(integrationDeployment,"Deleted"); return new StateUpdate(currentState); }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { try { openShiftService().scale(integrationDeployment.getName(), 0); logInfo(integrationDeployment,"Deactivated"); } catch (KubernetesClientException e) { // Ignore 404 errors, means the deployment does not exist for us // to scale down if( e.getCode() != 404 ) { throw e; } } IntegrationDeploymentState currentState = openShiftService().isScaled(integrationDeployment.getName(), 0) ? IntegrationDeploymentState.Inactive : IntegrationDeploymentState.Pending; return new StateUpdate(currentState); }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { IntegrationDeploymentState currentState = !openShiftService().exists(integrationDeployment.getSpec().getName()) || openShiftService().delete(integrationDeployment.getSpec().getName()) ? IntegrationDeploymentState.Unpublished : IntegrationDeploymentState.Pending; if (currentState == IntegrationDeploymentState.Unpublished) { logInfo(integrationDeployment,"Deleted"); IntegrationDeployment updated = new IntegrationDeployment.Builder().createFrom(integrationDeployment).addAllStepsDone(Collections.emptyList()).build(); dataManager.update(updated); } return new StateUpdate(currentState); }
/* default */ 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; StateUpdate update = handler.execute(integrationDeployment); if (update!=null) { if (LOG.isInfoEnabled()) { LOG.info("{} : Setting status to {}{}", getLabel(integrationDeployment), update.getState(), (update.getStatusMessage() != null ? " (" + update.getStatusMessage() + ")" : "")); if (update.getState() == IntegrationDeploymentState.Undeployed) { dataManager.delete(IntegrationDeployment.class, integrationDeploymentId); } else { .createFrom(current) .currentState(update.getState()) .stepsDone(update.getStepsPerformed()) .createdDate(IntegrationDeploymentState.Active.equals(update.getState()) ? now : integrationDeployment.getCreatedDate()) .lastUpdated(new Date()) .build(); reschedule(integrationDeploymentId);
@Autowired public IntegrationController(DataManager dataManager, EventBus eventBus, StateChangeHandlerProvider handlerFactory) { this.dataManager = dataManager; this.eventBus = eventBus; for (StateChangeHandler handler : handlerFactory.getStatusChangeHandlers()) { for (IntegrationDeploymentState state : handler.getTriggerStates()) { this.handlers.put(state, handler); } } }
@Override public StateUpdate execute(IntegrationDeployment integrationDeployment) { try { Thread.sleep(waitMillis); return new StateUpdate(state); } catch (InterruptedException e) { return null; } } }