Search in sources :

Example 11 with BuildRecord

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

the class SkippingBuiltConfigsTest method shouldNotBuildTheSameBuildConfigurationTwice.

@Test
public void shouldNotBuildTheSameBuildConfigurationTwice() throws Exception {
    coordinator.start();
    buildRecordRepository.clear();
    // given
    BuildConfiguration testConfiguration = config("shouldNotBuildTheSameBuildConfigurationTwice");
    BuildOptions buildOptions = new BuildOptions();
    buildOptions.setBuildDependencies(false);
    // when
    coordinator.build(testConfiguration, user, buildOptions);
    waitForEmptyBuildQueue();
    coordinator.build(testConfiguration, user, buildOptions);
    waitForEmptyBuildQueue();
    // then
    // there should be one non build
    assertThat(getNonRejectedBuildRecords().size()).isEqualTo(1);
    // there should be stored one NO_REBUILD_REQUIRED
    List<BuildRecord> collectNoRebuildRequired = buildRecordRepository.queryAll().stream().filter(r -> r.getStatus() == BuildStatus.NO_REBUILD_REQUIRED).collect(Collectors.toList());
    assertThat(collectNoRebuildRequired.size()).isEqualTo(1);
    assertThat(collectNoRebuildRequired.iterator().next().getNoRebuildCause()).isNotNull();
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) Logger(org.slf4j.Logger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DatastoreException(org.jboss.pnc.spi.datastore.DatastoreException) LoggerFactory(org.slf4j.LoggerFactory) BuildConfigurationSet(org.jboss.pnc.model.BuildConfigurationSet) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) BuildRecord(org.jboss.pnc.model.BuildRecord) Mockito.spy(org.mockito.Mockito.spy) RebuildMode(org.jboss.pnc.enums.RebuildMode) Collectors(java.util.stream.Collectors) BuildStatus(org.jboss.pnc.enums.BuildStatus) ArrayList(java.util.ArrayList) List(java.util.List) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) BuildSetTask(org.jboss.pnc.spi.coordinator.BuildSetTask) Assert(org.junit.Assert) BuildConflictException(org.jboss.pnc.spi.exception.BuildConflictException) BuildConfigurationRepositoryMock(org.jboss.pnc.mock.repository.BuildConfigurationRepositoryMock) Before(org.junit.Before) BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 12 with BuildRecord

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

the class SkippingBuiltConfigsTest method shouldRerunTheSameBuildConfigurationIfRebuildAllIsSpecified.

@Test
public void shouldRerunTheSameBuildConfigurationIfRebuildAllIsSpecified() throws Exception {
    buildRecordRepository.clear();
    BuildOptions buildOptions = new BuildOptions();
    buildOptions.setRebuildMode(RebuildMode.FORCE);
    // when
    coordinator.build(configA, user, buildOptions);
    waitForEmptyBuildQueue();
    coordinator.build(configA, user, buildOptions);
    waitForEmptyBuildQueue();
    // then
    List<BuildRecord> buildRecords = getNonRejectedBuildRecords();
    assertThat(buildRecords.size()).isEqualTo(2);
    logRecords(buildRecords);
}
Also used : BuildOptions(org.jboss.pnc.spi.BuildOptions) BuildRecord(org.jboss.pnc.model.BuildRecord) Test(org.junit.Test)

Example 13 with BuildRecord

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

the class DatastoreMock method storeCompletedBuild.

@Override
public BuildRecord storeCompletedBuild(BuildRecord.Builder buildRecordBuilder, List<Artifact> builtArtifacts, List<Artifact> dependencies) {
    buildRecordBuilder.dependencies(dependencies);
    BuildRecord buildRecord = Mockito.spy(buildRecordBuilder.build());
    Mockito.when(buildRecord.getBuiltArtifacts()).thenReturn(new HashSet<>(builtArtifacts));
    BuildConfiguration buildConfiguration = buildRecord.getBuildConfigurationAudited().getBuildConfiguration();
    log.info("Storing build " + buildConfiguration);
    synchronized (this) {
        boolean exists = getBuildRecords().stream().anyMatch(br -> br.equals(buildRecord));
        if (exists) {
            throw new PersistenceException("Unique constraint violation, the record with id [" + buildRecord.getId() + "] already exists.");
        }
        buildRecords.add(buildRecord);
    }
    return buildRecord;
}
Also used : BuildConfiguration(org.jboss.pnc.model.BuildConfiguration) PersistenceException(javax.persistence.PersistenceException) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 14 with BuildRecord

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

