Search in sources :

Example 1 with GitEventData

use of com.epam.pipeline.elasticsearchagent.model.git.GitEventData 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 2 with GitEventData

use of com.epam.pipeline.elasticsearchagent.model.git.GitEventData 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 3 with GitEventData

use of com.epam.pipeline.elasticsearchagent.model.git.GitEventData 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 4 with GitEventData

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

the class PipelineCodeHandler method processTagEvent.

private List<DocWriteRequest> processTagEvent(final String indexName, final Pipeline pipeline, final PermissionsContainer permissions, final List<GitEventDescription> gitEventData) {
    final GitEventDescription lastEvent = Utils.last(gitEventData);
    final GitEventData eventData = lastEvent.getEventData();
    final String versionName = eventData.getVersion();
    if (lastEvent.getPipelineEvent().getEventType() == EventType.DELETE) {
        return indexService.getDeleteRequestsByTerm("pipelineVersion", versionName, indexName);
    }
    return createPipelineCodeDocuments(pipeline, permissions, versionName, indexName, pipelineFileIndexPaths);
}
Also used : GitEventData(com.epam.pipeline.elasticsearchagent.model.git.GitEventData) GitEventDescription(com.epam.pipeline.elasticsearchagent.model.git.GitEventDescription)

Aggregations

GitEventData (com.epam.pipeline.elasticsearchagent.model.git.GitEventData)4 PipelineEvent (com.epam.pipeline.elasticsearchagent.model.PipelineEvent)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 PipelineDoc (com.epam.pipeline.elasticsearchagent.model.PipelineDoc)1 GitEventDescription (com.epam.pipeline.elasticsearchagent.model.git.GitEventDescription)1 PipelineCodeMapper (com.epam.pipeline.elasticsearchagent.service.impl.converter.pipeline.PipelineCodeMapper)1 GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)1 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)1 Revision (com.epam.pipeline.entity.pipeline.Revision)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1