Search in sources :

Example 11 with RunInstance

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;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) PipelineRunPrice(com.epam.pipeline.entity.cluster.PipelineRunPrice) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance)

Example 12 with RunInstance

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);
        }
    });
}
Also used : StateReason(com.amazonaws.services.ec2.model.StateReason) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance)

Example 13 with RunInstance

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

Example 14 with RunInstance

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;
}
Also used : RunInstance(com.epam.pipeline.entity.pipeline.RunInstance)

Example 15 with RunInstance

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;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)20 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)14 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)6 Date (java.util.Date)6 PipelineRunParameter (com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter)5 CmdExecutionException (com.epam.pipeline.exception.CmdExecutionException)5 List (java.util.List)5 GitClientException (com.epam.pipeline.exception.git.GitClientException)4 PipelineRunManager (com.epam.pipeline.manager.pipeline.PipelineRunManager)4 PreferenceManager (com.epam.pipeline.manager.preference.PreferenceManager)4 SystemPreferences (com.epam.pipeline.manager.preference.SystemPreferences)4 Duration (java.time.Duration)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 PostConstruct (javax.annotation.PostConstruct)4 TaskStatus (com.epam.pipeline.entity.pipeline.TaskStatus)3 ParallelExecutorService (com.epam.pipeline.manager.parallel.ParallelExecutorService)3