Search in sources :

Example 1 with StateUpdate

use of io.syndesis.server.controller.StateUpdate in project syndesis by syndesisio.

the class PublishHandler method execute.

@Override
public StateUpdate execute(final IntegrationDeployment integrationDeployment) {
    final int maxIntegrationsPerUser = properties.getMaxIntegrationsPerUser();
    if (maxIntegrationsPerUser != ControllersConfigurationProperties.UNLIMITED) {
        int userIntegrations = countActiveIntegrationsOfSameUserAs(integrationDeployment);
        if (userIntegrations >= maxIntegrationsPerUser) {
            // What the user sees.
            return new StateUpdate(IntegrationDeploymentState.Unpublished, integrationDeployment.getStepsDone(), "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) {
            // What we actually want to limit. So even though this should never happen, we still need to make sure.
            return new StateUpdate(IntegrationDeploymentState.Unpublished, integrationDeployment.getStepsDone(), "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);
        DeploymentData deploymentData = createDeploymentData(integration, integrationDeployment);
        stepPerformer.perform("build", this::build, deploymentData);
        deploymentData = new DeploymentData.Builder().createFrom(deploymentData).withImage(stepPerformer.stepsPerformed.get("build")).build();
        if (hasPublishedDeployments(integrationDeployment)) {
            return new StateUpdate(IntegrationDeploymentState.Unpublished, integrationDeployment.getStepsDone(), "Integration has still active deployments. Will retry shortly");
        }
        stepPerformer.perform("deploy", this::deploy, deploymentData);
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
        logError(integrationDeployment, "[ERROR] Activation failure", e);
        // Setting a message to update means implicitly thats in an error state (for the UI)
        return new StateUpdate(IntegrationDeploymentState.Pending, stepPerformer.getStepsPerformed(), e.getMessage());
    }
    // Set status to activate if finally running. Also clears the previous step which has been performed
    if (isRunning(integrationDeployment)) {
        logInfo(integrationDeployment, "[ACTIVATED] bc. integration is running with 1 pod");
        updateDeploymentState(integrationDeployment, IntegrationDeploymentState.Published);
        return new StateUpdate(IntegrationDeploymentState.Published, stepPerformer.getStepsPerformed());
    }
    logInfo(integrationDeployment, "Build started: {}, isRunning: {}, Deployment ready: {}", isBuildStarted(integrationDeployment), isRunning(integrationDeployment), isReady(integrationDeployment));
    logInfo(integrationDeployment, "[PENDING] [" + stepPerformer.getStepsPerformed() + "]");
    return new StateUpdate(IntegrationDeploymentState.Pending, stepPerformer.getStepsPerformed());
}
Also used : Integration(io.syndesis.common.model.integration.Integration) DeploymentData(io.syndesis.server.openshift.DeploymentData) StateUpdate(io.syndesis.server.controller.StateUpdate) IOException(java.io.IOException) SyndesisServerException(io.syndesis.common.util.SyndesisServerException)

Example 2 with StateUpdate

use of io.syndesis.server.controller.StateUpdate in project syndesis by syndesisio.

the class UnpublishHandler method execute.

@Override
public StateUpdate execute(IntegrationDeployment integrationDeployment) {
    Map<String, String> stepsDone = new HashMap<>(integrationDeployment.getStepsDone());
    // we are literally undoing this step.
    stepsDone.remove("deploy");
    IntegrationDeploymentState currentState = IntegrationDeploymentState.Pending;
    Map<String, String> labels = new HashMap<>();
    labels.put(OpenShiftService.INTEGRATION_ID_LABEL, Labels.validate(integrationDeployment.getIntegrationId().get()));
    labels.put(OpenShiftService.DEPLOYMENT_VERSION_LABEL, String.valueOf(integrationDeployment.getVersion()));
    if (!openShiftService().getDeploymentsByLabel(labels).isEmpty()) {
        try {
            openShiftService().scale(integrationDeployment.getSpec().getName(), labels, 0, 1, TimeUnit.MINUTES);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            return new StateUpdate(currentState, stepsDone);
        }
    } else {
        currentState = IntegrationDeploymentState.Unpublished;
    }
    return new StateUpdate(currentState, stepsDone);
}
Also used : IntegrationDeploymentState(io.syndesis.common.model.integration.IntegrationDeploymentState) StateUpdate(io.syndesis.server.controller.StateUpdate) HashMap(java.util.HashMap)

Aggregations

StateUpdate (io.syndesis.server.controller.StateUpdate)2 Integration (io.syndesis.common.model.integration.Integration)1 IntegrationDeploymentState (io.syndesis.common.model.integration.IntegrationDeploymentState)1 SyndesisServerException (io.syndesis.common.util.SyndesisServerException)1 DeploymentData (io.syndesis.server.openshift.DeploymentData)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1