Search in sources :

Example 1 with PipelineDoc

use of com.epam.pipeline.elasticsearchagent.model.PipelineDoc in project cloud-pipeline by epam.

the class PipelineLoader method fetchEntity.

@Override
protected PipelineDoc fetchEntity(final Long id) {
    Pipeline pipeline = getApiClient().loadPipeline(String.valueOf(id));
    List<Revision> revisions = getApiClient().loadPipelineVersions(pipeline.getId()).stream().filter(revision -> !revision.getName().startsWith(DRAFT_VERSION)).collect(Collectors.toList());
    PipelineDoc.PipelineDocBuilder pipelineDocBuilder = PipelineDoc.builder().pipeline(pipeline).revisions(revisions);
    return pipelineDocBuilder.build();
}
Also used : AbstractCloudPipelineEntityLoader(com.epam.pipeline.elasticsearchagent.service.impl.converter.AbstractCloudPipelineEntityLoader) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) Component(org.springframework.stereotype.Component) List(java.util.List) PipelineDoc(com.epam.pipeline.elasticsearchagent.model.PipelineDoc) CloudPipelineAPIClient(com.epam.pipeline.elasticsearchagent.service.impl.CloudPipelineAPIClient) Revision(com.epam.pipeline.entity.pipeline.Revision) AclClass(com.epam.pipeline.entity.security.acl.AclClass) Collectors(java.util.stream.Collectors) Revision(com.epam.pipeline.entity.pipeline.Revision) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) PipelineDoc(com.epam.pipeline.elasticsearchagent.model.PipelineDoc)

Example 2 with PipelineDoc

use of com.epam.pipeline.elasticsearchagent.model.PipelineDoc in project cloud-pipeline by epam.

the class PipelineMapper method map.

@Override
public XContentBuilder map(final EntityContainer<PipelineDoc> container) {
    PipelineDoc pipelineDoc = container.getEntity();
    try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
        List<String> revisions = pipelineDoc.getRevisions().stream().map(Revision::getName).collect(Collectors.toList());
        jsonBuilder.startObject().field("id", pipelineDoc.getPipeline().getId()).field(DOC_TYPE_FIELD, SearchDocumentType.PIPELINE.name()).field("name", pipelineDoc.getPipeline().getName()).field("description", pipelineDoc.getPipeline().getDescription()).field("createdDate", parseDataToString(pipelineDoc.getPipeline().getCreatedDate())).field("parentId", pipelineDoc.getPipeline().getParentFolderId()).field("repository", pipelineDoc.getPipeline().getRepository()).field("versions", revisions).field("templateId", pipelineDoc.getPipeline().getTemplateId());
        buildUserContent(container.getOwner(), jsonBuilder);
        buildMetadata(container.getMetadata(), jsonBuilder);
        buildPermissions(container.getPermissions(), jsonBuilder);
        jsonBuilder.endObject();
        return jsonBuilder;
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to create elasticsearch document for pipeline: ", e);
    }
}
Also used : IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) PipelineDoc(com.epam.pipeline.elasticsearchagent.model.PipelineDoc)

Example 3 with PipelineDoc

use of com.epam.pipeline.elasticsearchagent.model.PipelineDoc in project cloud-pipeline by epam.

the class PipelineCodeHandlerTest method setup.

@BeforeEach
void setup() {
    pipelineCodeHandler = new PipelineCodeHandler(INDEX_PREFIX, INDEX_NAME, apiClient, new ElasticIndexService(), FILE_INDEX_PATHS, objectMapper, pipelineLoader, new PipelineCodeMapper(), "master");
    expectedPipelineEvent = new PipelineEvent();
    expectedPipelineEvent.setEventType(EventType.INSERT);
    expectedPipelineEvent.setObjectType(PipelineEvent.ObjectType.PIPELINE);
    expectedPipelineEvent.setObjectId(1L);
    expectedPipelineEvent.setCreatedDate(LocalDateTime.now());
    expectedPipelineEvent.setData("{\"tag\": {\"type\": \"string\", \"value\": \"admin\"}}");
    pipeline = new Pipeline();
    pipeline.setId(1L);
    pipeline.setName(TEST_NAME);
    pipeline.setCreatedDate(DateUtils.now());
    pipeline.setParentFolderId(2L);
    pipeline.setDescription(TEST_DESCRIPTION);
    pipeline.setRepository(TEST_REPO);
    pipeline.setTemplateId(TEST_TEMPLATE);
    Revision revision = new Revision();
    revision.setName(TEST_VERSION);
    PipelineDoc pipelineDoc = PipelineDoc.builder().pipeline(pipeline).revisions(Collections.singletonList(revision)).build();
    gitPushEventData = new GitEventData();
    gitPushEventData.setGitEventType(GitEventType.push);
    gitPushEventData.setPaths(Collections.singletonList(FILE_INDEX_PATHS));
    gitPushEventData.setVersion(VERSION);
    gitTagEventData = new GitEventData();
    gitTagEventData.setGitEventType(GitEventType.tag_push);
    gitTagEventData.setPaths(Collections.singletonList(FILE_INDEX_PATHS));
    gitTagEventData.setVersion(VERSION);
    gitRepositoryEntry = new GitRepositoryEntry();
    gitRepositoryEntry.setId("1");
    gitRepositoryEntry.setName(TEST_NAME);
    gitRepositoryEntry.setPath(FOLDER_INDEX_PATHS);
    gitRepositoryEntry.setType("blob");
    container = EntityContainer.<PipelineDoc>builder().entity(pipelineDoc).owner(USER).metadata(METADATA).permissions(PERMISSIONS_CONTAINER).build();
}
Also used : GitEventData(com.epam.pipeline.elasticsearchagent.model.git.GitEventData) PipelineCodeMapper(com.epam.pipeline.elasticsearchagent.service.impl.converter.pipeline.PipelineCodeMapper) PipelineEvent(com.epam.pipeline.elasticsearchagent.model.PipelineEvent) Revision(com.epam.pipeline.entity.pipeline.Revision) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) PipelineDoc(com.epam.pipeline.elasticsearchagent.model.PipelineDoc) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with PipelineDoc

