Search in sources :

Example 16 with FlowTriggerEventQueue

use of com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue in project cloudbreak by hortonworks.

the class OperationServiceTest method testGetOperationProgressByResourceCrnWithDatalake.

@Test
public void testGetOperationProgressByResourceCrnWithDatalake() {
    // GIVEN
    ProvisionFlowEventChainFactory provisionFlowEventChainFactory = new ProvisionFlowEventChainFactory();
    FlowTriggerEventQueue eventQueue = provisionFlowEventChainFactory.createFlowTriggerEventQueue(new StackEvent(null, null));
    given(flowService.getLastFlowOperationByResourceCrn(anyString())).willReturn(Optional.of(operationFlowsView));
    given(operationFlowsView.getOperationType()).willReturn(OperationType.PROVISION);
    given(operationDetailsPopulator.createOperationView(operationFlowsView, OperationResource.DATALAKE, EXPECTED_TYPE_LIST)).willReturn(operationView);
    // WHEN
    OperationView result = underTest.getOperationProgressByResourceCrn(TEST_DATALAKE_CRN, true);
    // THEN
    assertEquals(operationView, result);
    verify(operationDetailsPopulator, times(1)).createOperationView(operationFlowsView, OperationResource.DATALAKE, EXPECTED_TYPE_LIST);
    // Checks that the number of provision flows are the same as in the operation check
    assertEquals(eventQueue.getQueue().size(), EXPECTED_TYPE_LIST.size());
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) ProvisionFlowEventChainFactory(com.sequenceiq.cloudbreak.core.flow2.chain.ProvisionFlowEventChainFactory) OperationView(com.sequenceiq.flow.api.model.operation.OperationView) Test(org.junit.jupiter.api.Test)

Example 17 with FlowTriggerEventQueue

use of com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue in project cloudbreak by hortonworks.

the class ClusterRepairFlowEventChainFactoryTest method testRepairOneNodeFromEachHostGroupAtOnce.

