Search in sources :

Example 1 with BpmTask

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);
}
Also used : BpmTask(org.jboss.pnc.bpm.BpmTask) HashMap(java.util.HashMap) BpmStringMapNotificationRest(org.jboss.pnc.bpm.model.BpmStringMapNotificationRest) Test(org.junit.Test)

Example 2 with BpmTask

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

Example 3 with BpmTask

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);
}
Also used : GlobalModuleGroup(org.jboss.pnc.common.json.GlobalModuleGroup) BuildImportResultRest(org.jboss.pnc.bpm.model.causeway.BuildImportResultRest) Date(java.util.Date) CollectionUtils.ofNullableCollection(org.jboss.pnc.common.util.CollectionUtils.ofNullableCollection) LoggerFactory(org.slf4j.LoggerFactory) BpmTask(org.jboss.pnc.bpm.BpmTask) Function(java.util.function.Function) BuildMapper(org.jboss.pnc.mapper.api.BuildMapper) BuildRecordRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository) Inject(javax.inject.Inject) ProductMilestoneRepository(org.jboss.pnc.spi.datastore.repositories.ProductMilestoneRepository) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) ProductMilestoneRelease(org.jboss.pnc.model.ProductMilestoneRelease) BuildPushStatus(org.jboss.pnc.enums.BuildPushStatus) BpmManager(org.jboss.pnc.bpm.BpmManager) ProductMilestone(org.jboss.pnc.model.ProductMilestone) ProductVersionRepository(org.jboss.pnc.spi.datastore.repositories.ProductVersionRepository) BpmEventType(org.jboss.pnc.bpm.BpmEventType) BuildImportStatus(org.jboss.pnc.bpm.model.causeway.BuildImportStatus) ProductVersion(org.jboss.pnc.model.ProductVersion) Event(javax.enterprise.event.Event) Stateless(javax.ejb.Stateless) MilestoneReleaseTask(org.jboss.pnc.bpm.task.MilestoneReleaseTask) Logger(org.slf4j.Logger) Collection(java.util.Collection) RestConnector(org.jboss.pnc.bpm.RestConnector) BuildRecord(org.jboss.pnc.model.BuildRecord) NoEntityException(org.jboss.pnc.bpm.NoEntityException) MilestoneReleaseResultRest(org.jboss.pnc.bpm.model.causeway.MilestoneReleaseResultRest) ProductMilestoneReleaseRepository(org.jboss.pnc.spi.datastore.repositories.ProductMilestoneReleaseRepository) CoreException(org.jboss.pnc.spi.exception.CoreException) BuildRecordPushResultRepository(org.jboss.pnc.spi.datastore.repositories.BuildRecordPushResultRepository) ProductMilestoneCloseResult(org.jboss.pnc.dto.ProductMilestoneCloseResult) Optional(java.util.Optional) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) ProductMilestoneCloseResultMapper(org.jboss.pnc.mapper.api.ProductMilestoneCloseResultMapper) BpmModuleConfig(org.jboss.pnc.common.json.moduleconfig.BpmModuleConfig) Sequence(org.jboss.pnc.common.concurrent.Sequence) Numbers(org.jboss.pnc.common.Numbers) MilestoneCloseStatus(org.jboss.pnc.enums.MilestoneCloseStatus) Base32LongID(org.jboss.pnc.model.Base32LongID) RestConnector(org.jboss.pnc.bpm.RestConnector) BpmTask(org.jboss.pnc.bpm.BpmTask) MilestoneReleaseTask(org.jboss.pnc.bpm.task.MilestoneReleaseTask) ProductMilestoneRelease(org.jboss.pnc.model.ProductMilestoneRelease)

Aggregations

BpmTask (org.jboss.pnc.bpm.BpmTask)3 BuildRecord (org.jboss.pnc.model.BuildRecord)2 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 Function (java.util.function.Function)1 Stateless (javax.ejb.Stateless)1 Event (javax.enterprise.event.Event)1 Inject (javax.inject.Inject)1 BpmEventType (org.jboss.pnc.bpm.BpmEventType)1 BpmManager (org.jboss.pnc.bpm.BpmManager)1 NoEntityException (org.jboss.pnc.bpm.NoEntityException)1 RestConnector (org.jboss.pnc.bpm.RestConnector)1 BpmStringMapNotificationRest (org.jboss.pnc.bpm.model.BpmStringMapNotificationRest)1 BuildResultRest (org.jboss.pnc.bpm.model.BuildResultRest)1 BuildImportResultRest (org.jboss.pnc.bpm.model.causeway.BuildImportResultRest)1 BuildImportStatus (org.jboss.pnc.bpm.model.causeway.BuildImportStatus)1 MilestoneReleaseResultRest (org.jboss.pnc.bpm.model.causeway.MilestoneReleaseResultRest)1