use of com.epam.pipeline.elasticsearchagent.model.PipelineDoc in project cloud-pipeline by epam.

the class PipelineSynchronizer method createIndexDocuments.

private void createIndexDocuments(final PipelineEvent event, final String pipelineIndex, final String codeIndex, final PipelineDocRequests.PipelineDocRequestsBuilder requestsBuilder, final EntityContainer<PipelineDoc> pipelineEntity) {
    requestsBuilder.pipelineRequests(Collections.singletonList(new IndexRequest(pipelineIndex, INDEX_TYPE, String.valueOf(event.getObjectId())).source(mapper.map(pipelineEntity))));
    final Pipeline pipeline = pipelineEntity.getEntity().getPipeline();
    final List<Revision> revisions = cloudPipelineAPIClient.loadPipelineVersions(pipeline.getId());
    log.debug("Loaded revisions for pipeline: {}", ListUtils.emptyIfNull(revisions).stream().map(Revision::getName).collect(Collectors.joining(", ")));
    requestsBuilder.codeRequests(revisions.stream().map(revision -> pipelineCodeHandler.createPipelineCodeDocuments(pipeline, pipelineEntity.getPermissions(), revision.getName(), codeIndex, pipelineFileIndexPaths)).flatMap(Collection::stream).collect(Collectors.toList()));
    log.debug("Created index and documents for {} pipeline.", pipeline.getName());
}
Also used : Arrays(java.util.Arrays) LocalDateTime(java.time.LocalDateTime) EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) ElasticsearchSynchronizer(com.epam.pipeline.elasticsearchagent.service.ElasticsearchSynchronizer) ElasticsearchServiceClient(com.epam.pipeline.elasticsearchagent.service.ElasticsearchServiceClient) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Value(org.springframework.beans.factory.annotation.Value) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) PipelineIdConverter(com.epam.pipeline.elasticsearchagent.service.impl.converter.pipeline.PipelineIdConverter) Service(org.springframework.stereotype.Service) EventProcessorUtils(com.epam.pipeline.elasticsearchagent.utils.EventProcessorUtils) ListUtils(org.apache.commons.collections4.ListUtils) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) PipelineEvent(com.epam.pipeline.elasticsearchagent.model.PipelineEvent) PipelineLoader(com.epam.pipeline.elasticsearchagent.service.impl.converter.pipeline.PipelineLoader) INDEX_TYPE(com.epam.pipeline.elasticsearchagent.service.EventToRequestConverter.INDEX_TYPE) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) PipelineMapper(com.epam.pipeline.elasticsearchagent.service.impl.converter.pipeline.PipelineMapper) BulkResponsePostProcessor(com.epam.pipeline.elasticsearchagent.service.BulkResponsePostProcessor) Collection(java.util.Collection) EventType(com.epam.pipeline.elasticsearchagent.model.EventType) EntityNotFoundException(com.epam.pipeline.elasticsearchagent.exception.EntityNotFoundException) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PipelineEventDao(com.epam.pipeline.elasticsearchagent.dao.PipelineEventDao) Stream(java.util.stream.Stream) Builder(lombok.Builder) PipelineDoc(com.epam.pipeline.elasticsearchagent.model.PipelineDoc) Revision(com.epam.pipeline.entity.pipeline.Revision) Data(lombok.Data) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) Revision(com.epam.pipeline.entity.pipeline.Revision) Collection(java.util.Collection) IndexRequest(org.elasticsearch.action.index.IndexRequest) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Example 5 with PipelineDoc

use of com.epam.pipeline.elasticsearchagent.model.PipelineDoc in project cloud-pipeline by epam.

the class PipelineLoaderTest method shouldLoadPipeline.

@Test
void shouldLoadPipeline() throws EntityNotFoundException {
    Pipeline expectedPipeline = new Pipeline(1L);
    expectedPipeline.setName(TEST_NAME);
    expectedPipeline.setCreatedDate(DateUtils.now());
    expectedPipeline.setParentFolderId(2L);
    expectedPipeline.setDescription(TEST_DESCRIPTION);
    expectedPipeline.setRepository(TEST_REPO);
    expectedPipeline.setTemplateId(TEST_TEMPLATE);
    expectedPipeline.setOwner(TEST_NAME);
    Revision expectedRevision = new Revision();
    expectedRevision.setName(TEST_NAME);
    PipelineLoader pipelineLoader = new PipelineLoader(apiClient);
    when(apiClient.loadPipeline(anyString())).thenReturn(expectedPipeline);
    when(apiClient.loadPipelineVersions(anyLong())).thenReturn(Collections.singletonList(expectedRevision));
    Optional<EntityContainer<PipelineDoc>> container = pipelineLoader.loadEntity(1L);
    EntityContainer<PipelineDoc> pipelineDocEntityContainer = container.orElseThrow(AssertionError::new);
    PipelineDoc actualPipelineDoc = pipelineDocEntityContainer.getEntity();
    assertNotNull(actualPipelineDoc);
    Pipeline actualPipeline = actualPipelineDoc.getPipeline();
    assertNotNull(actualPipeline);
    List<Revision> revisions = actualPipelineDoc.getRevisions();
    assertNotNull(revisions);
    assertEquals(expectedPipeline.getId(), actualPipeline.getId());
    assertEquals(expectedPipeline.getName(), actualPipeline.getName());
    assertEquals(expectedPipeline.getCreatedDate(), actualPipeline.getCreatedDate());
    assertEquals(expectedPipeline.getParentFolderId(), actualPipeline.getParentFolderId());
    assertEquals(expectedPipeline.getDescription(), actualPipeline.getDescription());
    assertEquals(expectedPipeline.getRepository(), actualPipeline.getRepository());
    assertEquals(expectedPipeline.getTemplateId(), actualPipeline.getTemplateId());
    verifyPipelineUser(pipelineDocEntityContainer.getOwner());
    verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, pipelineDocEntityContainer.getPermissions());
    verifyMetadata(EXPECTED_METADATA, new ArrayList<>(pipelineDocEntityContainer.getMetadata().values()));
}
Also used : Revision(com.epam.pipeline.entity.pipeline.Revision) EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) PipelineDoc(com.epam.pipeline.elasticsearchagent.model.PipelineDoc) Test(org.junit.jupiter.api.Test)

Aggregations

PipelineDoc (com.epam.pipeline.elasticsearchagent.model.PipelineDoc)6 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)5 Revision (com.epam.pipeline.entity.pipeline.Revision)5 EntityContainer (com.epam.pipeline.elasticsearchagent.model.EntityContainer)2 PipelineEvent (com.epam.pipeline.elasticsearchagent.model.PipelineEvent)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 Test (org.junit.jupiter.api.Test)2 MapperVerificationUtils.verifyPipeline (com.epam.pipeline.elasticsearchagent.MapperVerificationUtils.verifyPipeline)1 PipelineEventDao (com.epam.pipeline.elasticsearchagent.dao.PipelineEventDao)1 EntityNotFoundException (com.epam.pipeline.elasticsearchagent.exception.EntityNotFoundException)1 EventType (com.epam.pipeline.elasticsearchagent.model.EventType)1 GitEventData (com.epam.pipeline.elasticsearchagent.model.git.GitEventData)1 BulkResponsePostProcessor (com.epam.pipeline.elasticsearchagent.service.BulkResponsePostProcessor)1 ElasticsearchServiceClient (com.epam.pipeline.elasticsearchagent.service.ElasticsearchServiceClient)1 ElasticsearchSynchronizer (com.epam.pipeline.elasticsearchagent.service.ElasticsearchSynchronizer)1 INDEX_TYPE (com.epam.pipeline.elasticsearchagent.service.EventToRequestConverter.INDEX_TYPE)1 CloudPipelineAPIClient (com.epam.pipeline.elasticsearchagent.service.impl.CloudPipelineAPIClient)1 AbstractCloudPipelineEntityLoader (com.epam.pipeline.elasticsearchagent.service.impl.converter.AbstractCloudPipelineEntityLoader)1