Search in sources :

Example 61 with PipelineRun

use of com.epam.pipeline.entity.pipeline.PipelineRun in project cloud-pipeline by epam.

the class PipelineRunManager method loadPipelineRun.

@Transactional(propagation = Propagation.REQUIRED)
public PipelineRun loadPipelineRun(Long id) {
    PipelineRun pipelineRun = pipelineRunDao.loadPipelineRun(id);
    Assert.notNull(pipelineRun, messageHelper.getMessage(MessageConstants.ERROR_PIPELINE_NOT_FOUND, id));
    setParent(pipelineRun);
    checkCommitRunStatus(pipelineRun);
    if (permissionManager.isOwnerOrAdmin(pipelineRun.getOwner())) {
        pipelineRun.setSshPassword(pipelineRunDao.loadSshPassword(id));
    }
    pipelineRun.setPipelineRunParameters(replaceParametersWithEnvVars(pipelineRun.getPipelineRunParameters(), pipelineRun.getEnvVars()));
    dataStorageManager.analyzePipelineRunsParameters(Collections.singletonList(pipelineRun));
    return pipelineRun;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Transactional(org.springframework.transaction.annotation.Transactional)

Example 62 with PipelineRun

use of com.epam.pipeline.entity.pipeline.PipelineRun in project cloud-pipeline by epam.

the class PipelineRunManager method resumeRun.

/**
 * Resumes pipeline run for specified {@code runId}.
 * @param runId {@link PipelineRun} id for pipeline run to be resumed
 * @return resumed {@link PipelineRun}
 */
public PipelineRun resumeRun(Long runId) {
    PipelineRun pipelineRun = pipelineRunDao.loadPipelineRun(runId);
    verifyPipelineRunForPauseResume(pipelineRun, runId);
    Assert.state(pipelineRun.getStatus() == TaskStatus.PAUSED, messageHelper.getMessage(MessageConstants.ERROR_PIPELINE_RUN_NOT_STOPPED, runId));
    if (StringUtils.isEmpty(pipelineRun.getActualCmd())) {
        throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_ACTUAL_CMD_NOT_FOUND, runId));
    }
    Tool tool = toolManager.loadByNameOrId(pipelineRun.getDockerImage());
    pipelineRun.setStatus(TaskStatus.RESUMING);
    updatePipelineStatus(pipelineRun);
    dockerContainerOperationManager.resumeRun(pipelineRun, tool.getEndpoints());
    return pipelineRun;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Tool(com.epam.pipeline.entity.pipeline.Tool)

Example 63 with PipelineRun

use of com.epam.pipeline.entity.pipeline.PipelineRun in project cloud-pipeline by epam.

the class PipelineRunManager method checkFreeSpaceAvailable.

/**
 * Checks that free node space is enough. Calls before commit/pause operations.
 * @param runId {@link PipelineRun} id for pipeline run
 * @return true if free space is enough
 */
public Boolean checkFreeSpaceAvailable(final Long runId) {
    final PipelineRun pipelineRun = pipelineRunDao.loadPipelineRun(runId);
    Assert.notNull(pipelineRun, messageHelper.getMessage(MessageConstants.ERROR_RUN_PIPELINES_NOT_FOUND, runId));
    final long availableDisk = cAdvisorMonitoringManager.getDiskAvailableForDocker(pipelineRun.getInstance().getNodeName(), pipelineRun.getPodId(), pipelineRun.getDockerImage());
    final long requiredImageSize = (long) Math.ceil((double) toolManager.getCurrentImageSize(pipelineRun.getDockerImage()) * preferenceManager.getPreference(SystemPreferences.CLUSTER_DOCKER_EXTRA_MULTI) / 2);
    LOGGER.debug("Run {} available disk: {} required for image size: {}", runId, availableDisk, requiredImageSize);
    if (availableDisk < requiredImageSize) {
        LOGGER.warn("Free disk space is not enough");
        return false;
    }
    return true;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun)

Example 64 with PipelineRun

use of com.epam.pipeline.entity.pipeline.PipelineRun in project cloud-pipeline by epam.

the class PipelineRunManager method createPipelineRun.