@Test
public void testRepairOneNodeFromEachHostGroupAtOnce() {
    Stack stack = getStack(MULTIPLE_GATEWAY);
    when(stackService.findClustersConnectedToDatalakeByDatalakeStackId(STACK_ID)).thenReturn(Set.of());
    HostGroup masterHostGroup = setupHostGroup("hostGroup-master", setupInstanceGroup(InstanceGroupType.GATEWAY));
    when(hostGroupService.findHostGroupInClusterByName(anyLong(), eq("hostGroup-master"))).thenReturn(Optional.of(masterHostGroup));
    HostGroup coreHostGroup = setupHostGroup("hostGroup-core", setupInstanceGroup(InstanceGroupType.CORE));
    when(hostGroupService.findHostGroupInClusterByName(anyLong(), eq("hostGroup-core"))).thenReturn(Optional.of(coreHostGroup));
    HostGroup auxiliaryHostGroup = setupHostGroup("hostGroup-auxiliary", setupInstanceGroup(InstanceGroupType.CORE));
    when(hostGroupService.findHostGroupInClusterByName(anyLong(), eq("hostGroup-auxiliary"))).thenReturn(Optional.of(auxiliaryHostGroup));
    when(entitlementService.isDatalakeZduOSUpgradeEnabled(anyString())).thenReturn(true);
    setupStackView();
    setupPrimaryGateway();
    InstanceMetaData primaryGWInstanceMetadata = new InstanceMetaData();
    primaryGWInstanceMetadata.setDiscoveryFQDN("failedNode-FQDN-primary-gateway");
    when(instanceMetaDataService.getPrimaryGatewayInstanceMetadata(STACK_ID)).thenReturn(Optional.of(primaryGWInstanceMetadata));
    Crn crn = mock(Crn.class);
    when(crn.getAccountId()).thenReturn("accountid");
    when(stackService.getCrnById(anyLong())).thenReturn(crn);
    ClusterRepairTriggerEvent triggerEvent = new TriggerEventBuilder(stack).withFailedPrimaryGateway().withFailedSecondaryGateway().with3FailedCore().withFailedAuxiliary().withOneNodeFromEachHostGroupAtOnce().build();
    FlowTriggerEventQueue eventQueues = underTest.createFlowTriggerEventQueue(triggerEvent);
    List<String> triggeredOperations = eventQueues.getQueue().stream().map(Selectable::selector).collect(Collectors.toList());
    assertEquals(List.of("FLOWCHAIN_INIT_TRIGGER_EVENT", "STACK_DOWNSCALE_TRIGGER_EVENT", "FULL_UPSCALE_TRIGGER_EVENT", "FULL_DOWNSCALE_TRIGGER_EVENT", "FULL_UPSCALE_TRIGGER_EVENT", "FULL_DOWNSCALE_TRIGGER_EVENT", "FULL_UPSCALE_TRIGGER_EVENT", "RESCHEDULE_STATUS_CHECK_TRIGGER_EVENT", "FLOWCHAIN_FINALIZE_TRIGGER_EVENT"), triggeredOperations);
    Set<String> downscaledMasterHosts = new HashSet<>();
    Set<String> downscaledCoreHosts = new HashSet<>();
    Set<String> downscaledAuxHosts = new HashSet<>();
    Set<String> upscaledMasterHosts = new HashSet<>();
    Set<String> upscaledCoreHosts = new HashSet<>();
    Set<String> upscaledAuxHosts = new HashSet<>();
    eventQueues.getQueue().remove();
    StackDownscaleTriggerEvent downscale1 = (StackDownscaleTriggerEvent) eventQueues.getQueue().poll();
    Set<String> firstDownscaledHostsInMaster = downscale1.getHostGroupsWithHostNames().get("hostGroup-master");
    assertEquals(1, firstDownscaledHostsInMaster.size());
    String firstDownscaledMasterHost = firstDownscaledHostsInMaster.iterator().next();
    downscaledMasterHosts.add(firstDownscaledMasterHost);
    assertEquals("failedNode-FQDN-primary-gateway", firstDownscaledMasterHost);
    Set<String> firstDownscaledHostsInCore = downscale1.getHostGroupsWithHostNames().get("hostGroup-core");
    assertEquals(1, firstDownscaledHostsInCore.size());
    String firstDownscaleCoreHost = firstDownscaledHostsInCore.iterator().next();
    downscaledCoreHosts.add(firstDownscaleCoreHost);
    Set<String> firstDownscaledHostsInAux = downscale1.getHostGroupsWithHostNames().get("hostGroup-auxiliary");
    assertEquals(1, firstDownscaledHostsInAux.size());
    String downscaledAuxHost = firstDownscaledHostsInAux.iterator().next();
    downscaledAuxHosts.add(downscaledAuxHost);
    StackAndClusterUpscaleTriggerEvent upscale1 = (StackAndClusterUpscaleTriggerEvent) eventQueues.getQueue().poll();
    Set<String> firstUpscaledHostsInMaster = upscale1.getHostGroupsWithHostNames().get("hostGroup-master");
    assertEquals(1, firstUpscaledHostsInMaster.size());
    String firstUpscaledMasterHost = firstUpscaledHostsInMaster.iterator().next();
    assertEquals("failedNode-FQDN-primary-gateway", firstUpscaledMasterHost);
    upscaledMasterHosts.add(firstUpscaledMasterHost);
    Set<String> firstUpscaledHostsInCore = upscale1.getHostGroupsWithHostNames().get("hostGroup-core");
    assertEquals(1, firstUpscaledHostsInCore.size());
    upscaledCoreHosts.add(firstUpscaledHostsInCore.iterator().next());
    Set<String> firstUpscaledHostsInAux = upscale1.getHostGroupsWithHostNames().get("hostGroup-auxiliary");
    assertEquals(1, firstUpscaledHostsInAux.size());
    upscaledAuxHosts.add(firstUpscaledHostsInAux.iterator().next());
    ClusterAndStackDownscaleTriggerEvent downscale2 = (ClusterAndStackDownscaleTriggerEvent) eventQueues.getQueue().poll();
    Set<String> secondDownscaledHostsInMaster = downscale2.getHostGroupsWithHostNames().get("hostGroup-master");
    assertEquals(1, secondDownscaledHostsInMaster.size());
    String secondDownscaledMasterHost = secondDownscaledHostsInMaster.iterator().next();
    downscaledMasterHosts.add(secondDownscaledMasterHost);
    assertEquals("failedNode-FQDN-secondary-gateway", secondDownscaledMasterHost);
    Set<String> secondDownscaledHostsInCore = downscale2.getHostGroupsWithHostNames().get("hostGroup-core");
    assertEquals(1, secondDownscaledHostsInCore.size());
    String secondDownscaleCoreHost = secondDownscaledHostsInCore.iterator().next();
    downscaledCoreHosts.add(secondDownscaleCoreHost);
    StackAndClusterUpscaleTriggerEvent upscale2 = (StackAndClusterUpscaleTriggerEvent) eventQueues.getQueue().poll();
    Set<String> secondUpscaledHostsInMaster = upscale2.getHostGroupsWithHostNames().get("hostGroup-master");
    assertEquals(1, secondUpscaledHostsInMaster.size());
    String secondUpscaledMasterHost = secondUpscaledHostsInMaster.iterator().next();
    assertEquals("failedNode-FQDN-secondary-gateway", secondUpscaledMasterHost);
    upscaledMasterHosts.add(secondUpscaledMasterHost);
    Set<String> secondUpscaledHostsInCore = upscale2.getHostGroupsWithHostNames().get("hostGroup-core");
    assertEquals(1, secondUpscaledHostsInCore.size());
    upscaledCoreHosts.add(secondUpscaledHostsInCore.iterator().next());
    ClusterAndStackDownscaleTriggerEvent downscale3 = (ClusterAndStackDownscaleTriggerEvent) eventQueues.getQueue().poll();
    Set<String> thirdDownscaledHostsInCore = downscale3.getHostGroupsWithHostNames().get("hostGroup-core");
    assertEquals(1, thirdDownscaledHostsInCore.size());
    String thirdDownscaleCoreHost = thirdDownscaledHostsInCore.iterator().next();
    downscaledCoreHosts.add(thirdDownscaleCoreHost);
    StackAndClusterUpscaleTriggerEvent upscale3 = (StackAndClusterUpscaleTriggerEvent) eventQueues.getQueue().poll();
    Set<String> thirdUpscaledHostsInCore = upscale3.getHostGroupsWithHostNames().get("hostGroup-core");
    assertEquals(1, thirdUpscaledHostsInCore.size());
    upscaledCoreHosts.add(thirdUpscaledHostsInCore.iterator().next());
    assertThat(downscaledCoreHosts, containsInAnyOrder("core1", "core2", "core3"));
    assertThat(downscaledMasterHosts, containsInAnyOrder(FAILED_NODE_FQDN_PRIMARY_GATEWAY, FAILED_NODE_FQDN_SECONDARY_GATEWAY));
    assertThat(downscaledAuxHosts, containsInAnyOrder("aux1"));
    assertThat(upscaledCoreHosts, containsInAnyOrder("core1", "core2", "core3"));
    assertThat(upscaledMasterHosts, containsInAnyOrder(FAILED_NODE_FQDN_PRIMARY_GATEWAY, FAILED_NODE_FQDN_SECONDARY_GATEWAY));
    assertThat(upscaledAuxHosts, containsInAnyOrder("aux1"));
}
Also used : ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ClusterRepairTriggerEvent(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterRepairTriggerEvent) StackAndClusterUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackAndClusterUpscaleTriggerEvent) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) ClusterAndStackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent) StackDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 18 with FlowTriggerEventQueue

