Search in sources :

Example 1 with PipelineRunWithLog

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

Example 2 with PipelineRunWithLog

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());
}
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 3 with PipelineRunWithLog

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();
    }
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) PipelineResponseException(com.epam.pipeline.exception.PipelineResponseException) PipelineRunWithLog(com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 4 with PipelineRunWithLog

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);
    }
}
Also used : PipelineRunWithLog(com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 5 with PipelineRunWithLog

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);
}
Also used : MapperVerificationUtils.verifyPipelineRun(com.epam.pipeline.elasticsearchagent.MapperVerificationUtils.verifyPipelineRun) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) RunStatus(com.epam.pipeline.entity.pipeline.run.RunStatus) RunLog(com.epam.pipeline.entity.pipeline.RunLog) PipelineRunWithLog(com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance) PipelineTask(com.epam.pipeline.entity.pipeline.PipelineTask) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) PipelineRunParameter(com.epam.pipeline.entity.pipeline.run.parameter.PipelineRunParameter) Test(org.junit.jupiter.api.Test)

Aggregations

PipelineRunWithLog (com.epam.pipeline.elasticsearchagent.model.PipelineRunWithLog)5 RunLog (com.epam.pipeline.entity.pipeline.RunLog)3 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)2 PipelineTask (com.epam.pipeline.entity.pipeline.PipelineTask)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 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 Test (org.junit.jupiter.api.Test)2 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 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)1 PipelineResponseException (com.epam.pipeline.exception.PipelineResponseException)1 IOException (java.io.IOException)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1