Search in sources :

Example 11 with PipelineRun

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

the class PipelineRunManager method createRestartRun.

private PipelineRun createRestartRun(final PipelineRun run) {
    PipelineRun restartedRun = new PipelineRun();
    Long runId = pipelineRunDao.createRunId();
    restartedRun.setId(runId);
    restartedRun.setStartDate(DateUtils.now());
    Optional<Pipeline> pipeline = Optional.ofNullable(run.getPipelineId()).map(pipelineId -> pipelineManager.load(pipelineId));
    pipeline.ifPresent(p -> {
        restartedRun.setPipelineName(p.getName());
        restartedRun.setRepository(p.getRepository());
        restartedRun.setPipelineId(p.getId());
        restartedRun.setVersion(run.getVersion());
        restartedRun.setRevisionName(gitManager.getRevisionName(run.getVersion()));
    });
    if (!pipeline.isPresent()) {
        fillMissingPipelineFields(restartedRun);
    }
    restartedRun.setStatus(TaskStatus.RUNNING);
    restartedRun.setCommitStatus(CommitStatus.NOT_COMMITTED);
    restartedRun.setLastChangeCommitTime(DateUtils.now());
    restartedRun.setPodId(getRootPodIDFromPipeline(restartedRun));
    restartedRun.setParams(run.getParams());
    restartedRun.parseParameters();
    restartedRun.setTimeout(run.getTimeout());
    restartedRun.setDockerImage(run.getDockerImage());
    restartedRun.setCmdTemplate(run.getCmdTemplate());
    restartedRun.setNodeCount(run.getNodeCount());
    RunInstance instance = copyInstance(run.getInstance());
    restartedRun.setInstance(instance);
    setRunPrice(instance, restartedRun);
    restartedRun.setSshPassword(PasswordGenerator.generatePassword());
    restartedRun.setOwner(run.getOwner());
    restartedRun.setEntitiesIds(run.getEntitiesIds());
    restartedRun.setConfigurationId(run.getConfigurationId());
    restartedRun.setExecutionPreferences(run.getExecutionPreferences());
    restartedRun.setRunSids(run.getRunSids());
    return restartedRun;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Example 12 with PipelineRun

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

the class RunLogManager method loadAllLogsForTask.

@Transactional(propagation = Propagation.SUPPORTS)
public List<RunLog> loadAllLogsForTask(Long runId, String taskName, String parameters) {
    PipelineRun run = pipelineRunManager.loadPipelineRun(runId);
    if (consoleLogTask.equals(taskName)) {
        return getPodLogs(run);
    }
    String taskId = PipelineTask.buildTaskId(taskName, parameters);
    return runLogDao.loadAllLogsForTask(runId, taskId);
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with PipelineRun

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

the class RunLogManager method saveLog.

@Transactional(propagation = Propagation.REQUIRED)
public RunLog saveLog(final RunLog runLog) {
    Assert.notNull(runLog.getRunId(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_REQUIRED, "runId", RunLog.class.getSimpleName()));
    Assert.notNull(runLog.getDate(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_REQUIRED, "date", RunLog.class.getSimpleName()));
    Assert.notNull(runLog.getStatus(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_REQUIRED, "status", RunLog.class.getSimpleName()));
    PipelineRun run = pipelineRunDao.loadPipelineRun(runLog.getRunId());
    Assert.notNull(run, messageHelper.getMessage(MessageConstants.ERROR_PIPELINE_NOT_FOUND, runLog.getRunId()));
    if (!StringUtils.isEmpty(runLog.getLogText())) {
        runLog.setLogText(runLog.getLogText().replaceAll("\\u0000", ""));
    }
    // Check previous status, it may differ from pod status as error may occur during
    // results upload to s3
    TaskStatus statusToSave = runLog.getStatus();
    if (!StringUtils.isEmpty(runLog.getTaskName())) {
        PipelineTask task = self.loadPreviousTaskStatus(run, runLog);
        if (task != null && task.getStatus().isFinal()) {
            statusToSave = task.getStatus();
        }
    }
    // this status
    if (!statusToSave.isFinal() && run.getStatus().isFinal()) {
        statusToSave = run.getStatus();
    }
    runLog.setStatus(statusToSave);
    runLogDao.createRunLog(runLog);
    return runLog;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) TaskStatus(com.epam.pipeline.entity.pipeline.TaskStatus) PipelineTask(com.epam.pipeline.entity.pipeline.PipelineTask) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with PipelineRun

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

the class DtsRunner method runEntry.

private PipelineRun runEntry(DtsRunConfigurationEntry entry, Long configurationId, List<Long> entitiesIds, PipelineConfiguration configuration) {
    Pipeline pipeline = entry.getPipelineId() == null ? null : pipelineManager.load(entry.getPipelineId());
    PipelineRun run = pipelineRunManager.createPipelineRun(entry.getPipelineVersion(), configuration, pipeline, null, entitiesIds, configurationId);
    run.setConfigName(entry.getConfigName());
    run.setDockerImage(toolManager.getExternalToolName(run.getDockerImage()));
    run.setExecutionPreferences(DtsExecutionPreferences.builder().dtsId(entry.getDtsId()).coresNumber(entry.getCoresNumber()).build());
    Map<SystemParams, String> systemParams = pipelineLauncher.matchCommonParams(run, preferenceManager.getPreference(SystemPreferences.BASE_API_HOST_EXTERNAL), configuration.getGitCredentials());
    systemParams.put(SystemParams.DISTRIBUTION_URL, preferenceManager.getPreference(SystemPreferences.DTS_DISTRIBUTION_URL));
    GitCredentials gitCredentials = configuration.getGitCredentials();
    String gitCloneUrl = gitCredentials == null ? run.getRepository() : gitCredentials.getUrl();
    String pipelineCommand = commandBuilder.build(configuration, systemParams);
    run.setActualCmd(pipelineCommand);
    String launchCmd = preferenceManager.getPreference(SystemPreferences.DTS_LAUNCH_CMD_TEMPLATE);
    String launchScriptUrl = preferenceManager.getPreference(SystemPreferences.DTS_LAUNCH_URL);
    String fullCmd = String.format(launchCmd, launchScriptUrl, launchScriptUrl, gitCloneUrl, run.getRevisionName(), pipelineCommand);
    pipelineRunManager.save(run);
    DtsSubmission submission = buildSubmission(run, configuration, entry.getCoresNumber(), systemParams, fullCmd);
    log.debug("Creating DTS submission");
    try {
        DtsSubmission scheduled = submissionManager.createSubmission(entry.getDtsId(), submission);
        if (scheduled.getState().getStatus() != TaskStatus.RUNNING) {
            return failRun(run, String.format("Submission failed to start: %s", scheduled.getState().getReason()));
        }
        log.debug("Successfully scheduled submission on DTS");
        return run;
    } catch (DtsRequestException e) {
        return failRun(run, e.getMessage());
    }
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) GitCredentials(com.epam.pipeline.entity.git.GitCredentials) SystemParams(com.epam.pipeline.manager.execution.SystemParams) DtsRequestException(com.epam.pipeline.exception.DtsRequestException) DtsSubmission(com.epam.pipeline.entity.dts.DtsSubmission) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Example 15 with PipelineRun

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

the class CloudPlatformRunner method runConfiguration.

private List<PipelineRun> runConfiguration(Long configurationId, List<RunConfigurationEntry> entries, ResolvedConfiguration resolvedConfigurations) {
    SplitConfig splitConfig = new SplitConfig(entries);
    RunConfigurationEntry mainEntry = splitConfig.getMain();
    List<RunConfigurationEntry> childEntries = splitConfig.getChildEntries();
    boolean isMasterNFSServer = pipelineConfigurationManager.hasNFSParameter(mainEntry.getConfiguration()) || childEntries.stream().noneMatch(entry -> pipelineConfigurationManager.hasNFSParameter(entry.getConfiguration()));
    boolean nfsStarted = isMasterNFSServer;
    PipelineConfiguration mainConfiguration = resolvedConfigurations.getConfiguration(mainEntry.getName());
    List<PipelineConfiguration> childConfigurations = childEntries.stream().map(entry -> resolvedConfigurations.getConfiguration(entry.getName())).collect(Collectors.toList());
    int masterNodeCount = getNodeCount(mainConfiguration.getNodeCount(), 0);
    int totalNodes = childConfigurations.stream().map(PipelineConfiguration::getNodeCount).mapToInt(nodeCount -> getNodeCount(nodeCount, 1)).sum();
    totalNodes += masterNodeCount;
    log.debug("Running total {} nodes", totalNodes + 1);
    mainConfiguration.setNodeCount(totalNodes);
    // create master run
    List<PipelineRun> masterRun = runConfigurationEntry(mainEntry, mainConfiguration, 1, null, isMasterNFSServer, resolvedConfigurations.getAllAssociatedIds(), configurationId);
    List<PipelineRun> launched = new ArrayList<>(masterRun);
    String clusterId = String.valueOf(masterRun.get(0).getId());
    // create master workers
    if (masterNodeCount > 0) {
        mainEntry.getConfiguration().setWorkerCmd(WORKER_CMD_TEMPLATE);
        launched.addAll(runConfigurationEntry(mainEntry, mainConfiguration, masterNodeCount, clusterId, false, resolvedConfigurations.getAllAssociatedIds(), configurationId));
    }
    // create all other workers
    for (int i = 0; i < childConfigurations.size(); i++) {
        PipelineConfiguration childConfig = childConfigurations.get(i);
        boolean startNFS = !nfsStarted && pipelineConfigurationManager.hasNFSParameter(childConfig);
        nfsStarted = nfsStarted || startNFS;
        int copies = getNodeCount(childConfig.getNodeCount(), 1);
        launched.addAll(runConfigurationEntry(childEntries.get(i), childConfig, copies, clusterId, startNFS, resolvedConfigurations.getAllAssociatedIds(), configurationId));
    }
    return launched;
}
Also used : PipelineManager(com.epam.pipeline.manager.pipeline.PipelineManager) MessageConstants(com.epam.pipeline.common.MessageConstants) ParameterMapper(com.epam.pipeline.manager.pipeline.ParameterMapper) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) RequiredArgsConstructor(lombok.RequiredArgsConstructor) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) MessageHelper(com.epam.pipeline.common.MessageHelper) Service(org.springframework.stereotype.Service) AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry) RunConfigurationEntry(com.epam.pipeline.entity.configuration.RunConfigurationEntry) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) PipelineConfigurationManager(com.epam.pipeline.manager.pipeline.PipelineConfigurationManager) WORKER_CMD_TEMPLATE(com.epam.pipeline.manager.pipeline.PipelineConfigurationManager.WORKER_CMD_TEMPLATE) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Collection(java.util.Collection) RunConfigurationUtils.getNodeCount(com.epam.pipeline.entity.configuration.RunConfigurationUtils.getNodeCount) Collectors(java.util.stream.Collectors) ResolvedConfiguration(com.epam.pipeline.entity.pipeline.ResolvedConfiguration) NFS_CLUSTER_ROLE(com.epam.pipeline.manager.pipeline.PipelineConfigurationManager.NFS_CLUSTER_ROLE) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Data(lombok.Data) PipelineStart(com.epam.pipeline.entity.pipeline.run.PipelineStart) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ArrayList(java.util.ArrayList) AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry) RunConfigurationEntry(com.epam.pipeline.entity.configuration.RunConfigurationEntry) PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration)

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