the class DefaultBuildCoordinator method completeNoBuild.

public void completeNoBuild(BuildTask buildTask, CompletionStatus completionStatus) {
    String buildTaskId = buildTask.getId();
    BuildCoordinationStatus coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
    try {
        if (CompletionStatus.NO_REBUILD_REQUIRED.equals(completionStatus)) {
            updateBuildTaskStatus(buildTask, BuildCoordinationStatus.REJECTED_ALREADY_BUILT);
        // TODO cancel should be here enable in 2.0 as CANCELed is not failed build
        // } else if (CompletionStatus.CANCELLED.equals(completionStatus)) {
        // updateBuildTaskStatus(buildTask, BuildCoordinationStatus.CANCELLED);
        } else {
            throw new BuildCoordinationException(String.format("Invalid status %s.", completionStatus));
        }
        log.debug("Storing no build required result. Id: {}", buildTaskId);
        BuildRecord buildRecord = datastoreAdapter.storeRecordForNoRebuild(buildTask);
        if (buildRecord.getStatus().completedSuccessfully()) {
            coordinationStatus = BuildCoordinationStatus.DONE;
        } else {
            log.warn("[buildTaskId: {}] Something went wrong while storing the success result. The status has changed to {}.", buildTaskId, buildRecord.getStatus());
            coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
        }
    } catch (Throwable e) {
        log.error("[buildTaskId: " + buildTaskId + "] Cannot store results to datastore.", e);
        coordinationStatus = BuildCoordinationStatus.SYSTEM_ERROR;
    } finally {
        updateBuildTaskStatus(buildTask, coordinationStatus);
    }
}
Also used : BuildCoordinationStatus(org.jboss.pnc.enums.BuildCoordinationStatus) BuildCoordinationException(org.jboss.pnc.coordinator.BuildCoordinationException) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 15 with BuildRecord

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

the class BuildResultPushManagerTest method shouldRejectWithMissingData.

@Test
public void shouldRejectWithMissingData() {
    // given
    BuildRecord record = buildRecord(false);
    // when
    Result result = release(record);
    // then
    assertThat(result).extracting(Result::getStatus).isEqualTo(BuildPushStatus.SYSTEM_ERROR);
    assertThat(result.getMessage()).containsIgnoringCase("attribute BREW_BUILD_NAME");
}
Also used : BuildRecord(org.jboss.pnc.model.BuildRecord) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) Result(org.jboss.pnc.bpm.causeway.Result) Test(org.junit.Test)

Aggregations

BuildRecord (org.jboss.pnc.model.BuildRecord)92 Test (org.junit.Test)50 Base32LongID (org.jboss.pnc.model.Base32LongID)19 Build (org.jboss.pnc.dto.Build)15 BuildTask (org.jboss.pnc.spi.coordinator.BuildTask)15 ContainerTest (org.jboss.pnc.test.category.ContainerTest)14 HashSet (java.util.HashSet)13 Artifact (org.jboss.pnc.model.Artifact)13 BuildConfiguration (org.jboss.pnc.model.BuildConfiguration)13 SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)13 Date (java.util.Date)12 List (java.util.List)12 BuildConfigSetRecord (org.jboss.pnc.model.BuildConfigSetRecord)12 BuildConfigurationAudited (org.jboss.pnc.model.BuildConfigurationAudited)12 DatastoreMock (org.jboss.pnc.mock.datastore.DatastoreMock)11 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 BuildStatus (org.jboss.pnc.enums.BuildStatus)10