use of org.jboss.pnc.bpm.BpmTask in project pnc by project-ncl.
the class BpmSchedulerSmokeTest method notificationTest.
@Test
public void notificationTest() throws CoreException {
successNotification = false;
errorNotification = false;
BpmTask task = new BpmTask("") {
@Override
public String getProcessId() {
return "colors";
}
@Override
protected Serializable getProcessParameters() throws CoreException {
return new SimpleParameters();
}
};
task.<BpmStringMapNotificationRest>addListener(RC_REPO_CREATION_SUCCESS, t -> {
assertEquals("green", t.getData().get("color"));
successNotification = true;
});
task.<BpmStringMapNotificationRest>addListener(RC_REPO_CREATION_ERROR, t -> {
assertEquals("red", t.getData().get("color"));
errorNotification = true;
});
bpmManager.startTask(task);
// notify
assertEquals(new Integer(1), task.getTaskId());
BpmStringMapNotificationRest notification = mock(BpmStringMapNotificationRest.class);
when(notification.getEventType()).thenReturn(RC_REPO_CREATION_SUCCESS.name());
Map<String, String> data = new HashMap<>();
data.put("color", "green");
when(notification.getData()).thenReturn(data);
bpmManager.notify(1, notification);
assertTrue(successNotification);
assertFalse(errorNotification);
}
use of org.jboss.pnc.bpm.BpmTask 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());
}
use of org.jboss.pnc.bpm.BpmTask in project pnc by project-ncl.
the class ProductMilestoneReleaseManager method cancel.
public void cancel(ProductMilestone milestoneInDb, String accessToken, boolean useRHPAM) {
if (!useRHPAM) {
Collection<BpmTask> activeTasks = bpmManager.getActiveTasks();
Optional<MilestoneReleaseTask> milestoneReleaseTask = activeTasks.stream().map(task -> (MilestoneReleaseTask) task).filter(task -> task.getMilestone().getId().equals(milestoneInDb.getId())).findAny();
if (milestoneReleaseTask.isPresent()) {
bpmManager.cancelTask(milestoneReleaseTask.get());
}
} else {
RestConnector restConnector = new RestConnector(bpmConfig);
restConnector.cancelByCorrelation(Numbers.decimalToBase32(milestoneInDb.getId()), accessToken);
}
ProductMilestoneRelease milestoneRelease = productMilestoneReleaseRepository.findLatestByMilestone(milestoneInDb);
milestoneRelease.setStatus(MilestoneCloseStatus.CANCELED);
productMilestoneReleaseRepository.save(milestoneRelease);
}
Aggregations