Search in sources :

Example 1 with STOPSTART_UPSCALE_FINALIZED_EVENT

use of com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleEvent.STOPSTART_UPSCALE_FINALIZED_EVENT in project cloudbreak by hortonworks.

the class StopStartUpscaleActionsTest method testUpscaleFinishedAction2.

@Test
void testUpscaleFinishedAction2() throws Exception {
    // Some did not commission.
    AbstractStopStartUpscaleActions<StopStartUpscaleCommissionViaCMResult> action = (AbstractStopStartUpscaleActions<StopStartUpscaleCommissionViaCMResult>) underTest.upscaleFinishedAction();
    initActionPrivateFields(action);
    int adjustment = 5;
    StopStartUpscaleContext stopStartUpscaleContext = createContext(adjustment);
    List<InstanceMetaData> instancesActionableNotStopped = generateInstances(5, 100, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_ACTIONABLE);
    List<InstanceMetaData> instancesActionableStopped = generateInstances(10, 200, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_ACTIONABLE);
    List<InstanceMetaData> instancesRandomNotStopped = generateInstances(3, 300, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_RANDOM);
    List<InstanceMetaData> instancesRandomStopped = generateInstances(8, 400, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_RANDOM);
    List<InstanceMetaData> startedInstances = instancesActionableStopped.subList(0, adjustment - 2);
    List<InstanceMetaData> notCommissioned = instancesActionableStopped.subList(adjustment - 2, adjustment);
    List<String> notCommissionedFqdns = notCommissioned.stream().map(x -> x.getDiscoveryFQDN()).collect(Collectors.toList());
    StopStartUpscaleCommissionViaCMRequest request = new StopStartUpscaleCommissionViaCMRequest(1L, INSTANCE_GROUP_NAME_ACTIONABLE, startedInstances, notCommissioned);
    Set<String> successfullyCommissionedFqdns = startedInstances.stream().map(i -> i.getDiscoveryFQDN()).collect(Collectors.toUnmodifiableSet());
    StopStartUpscaleCommissionViaCMResult payload = new StopStartUpscaleCommissionViaCMResult(request, successfullyCommissionedFqdns, notCommissionedFqdns);
    // Mocks
    mockStackEtc(instancesActionableNotStopped, instancesActionableStopped, instancesRandomNotStopped, instancesRandomStopped);
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    new AbstractActionTestSupport<>(action).doExecute(stopStartUpscaleContext, payload, Collections.emptyMap());
    verify(stopStartUpscaleFlowService).logInstancesFailedToCommission(eq(STACK_ID), eq(notCommissionedFqdns));
    verify(stopStartUpscaleFlowService).clusterUpscaleFinished(any(), eq(INSTANCE_GROUP_NAME_ACTIONABLE), eq(startedInstances), eq(DetailedStackStatus.AVAILABLE));
    ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
    verify(reactorEventFactory).createEvent(anyMap(), argumentCaptor.capture());
    verify(eventBus).notify("STOPSTART_UPSCALE_FINALIZED_EVENT", event);
    assertThat(argumentCaptor.getValue()).isInstanceOf(StopStartUpscaleCommissionViaCMResult.class);
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Action(org.springframework.statemachine.action.Action) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) MetricService(com.sequenceiq.cloudbreak.common.metrics.MetricService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) StopStartUpscaleStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ErrorHandlerAwareReactorEventFactory(com.sequenceiq.flow.reactor.ErrorHandlerAwareReactorEventFactory) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) CloudbreakMetricService(com.sequenceiq.cloudbreak.service.metrics.CloudbreakMetricService) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Collection(java.util.Collection) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Set(java.util.Set) FlowParameters(com.sequenceiq.flow.core.FlowParameters) StopStartUpscaleStartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult) EventBus(reactor.bus.EventBus) AbstractActionTestSupport(com.sequenceiq.flow.core.AbstractActionTestSupport) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) Stream(java.util.stream.Stream) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) FlowRegister(com.sequenceiq.flow.core.FlowRegister) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Mock(org.mockito.Mock) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) Mockito.lenient(org.mockito.Mockito.lenient) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) ArrayList(java.util.ArrayList) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) HashSet(java.util.HashSet) CloudInstanceIdToInstanceMetaDataConverter(com.sequenceiq.cloudbreak.converter.CloudInstanceIdToInstanceMetaDataConverter) ArgumentCaptor(org.mockito.ArgumentCaptor) ClusterManagerType(com.sequenceiq.cloudbreak.common.type.ClusterManagerType) Event(reactor.bus.Event) ArgumentMatchers.isNotNull(org.mockito.ArgumentMatchers.isNotNull) LinkedList(java.util.LinkedList) InjectMocks(org.mockito.InjectMocks) AbstractStopStartUpscaleActions(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleActions.AbstractStopStartUpscaleActions) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.times(org.mockito.Mockito.times) StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Mockito.verify(org.mockito.Mockito.verify) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StopStartUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StopStartUpscaleTriggerEvent) Assert(org.junit.Assert) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) AbstractStopStartUpscaleActions(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleActions.AbstractStopStartUpscaleActions) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) Test(org.junit.jupiter.api.Test)

Example 2 with STOPSTART_UPSCALE_FINALIZED_EVENT

use of com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleEvent.STOPSTART_UPSCALE_FINALIZED_EVENT in project cloudbreak by hortonworks.

the class StopStartUpscaleActionsTest method testUpscaleFinishedAction1.

