Search in sources :

Example 11 with BuildTask

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

the class StatusUpdatesTest method buildSetStatusShouldUpdateWhenAllBuildStatusChangeToCompletedState.

@Test
@InSequence(10)
public void buildSetStatusShouldUpdateWhenAllBuildStatusChangeToCompletedState() throws DatastoreException, InterruptedException, CoreException {
    ObjectWrapper<BuildSetStatusChangedEvent> receivedBuildSetStatusChangedEvent = new ObjectWrapper<>();
    Consumer<BuildSetStatusChangedEvent> statusUpdateListener = receivedBuildSetStatusChangedEvent::set;
    testCDIBuildSetStatusChangedReceiver.addBuildSetStatusChangedEventListener(statusUpdateListener);
    User user = User.Builder.newBuilder().id(1).username("test-user-1").build();
    Set<BuildTask> buildTasks = initializeBuildTaskSet(configurationBuilder, user, (buildConfigSetRecord) -> {
    }).getBuildTasks();
    buildTasks.forEach((bt) -> {
        buildCoordinator.updateBuildTaskStatus(bt, BuildCoordinationStatus.DONE);
        buildCoordinator.completeBuild(bt, createBuildResult());
    });
    this.waitForConditionWithTimeout(() -> buildTasks.stream().allMatch(task -> task.getStatus().isCompleted()), 4);
    Assert.assertNotNull("Did not receive build set status update.", receivedBuildSetStatusChangedEvent.get());
    Assert.assertEquals(BuildSetStatus.DONE, receivedBuildSetStatusChangedEvent.get().getNewStatus());
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildStatusNotifications(org.jboss.pnc.coordinator.notifications.buildTask.BuildStatusNotifications) Arquillian(org.jboss.arquillian.junit.Arquillian) BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) LoggerFactory(org.slf4j.LoggerFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) User(org.jboss.pnc.model.User) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) BuildResult(org.jboss.pnc.spi.BuildResult) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Set(java.util.Set) BuildStatus(org.jboss.pnc.enums.BuildStatus) Collectors(java.util.stream.Collectors) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) CoreException(org.jboss.pnc.spi.exception.CoreException) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) Optional(java.util.Optional) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) IndyRepositoryManagerResult(org.jboss.pnc.indyrepositorymanager.IndyRepositoryManagerResult) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) RunWith(org.junit.runner.RunWith) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) BuildSetStatusNotifications(org.jboss.pnc.coordinator.notifications.buildSetTask.BuildSetStatusNotifications) BuildCallBack(org.jboss.pnc.coordinator.notifications.buildTask.BuildCallBack) RebuildMode(org.jboss.pnc.enums.RebuildMode) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) HashSet(java.util.HashSet) BuildCoordinatorDeployments(org.jboss.pnc.coordinator.test.BuildCoordinatorDeployments) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) BuildTasksInitializer(org.jboss.pnc.coordinator.builder.BuildTasksInitializer) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) Event(javax.enterprise.event.Event) Logger(org.slf4j.Logger) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence) Consumer(java.util.function.Consumer) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) Deployment(org.jboss.arquillian.container.test.api.Deployment) Assert(org.junit.Assert) Sequence(org.jboss.pnc.common.concurrent.Sequence) Collections(java.util.Collections) User(org.jboss.pnc.model.User) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildSetStatusChangedEvent(org.jboss.pnc.spi.events.BuildSetStatusChangedEvent) ObjectWrapper(org.jboss.pnc.common.util.ObjectWrapper) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 12 with BuildTask

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

use of org.jboss.pnc.spi.coordinator.BuildTask 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 14 with BuildTask

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

the class DefaultBuildCoordinator method isBuildConfigurationAlreadyInQueue.

private boolean isBuildConfigurationAlreadyInQueue(BuildTask buildTask) {
    BuildConfigurationAudited buildConfigurationAudited = buildTask.getBuildConfigurationAudited();
    Optional<BuildTask> unfinishedTask = buildQueue.getUnfinishedTask(buildConfigurationAudited);
    if (unfinishedTask.isPresent()) {
        log.debug("Task with the same buildConfigurationAudited is in the queue {}.", unfinishedTask.get());
        return true;
    } else {
        return false;
    }
}
Also used : BuildConfigurationAudited(org.jboss.pnc.model.BuildConfigurationAudited) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask)

Example 15 with BuildTask

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

the class BpmBuildScheduler method cancel.

@Override
public boolean cancel(BuildTask buildTask) {
    Map<String, String> genericParameters = buildTask.getBuildConfigurationAudited().getGenericParameters();
    BpmBuildTask task = new BpmBuildTask(buildTask);
    if (useNewProcessForBuild(genericParameters, bpmConfig.isNewBpmForced())) {
        return restConnector.cancelByCorrelation(buildTask.getId(), task.getAccessToken());
    } else {
        Optional<BpmBuildTask> taskOptional = manager.getActiveTasks().stream().filter(bpmTask -> bpmTask instanceof BpmBuildTask).map(bpmTask -> (BpmBuildTask) bpmTask).filter(bpmTask -> bpmTask.getBuildTask().getId().equals(buildTask.getId())).findAny();
        if (taskOptional.isPresent()) {
            return manager.cancelTask(taskOptional.get());
        } else {
            return false;
        }
    }
}
Also used : GlobalModuleGroup(org.jboss.pnc.common.json.GlobalModuleGroup) Connector(org.jboss.pnc.bpm.Connector) BuildScheduler(org.jboss.pnc.coordinator.builder.BuildScheduler) ConnectorSelector.useNewProcessForBuild(org.jboss.pnc.bpm.ConnectorSelector.useNewProcessForBuild) RestConnector(org.jboss.pnc.bpm.RestConnector) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) Inject(javax.inject.Inject) BpmBuildTask(org.jboss.pnc.bpm.task.BpmBuildTask) PreDestroy(javax.annotation.PreDestroy) CoreException(org.jboss.pnc.spi.exception.CoreException) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) BpmManager(org.jboss.pnc.bpm.BpmManager) BpmModuleConfig(org.jboss.pnc.common.json.moduleconfig.BpmModuleConfig) BpmBuildTask(org.jboss.pnc.bpm.task.BpmBuildTask)

Aggregations

BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)43 Test (org.junit.Test)23 BuildRecord (org.jboss.pnc.model.BuildRecord)15 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)15 Build (org.jboss.pnc.dto.Build)13 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)13 BuildCoordinator (org.jboss.pnc.spi.coordinator.BuildCoordinator)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)12 BuildOptions (org.jboss.pnc.spi.BuildOptions)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 Inject (javax.inject.Inject)11 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)11 CoreException (org.jboss.pnc.spi.exception.CoreException)11 User (org.jboss.pnc.model.User)10 BuildStatusChangedEvent (org.jboss.pnc.spi.events.BuildStatusChangedEvent)10 Date (java.util.Date)9 Set (java.util.Set)9 HashSet (java.util.HashSet)8 List (java.util.List)8