Search in sources :

Example 6 with BuildConfigSetRecord

use of org.jboss.pnc.model.BuildConfigSetRecord in project pnc by project-ncl.

the class TemporaryBuildsCleanerAsyncInvoker method deleteTemporaryBuildConfigSetRecord.

/**
 * Deletes a temporary BuildConfigSetRecord.
 *
 * @param buildConfigSetRecordId ID of the BuildConfigSetRecord to be deleted
 * @param authToken Bearer token
 * @param onComplete Operation to be executed after deletion operation
 * @return True if the build exists and deletion started otherwise, false is build doesn't exist
 * @throws ValidationException Thrown when build cannot be deleted
 */
public boolean deleteTemporaryBuildConfigSetRecord(Integer buildConfigSetRecordId, String authToken, Consumer<Result> onComplete) throws ValidationException {
    BuildConfigSetRecord buildConfigSetRecord = buildConfigSetRecordRepository.queryById(buildConfigSetRecordId);
    if (buildConfigSetRecord == null) {
        return false;
    }
    if (!buildConfigSetRecord.isTemporaryBuild()) {
        throw new ValidationException("Only deletion of the temporary builds is allowed");
    }
    executorService.submit(() -> {
        try {
            Result result = temporaryBuildsCleaner.deleteTemporaryBuildConfigSetRecord(buildConfigSetRecordId, authToken);
            onComplete.accept(result);
        } catch (ValidationException e) {
            logger.error("Failed to delete temporary buildConfigSetRecord.id: " + buildConfigSetRecordId + ".", e);
            onComplete.accept(new Result(buildConfigSetRecordId.toString(), ResultStatus.FAILED, "Failed to delete temporary buildConfigSetRecord."));
        }
    });
    return true;
}
Also used : ValidationException(org.jboss.pnc.spi.exception.ValidationException) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord) Result(org.jboss.pnc.spi.coordinator.Result)

Example 7 with BuildConfigSetRecord

use of org.jboss.pnc.model.BuildConfigSetRecord 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 8 with BuildConfigSetRecord

use of org.jboss.pnc.model.BuildConfigSetRecord 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 9 with BuildConfigSetRecord

use of org.jboss.pnc.model.BuildConfigSetRecord in project pnc by project-ncl.

the class BuildTasksInitializer method initBuildSetTask.

private BuildSetTask initBuildSetTask(BuildConfigurationSet buildConfigurationSet, User user, BuildOptions buildOptions) throws CoreException {
    BuildConfigSetRecord buildConfigSetRecord = BuildConfigSetRecord.Builder.newBuilder().buildConfigurationSet(buildConfigurationSet).user(user).startTime(new Date()).status(org.jboss.pnc.enums.BuildStatus.BUILDING).temporaryBuild(buildOptions.isTemporaryBuild()).alignmentPreference(buildOptions.getAlignmentPreference()).build();
    final BuildConfigSetRecord configSetRecord;
    try {
        configSetRecord = saveBuildConfigSetRecord(buildConfigSetRecord);
    } catch (DatastoreException e) {
        log.error("Failed to store build config set record: " + e);
        throw new CoreException(e);
    }
    return BuildSetTask.Builder.newBuilder().buildConfigSetRecord(configSetRecord).buildOptions(buildOptions).build();
}
Also used : CoreException(org.jboss.pnc.spi.exception.CoreException) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) Date(java.util.Date) ExpiresDate(org.jboss.pnc.common.Date.ExpiresDate) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 10 with BuildConfigSetRecord

use of org.jboss.pnc.model.BuildConfigSetRecord in project pnc by project-ncl.

the class DefaultBuildCoordinator method updateBuildSetTaskStatus.

private void updateBuildSetTaskStatus(BuildSetTask buildSetTask, BuildSetStatus status, String description) {
    log.info("Setting new status {} on buildSetTask.id {}. Description: {}.", status, buildSetTask.getId(), description);
    BuildSetStatus oldStatus = buildSetTask.getStatus();
    Optional<BuildConfigSetRecord> buildConfigSetRecord = buildSetTask.getBuildConfigSetRecord();
    // Completed BuildSets are updated using BuildSetTask#taskStatusUpdatedToFinalState()
    if (buildConfigSetRecord.isPresent() && REJECTED_STATES.containsKey(status)) {
        buildConfigSetRecord.get().setStatus(REJECTED_STATES.get(status));
        try {
            datastoreAdapter.saveBuildConfigSetRecord(buildConfigSetRecord.get());
        } catch (DatastoreException de) {
            log.warn("Failed to update build config set record to REJECTED status: " + de);
        }
    }
    buildConfigSetRecord.ifPresent(record -> sendSetStatusChangeEvent(buildSetTask, status, oldStatus, record, description));
    buildSetTask.setStatus(status);
    buildSetTask.setStatusDescription(description);
}
Also used : BuildSetStatus(org.jboss.pnc.spi.BuildSetStatus) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Aggregations

BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)23 Test (org.junit.Test)10 BuildRecord (org.jboss.pnc.model.BuildRecord)9 BuildOptions (org.jboss.pnc.spi.BuildOptions)8 BuildConfigurationSet (org.jboss.pnc.model.BuildConfigurationSet)7 BuildSetStatus (org.jboss.pnc.spi.BuildSetStatus)7 BuildSetTask (org.jboss.pnc.spi.coordinator.BuildSetTask)7 HashSet (java.util.HashSet)6 User (org.jboss.pnc.model.User)6 DatastoreException (org.jboss.pnc.spi.datastore.DatastoreException)6 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)5 CoreException (org.jboss.pnc.spi.exception.CoreException)5 Optional (java.util.Optional)4 Set (java.util.Set)4 DatastoreAdapter (org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Collections (java.util.Collections)3 Date (java.util.Date)3 Event (javax.enterprise.event.Event)3