@Test
void testUpscaleFinishedAction1() throws Exception {
    // All started.
    AbstractStopStartUpscaleActions<StopStartUpscaleCommissionViaCMResult> action = (AbstractStopStartUpscaleActions<StopStartUpscaleCommissionViaCMResult>) underTest.upscaleFinishedAction();
    initActionPrivateFields(action);
    int adjustment = 10;
    StopStartUpscaleContext stopStartUpscaleContext = createContext(adjustment);
    List<InstanceMetaData> instancesActionableNotStopped = generateInstances(5, 100, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_ACTIONABLE);
    List<InstanceMetaData> instancesActionableStopped = generateInstances(10, 200, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_ACTIONABLE);
    List<InstanceMetaData> instancesRandomNotStopped = generateInstances(3, 300, InstanceStatus.SERVICES_HEALTHY, INSTANCE_GROUP_NAME_RANDOM);
    List<InstanceMetaData> instancesRandomStopped = generateInstances(8, 400, InstanceStatus.STOPPED, INSTANCE_GROUP_NAME_RANDOM);
    List<InstanceMetaData> startedInstances = instancesActionableStopped.subList(0, adjustment);
    StopStartUpscaleCommissionViaCMRequest request = new StopStartUpscaleCommissionViaCMRequest(1L, INSTANCE_GROUP_NAME_ACTIONABLE, startedInstances, Collections.emptyList());
    Set<String> successfullyCommissionedFqdns = startedInstances.stream().map(i -> i.getDiscoveryFQDN()).collect(Collectors.toUnmodifiableSet());
    StopStartUpscaleCommissionViaCMResult payload = new StopStartUpscaleCommissionViaCMResult(request, successfullyCommissionedFqdns, Collections.emptyList());
    // Mocks
    mockStackEtc(instancesActionableNotStopped, instancesActionableStopped, instancesRandomNotStopped, instancesRandomStopped);
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    new AbstractActionTestSupport<>(action).doExecute(stopStartUpscaleContext, payload, Collections.emptyMap());
    verify(stopStartUpscaleFlowService).clusterUpscaleFinished(any(), eq(INSTANCE_GROUP_NAME_ACTIONABLE), eq(startedInstances), eq(DetailedStackStatus.AVAILABLE));
    ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
    verify(reactorEventFactory).createEvent(anyMap(), argumentCaptor.capture());
    verify(eventBus).notify("STOPSTART_UPSCALE_FINALIZED_EVENT", event);
    assertThat(argumentCaptor.getValue()).isInstanceOf(StopStartUpscaleCommissionViaCMResult.class);
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Action(org.springframework.statemachine.action.Action) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) MetricService(com.sequenceiq.cloudbreak.common.metrics.MetricService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) StopStartUpscaleStartInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ErrorHandlerAwareReactorEventFactory(com.sequenceiq.flow.reactor.ErrorHandlerAwareReactorEventFactory) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) CloudbreakMetricService(com.sequenceiq.cloudbreak.service.metrics.CloudbreakMetricService) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Collection(java.util.Collection) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Set(java.util.Set) FlowParameters(com.sequenceiq.flow.core.FlowParameters) StopStartUpscaleStartInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult) EventBus(reactor.bus.EventBus) AbstractActionTestSupport(com.sequenceiq.flow.core.AbstractActionTestSupport) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) Stream(java.util.stream.Stream) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) FlowRegister(com.sequenceiq.flow.core.FlowRegister) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Mock(org.mockito.Mock) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) Mockito.lenient(org.mockito.Mockito.lenient) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) ArrayList(java.util.ArrayList) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) HashSet(java.util.HashSet) CloudInstanceIdToInstanceMetaDataConverter(com.sequenceiq.cloudbreak.converter.CloudInstanceIdToInstanceMetaDataConverter) ArgumentCaptor(org.mockito.ArgumentCaptor) ClusterManagerType(com.sequenceiq.cloudbreak.common.type.ClusterManagerType) Event(reactor.bus.Event) ArgumentMatchers.isNotNull(org.mockito.ArgumentMatchers.isNotNull) LinkedList(java.util.LinkedList) InjectMocks(org.mockito.InjectMocks) AbstractStopStartUpscaleActions(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleActions.AbstractStopStartUpscaleActions) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.times(org.mockito.Mockito.times) StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Mockito.verify(org.mockito.Mockito.verify) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StopStartUpscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StopStartUpscaleTriggerEvent) Assert(org.junit.Assert) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StopStartUpscaleCommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartUpscaleCommissionViaCMResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) AbstractStopStartUpscaleActions(com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleActions.AbstractStopStartUpscaleActions) StopStartUpscaleCommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartUpscaleCommissionViaCMRequest) Test(org.junit.jupiter.api.Test)

Aggregations

DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)2 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 StopStartUpscaleStartInstancesRequest (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesRequest)2 StopStartUpscaleStartInstancesResult (com.sequenceiq.cloudbreak.cloud.event.instance.StopStartUpscaleStartInstancesResult)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)2 MetricService (com.sequenceiq.cloudbreak.common.metrics.MetricService)2 ClusterManagerType (com.sequenceiq.cloudbreak.common.type.ClusterManagerType)2 CloudInstanceIdToInstanceMetaDataConverter (com.sequenceiq.cloudbreak.converter.CloudInstanceIdToInstanceMetaDataConverter)2 InstanceMetaDataToCloudInstanceConverter (com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter)2 AbstractStopStartUpscaleActions (com.sequenceiq.cloudbreak.core.flow2.cluster.stopstartus.StopStartUpscaleActions.AbstractStopStartUpscaleActions)2 StopStartUpscaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StopStartUpscaleTriggerEvent)2 AbstractStackFailureAction (com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction)2 StackFailureContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext)2 StackAuthentication (com.sequenceiq.cloudbreak.domain.StackAuthentication)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)2