Search in sources :

Example 41 with BuildRecord

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

the class BrewPusherImpl method pushGroup.

@Override
public Set<BuildPushResult> pushGroup(int buildGroupId, String tagPrefix) {
    BuildPushParameters buildPushParameters = BuildPushParameters.builder().tagPrefix(tagPrefix).reimport(false).build();
    List<BuildRecord> buildRecords = buildRecordRepository.queryWithPredicates(BuildRecordPredicates.withBuildConfigSetRecordId(buildGroupId));
    Set<BuildPushResult> results = new HashSet<>();
    for (BuildRecord buildRecord : buildRecords) {
        Long buildPushResultId = Sequence.nextId();
        MDCUtils.addProcessContext(buildPushResultId.toString());
        MDCUtils.addCustomContext(BUILD_ID_KEY, buildRecord.getId().getId());
        try {
            results.add(doPushBuild(buildRecord.getId(), buildPushParameters, buildPushResultId));
        } catch (OperationNotAllowedException | AlreadyRunningException e) {
            results.add(BuildPushResult.builder().status(BuildPushStatus.REJECTED).id(buildPushResultId.toString()).buildId(BuildMapper.idMapper.toDto(buildRecord.getId())).message(e.getMessage()).build());
        } catch (InconsistentDataException | ProcessException e) {
            results.add(BuildPushResult.builder().status(BuildPushStatus.SYSTEM_ERROR).id(buildPushResultId.toString()).buildId(BuildMapper.idMapper.toDto(buildRecord.getId())).message(e.getMessage()).build());
        } finally {
            MDCUtils.removeProcessContext();
            MDCUtils.removeCustomContext(BUILD_ID_KEY);
        }
    }
    return results;
}
Also used : BuildPushParameters(org.jboss.pnc.dto.requests.BuildPushParameters) BuildPushResult(org.jboss.pnc.dto.BuildPushResult) OperationNotAllowedException(org.jboss.pnc.facade.validation.OperationNotAllowedException) BuildRecord(org.jboss.pnc.model.BuildRecord) AlreadyRunningException(org.jboss.pnc.facade.validation.AlreadyRunningException) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) InconsistentDataException(org.jboss.pnc.spi.datastore.InconsistentDataException) HashSet(java.util.HashSet)

Example 42 with BuildRecord

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

the class BuildRecordRepositoryTest method shouldGetRecordsWithoutAttributeKey.

@InSequence(4)
@Test
public void shouldGetRecordsWithoutAttributeKey() {
    // given
    Date now = new Date();
    BuildRecord buildRecord0 = initBuildRecordBuilder("CERBB5D55GARK").endTime(now).temporaryBuild(true).attribute("ATTR1", "X").attribute("TEST", // exclude all other builds
    "true").build();
    buildRecordRepository.save(buildRecord0);
    BuildRecord buildRecord1 = initBuildRecordBuilder("200001").endTime(now).temporaryBuild(true).attribute("ATTR1", "X").attribute("ATTR2", "X").attribute("TEST", "true").build();
    buildRecordRepository.save(buildRecord1);
    // when
    List<BuildRecord> result = buildRecordRepository.queryWithPredicates(BuildRecordPredicates.withoutAttribute("ATTR2"), BuildRecordPredicates.withAttribute("TEST", "true"));
    // then
    logger.debug("Builds {}", result);
    Assertions.assertThat(result.size()).isEqualTo(1);
}
Also used : Date(java.util.Date) BuildRecord(org.jboss.pnc.model.BuildRecord) InSequence(org.jboss.arquillian.junit.InSequence) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 43 with BuildRecord

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

the class BuildRecordRepositoryTest method shouldFindNoneExpiredTemporaryBuilds.

@InSequence(1)
@Test
public void shouldFindNoneExpiredTemporaryBuilds() {
    // given
    Date now = new Date();
    BuildRecord givenBr = initBuildRecordBuilder(Sequence.nextBase32Id()).endTime(now).temporaryBuild(true).build();
    buildRecordRepository.save(givenBr);
    // when
    List<BuildRecord> found = buildRecordRepository.findIndependentTemporaryBuildsOlderThan(new Date(now.getTime() - 1000));
    // then
    assertEquals(0, found.size());
}
Also used : Date(java.util.Date) BuildRecord(org.jboss.pnc.model.BuildRecord) InSequence(org.jboss.arquillian.junit.InSequence) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 44 with BuildRecord

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

the class BuildRecordRepositoryTest method shouldHaveNotNullLastUpdateTime.

