use of com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog in project cloud-pipeline by epam.
the class CloudPipelineAPIClient method loadPipelineRunWithLogs.
public PipelineRunWithLog loadPipelineRunWithLogs(final Long pipelineRunId) {
PipelineRunWithLog runWithLog = new PipelineRunWithLog();
runWithLog.setPipelineRun(loadPipelineRun(pipelineRunId));
List<RunLog> runLogs = QueryUtils.execute(cloudPipelineAPI.loadLogs(pipelineRunId));
runWithLog.setRunLogs(runLogs);
return runWithLog;
}
use of com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog 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.elasticsearchagent.model.PipelineRunWithLog in project cloud-pipeline by epam.
the class PipelineRunMapperOld method getRequestForRun.
private Optional<DocWriteRequest> getRequestForRun(final String indexName, final PipelineEvent event, final Map<String, PipelineUser> users) {
try {
PipelineRunWithLog run = cloudPipelineAPIClient.loadPipelineRunWithLogs(event.getObjectId());
PipelineUser pipelineUser = users.get(run.getPipelineRun().getOwner());
run.setRunOwner(pipelineUser);
return Optional.of(new IndexRequest(indexName, INDEX_TYPE, String.valueOf(run.getPipelineRun().getId())).source(pipelineRunToDocument(run)));
} catch (PipelineResponseException e) {
log.error(e.getMessage(), e);
if (isRunMissingError(event, e)) {
return Optional.of(createDeleteRequest(event, indexName));
}
return Optional.empty();
}
}
use of com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog in project cloud-pipeline by epam.
the class PipelineRunMapper method map.
@Override
public XContentBuilder map(final EntityContainer<PipelineRunWithLog> container) {
PipelineRunWithLog run = container.getEntity();
try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
jsonBuilder.startObject().field("id", run.getPipelineRun().getId()).field(DOC_TYPE_FIELD, SearchDocumentType.PIPELINE_RUN.name()).field("description", getRunDescription(run.getPipelineRun())).field("createdDate", parseDataToString(run.getPipelineRun().getCreatedDate())).field("startDate", parseDataToString(run.getPipelineRun().getStartDate())).field("endDate", parseDataToString(run.getPipelineRun().getEndDate())).field("pipelineName", run.getPipelineRun().getPipelineName()).field("pipelineVersion", run.getPipelineRun().getVersion()).field("status", run.getPipelineRun().getStatus()).field("dockerImage", run.getPipelineRun().getDockerImage()).field("actualCmd", run.getPipelineRun().getActualCmd()).field("configurationName", run.getPipelineRun().getConfigName()).field("configurationId", run.getPipelineRun().getConfigurationId()).field("environment", Optional.ofNullable(run.getPipelineRun().getExecutionPreferences()).map(preferences -> preferences.getEnvironment().name()).orElse(null)).field("pricePerHour", run.getPipelineRun().getPricePerHour().doubleValue()).field("parentRunId", run.getPipelineRun().getParentRunId()).field("nodeCount", run.getPipelineRun().getNodeCount()).field("podId", run.getPipelineRun().getPodId());
buildRunInstance(run.getPipelineRun().getInstance(), jsonBuilder);
buildRunStatus(run.getPipelineRun().getRunStatuses(), jsonBuilder);
buildRunParam(run.getPipelineRun().getPipelineRunParameters(), jsonBuilder);
buildRunLog(run.getRunLogs(), jsonBuilder);
buildUserContent(container.getOwner(), jsonBuilder);
buildPermissions(container.getPermissions(), jsonBuilder);
jsonBuilder.endObject();
return jsonBuilder;
} catch (IOException e) {
throw new IllegalArgumentException("Failed to create elasticsearch document for pipeline run: ", e);
}
}
use of com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog in project cloud-pipeline by epam.
the class RunMapperTest method shouldMapRun.
@Test
void shouldMapRun() throws IOException {
PipelineRunMapper mapper = new PipelineRunMapper();
PipelineRunWithLog pipelineRunWithLog = new PipelineRunWithLog();
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 run = new PipelineRun();
run.setId(1L);
run.setName(TEST_NAME);
run.setPipelineName(TEST_NAME);
run.setInstance(instance);
run.setStatus(TaskStatus.SUCCESS);
run.setPipelineName(TEST_NAME);
run.setVersion(TEST_VERSION);
run.setRunStatuses(Collections.singletonList(runStatus));
run.setPricePerHour(PRICE);
run.setPipelineRunParameters(Collections.singletonList(parameter));
RunLog runLog = new RunLog();
runLog.setLogText(TEST_DESCRIPTION);
runLog.setStatus(TaskStatus.SUCCESS);
runLog.setTask(new PipelineTask(TEST_NAME));
pipelineRunWithLog.setPipelineRun(run);
pipelineRunWithLog.setRunOwner(USER);
pipelineRunWithLog.setRunLogs(Collections.singletonList(runLog));
EntityContainer<PipelineRunWithLog> container = EntityContainer.<PipelineRunWithLog>builder().entity(pipelineRunWithLog).owner(USER).permissions(PERMISSIONS_CONTAINER).build();
XContentBuilder contentBuilder = mapper.map(container);
verifyPipelineRun(run, TEST_NAME + " " + TEST_VERSION, contentBuilder);
verifyRunParameters(Collections.singletonList(TEST_NAME + " " + TEST_VALUE), contentBuilder);
verifyRunLogs(Collections.singletonList(TEST_NAME + " " + TEST_DESCRIPTION), contentBuilder);
verifyPipelineUser(USER, contentBuilder);
verifyPermissions(PERMISSIONS_CONTAINER, contentBuilder);
}
Aggregations