Search in sources :

Example 16 with Acceptable

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());
    }
}
Also used : FlowAcceptResult(com.sequenceiq.flow.core.model.FlowAcceptResult) FlowsAlreadyRunningException(com.sequenceiq.cloudbreak.exception.FlowsAlreadyRunningException) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) FlowNotAcceptedException(com.sequenceiq.cloudbreak.exception.FlowNotAcceptedException)

Example 17 with Acceptable

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());
}
Also used : MaintenanceModeValidationTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.MaintenanceModeValidationTriggerEvent) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Test(org.junit.Test)

Example 18 with Acceptable

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());
}
Also used : ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) Test(org.junit.Test)

Example 19 with Acceptable

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());
}
Also used : StackAndClusterUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request) Test(org.junit.Test)

Example 20 with Acceptable

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));
}
Also used : BaseFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseFlowEvent) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Event(reactor.bus.Event) BaseFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseFlowEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Aggregations

Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)27 Test (org.junit.Test)9 Test (org.junit.jupiter.api.Test)9 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 FlowAcceptResult (com.sequenceiq.flow.core.model.FlowAcceptResult)5 Constructor (java.lang.reflect.Constructor)5 Modifier (java.lang.reflect.Modifier)5 Set (java.util.Set)5 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)5 AcceptResult (com.sequenceiq.cloudbreak.common.event.AcceptResult)4 StackAndClusterUpscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent)4 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)4 BaseFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseFlowEvent)4 Operation (com.sequenceiq.freeipa.entity.Operation)4 ReflectionUtils (org.reflections.ReflectionUtils)4 Reflections (org.reflections.Reflections)4 SubTypesScanner (org.reflections.scanners.SubTypesScanner)4 Event (reactor.bus.Event)4 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)3 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)3