Search in sources :

Example 16 with BuildSetTask

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

the class DefaultBuildCoordinator method build.

/**
 * Run a build of BuildConfigurationSet with BuildConfigurations in specific versions.
 *
 * The set of the BuildConfigurations to be executed is determined by the buildConfigurationSet entity. If there is
 * a revision of a BuildConfiguration available in the buildConfigurationAuditedsMap parameter, then this revision
 * is executed. If it's not available, latest revision of the BuildConfiguration will be executed.
 *
 * @param buildConfigurationSet The set of the configurations to be executed
 * @param buildConfigurationAuditedsMap A map BuildConfiguration::id:BuildConfigurationAudited of specific revisions
 *        of BuildConfigurations contained in the buildConfigurationSet
 * @param user The user who triggered the build.
 * @param buildOptions Customization of a build specified by user
 *
 * @return The new build set task
 * @throws CoreException Thrown if there is a problem initializing the build
 */
@Override
public BuildSetTask build(BuildConfigurationSet buildConfigurationSet, Map<Integer, BuildConfigurationAudited> buildConfigurationAuditedsMap, User user, BuildOptions buildOptions) throws CoreException {
    synchronized (buildMethodLock) {
        BuildSetTask buildSetTask = buildTasksInitializer.createBuildSetTask(buildConfigurationSet, buildConfigurationAuditedsMap, user, buildOptions, this::buildRecordIdSupplier, buildQueue.getUnfinishedTasks());
        updateBuildSetTaskStatus(buildSetTask, BuildSetStatus.NEW);
        validateAndEnqueueBuildConfigurationSetTasks(buildConfigurationSet, buildOptions, buildSetTask);
        return buildSetTask;
    }
}
Also used : BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask)

Example 17 with BuildSetTask

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

the class DefaultBuildCoordinator method handleErroneousFinish.

private void handleErroneousFinish(BuildTask failedTask) {
    BuildSetTask taskSet = failedTask.getBuildSetTask();
    if (taskSet != null) {
        log.debug("Finishing tasks in set {}, after failedTask {}.", taskSet, failedTask);
        taskSet.getBuildTasks().stream().filter(t -> isDependentOn(failedTask, t)).filter(t -> !t.getStatus().isCompleted()).forEach(t -> finishDueToFailedDependency(failedTask, t));
    }
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) ScheduledFuture(java.util.concurrent.ScheduledFuture) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) GroupBuildMapper(org.jboss.pnc.mapper.api.GroupBuildMapper) MDCUtils(org.jboss.pnc.common.logging.MDCUtils) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) Map(java.util.Map) CollectionUtils.hasCycle(org.jboss.pnc.common.util.CollectionUtils.hasCycle) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) User(org.jboss.pnc.model.User) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) EnumMap(java.util.EnumMap) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildResult(org.jboss.pnc.spi.BuildResult) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) Instant(java.time.Instant) BuildStatus(org.jboss.pnc.enums.BuildStatus) Objects(java.util.Objects) List(java.util.List) CoreException(org.jboss.pnc.spi.exception.CoreException) MDCExecutors(org.jboss.pnc.common.concurrent.MDCExecutors) PostConstruct(javax.annotation.PostConstruct) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) NamedThreadFactory(org.jboss.pnc.common.concurrent.NamedThreadFactory) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) DefaultBuildSetStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildSetStatusChangedEvent) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) ExecutorException(org.jboss.pnc.spi.executor.exceptions.ExecutorException) RepourResult(org.jboss.pnc.spi.repour.RepourResult) Quicksort(org.jboss.pnc.common.util.Quicksort) ExecutorService(java.util.concurrent.ExecutorService) Event(javax.enterprise.event.Event) DefaultBuildStatusChangedEvent(org.jboss.pnc.spi.coordinator.events.DefaultBuildStatusChangedEvent) Logger(org.slf4j.Logger) BuildTaskContext(org.jboss.pnc.common.logging.BuildTaskContext) BuildRecord(org.jboss.pnc.model.BuildRecord) ProcessStageUtils(org.jboss.pnc.common.util.ProcessStageUtils) PollingMonitor(org.jboss.pnc.common.monitor.PollingMonitor) TimeUnit(java.util.concurrent.TimeUnit) Build(org.jboss.pnc.dto.Build) Sequence(org.jboss.pnc.common.concurrent.Sequence) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask)

Example 18 with BuildSetTask

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

the class ProjectBuilder method buildProjectsAndWaitForUpdates.

