use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.
the class SdxReactorFlowManager method notify.
private FlowIdentifier notify(String selector, SdxEvent acceptable, String identifier) {
Map<String, Object> flowTriggerUserCrnHeader = Map.of(FlowConstants.FLOW_TRIGGER_USERCRN, acceptable.getUserId());
Event<Acceptable> event = eventFactory.createEventWithErrHandler(flowTriggerUserCrnHeader, acceptable);
reactor.notify(selector, event);
try {
FlowAcceptResult accepted = (FlowAcceptResult) event.getData().accepted().await(WAIT_FOR_ACCEPT, TimeUnit.SECONDS);
if (accepted == null) {
throw new FlowNotAcceptedException(String.format("Timeout happened when trying to start the flow for sdx cluster %s.", event.getData().getResourceId()));
} else {
switch(accepted.getResultType()) {
case ALREADY_EXISTING_FLOW:
throw new FlowsAlreadyRunningException(String.format("Request not allowed, datalake cluster '%s' already has a running operation. " + "Running operation(s): [%s]", identifier, flowNameFormatService.formatFlows(accepted.getAlreadyRunningFlows())));
case RUNNING_IN_FLOW:
return new FlowIdentifier(FlowType.FLOW, accepted.getAsFlowId());
case RUNNING_IN_FLOW_CHAIN:
return new FlowIdentifier(FlowType.FLOW_CHAIN, accepted.getAsFlowChainId());
default:
throw new IllegalStateException("Unsupported accept result type: " + accepted.getClass());
}
}
} catch (InterruptedException e) {
throw new CloudbreakApiException(e.getMessage());
}
}
use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.
the class ReactorFlowManagerTest method testTriggerMaintenanceModeValidationFlow.
@Test
public void testTriggerMaintenanceModeValidationFlow() {
long stackId = 1L;
underTest.triggerMaintenanceModeValidationFlow(stackId);
ArgumentCaptor<Acceptable> captor = ArgumentCaptor.forClass(Acceptable.class);
verify(reactorNotifier).notify(eq(stackId), eq(FlowChainTriggers.CLUSTER_MAINTENANCE_MODE_VALIDATION_TRIGGER_EVENT), captor.capture());
MaintenanceModeValidationTriggerEvent event = (MaintenanceModeValidationTriggerEvent) captor.getValue();
assertEquals(stack.getId(), event.getResourceId());
assertEquals(FlowChainTriggers.CLUSTER_MAINTENANCE_MODE_VALIDATION_TRIGGER_EVENT, event.selector());
}
use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.
the class ReactorFlowManagerTest method testTriggerStackImageUpdate.
@Test
public void testTriggerStackImageUpdate() {
long stackId = 1L;
String imageID = "imageID";
String imageCatalogName = "imageCatalogName";
String imageCatalogUrl = "imageCatalogUrl";
underTest.triggerStackImageUpdate(new ImageChangeDto(stackId, imageID, imageCatalogName, imageCatalogUrl));
ArgumentCaptor<Acceptable> captor = ArgumentCaptor.forClass(Acceptable.class);
verify(reactorNotifier).notify(eq(stackId), eq(FlowChainTriggers.STACK_IMAGE_UPDATE_TRIGGER_EVENT), captor.capture());
StackImageUpdateTriggerEvent event = (StackImageUpdateTriggerEvent) captor.getValue();
assertEquals(FlowChainTriggers.STACK_IMAGE_UPDATE_TRIGGER_EVENT, event.selector());
assertEquals(stack.getId(), event.getResourceId());
assertEquals(imageCatalogName, event.getImageCatalogName());
assertEquals(imageID, event.getNewImageId());
assertEquals(imageCatalogUrl, event.getImageCatalogUrl());
}
use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.
the class ReactorFlowManagerTest method testTriggerUpscaleWithClusterEvent.
@Test
public void testTriggerUpscaleWithClusterEvent() {
InstanceGroupAdjustmentV4Request instanceGroupAdjustment = new InstanceGroupAdjustmentV4Request();
instanceGroupAdjustment.setInstanceGroup("ig");
instanceGroupAdjustment.setScalingAdjustment(3);
when(stackService.getPlatformVariantByStackId(STACK_ID)).thenReturn(cloudPlatformVariant);
when(cloudPlatformVariant.getVariant()).thenReturn(Variant.variant("AWS"));
underTest.triggerStackUpscale(stack.getId(), instanceGroupAdjustment, true);
ArgumentCaptor<Acceptable> captor = ArgumentCaptor.forClass(Acceptable.class);
verify(reactorNotifier, times(1)).notify(eq(stack.getId()), eq(FlowChainTriggers.FULL_UPSCALE_TRIGGER_EVENT), captor.capture());
StackAndClusterUpscaleTriggerEvent event = (StackAndClusterUpscaleTriggerEvent) captor.getValue();
assertEquals(FlowChainTriggers.FULL_UPSCALE_TRIGGER_EVENT, event.selector());
assertEquals(stack.getId(), event.getResourceId());
assertEquals(instanceGroupAdjustment.getInstanceGroup(), event.getHostGroupsWithAdjustment().keySet().stream().findFirst().get());
assertEquals(instanceGroupAdjustment.getScalingAdjustment(), event.getHostGroupsWithAdjustment().values().stream().findFirst().get());
assertEquals(ScalingType.UPSCALE_TOGETHER, event.getScalingType());
}
use of com.sequenceiq.cloudbreak.common.event.Acceptable in project cloudbreak by hortonworks.
the class ReactorNotifierTest method testNonAllowedFlowInMaintenanceMode.
@Test(expected = CloudbreakApiException.class)
public void testNonAllowedFlowInMaintenanceMode() {
Stack stack = TestUtil.stack();
stack.setCluster(TestUtil.cluster());
stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.MAINTENANCE_MODE_ENABLED));
when(stackService.getByIdWithTransaction(1L)).thenReturn(stack);
BaseFlowEvent baseFlowEvent = new BaseFlowEvent("dontcare", 1L, "crn");
when(eventFactory.createEventWithErrHandler(anyMap(), any(Acceptable.class))).thenReturn(new Event<Acceptable>(baseFlowEvent));
underTest.notify(1L, "RANDOM", baseFlowEvent, stackService::getByIdWithTransaction);
verify(reactor, never()).notify(anyString(), any(Event.class));
}
Aggregations