Search in sources :

Example 6 with PipelineTask

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

the class PipelineRunLoaderTest method shouldLoadPipelineRunTest.

@Test
void shouldLoadPipelineRunTest() throws EntityNotFoundException {
    RunInstance instance = new RunInstance();
    instance.setNodeType("type");
    instance.setAwsRegionId(TEST_REGION);
    instance.setSpot(true);
    instance.setNodeDisk(NODE_DISK);
    instance.setNodeId("id");
    instance.setNodeImage(TEST_PATH);
    instance.setNodeName(TEST_NAME);
    RunStatus runStatus = new RunStatus();
    runStatus.setRunId(1L);
    runStatus.setStatus(TaskStatus.SUCCESS);
    PipelineRunParameter parameter = new PipelineRunParameter();
    parameter.setName(TEST_NAME);
    parameter.setValue(TEST_VALUE);
    PipelineRun expectedPipelineRun = new PipelineRun();
    expectedPipelineRun.setId(1L);
    expectedPipelineRun.setName(TEST_NAME);
    expectedPipelineRun.setPipelineName(TEST_NAME);
    expectedPipelineRun.setPipelineId(1L);
    expectedPipelineRun.setInstance(instance);
    expectedPipelineRun.setStatus(TaskStatus.SUCCESS);
    expectedPipelineRun.setVersion(TEST_VERSION);
    expectedPipelineRun.setRunStatuses(Collections.singletonList(runStatus));
    expectedPipelineRun.setPricePerHour(PRICE);
    expectedPipelineRun.setOwner(TEST_NAME);
    expectedPipelineRun.setPipelineRunParameters(Collections.singletonList(parameter));
    RunLog runLog = new RunLog();
    runLog.setLogText(TEST_DESCRIPTION);
    runLog.setStatus(TaskStatus.SUCCESS);
    runLog.setTask(new PipelineTask(TEST_NAME));
    List<RunLog> runLogs = Collections.singletonList(runLog);
    PipelineRunWithLog expectedPipelineRunWithLog = new PipelineRunWithLog();
    expectedPipelineRunWithLog.setPipelineRun(expectedPipelineRun);
    expectedPipelineRunWithLog.setRunOwner(USER);
    expectedPipelineRunWithLog.setRunLogs(runLogs);
    PipelineRunLoader pipelineRunLoader = new PipelineRunLoader(apiClient);
    when(apiClient.loadPipelineRunWithLogs(anyLong())).thenReturn(expectedPipelineRunWithLog);
    when(apiClient.loadPipelineRun(anyLong())).thenReturn(expectedPipelineRun);
    Optional<EntityContainer<PipelineRunWithLog>> container = pipelineRunLoader.loadEntity(1L);
    EntityContainer<PipelineRunWithLog> pipelineRunEntityContainer = container.orElseThrow(AssertionError::new);
    PipelineRunWithLog actualPipelineRunWithLog = pipelineRunEntityContainer.getEntity();
    assertNotNull(actualPipelineRunWithLog);
    PipelineRun actualPipelineRun = actualPipelineRunWithLog.getPipelineRun();
    assertNotNull(actualPipelineRun);
    List<RunLog> actualRunLogs = actualPipelineRunWithLog.getRunLogs();
    assertNotNull(actualRunLogs);
    verifyPipelineRun(expectedPipelineRun, actualPipelineRun);
    verifyRunInstance(expectedPipelineRun.getInstance(), actualPipelineRun.getInstance());
    verifyRunStatuses(expectedPipelineRun.getRunStatuses(), actualPipelineRun.getRunStatuses());
    verifyRunParameters(expectedPipelineRun.getPipelineRunParameters(), actualPipelineRun.getPipelineRunParameters());
    verifyRunLogs(runLogs, actualRunLogs);
    verifyPipelineUser(pipelineRunEntityContainer.getOwner());
    verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, pipelineRunEntityContainer.getPermissions());
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) LoaderVerificationUtils.verifyPipelineRun(com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyPipelineRun) RunStatus(com.epam.pipeline.entity.pipeline.run.RunStatus) RunLog(com.epam.pipeline.entity.pipeline.RunLog) EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) LoaderVerificationUtils.verifyRunInstance(com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyRunInstance) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) PipelineTask(com.epam.pipeline.entity.pipeline.PipelineTask) PipelineRunWithLog(com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog) PipelineRunParameter(com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter) Test(org.junit.jupiter.api.Test)

Example 7 with PipelineTask

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

the class RunLogDao method loadTasksForRun.

