Search in sources :

Example 1 with UpscaleStackValidationRequest

use of com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest in project cloudbreak by hortonworks.

the class StackUpscaleActionsTest method prevalidateTestDoExecuteWhenScalingNeededAndAllowed.

// Note: this implicitly tests getPrevalidateAction().createRequest() as well.
@Test
void prevalidateTestDoExecuteWhenScalingNeededAndAllowed() throws Exception {
    when(cloudContext.getId()).thenReturn(STACK_ID);
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, ADJUSTMENT.longValue());
    UpdateDomainDnsResolverResult payload = new UpdateDomainDnsResolverResult(STACK_ID);
    when(stackUpscaleService.getInstanceCountToCreate(stack, INSTANCE_GROUP_NAME, ADJUSTMENT, false)).thenReturn(ADJUSTMENT);
    Stack updatedStack = mock(Stack.class);
    when(instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, Map.of(INSTANCE_GROUP_NAME, 3), Map.of(), false, false, context.getStackNetworkScaleDetails())).thenReturn(updatedStack);
    CloudStack convertedCloudStack = mock(CloudStack.class);
    when(cloudStackConverter.convert(updatedStack)).thenReturn(convertedCloudStack);
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    new AbstractActionTestSupport<>(getPrevalidateAction()).doExecute(context, payload, createVariables(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT), Map.of(), NetworkScaleDetails.getEmpty(), adjustmentTypeWithThreshold, VARIANT));
    verify(stackUpscaleService).addInstanceFireEventAndLog(stack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT), adjustmentTypeWithThreshold);
    verify(stackUpscaleService).startAddInstances(stack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT));
    verify(reactorEventFactory).createEvent(anyMap(), payloadArgumentCaptor.capture());
    verify(eventBus).notify("UPSCALESTACKVALIDATIONREQUEST", event);
    Object responsePayload = payloadArgumentCaptor.getValue();
    assertThat(responsePayload).isInstanceOf(UpscaleStackValidationRequest.class);
    UpscaleStackValidationRequest<UpscaleStackValidationResult> upscaleStackValidationRequest = (UpscaleStackValidationRequest<UpscaleStackValidationResult>) responsePayload;
    assertThat(upscaleStackValidationRequest.getResourceId()).isEqualTo(STACK_ID);
    assertThat(upscaleStackValidationRequest.getCloudContext()).isSameAs(cloudContext);
    assertThat(upscaleStackValidationRequest.getCloudStack()).isSameAs(convertedCloudStack);
    assertThat(upscaleStackValidationRequest.getCloudCredential()).isSameAs(cloudCredential);
}
Also used : AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) UpscaleStackValidationResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) UpscaleStackValidationRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest) Test(org.junit.jupiter.api.Test)

Example 2 with UpscaleStackValidationRequest

use of com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest in project cloudbreak by hortonworks.

the class StackUpscaleActions method prevalidate.

@Bean(name = "UPSCALE_PREVALIDATION_STATE")
public Action<?, ?> prevalidate() {
    return new AbstractStackUpscaleAction<>(UpdateDomainDnsResolverResult.class) {

        @Override
        protected void doExecute(StackScalingFlowContext context, UpdateDomainDnsResolverResult payload, Map<Object, Object> variables) {
            Map<String, Integer> hostGroupsWithAdjustment = (Map<String, Integer>) variables.get(HOST_GROUP_WITH_ADJUSTMENT);
            int instanceCountToCreate = 0;
            for (Map.Entry<String, Integer> hostGroupWithAdjustment : hostGroupsWithAdjustment.entrySet()) {
                instanceCountToCreate += stackUpscaleService.getInstanceCountToCreate(context.getStack(), hostGroupWithAdjustment.getKey(), hostGroupWithAdjustment.getValue(), context.isRepair());
            }
            stackUpscaleService.addInstanceFireEventAndLog(context.getStack(), hostGroupsWithAdjustment, (AdjustmentTypeWithThreshold) variables.get(ADJUSTMENT_WITH_THRESHOLD));
            if (instanceCountToCreate > 0) {
                stackUpscaleService.startAddInstances(context.getStack(), hostGroupsWithAdjustment);
                sendEvent(context);
            } else {
                StackEvent event = new StackEvent(StackUpscaleEvent.EXTEND_METADATA_EVENT.event(), payload.getResourceId());
                sendEvent(context, event.selector(), event);
            }
        }

        @Override
        protected Selectable createRequest(StackScalingFlowContext context) {
            Map<String, Integer> hostGroupWithInstanceCountToCreate = getHostGroupsWithInstanceCountToCreate(context);
            Stack updatedStack = instanceMetaDataService.saveInstanceAndGetUpdatedStack(context.getStack(), hostGroupWithInstanceCountToCreate, context.getHostgroupWithHostnames(), false, context.isRepair(), context.getStackNetworkScaleDetails());
            CloudStack cloudStack = cloudStackConverter.convert(updatedStack);
            return new UpscaleStackValidationRequest<UpscaleStackValidationResult>(context.getCloudContext(), context.getCloudCredential(), cloudStack);
        }
    };
}
Also used : CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Map(java.util.Map) HashMap(java.util.HashMap) UpscaleStackValidationRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest) Bean(org.springframework.context.annotation.Bean)

Aggregations

UpscaleStackValidationRequest (com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 UpdateDomainDnsResolverResult (com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult)2 UpscaleStackValidationResult (com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult)1 StackScalingFlowContext (com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext)1 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)1 AdjustmentTypeWithThreshold (com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1 Bean (org.springframework.context.annotation.Bean)1