Search in sources :

Example 1 with PipelineRunServiceUrlVO

use of com.epam.pipeline.controller.vo.PipelineRunServiceUrlVO in project cloud-pipeline by epam.

the class DockerContainerOperationManager method pauseRun.

@Async("pauseRunExecutor")
public void pauseRun(PipelineRun run) {
    try {
        final String containerId = kubernetesManager.getContainerIdFromKubernetesPod(run.getPodId(), run.getDockerImage());
        final String apiToken = authManager.issueTokenForCurrentUser().getToken();
        Assert.notNull(containerId, messageHelper.getMessage(MessageConstants.ERROR_CONTAINER_ID_FOR_RUN_NOT_FOUND, run.getId()));
        String pauseRunCommand = String.format(PAUSE_COMMAND_TEMPLATE, pauseRunScriptUrl, preferenceManager.getPreference(SystemPreferences.BASE_API_HOST), apiToken, commitScriptsDistributionsUrl, preferenceManager.getPreference(SystemPreferences.BASE_PIPE_DISTR_URL), run.getId(), containerId, preferenceManager.getPreference(SystemPreferences.COMMIT_TIMEOUT), run.getDockerImage(), run.getTaskName());
        RunInstance instance = run.getInstance();
        kubernetesManager.addNodeLabel(instance.getNodeName(), KubernetesConstants.PAUSED_NODE_LABEL, TaskStatus.PAUSED.name());
        run.setPodIP(null);
        runManager.updatePodIP(run);
        runManager.updateServiceUrl(run.getId(), new PipelineRunServiceUrlVO());
        Process sshConnection = submitCommandViaSSH(instance.getNodeIP(), pauseRunCommand);
        // TODO: change SystemPreferences.COMMIT_TIMEOUT in according to
        // f_EPMCMBIBPC-2025_add_lastStatusUpdate_time branche
        boolean isFinished = sshConnection.waitFor(preferenceManager.getPreference(SystemPreferences.COMMIT_TIMEOUT), TimeUnit.SECONDS);
        if (isFinished && sshConnection.exitValue() == COMMAND_CANNOT_EXECUTE_CODE) {
            // TODO: change in according to f_EPMCMBIBPC-2025_add_lastStatusUpdate_time branche
            run.setStatus(TaskStatus.RUNNING);
            runManager.updatePipelineStatus(run);
            kubernetesManager.removeNodeLabel(instance.getNodeName(), KubernetesConstants.PAUSED_NODE_LABEL);
            return;
        }
        Assert.state(sshConnection.exitValue() == 0, messageHelper.getMessage(MessageConstants.ERROR_RUN_PIPELINES_PAUSE_FAILED, run.getId()));
        kubernetesManager.deletePod(run.getPodId());
        clusterManager.stopInstance(instance.getNodeId(), instance.getAwsRegionId());
        kubernetesManager.deleteNode(instance.getNodeName());
        run.setStatus(TaskStatus.PAUSED);
        runManager.updatePipelineStatus(run);
    } catch (Exception e) {
        failRunAndTerminateNode(run, e);
        throw new IllegalArgumentException(PAUSE_COMMAND_DESCRIPTION, e);
    }
}
Also used : PipelineRunServiceUrlVO(com.epam.pipeline.controller.vo.PipelineRunServiceUrlVO) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) IOException(java.io.IOException) CmdExecutionException(com.epam.pipeline.exception.CmdExecutionException) Async(org.springframework.scheduling.annotation.Async)

Aggregations

PipelineRunServiceUrlVO (com.epam.pipeline.controller.vo.PipelineRunServiceUrlVO)1 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)1 CmdExecutionException (com.epam.pipeline.exception.CmdExecutionException)1 IOException (java.io.IOException)1 Async (org.springframework.scheduling.annotation.Async)1