Search in sources :

Example 1 with Graph

use of org.jboss.pnc.dto.response.Graph in project pnc by project-ncl.

the class BuildProviderImpl method getBuildGraphForGroupBuild.

@Override
public Graph<Build> getBuildGraphForGroupBuild(String groupBuildId) {
    BuildConfigSetRecord buildConfigSetRecord = buildConfigSetRecordRepository.queryById(Integer.valueOf(groupBuildId));
    if (buildConfigSetRecord == null) {
        throw new EmptyEntityException("Build group " + groupBuildId + " does not exists.");
    }
    List<String> runningAndStoredIds = getBuildIdsInTheGroup(buildConfigSetRecord);
    org.jboss.util.graph.Graph<BuildWithDependencies> buildGraph = new org.jboss.util.graph.Graph<>();
    for (String buildId : runningAndStoredIds) {
        org.jboss.util.graph.Graph<BuildWithDependencies> dependencyGraph = createBuildDependencyGraph(buildId);
        GraphUtils.merge(buildGraph, dependencyGraph);
        logger.trace("Merged graph from buildRecordId {} to BuildConfigSetRecordGraph {}; Edges {},", buildId, buildGraph, buildGraph.getEdges());
    }
    GraphDtoBuilder<BuildWithDependencies, Build> graphBuilder = new GraphDtoBuilder();
    Graph<Build> graphDto = graphBuilder.from(buildGraph, Build.class, vertex -> vertex.getData().getBuild());
    return graphDto;
}
Also used : GraphDtoBuilder(org.jboss.pnc.facade.util.GraphDtoBuilder) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) Graph(org.jboss.pnc.dto.response.Graph) BuildRecordPredicates.temporaryBuild(org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild) Build(org.jboss.pnc.dto.Build) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 2 with Graph

use of org.jboss.pnc.dto.response.Graph in project pnc by project-ncl.

the class BuildProviderImplTest method shouldGetGraphWithDependencies.

@Test
public void shouldGetGraphWithDependencies() {
    // With
    Integer buildSetTaskId = 1;
    BuildSetTask buildSetTask = mock(BuildSetTask.class);
    when(buildSetTask.getId()).thenReturn(buildSetTaskId);
    BuildTask task = mockBuildTaskWithSet(buildSetTask);
    BuildTask taskDep = mockBuildTaskWithSet(buildSetTask);
    BuildTask taskDepDep = mockBuildTaskWithSet(buildSetTask);
    when(task.getDependencies()).thenReturn(asSet(taskDep));
    when(taskDep.getDependencies()).thenReturn(asSet(taskDepDep));
    // When
    Graph<Build> graph = provider.getBuildGraphForGroupBuild(Integer.toString(buildSetTaskId));
    // Then
    assertThat(graph.getVertices()).hasSize(3);
    List<String> buildTaskIDsOrderedByBCName = Stream.of(task, taskDep, taskDepDep).sorted(Comparator.comparing(t -> t.getBuildConfigurationAudited().getName())).map(t -> t.getId()).collect(Collectors.toList());
    assertThat(graph.getVertices().values().stream().map(Vertex::getName)).containsExactlyElementsOf(buildTaskIDsOrderedByBCName);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PageInfo(org.jboss.pnc.spi.datastore.repositories.api.PageInfo) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) Date(java.util.Date) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationAuditedRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigurationAuditedRepository) Repository(org.jboss.pnc.spi.datastore.repositories.api.Repository) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) EmptyEntityException(org.jboss.pnc.facade.validation.EmptyEntityException) BuildConfigSetRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildConfigSetRecordRepository) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BDDMockito.given(org.mockito.BDDMockito.given) UserService(org.jboss.pnc.facade.util.UserService) Graph(org.jboss.pnc.dto.response.Graph) Assert.fail(org.junit.Assert.fail) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) User(org.jboss.pnc.model.User) SortInfoProducer(org.jboss.pnc.spi.datastore.repositories.SortInfoProducer) ResultStatus(org.jboss.pnc.enums.ResultStatus) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) Result(org.jboss.pnc.spi.coordinator.Result) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) Assert.assertFalse(org.junit.Assert.assertFalse) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) WireMock.matchingJsonPath(com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath) Base32LongID(org.jboss.pnc.model.Base32LongID) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Predicate(org.jboss.pnc.spi.datastore.repositories.api.Predicate) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) WireMock.postRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor) BuildPageInfo(org.jboss.pnc.facade.providers.api.BuildPageInfo) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) ArrayList(java.util.ArrayList) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) HashSet(java.util.HashSet) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Edge(org.jboss.pnc.dto.response.Edge) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) CorruptedDataException(org.jboss.pnc.facade.validation.CorruptedDataException) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) Logger(org.slf4j.Logger) LongStream(java.util.stream.LongStream) Iterator(java.util.Iterator) Test(org.junit.Test) BuildRecord(org.jboss.pnc.model.BuildRecord) Mockito.when(org.mockito.Mockito.when) TemporaryBuildsCleanerAsyncInvoker(org.jboss.pnc.coordinator.maintenance.TemporaryBuildsCleanerAsyncInvoker) Page(org.jboss.pnc.dto.response.Page) Vertex(org.jboss.pnc.dto.response.Vertex) Consumer(java.util.function.Consumer) Build(org.jboss.pnc.dto.Build) Condition(org.assertj.core.api.Condition) RandomUtils.randInt(org.jboss.pnc.common.util.RandomUtils.randInt) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.same(org.mockito.ArgumentMatchers.same) Vertex(org.jboss.pnc.dto.response.Vertex) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Build(org.jboss.pnc.dto.Build) Test(org.junit.Test)

Aggregations

Build (org.jboss.pnc.dto.Build)2 Graph (org.jboss.pnc.dto.response.Graph)2 EmptyEntityException (org.jboss.pnc.facade.validation.EmptyEntityException)2 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMock.equalTo (com.github.tomakehurst.wiremock.client.WireMock.equalTo)1 WireMock.matchingJsonPath (com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath)1 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)1 WireMock.postRequestedFor (com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor)1 WireMock.urlEqualTo (com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1