use of com.epam.pipeline.entity.pipeline.RunInstance in project cloud-pipeline by epam.
the class InstanceOfferManager method getPipelineRunEstimatedPrice.
public PipelineRunPrice getPipelineRunEstimatedPrice(Long runId, Long regionId) {
PipelineRun pipelineRun = pipelineRunManager.loadPipelineRun(runId);
RunInstance runInstance = pipelineRun.getInstance();
AwsRegion region = awsRegionManager.loadRegionOrGetDefault(regionId);
double pricePerHourForInstance = getPricePerHourForInstance(runInstance.getNodeType(), isSpotRequest(runInstance.getSpot()), region.getAwsRegionName());
double pricePerDisk = getPriceForDisk(runInstance.getNodeDisk(), region.getAwsRegionName());
double pricePerHour = pricePerDisk + pricePerHourForInstance;
PipelineRunPrice price = new PipelineRunPrice();
price.setInstanceDisk(runInstance.getNodeDisk());
price.setInstanceType(runInstance.getNodeType());
price.setPricePerHour(pricePerHour);
if (pipelineRun.getStatus().isFinal()) {
long duration = pipelineRun.getEndDate().getTime() - pipelineRun.getStartDate().getTime();
price.setTotalPrice(duration / ONE_HOUR * pricePerHour);
} else {
price.setTotalPrice(0);
}
return price;
}
use of com.epam.pipeline.entity.pipeline.RunInstance in project cloud-pipeline by epam.
the class PodMonitor method checkAndUpdateEc2State.
private void checkAndUpdateEc2State(final PipelineRun run, final boolean allowRestart) {
final RunInstance instance = run.getInstance();
if (instance == null || run.getExecutionPreferences().getEnvironment() != ExecutionEnvironment.CLOUD_PLATFORM || StringUtils.isBlank(instance.getNodeId()) || run.getStatus() == TaskStatus.STOPPED) {
return;
}
final Optional<StateReason> stateReason = ec2Helper.getInstanceStateReason(instance.getNodeId(), instance.getAwsRegionId());
stateReason.ifPresent(reason -> {
pipelineRunManager.updateStateReasonMessage(run, reason.getMessage());
if (allowRestart && shouldRerunBatchRun(run, reason.getCode())) {
LOGGER.debug("Restarting run {}", run.getId());
pipelineRunManager.restartRun(run);
}
});
}
use of com.epam.pipeline.entity.pipeline.RunInstance 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);
}
}
use of com.epam.pipeline.entity.pipeline.RunInstance in project cloud-pipeline by epam.
the class PipelineRunManager method configureRunInstance.
private RunInstance configureRunInstance(PipelineConfiguration configuration) {
RunInstance instance = new RunInstance();
instance.setNodeDisk(Optional.ofNullable(configuration.getInstanceDisk()).map(disk -> Integer.parseInt(configuration.getInstanceDisk())).orElse(null));
instance.setEffectiveNodeDisk(Optional.ofNullable(configuration.getEffectiveDiskSize()).orElse(instance.getNodeDisk()));
instance.setNodeType(configuration.getInstanceType());
instance.setNodeImage(configuration.getInstanceImage());
String regionId = Optional.ofNullable(configuration.getAwsRegionId()).map(id -> awsRegionManager.load(id)).orElse(awsRegionManager.loadDefaultRegion()).getAwsRegionName();
instance.setAwsRegionId(regionId);
boolean defaultUseSpot = preferenceManager.getPreference(SystemPreferences.CLUSTER_SPOT);
instance.setSpot(Optional.ofNullable(configuration.getIsSpot()).orElse(defaultUseSpot));
return instance;
}
use of com.epam.pipeline.entity.pipeline.RunInstance 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;
}
Aggregations