Search in sources :

Example 21 with BuildConfigSetRecord

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

the class DatastoreAdapter method initBuildRecordBuilder.

/**
 * Initialize a new BuildRecord.Builder based on the data contained in the BuildTask. Note, this must be done inside
 * a transaction because it fetches the BuildRecordSet entities from the database.
 *
 * @return The initialized build record builder
 */
private BuildRecord.Builder initBuildRecordBuilder(BuildTask buildTask) {
    BuildOptions buildOptions = buildTask.getBuildOptions();
    BuildRecord.Builder builder = BuildRecord.Builder.newBuilder().id(buildTask.getId()).buildConfigurationAudited(buildTask.getBuildConfigurationAudited()).user(buildTask.getUser()).submitTime(buildTask.getSubmitTime()).startTime(buildTask.getStartTime()).productMilestone(buildTask.getProductMilestone()).temporaryBuild(buildOptions.isTemporaryBuild()).alignmentPreference(buildOptions.getAlignmentPreference()).noRebuildCause(buildTask.getNoRebuildCause());
    if (buildTask.getEndTime() == null) {
        buildTask.setEndTime(Date.from(Instant.now()));
    }
    builder.endTime(buildTask.getEndTime());
    if (buildTask.getBuildConfigSetRecordId() != null) {
        BuildConfigSetRecord buildConfigSetRecord = datastore.getBuildConfigSetRecordById(buildTask.getBuildConfigSetRecordId());
        builder.buildConfigSetRecord(buildConfigSetRecord);
    }
    List<Base32LongID> dependencies = buildTask.getDependencies().stream().map(BuildTask::getId).map(Base32LongID::new).collect(Collectors.toList());
    builder.dependencyBuildRecordIds(dependencies.toArray(new Base32LongID[dependencies.size()]));
    List<Base32LongID> dependants = buildTask.getDependants().stream().map(BuildTask::getId).map(Base32LongID::new).collect(Collectors.toList());
    builder.dependentBuildRecordIds(dependants.toArray(new Base32LongID[dependants.size()]));
    return builder;
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildTask(org.jboss.pnc.spi.coordinator.BuildTask) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildConfigSetRecord(org.jboss.pnc.model.BuildConfigSetRecord)

Example 22 with BuildConfigSetRecord

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

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

the class DefaultBuildCoordinator method cancelSet.

@Override
public boolean cancelSet(int buildSetTaskId) {
    BuildConfigSetRecord record = datastoreAdapter.getBuildCongigSetRecordById(buildSetTaskId);
    if (record == null) {
        log.error("Could not find buildConfigSetRecord with id : {}", buildSetTaskId);
        return false;
    }
    log.debug("Cancelling Build Configuration Set: {}", buildSetTaskId);
    getSubmittedBuildTasks().stream().filter(Objects::nonNull).filter(t -> t.getBuildSetTask() != null && t.getBuildSetTask().getId().equals(buildSetTaskId)).forEach(buildTask -> {
        try {
            MDCUtils.addBuildContext(getMDCMeta(buildTask));
            log.debug("Received cancel request for buildTaskId: {}.", buildTask.getId());
            cancel(buildTask.getId());
        } catch (CoreException e) {
            log.error("Unable to cancel the build [" + buildTask.getId() + "].", e);
        } finally {
            MDCUtils.removeBuildContext();
        }
    });
    record.setStatus(BuildStatus.CANCELLED);
    record.setEndTime(Date.from(Instant.now()));
    try {
        datastoreAdapter.saveBuildConfigSetRecord(record);
    } catch (DatastoreException e) {
        log.error("Failed to update BuildConfigSetRecord (id: {} ) with status CANCELLED", record.getId(), e);
    }
    return true;
}
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) CoreException(org.jboss.pnc.spi.exception.CoreException) Objects(java.util.Objects) 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