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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations