Search in sources :

Example 11 with BuildSetTask

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

the class SkippingBuiltConfigsTest method shouldTriggerTheSameBuildConfigurationWithNewRevision.

@Test
public void shouldTriggerTheSameBuildConfigurationWithNewRevision() throws Exception {
    coordinator.start();
    buildRecordRepository.clear();
    // given
    BuildConfiguration testConfiguration = config("shouldRejectBCWithNewRevision");
    BuildOptions buildOptions = new BuildOptions();
    buildOptions.setBuildDependencies(false);
    // when
    coordinator.build(testConfiguration, user, buildOptions);
    BuildConfiguration updatedConfiguration = updateConfiguration(testConfiguration);
    BuildSetTask buildSetTask;
    boolean rejected = false;
    try {
        buildSetTask = coordinator.build(updatedConfiguration, user, buildOptions);
    } catch (BuildConflictException e) {
        rejected = true;
    }
    // then
    Assert.assertFalse("The task was rejected.", rejected);
    waitForEmptyBuildQueue();
    assertThat(getNonRejectedBuildRecords().size()).isEqualTo(2);
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) Test(org.junit.Test)

Example 12 with BuildSetTask

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

the class BuildTasksInitializer method fillBuildTaskSet.

/**
 * Creates build tasks and sets up the appropriate dependency relations
 *
 * @param buildSetTask The build set task which will contain the build tasks. This must already have initialized the
 *        BuildConfigSet, BuildConfigSetRecord, Milestone, etc.
 */
private void fillBuildTaskSet(BuildSetTask buildSetTask, User user, Supplier<String> buildTaskIdProvider, ProductMilestone productMilestone, Set<BuildConfigurationAudited> toBuild, Set<BuildTask> alreadySubmittedBuildTasks, BuildOptions buildOptions) {
    for (BuildConfigurationAudited buildConfigAudited : toBuild) {
        Optional<BuildTask> taskOptional = alreadySubmittedBuildTasks.stream().filter(bt -> bt.getBuildConfigurationAudited().equals(buildConfigAudited)).findAny();
        BuildTask buildTask;
        if (taskOptional.isPresent()) {
            buildTask = taskOptional.get();
            log.debug("Linking BuildConfigurationAudited {} to existing task {}.", buildConfigAudited, buildTask);
        } else {
            String buildId = buildTaskIdProvider.get();
            String buildContentId = ContentIdentityManager.getBuildContentId(buildId);
            // Used only for this operation inside the loop
            MDCUtils.addBuildContext(buildContentId, buildOptions.isTemporaryBuild(), ExpiresDate.getTemporaryBuildExpireDate(temporaryBuildLifespanDays, buildOptions.isTemporaryBuild()), user.getId().toString());
            try {
                Optional<String> requestContext = MDCUtils.getRequestContext();
                buildTask = BuildTask.build(buildConfigAudited, buildSetTask.getBuildOptions(), user, buildId, buildSetTask, buildSetTask.getStartTime(), productMilestone, buildContentId, requestContext);
                log.debug("Created new buildTask {} for BuildConfigurationAudited {}.", buildTask, buildConfigAudited);
            } finally {
                MDCUtils.removeBuildContext();
            }
        }
        buildSetTask.addBuildTask(buildTask);
    }
    // Loop again to set dependencies
    for (BuildTask buildTask : buildSetTask.getBuildTasks()) {
        for (BuildTask checkDepBuildTask : buildSetTask.getBuildTasks()) {
            if (buildTask.hasDirectConfigDependencyOn(checkDepBuildTask)) {
                buildTask.addDependency(checkDepBuildTask);
            }
        }
    }
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) AlignmentPreference(org.jboss.pnc.api.enums.AlignmentPreference) MDCUtils(org.jboss.pnc.common.logging.MDCUtils) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Supplier(java.util.function.Supplier) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) HashSet(java.util.HashSet) Map(java.util.Map) ProductMilestone(org.jboss.pnc.model.ProductMilestone) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) User(org.jboss.pnc.model.User) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) Logger(org.slf4j.Logger) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate) ContentIdentityManager(org.jboss.pnc.model.utils.ContentIdentityManager) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) Collectors(java.util.stream.Collectors) CoreException(org.jboss.pnc.spi.exception.CoreException) Optional(java.util.Optional) Collections(java.util.Collections) BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask)

Example 13 with BuildSetTask

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

the class BuildTasksInitializer method createBuildSetTask.

public BuildSetTask createBuildSetTask(BuildConfigurationAudited buildConfigurationAudited, User user, BuildOptions buildOptions, Supplier<String> buildTaskIdProvider, Set<BuildTask> submittedBuildTasks) {
    BuildSetTask buildSetTask = BuildSetTask.Builder.newBuilder().buildOptions(buildOptions).startTime(new Date()).build();
    Set<BuildConfigurationAudited> toBuild = new HashSet<>();
    collectBuildTasks(buildConfigurationAudited, buildOptions, toBuild);
    log.debug("Collected build tasks for the BuildConfigurationAudited: {}. Collected: {}.", buildConfigurationAudited, toBuild.stream().map(BuildConfigurationAudited::toString).collect(Collectors.joining(", ")));
    fillBuildTaskSet(buildSetTask, user, buildTaskIdProvider, buildConfigurationAudited.getBuildConfiguration().getCurrentProductMilestone(), toBuild, submittedBuildTasks, buildOptions);
    return buildSetTask;
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Date(java.util.Date) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate) HashSet(java.util.HashSet)

Example 14 with BuildSetTask

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

the class DefaultBuildCoordinator method build.

/**
 * Run a set of builds. Only the current/latest version of builds in the given set will be executed. The order of
 * execution is determined by the dependency relations between the build configurations.
 *
 * @param buildConfigurationSet The set of builds to be executed.
 * @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
@Deprecated
public BuildSetTask build(BuildConfigurationSet buildConfigurationSet, User user, BuildOptions buildOptions) throws CoreException {
    synchronized (buildMethodLock) {
        BuildSetTask buildSetTask = buildTasksInitializer.createBuildSetTask(buildConfigurationSet, 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 15 with BuildSetTask

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

the class DefaultBuildCoordinator method build0.

private BuildSetTask build0(User user, BuildOptions buildOptions, BuildConfigurationAudited buildConfigurationAudited) throws BuildConflictException {
    synchronized (buildMethodLock) {
        checkNotRunning(buildConfigurationAudited);
        BuildSetTask buildSetTask = buildTasksInitializer.createBuildSetTask(buildConfigurationAudited, user, buildOptions, this::buildRecordIdSupplier, buildQueue.getUnfinishedTasks());
        buildQueue.enqueueTaskSet(buildSetTask);
        buildSetTask.getBuildTasks().stream().sorted(this::dependantsFirst).forEach(this::addTaskToBuildQueue);
        return 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