use of com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue in project cloudbreak by hortonworks.

the class ClusterRepairFlowEventChainFactoryTest method testRepairSingleGatewayWithAttached.

@Test
public void testRepairSingleGatewayWithAttached() {
    Stack stack = getStack(NOT_MULTIPLE_GATEWAY);
    when(stackService.findClustersConnectedToDatalakeByDatalakeStackId(STACK_ID)).thenReturn(Set.of(ATTACHED_WORKLOAD));
    setupStackView();
    setupHostGroup(true);
    FlowTriggerEventQueue eventQueues = underTest.createFlowTriggerEventQueue(new TriggerEventBuilder(stack).withFailedPrimaryGateway().build());
    List<String> triggeredOperations = eventQueues.getQueue().stream().map(Selectable::selector).collect(Collectors.toList());
    assertEquals(List.of("FLOWCHAIN_INIT_TRIGGER_EVENT", "STACK_DOWNSCALE_TRIGGER_EVENT", "FULL_UPSCALE_TRIGGER_EVENT", "RESCHEDULE_STATUS_CHECK_TRIGGER_EVENT", "FLOWCHAIN_FINALIZE_TRIGGER_EVENT"), triggeredOperations);
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 19 with FlowTriggerEventQueue

use of com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue in project cloudbreak by hortonworks.

the class ProvisionFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(StackEvent event) {
    Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
    flowEventChain.add(new StackEvent(StackProvisionEvent.START_CREATION_EVENT.event(), event.getResourceId(), event.accepted()));
    flowEventChain.add(new StackEvent(FreeIpaProvisionEvent.FREEIPA_PROVISION_EVENT.event(), event.getResourceId()));
    return new FlowTriggerEventQueue(getName(), event, flowEventChain);
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 20 with FlowTriggerEventQueue

use of com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue in project cloudbreak by hortonworks.

the class UpgradeCcmFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(UpgradeCcmFlowChainTriggerEvent event) {
    Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
    flowEventChain.add(new UpgradeCcmTriggerEvent(UpgradeCcmStateSelector.UPGRADE_CCM_TRIGGER_EVENT.event(), event.getOperationId(), event.getResourceId(), event.getOldTunnel(), event.accepted()).withIsChained(true).withIsFinal(false));
    flowEventChain.add(new UserDataUpdateRequest(UpdateUserDataEvents.UPDATE_USERDATA_TRIGGER_EVENT.event(), event.getResourceId(), event.getOldTunnel()).withOperationId(event.getOperationId()).withIsChained(true).withIsFinal(true));
    return new FlowTriggerEventQueue(getName(), event, flowEventChain);
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) UserDataUpdateRequest(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateRequest) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) UpgradeCcmTriggerEvent(com.sequenceiq.freeipa.flow.stack.upgrade.ccm.event.UpgradeCcmTriggerEvent)

Aggregations

FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)52 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)35 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)26 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)15 Test (org.junit.Test)10 Test (org.junit.jupiter.api.Test)9 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)5 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)4 TerminationEvent (com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationEvent)4 ClusterTerminationEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.termination.ClusterTerminationEvent)3 StackDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackDownscaleTriggerEvent)3 StackSyncTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackSyncTriggerEvent)3 StackTerminationEvent (com.sequenceiq.cloudbreak.core.flow2.stack.termination.StackTerminationEvent)3 DatalakeResizeRecoveryFlowChainStartEvent (com.sequenceiq.datalake.flow.detach.event.DatalakeResizeRecoveryFlowChainStartEvent)3 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)2 Payload (com.sequenceiq.cloudbreak.common.event.Payload)2 ClusterAndStackDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterAndStackDownscaleTriggerEvent)2 ClusterDownscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterDownscaleTriggerEvent)2