Search in sources :

Example 6 with PipelineEvent

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

the class GitPushEventProcessor method buildEvent.

private Optional<PipelineEvent> buildEvent(final GitCommit commit, final EventType eventType, final List<String> paths, final Long pipelineId) {
    if (CollectionUtils.isEmpty(paths)) {
        return Optional.empty();
    }
    final GitEventData data = GitEventData.builder().gitEventType(supportedEventType()).version(defaultBranch).paths(paths).build();
    final PipelineEvent pipelineEvent;
    try {
        pipelineEvent = PipelineEvent.builder().createdDate(commit.getTimestamp()).eventType(eventType).objectType(PipelineEvent.ObjectType.PIPELINE_CODE).data(objectMapper.writeValueAsString(data)).objectId(pipelineId).build();
        return Optional.of(pipelineEvent);
    } catch (JsonProcessingException e) {
        log.error(e.getMessage(), e);
        return Optional.empty();
    }
}
Also used : GitEventData(com.epam.pipeline.elasticsearchagent.model.git.GitEventData) PipelineEvent(com.epam.pipeline.elasticsearchagent.model.PipelineEvent) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 7 with PipelineEvent

use of com.epam.pipeline.elasticsearchagent.model.PipelineEvent 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 8 with PipelineEvent

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

the class PipelineEventDaoTest method setup.

@BeforeEach
void setup() {
    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\"}}");
}
Also used : PipelineEvent(com.epam.pipeline.elasticsearchagent.model.PipelineEvent) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with PipelineEvent

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

the class GitPushEventProcessorTest method shouldProcessPushEventTest.

@Test
void shouldProcessPushEventTest() throws IOException {
    Pipeline pipeline = new Pipeline();
    pipeline.setId(1L);
    pipeline.setName(TEST_NAME);
    pipeline.setRepository(TEST_PATH);
    when(apiClient.loadPipelineByRepositoryUrl(anyString())).thenReturn(pipeline);
    gitPushEventProcessor.processEvent(gitEvent);
    LocalDateTime dateTime = LocalDateTime.now();
    List<PipelineEvent> pipelineCodeEvents = eventDao.loadPipelineEventsByObjectType(PipelineEvent.ObjectType.PIPELINE_CODE, dateTime);
    assertEquals(1, pipelineCodeEvents.size());
    PipelineEvent event = pipelineCodeEvents.get(0);
    Map<String, Object> map = objectMapper.readValue(event.getData(), new TypeReference<Map<String, Object>>() {
    });
    assertAll("event", () -> assertEquals(PipelineEvent.ObjectType.PIPELINE_CODE, event.getObjectType()), () -> assertEquals(EventType.UPDATE, event.getEventType()), () -> assertEquals(GitEventType.push.name(), map.get("gitEventType")), () -> assertEquals(BRANCH, map.get("version")), () -> assertEquals(Collections.singletonList(COMMIT_FILE_PATH), map.get("paths")));
}
Also used : LocalDateTime(java.time.LocalDateTime) PipelineEvent(com.epam.pipeline.elasticsearchagent.model.PipelineEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractSpringApplicationTest(com.epam.pipeline.elasticsearchagent.AbstractSpringApplicationTest) Test(org.junit.jupiter.api.Test)

Example 10 with PipelineEvent

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

the class EntitySynchronizerTest method createEvent.

private PipelineEvent createEvent(EventType eventType, LocalDateTime createdDate, PipelineEvent.ObjectType type, Long objectId) {
    PipelineEvent event = new PipelineEvent();
    event.setEventType(eventType);
    event.setCreatedDate(createdDate);
    event.setObjectType(type);
    event.setObjectId(objectId);
    return event;
}
Also used : PipelineEvent(com.epam.pipeline.elasticsearchagent.model.PipelineEvent)

Aggregations

PipelineEvent (com.epam.pipeline.elasticsearchagent.model.PipelineEvent)12 Test (org.junit.jupiter.api.Test)5 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)4 AbstractSpringApplicationTest (com.epam.pipeline.elasticsearchagent.AbstractSpringApplicationTest)3 GitEventData (com.epam.pipeline.elasticsearchagent.model.git.GitEventData)3 LocalDateTime (java.time.LocalDateTime)3 PipelineDoc (com.epam.pipeline.elasticsearchagent.model.PipelineDoc)2 Revision (com.epam.pipeline.entity.pipeline.Revision)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 PipelineEventDao (com.epam.pipeline.elasticsearchagent.dao.PipelineEventDao)1 EntityNotFoundException (com.epam.pipeline.elasticsearchagent.exception.EntityNotFoundException)1 EntityContainer (com.epam.pipeline.elasticsearchagent.model.EntityContainer)1 EventType (com.epam.pipeline.elasticsearchagent.model.EventType)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