private BuildSetTask buildProjectsAndWaitForUpdates(BuildConfigurationSet buildConfigurationSet, BuildCoordinator buildCoordinator, int nStatusUpdates, Consumer<BuildStatusChangedEvent> onStatusUpdate, List<BuildStatusChangedEvent> receivedStatuses, List<BuildSetStatusChangedEvent> receivedSetStatuses) throws InterruptedException, CoreException {
    Consumer<BuildStatusChangedEvent> onStatusUpdateInternal = (statusUpdate) -> {
        log.debug("Received status change event [" + (i++) + "]: {}.", statusUpdate);
        receivedStatuses.add(statusUpdate);
        onStatusUpdate.accept(statusUpdate);
    };
    final Semaphore semaphore = registerReleaseListenersAndAcquireSemaphore(onStatusUpdateInternal, nStatusUpdates);
    final Semaphore buildSetSemaphore = registerBuildSetListeners(receivedSetStatuses, BUILD_SET_STATUS_UPDATES);
    BuildOptions buildOptions = new BuildOptions();
    buildOptions.setRebuildMode(RebuildMode.FORCE);
    BuildSetTask buildSetTask = buildCoordinator.build(buildConfigurationSet, MockUser.newTestUser(1), buildOptions);
    assertBuildStartedSuccessfully(buildSetTask);
    log.info("Waiting to receive all {} status updates...", nStatusUpdates);
    waitForStatusUpdates(nStatusUpdates, semaphore, "");
    log.debug("All status updates should be received. Semaphore has {} free entries.", semaphore.availablePermits());
    log.info("Waiting to receive all {} build set status updates...", BUILD_SET_STATUS_UPDATES);
    waitForStatusUpdates(BUILD_SET_STATUS_UPDATES, buildSetSemaphore, "build set task: " + buildSetTask);
    log.debug("All status updates should be received. Semaphore has {} free entries.", semaphore.availablePermits());
    return buildSetTask;
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Arrays(java.util.Arrays) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) RebuildMode(org.jboss.pnc.enums.RebuildMode) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) Inject(javax.inject.Inject) TestCDIBuildSetStatusChangedReceiver(org.jboss.pnc.coordinator.test.event.TestCDIBuildSetStatusChangedReceiver) Assert.fail(org.junit.Assert.fail) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) Before(org.junit.Before) Logger(org.slf4j.Logger) Semaphore(java.util.concurrent.Semaphore) TestCDIBuildStatusChangedReceiver(org.jboss.pnc.coordinator.test.event.TestCDIBuildStatusChangedReceiver) Artifact(org.jboss.pnc.model.Artifact) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) BuildStatus(org.jboss.pnc.enums.BuildStatus) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) MockUser(org.jboss.pnc.mock.model.MockUser) CoreException(org.jboss.pnc.spi.exception.CoreException) Dependent(javax.enterprise.context.Dependent) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) ArtifactBuilder(org.jboss.pnc.mock.model.builders.ArtifactBuilder) Collections(java.util.Collections) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) Semaphore(java.util.concurrent.Semaphore)

Example 19 with BuildSetTask

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

the class ProjectBuilder method buildProjectsAndVerifyResult.

private void buildProjectsAndVerifyResult(BuildConfigurationSet buildConfigurationSet, BuildCoordinator buildCoordinator, int nStatusUpdates, Verifier verifier) throws InterruptedException, CoreException {
    log.info("Building configuration set {}", buildConfigurationSet.getName());
    List<BuildStatusChangedEvent> receivedStatuses = new CopyOnWriteArrayList<>();
    List<BuildSetStatusChangedEvent> receivedSetStatuses = new CopyOnWriteArrayList<>();
    BuildSetTask buildSetTask = buildProjectsAndWaitForUpdates(buildConfigurationSet, buildCoordinator, nStatusUpdates, x -> {
    }, receivedStatuses, receivedSetStatuses);
    log.info("Checking if received all status updates...");
    verifier.verify(receivedStatuses, buildSetTask);
}
Also used : BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 20 with BuildSetTask

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

the class ReadDependenciesTest method createDependenciesTestCase.

@Test
public void createDependenciesTestCase() throws DatastoreException {
    BuildConfigurationSet buildConfigurationSet = configurationBuilder.buildConfigurationSet(1);
    User user = User.Builder.newBuilder().id(1).username("test-user").build();
    BuildSetTask buildSetTask = null;
    try {
        buildSetTask = createBuildSetTask(buildConfigurationSet, user);
    } catch (CoreException e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertEquals("Missing build tasks in set.", 5, buildSetTask.getBuildTasks().size());
    BuildTask buildTask2 = buildSetTask.getBuildTasks().stream().filter(task -> task.getBuildConfigurationAudited().getId().equals(2)).findFirst().get();
    Assert.assertEquals("Wrong number of dependencies.", 2, buildTask2.getDependencies().size());
}
Also used : BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) User(org.jboss.pnc.model.User) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) CoreException(org.jboss.pnc.spi.exception.CoreException) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Test(org.junit.Test)

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