@InSequence(5)
@Test
public void shouldHaveNotNullLastUpdateTime() {
    // given
    Date now = new Date();
    String id = Sequence.nextBase32Id();
    BuildRecord givenBr = initBuildRecordBuilder(id).endTime(now).temporaryBuild(true).build();
    buildRecordRepository.save(givenBr);
    // when
    BuildRecord found = buildRecordRepository.queryById(new Base32LongID(id));
    // then
    Date firstLastUpdateTime = found.getLastUpdateTime();
    assertNotNull(firstLastUpdateTime);
    // Updating the build record
    givenBr.setStatus(BuildStatus.CANCELLED);
    buildRecordRepository.save(givenBr);
    // Refetch the build record saved
    found = buildRecordRepository.queryById(new Base32LongID(id));
    Date secondLastUpdateTime = found.getLastUpdateTime();
    assertNotNull(secondLastUpdateTime);
    // Verify that the last update was changed
    assertNotEquals(firstLastUpdateTime, secondLastUpdateTime);
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) Date(java.util.Date) BuildRecord(org.jboss.pnc.model.BuildRecord) InSequence(org.jboss.arquillian.junit.InSequence) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 45 with BuildRecord

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

the class CancelledBuildByBpmTest method buildSingleProjectTestCase.

@Test(timeout = 5_000)
public void buildSingleProjectTestCase() throws Exception {
    // given
    DatastoreMock datastoreMock = new DatastoreMock();
    TestProjectConfigurationBuilder configurationBuilder = new TestProjectConfigurationBuilder(datastoreMock);
    DatastoreAdapter datastoreAdapter = new DatastoreAdapter(datastoreMock);
    SystemConfig systemConfig = createConfiguration();
    BuildQueue queue = new BuildQueue(systemConfig);
    BlockingQueue<BuildStatusChangedEvent> receivedStatuses = new ArrayBlockingQueue<>(5);
    Consumer<BuildStatusChangedEvent> onStatusUpdate = receivedStatuses::add;
    EventListener buildStatusChangedEventNotifier = new EventListener(onStatusUpdate);
    BlockingQueue<BpmTask> task = new ArrayBlockingQueue<>(5);
    Consumer<BpmTask> onBpmTaskCreated = task::add;
    BuildSchedulerFactory buildSchedulerFactory = new BuildSchedulerFactory(onBpmTaskCreated);
    BuildCoordinator coordinator = new DefaultBuildCoordinator(datastoreAdapter, buildStatusChangedEventNotifier, null, buildSchedulerFactory, queue, systemConfig, groupBuildMapper, buildMapper);
    coordinator.start();
    queue.initSemaphore();
    coordinator.build(configurationBuilder.buildConfigurationToCancel(1, "c1-bpm"), MockUser.newTestUser(1), new BuildOptions());
    waitForStatus(receivedStatuses, BuildStatus.BUILDING);
    BpmTask bpmTask = task.poll(1, TimeUnit.SECONDS);
    BuildResultRest result = new BuildResultRest();
    result.setCompletionStatus(CompletionStatus.CANCELLED);
    // when
    bpmTask.notify(BUILD_COMPLETE, result);
    waitForStatus(receivedStatuses, BuildStatus.CANCELLED);
    // expect
    List<BuildRecord> buildRecords = datastoreMock.getBuildRecords();
    Assert.assertEquals("Too many build records in datastore: " + buildRecords, 1, buildRecords.size());
    BuildRecord buildRecord = buildRecords.get(0);
    Assert.assertNotNull(buildRecord.getSubmitTime());
    Assert.assertNotNull(buildRecord.getStartTime());
    Assert.assertNotNull(buildRecord.getEndTime());
    Assert.assertEquals(BuildStatus.CANCELLED, buildRecord.getStatus());
}
Also used : BuildQueue(org.jboss.pnc.coordinator.builder.BuildQueue) BuildCoordinator(org.jboss.pnc.spi.coordinator.BuildCoordinator) DefaultBuildCoordinator(org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator) SystemConfig(org.jboss.pnc.common.json.moduleconfig.SystemConfig) BpmTask(org.jboss.pnc.bpm.BpmTask) TestProjectConfigurationBuilder(org.jboss.pnc.mock.model.builders.TestProjectConfigurationBuilder) BuildStatusChangedEvent(org.jboss.pnc.spi.events.BuildStatusChangedEvent) DatastoreMock(org.jboss.pnc.mock.datastore.DatastoreMock) BuildRecord(org.jboss.pnc.model.BuildRecord) BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) BuildOptions(org.jboss.pnc.spi.BuildOptions) DatastoreAdapter(org.jboss.pnc.coordinator.builder.datastore.DatastoreAdapter) DefaultBuildCoordinator(org.jboss.pnc.coordinator.builder.DefaultBuildCoordinator) 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