Search in sources :

Example 11 with Revision

use of com.epam.pipeline.entity.pipeline.Revision in project cloud-pipeline by epam.

the class GitManagerTest method shouldCreatePipelineRevision.

@Test
public void shouldCreatePipelineRevision() throws GitClientException {
    final String sha = "anothercommitsha";
    final GitCommitEntry commit = new GitCommitEntry();
    commit.setId(sha);
    commit.setAuthoredDate("2017-07-26T13:13:11Z");
    final GitTagEntry tag = new GitTagEntry();
    final String tagName = "v1.0.1";
    tag.setName(tagName);
    tag.setCommit(commit);
    givenThat(post(urlPathEqualTo(api(REPOSITORY_TAGS))).withQueryParam(REF, equalTo(sha)).withQueryParam(TAG_NAME, equalTo(tagName)).willReturn(created().withHeader(CONTENT_TYPE, "application/json").withBody(with(tag))));
    final Pipeline pipeline = testingPipeline();
    final Revision revision = gitManager.createPipelineRevision(pipeline, tagName, sha, "Message", "Release description");
    assertThat(revision.getName(), is(tag.getName()));
    assertThat(revision.getMessage(), is(tag.getMessage()));
}
Also used : Revision(com.epam.pipeline.entity.pipeline.Revision) IsEmptyString.isEmptyString(org.hamcrest.text.IsEmptyString.isEmptyString) Matchers.anyString(org.mockito.Matchers.anyString) GitTagEntry(com.epam.pipeline.entity.git.GitTagEntry) GitCommitEntry(com.epam.pipeline.entity.git.GitCommitEntry) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test)

Example 12 with Revision

use of com.epam.pipeline.entity.pipeline.Revision 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 13 with Revision

use of com.epam.pipeline.entity.pipeline.Revision 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)

Example 14 with Revision

use of com.epam.pipeline.entity.pipeline.Revision in project cloud-pipeline by epam.

the class PipelineMapperTest method shouldMapPipeline.

@Test
void shouldMapPipeline() throws IOException {
    PipelineMapper mapper = new PipelineMapper();
    Pipeline 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_NAME);
    PipelineDoc pipelineDoc = PipelineDoc.builder().pipeline(pipeline).revisions(Collections.singletonList(revision)).build();
    EntityContainer<PipelineDoc> container = EntityContainer.<PipelineDoc>builder().entity(pipelineDoc).owner(USER).metadata(METADATA).permissions(PERMISSIONS_CONTAINER).build();
    XContentBuilder contentBuilder = mapper.map(container);
    verifyPipeline(pipeline, contentBuilder);
    verifyPipelineUser(USER, contentBuilder);
    verifyPermissions(PERMISSIONS_CONTAINER, contentBuilder);
    verifyMetadata(EXPECTED_METADATA, contentBuilder);
}
Also used : Revision(com.epam.pipeline.entity.pipeline.Revision) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) MapperVerificationUtils.verifyPipeline(com.epam.pipeline.elasticsearchagent.MapperVerificationUtils.verifyPipeline) PipelineDoc(com.epam.pipeline.elasticsearchagent.model.PipelineDoc) Test(org.junit.jupiter.api.Test)

Aggregations

Revision (com.epam.pipeline.entity.pipeline.Revision)14 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)11 PipelineDoc (com.epam.pipeline.elasticsearchagent.model.PipelineDoc)5 Date (java.util.Date)5 GitCommitEntry (com.epam.pipeline.entity.git.GitCommitEntry)4 GitTagEntry (com.epam.pipeline.entity.git.GitTagEntry)4 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)4 Test (org.junit.Test)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 EntityContainer (com.epam.pipeline.elasticsearchagent.model.EntityContainer)2 PipelineEvent (com.epam.pipeline.elasticsearchagent.model.PipelineEvent)2 GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)2 GitClientException (com.epam.pipeline.exception.git.GitClientException)2 ArrayList (java.util.ArrayList)2 Slf4j (lombok.extern.slf4j.Slf4j)2 IsEmptyString.isEmptyString (org.hamcrest.text.IsEmptyString.isEmptyString)2 Test (org.junit.jupiter.api.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 TaskGraphVO (com.epam.pipeline.controller.vo.TaskGraphVO)1