Search in sources :

Example 1 with PipelineEvent

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

the class PipelineEventDao method loadPipelineEventsByObjectType.

@Transactional(propagation = Propagation.SUPPORTS)
public List<PipelineEvent> loadPipelineEventsByObjectType(final PipelineEvent.ObjectType objectType, final LocalDateTime before) {
    MapSqlParameterSource parameterSource = new MapSqlParameterSource();
    parameterSource.addValue(PipelineEventsParameters.OBJECT_TYPE.name(), objectType.getDbName());
    parameterSource.addValue(PipelineEventsParameters.STAMP.name(), OffsetDateTime.of(before, ZoneOffset.ofHours(0)));
    List<PipelineEvent> pipelineEvents = getNamedParameterJdbcTemplate().query(loadAllEventsByObjectTypeQuery, parameterSource, PipelineEventsParameters.getRowMapper());
    return ListUtils.emptyIfNull(pipelineEvents);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) PipelineEvent(com.epam.pipeline.elasticsearchagent.model.PipelineEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with PipelineEvent

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

the class GitTagEventProcessor method processEvent.

@Override
public void processEvent(final GitEvent event) {
    if (!validateEvent(event)) {
        return;
    }
    log.debug("Processing event: {}", event);
    fetchPipeline(event, apiClient).ifPresent(pipeline -> {
        final GitEventData eventData = GitEventData.builder().gitEventType(supportedEventType()).version(fetchVersion(event)).build();
        final PipelineEvent pipelineEvent;
        try {
            pipelineEvent = PipelineEvent.builder().objectType(PipelineEvent.ObjectType.PIPELINE_CODE).eventType(fetchPipelineEventType(event)).createdDate(LocalDateTime.now()).objectId(pipeline.getId()).data(objectMapper.writeValueAsString(eventData)).build();
            eventDao.createPipelineEvent(pipelineEvent);
        } catch (JsonProcessingException e) {
            log.error(e.getMessage(), e);
        }
    });
}
Also used : GitEventData(com.epam.pipeline.elasticsearchagent.model.git.GitEventData) PipelineEvent(com.epam.pipeline.elasticsearchagent.model.PipelineEvent) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with PipelineEvent

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

the class PipelineEventDaoTest method shouldCreatePipelineEventTest.

@Test
void shouldCreatePipelineEventTest() {
    pipelineEventDao.createPipelineEvent(expectedPipelineEvent);
    List<PipelineEvent> pipelineEvents = pipelineEventDao.loadPipelineEventsByObjectType(PipelineEvent.ObjectType.PIPELINE, LocalDateTime.now());
    assertEquals(1, pipelineEvents.size());
    PipelineEvent actualPipelineEvent = pipelineEvents.get(0);
    assertAll("actualPipelineEvent", () -> assertEquals(expectedPipelineEvent.getObjectId(), actualPipelineEvent.getObjectId()), () -> assertEquals(expectedPipelineEvent.getEventType(), actualPipelineEvent.getEventType()), () -> assertEquals(expectedPipelineEvent.getCreatedDate(), actualPipelineEvent.getCreatedDate()), () -> assertEquals(expectedPipelineEvent.getData(), actualPipelineEvent.getData()));
}
Also used : PipelineEvent(com.epam.pipeline.elasticsearchagent.model.PipelineEvent) Test(org.junit.jupiter.api.Test) AbstractSpringApplicationTest(com.epam.pipeline.elasticsearchagent.AbstractSpringApplicationTest)

Example 4 with PipelineEvent

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

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

the class GitTagEventProcessorTest method shouldProcessTagEventTest.

@Test
void shouldProcessTagEventTest() throws IOException {
    Pipeline pipeline = new Pipeline();
    pipeline.setId(1L);
    pipeline.setName(TEST_NAME);
    pipeline.setRepository(TEST_PATH);
    when(apiClient.loadPipelineByRepositoryUrl(anyString())).thenReturn(pipeline);
    gitTagEventProcessor.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, String>>() {
    });
    assertAll("event", () -> assertEquals(PipelineEvent.ObjectType.PIPELINE_CODE, event.getObjectType()), () -> assertEquals(EventType.INSERT, event.getEventType()), () -> assertEquals(GitEventType.tag_push.name(), map.get("gitEventType")), () -> assertEquals(BRANCH, map.get("version")));
}
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)

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