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;
}
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);
}
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());
}
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);
}
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());
}
Aggregations