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();
}
}
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());
}
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\"}}");
}
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")));
}
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;
}
Aggregations