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