@Transactional(propagation = Propagation.SUPPORTS)
public List<PipelineTask> loadTasksForRun(Long runId) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(PipelineLogParameters.RUN_ID.name(), runId);
    List<PipelineTask> result = getNamedParameterJdbcTemplate().query(loadTasksByRunIdQuery, params, PipelineLogParameters.getTaskRowMapper(true));
    return result.stream().filter(Objects::nonNull).collect(Collectors.toList());
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) PipelineTask(com.epam.pipeline.entity.pipeline.PipelineTask) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with PipelineTask

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

the class RunLogManager method loadTasksByRunId.

@Transactional(propagation = Propagation.SUPPORTS)
public List<PipelineTask> loadTasksByRunId(Long runId) {
    PipelineRun run = pipelineRunManager.loadPipelineRun(runId);
    List<PipelineTask> tasks = runLogDao.loadTasksForRun(runId);
    tasks.forEach(task -> {
        if (run.getStatus().isFinal() && !task.getStatus().isFinal()) {
            task.setStatus(run.getStatus());
            if (task.getFinished() == null) {
                task.setFinished(run.getEndDate());
            }
        }
        if ((StringUtils.isEmpty(task.getInstance()) || task.getInstance().equals(run.getPodId())) && !task.getStatus().isFinal()) {
            task.setStatus(run.getStatus());
        }
        if (task.getStarted() == null && (StringUtils.isEmpty(task.getInstance()) || task.getInstance().equals(run.getPodId()) || task.getStatus().isFinal())) {
            task.setStarted(task.getCreated());
        }
        if (!task.getStatus().isFinal()) {
            task.setFinished(null);
        }
        if (task.getName().equals(run.getPipelineName())) {
            task.setCreated(run.getStartDate());
            task.setStarted(tasks.get(0).getCreated());
        }
    });
    if (!run.getStatus().isFinal()) {
        // for running tasks we add dummy 'console' task to get online logs from Kubernetes
        PipelineTask consoleTask = new PipelineTask();
        consoleTask.setName(consoleLogTask);
        consoleTask.setStatus(TaskStatus.RUNNING);
        consoleTask.setStarted(run.getStartDate());
        tasks.add(consoleTask);
    }
    return tasks;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipelineTask(com.epam.pipeline.entity.pipeline.PipelineTask) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with PipelineTask

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

the class GraphReader method getOrCreateNode.

private TaskNode getOrCreateNode(String taskName, Map<String, TaskNode> tasks) {
    if (!tasks.containsKey(taskName)) {
        PipelineTask task = new PipelineTask(taskName);
        task.setId((long) tasks.size() + 1);
        tasks.put(taskName, new TaskNode(task));
    }
    return tasks.get(taskName);
}
Also used : TaskNode(com.epam.pipeline.entity.graph.TaskNode) PipelineTask(com.epam.pipeline.entity.pipeline.PipelineTask)

Example 10 with PipelineTask

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

the class LogsFormatter method formatLog.

public String formatLog(RunLog log) {
    StringBuilder builder = new StringBuilder();
    PipelineTask task = log.getTask();
    builder.append('[').append(dateFormat.format(log.getDate()).trim()).append(TAB_DELIMITER).append(']').append(log.getStatus()).append(TAB_DELIMITER).append(task.getName()).append(TAB_DELIMITER);
    if (task.getParameters() != null) {
        builder.append(task.getParameters()).append(NEW_LINE_DELIMITER);
    }
    builder.append(log.getLogText());
    if (!log.getLogText().endsWith(NEW_LINE_DELIMITER)) {
        builder.append(NEW_LINE_DELIMITER);
    }
    return builder.toString();
}
Also used : PipelineTask(com.epam.pipeline.entity.pipeline.PipelineTask)

Aggregations

PipelineTask (com.epam.pipeline.entity.pipeline.PipelineTask)11 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)5 RunLog (com.epam.pipeline.entity.pipeline.RunLog)4 Transactional (org.springframework.transaction.annotation.Transactional)3 PipelineRunWithLog (com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog)2 TaskNode (com.epam.pipeline.entity.graph.TaskNode)2 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)2 RunStatus (com.epam.pipeline.entity.pipeline.run.RunStatus)2 PipelineRunParameter (com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter)2 Test (org.junit.jupiter.api.Test)2 TaskGraphVO (com.epam.pipeline.controller.vo.TaskGraphVO)1 LoaderVerificationUtils.verifyPipelineRun (com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyPipelineRun)1 LoaderVerificationUtils.verifyRunInstance (com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyRunInstance)1 MapperVerificationUtils.verifyPipelineRun (com.epam.pipeline.elasticsearchagent.MapperVerificationUtils.verifyPipelineRun)1 EntityContainer (com.epam.pipeline.elasticsearchagent.model.EntityContainer)1 TaskStatus (com.epam.pipeline.entity.pipeline.TaskStatus)1 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 ArrayList (java.util.ArrayList)1