Search in sources :

Example 21 with BuildSetTask

use of org.jboss.pnc.spi.coordinator.BuildSetTask 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)

Example 22 with BuildSetTask

use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.

the class DefaultBuildCoordinatorTest method testBuildBuildConfigurationSet.

@Test
public void testBuildBuildConfigurationSet() throws BuildConflictException, CoreException, DatastoreException {
    BuildConfigurationAudited bca = mockDatastoreWithBCAudited(BC_1, 5);
    BuildConfigurationAudited bcaDep = mockDatastoreWithBCAudited(BC_2, 2);
    BuildConfigurationAudited bca3 = mockDatastoreWithBCAudited(BC_3, 9);
    when(datastore.getBuildConfigurations(BCS)).thenReturn(BCS.getBuildConfigurations());
    BuildSetTask buildSetTask = coordinator.build(BCS, USER, BUILD_OPTIONS);
    assertEquals(2, buildSetTask.getBuildTasks().size());
    assertNotNull(buildSetTask.getBuildTask(bca));
    // Dependencies outside group are not build
    assertNull(buildSetTask.getBuildTask(bcaDep));
    assertNotNull(buildSetTask.getBuildTask(bca3));
    assertSame(BUILD_OPTIONS, buildSetTask.getBuildOptions());
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Test(org.junit.Test)

Example 23 with BuildSetTask

use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.

the class BuildCoordinationTest method buildConfigSetRecordShouldBeMarkedFailedOnFailure.

@Test
public void buildConfigSetRecordShouldBeMarkedFailedOnFailure() throws CoreException, TimeoutException, InterruptedException {
    BuildConfigurationSet buildConfigurationSet = TestEntitiesFactory.newBuildConfigurationSet();
    testProjectConfigurationBuilder.buildConfigurationWithDependenciesThatFail(buildConfigurationSet);
    ObjectWrapper<BuildSetStatus> lastBuildSetStatus = registerCallback(buildConfigurationSet);
    BuildOptions buildOptions = new BuildOptions();
    buildOptions.setRebuildMode(RebuildMode.FORCE);
    BuildSetTask buildSetTask = buildCoordinator.build(buildConfigurationSet, TestEntitiesFactory.newUser(), buildOptions);
    Wait.forCondition(lastBuildSetStatus::isSet, 5, ChronoUnit.SECONDS);
    // check the result
    Assert.assertEquals(BuildSetStatus.DONE, lastBuildSetStatus.get());
    datastoreMock.getBuildConfigSetRecordById(buildConfigurationSet.getId());
    Optional<BuildConfigSetRecord> maybeSetRecord = buildSetTask.getBuildConfigSetRecord();
    assertThat(maybeSetRecord.isPresent()).isTrue();
    Assert.assertEquals(BuildStatus.FAILED, maybeSetRecord.get().getStatus());
    Collection<BuildStatus> statuses = getBuildStatuses();
    // dependent build failed with
    Assert.assertTrue(statuses.contains(BuildStatus.REJECTED_FAILED_DEPENDENCIES));
    // system error
    Assert.assertFalse(statuses.contains(BuildStatus.SYSTEM_ERROR));
    assertEmptyQueue();
}
Also used : BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildStatus(org.jboss.pnc.enums.BuildStatus) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) Test(org.junit.Test)

Example 24 with BuildSetTask

use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.

the class BuildTasksInitializer method createBuildSetTask.

/**
 * Create a BuildSetTask of BuildConfigurations contained in the BuildConfigurationSet.
 *
 * A specific revision of the BuildConfigurations contained in the set is used, if it's available in the
 * buildConfigurationAuditedsMap parameter. If it's not available, latest revision of the BuildConfiguration is
 * used.
 *
 * @param buildConfigurationSet BuildConfigurationSet to be built
 * @param buildConfigurationAuditedsMap A map BuildConfiguration::id:BuildConfigurationAudited of specific revisions
 *        of BuildConfigurations contained in the buildConfigurationSet
 * @param user A user, who triggered the build
 * @param buildOptions Build options
 * @param buildTaskIdProvider Provider to get build task ID
 * @param submittedBuildTasks Already submitted build tasks
 * @return Prepared BuildSetTask
 * @throws CoreException Thrown if the BuildConfigSetRecord cannot be stored
 */
public BuildSetTask createBuildSetTask(BuildConfigurationSet buildConfigurationSet, Map<Integer, BuildConfigurationAudited> buildConfigurationAuditedsMap, User user, BuildOptions buildOptions, Supplier<String> buildTaskIdProvider, Set<BuildTask> submittedBuildTasks) throws CoreException {
    BuildSetTask buildSetTask = initBuildSetTask(buildConfigurationSet, user, buildOptions);
    Set<BuildConfigurationAudited> buildConfigurationAuditeds = new HashSet<>();
    for (BuildConfiguration buildConfiguration : datastoreAdapter.getBuildConfigurations(buildConfigurationSet)) {
        BuildConfigurationAudited buildConfigurationAudited = buildConfigurationAuditedsMap.get(buildConfiguration.getId());
        if (buildConfigurationAudited == null) {
            buildConfigurationAudited = datastoreAdapter.getLatestBuildConfigurationAuditedInitializeBCDependencies(buildConfiguration.getId());
        }
        buildConfigurationAuditeds.add(buildConfigurationAudited);
    }
    // initializeBuildTasksInSet
    log.debug("Initializing BuildTasks In Set for BuildConfigurationAuditeds: {}.", buildConfigurationAuditeds.stream().map(BuildConfigurationAudited::toString).collect(Collectors.joining("; ")));
    fillBuildTaskSet(buildSetTask, user, buildTaskIdProvider, buildConfigurationSet.getCurrentProductMilestone(), buildConfigurationAuditeds, submittedBuildTasks, buildOptions);
    return buildSetTask;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) HashSet(java.util.HashSet)

Example 25 with BuildSetTask

use of org.jboss.pnc.spi.coordinator.BuildSetTask in project pnc by project-ncl.

the class DefaultBuildCoordinator method markFinished.

private synchronized void markFinished(BuildTask task, BuildCoordinationStatus status, String statusDescription) {
    log.debug("Finishing buildTask {}. Setting status {}.", task, status);
    buildQueue.removeTask(task);
    task.setStatus(status);
    task.setStatusDescription(statusDescription);
    switch(status) {
        case DONE:
        case REJECTED_ALREADY_BUILT:
            buildQueue.executeNewReadyTasks();
            break;
        case REJECTED:
        case REJECTED_FAILED_DEPENDENCIES:
        case SYSTEM_ERROR:
        case DONE_WITH_ERRORS:
        case CANCELLED:
            handleErroneousFinish(task);
            break;
        default:
            throw new IllegalArgumentException("Unhandled build task status: " + task.getStatus() + ". Build task: " + task);
    }
    BuildSetTask buildSetTask = task.getBuildSetTask();
    if (buildSetTask != null && buildSetTask.isFinished()) {
        completeBuildSetTask(buildSetTask);
    }
}
Also used : BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask)

Aggregations

BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)30 Test (org.junit.Test)15 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)12 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)12 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)11 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)10 BuildOptions (org.jboss.pnc.spi.BuildOptions)10 HashSet (java.util.HashSet)6 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)6 User (org.jboss.pnc.model.User)6 BuildSetStatus (org.jboss.pnc.spi.BuildSetStatus)6 CoreException (org.jboss.pnc.spi.exception.CoreException)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 List (java.util.List)5 Set (java.util.Set)5 BuildStatus (org.jboss.pnc.enums.BuildStatus)5 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)5 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)5 Collections (java.util.Collections)4