@Transactional(propagation = Propagation.REQUIRED)
public PipelineRun createPipelineRun(String version, PipelineConfiguration configuration, Pipeline pipeline, Long parentRunId, List<Long> entityIds, Long configurationId) {
    validateRunParameters(configuration, pipeline);
    RunInstance instance = configureRunInstance(configuration);
    PipelineRun run = new PipelineRun();
    Long runId = pipelineRunDao.createRunId();
    run.setId(runId);
    run.setStartDate(DateUtils.now());
    run.setProlongedAtTime(DateUtils.nowUTC());
    if (pipeline == null || version == null) {
        fillMissingPipelineFields(run);
    } else {
        run.setPipelineName(pipeline.getName());
        run.setRepository(pipeline.getRepository());
        run.setPipelineId(pipeline.getId());
        run.setVersion(version);
        run.setRevisionName(gitManager.getRevisionName(version));
    }
    run.setStatus(TaskStatus.RUNNING);
    run.setCommitStatus(CommitStatus.NOT_COMMITTED);
    run.setLastChangeCommitTime(DateUtils.now());
    run.setPodId(getRootPodIDFromPipeline(run));
    if (parentRunId != null) {
        run.setParentRunId(parentRunId);
    } else {
        setRunParentId(run, configuration.getParameters());
    }
    run.convertParamsToString(configuration.getParameters());
    run.setTimeout(configuration.getTimeout());
    run.setDockerImage(configuration.getDockerImage());
    run.setCmdTemplate(determinateCmdTemplateForRun(configuration));
    run.setNodeCount(configuration.getNodeCount());
    setRunPrice(instance, run);
    run.setSshPassword(PasswordGenerator.generatePassword());
    run.setOwner(securityManager.getAuthorizedUser());
    if (CollectionUtils.isNotEmpty(entityIds)) {
        run.setEntitiesIds(entityIds);
    }
    run.setConfigurationId(configurationId);
    run.setExecutionPreferences(Optional.ofNullable(configuration.getExecutionPreferences()).orElse(ExecutionPreferences.getDefault()));
    if (StringUtils.hasText(configuration.getPrettyUrl())) {
        validatePrettyUrlFree(configuration.getPrettyUrl());
        run.setPrettyUrl(configuration.getPrettyUrl());
    }
    if (instance.getSpot() != null && !instance.getSpot()) {
        run.setNonPause(configuration.isNonPause());
    }
    return run;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with PipelineRun

use of com.epam.pipeline.entity.pipeline.PipelineRun in project cloud-pipeline by epam.

the class PipelineRunManager method updateCommitRunStatus.

/**
 * Commits docker image and push it to a docker registry from specified run
 * @param id {@link PipelineRun} id for pipeline run which commit status should be updated
 * @param commitStatus new {@link CommitStatus} of the pipeline run
 * @return updated {@link PipelineRun}
 */
@Transactional(propagation = Propagation.REQUIRED)
public PipelineRun updateCommitRunStatus(Long id, CommitStatus commitStatus) {
    PipelineRun pipelineRun = pipelineRunDao.loadPipelineRun(id);
    Assert.notNull(pipelineRun, messageHelper.getMessage(MessageConstants.ERROR_PIPELINE_NOT_FOUND, id));
    pipelineRun.setCommitStatus(commitStatus);
    pipelineRun.setLastChangeCommitTime(DateUtils.now());
    return updatePipelineCommitStatus(pipelineRun);
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)88 Test (org.junit.Test)31 Transactional (org.springframework.transaction.annotation.Transactional)29 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)23 EnvVarsBuilderTest (com.epam.pipeline.manager.execution.EnvVarsBuilderTest)22 ArrayList (java.util.ArrayList)18 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)17 Date (java.util.Date)15 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)14 List (java.util.List)14 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)13 Map (java.util.Map)11 LocalDateTime (java.time.LocalDateTime)10 Arrays (java.util.Arrays)10 Collectors (java.util.stream.Collectors)10 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)9 Collections (java.util.Collections)9 HashMap (java.util.HashMap)9 MessageHelper (com.epam.pipeline.common.MessageHelper)8 RunSid (com.epam.pipeline.entity.pipeline.run.parameter.RunSid)8