use of org.jboss.pnc.dto.Build in project pnc by project-ncl.
the class BuildProviderImplTest method testGetLatestRunningBuild.
@Test
public void testGetLatestRunningBuild() {
// Prepare
mockBuildTask();
mockBuildTask();
mockBuildRecord();
BuildTask latestRunning = mockBuildTask();
mockBuildRecord();
// When
BuildPageInfo pageInfo = new BuildPageInfo(0, 10, "", "", true, true, "");
Page<Build> builds = provider.getBuilds(pageInfo);
// Verify
assertEquals(1, builds.getTotalHits());
assertEquals(latestRunning.getId(), builds.getContent().iterator().next().getId());
}
use of org.jboss.pnc.dto.Build in project pnc by project-ncl.
the class BuildProviderImplTest method testBuildIterator.
public void testBuildIterator() {
SortInfo sortInfo = mock(SortInfo.class);
Predicate<BuildRecord> predicate = mock(Predicate.class);
mockRepository(sortInfo, predicate);
BuildProviderImpl.BuildIterator bit;
List<Integer> ret;
bit = provider.new BuildIterator(1, 10, 1, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
Build next = bit.next();
System.out.println("next: " + next);
ret.add(Integer.valueOf(next.getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(1, 10, 10, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(1, 10, 100, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ret);
bit = provider.new BuildIterator(7, 12, 100, sortInfo, predicate);
ret = new ArrayList<>();
while (bit.hasNext()) {
ret.add(Integer.valueOf(bit.next().getId()));
}
assertEquals(Arrays.asList(7, 8, 9, 10, 11, 12), ret);
}
use of org.jboss.pnc.dto.Build in project pnc by project-ncl.
the class BuildProviderImplTest method testPage.
private void testPage(int idx, int size, Base32LongID... ids) {
BuildPageInfo pageInfo = new BuildPageInfo(idx, size, "", "", false, false, "");
Page<Build> builds = provider.getBuilds(pageInfo);
Iterator<Build> it = builds.getContent().iterator();
for (Base32LongID id : ids) {
assertEquals(BuildMapper.idMapper.toDto(id), it.next().getId());
}
assertFalse(it.hasNext());
}
use of org.jboss.pnc.dto.Build 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;
}
use of org.jboss.pnc.dto.Build in project pnc by project-ncl.
the class DefaultBuildCoordinator method updateBuildTaskStatus.
private void updateBuildTaskStatus(BuildTask task, BuildCoordinationStatus status, String statusDescription) {
BuildCoordinationStatus oldStatus = task.getStatus();
// REJECTED_ALREADY_BUILT -> DONE
if (status.isCompleted() && !oldStatus.isCompleted()) {
markFinished(task, status, statusDescription);
} else {
task.setStatus(status);
task.setStatusDescription(statusDescription);
}
Build build = buildMapper.fromBuildTask(task);
BuildStatusChangedEvent buildStatusChanged = new DefaultBuildStatusChangedEvent(build, BuildStatus.fromBuildCoordinationStatus(oldStatus), BuildStatus.fromBuildCoordinationStatus(status));
log.debug("Updated build task {} status to {}; old coord status: {}, new coord status: {}", task.getId(), buildStatusChanged, oldStatus, status);
userLog.info("Build status updated to {}; previous: {}", status, oldStatus);
BuildStatus oldBuildStatus = BuildStatus.fromBuildCoordinationStatus(oldStatus);
BuildStatus newBuildStatus = BuildStatus.fromBuildCoordinationStatus(status);
if ((oldBuildStatus != newBuildStatus) && !(oldBuildStatus.isFinal() && newBuildStatus.isFinal())) {
// only fire notification when BuildStatus changes
// and avoid firing the notification when old and new statuses are final (NCL-5885)
buildStatusChangedEventNotifier.fire(buildStatusChanged);
log.debug("Fired buildStatusChangedEventNotifier after task {} status update to {}.", task.getId(), status);
}
}
Aggregations