Search in sources :

Example 6 with UpdateDomainDnsResolverResult

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult 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)

Example 7 with UpdateDomainDnsResolverResult

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult in project cloudbreak by hortonworks.

the class StackUpscaleActionsTest method prevalidateTestCreateContextWhenTriggeredVariantSet.

@Test
void prevalidateTestCreateContextWhenTriggeredVariantSet() {
    NetworkScaleDetails networkScaleDetails = new NetworkScaleDetails();
    UpdateDomainDnsResolverResult payload = new UpdateDomainDnsResolverResult(STACK_ID);
    Map<Object, Object> variables = createVariables(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), Map.of(INSTANCE_GROUP_NAME, Set.of("hostname")), networkScaleDetails, null, VARIANT);
    new AbstractActionTestSupport<>(getPrevalidateAction()).prepareExecution(payload, variables);
    Assertions.assertEquals(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), variables.get(HOST_GROUP_WITH_ADJUSTMENT));
    Assertions.assertEquals(Map.of(INSTANCE_GROUP_NAME, Set.of("hostname")), variables.get(HOST_GROUP_WITH_HOSTNAMES));
    Assertions.assertEquals(false, variables.get(REPAIR));
    Assertions.assertEquals(VARIANT, variables.get(TRIGGERED_VARIANT));
    Assertions.assertEquals(networkScaleDetails, variables.get(NETWORK_SCALE_DETAILS));
}
Also used : NetworkScaleDetails(com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) Test(org.junit.jupiter.api.Test)

Example 8 with UpdateDomainDnsResolverResult

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult in project cloudbreak by hortonworks.

the class StackUpscaleActionsTest method prevalidateTestDoExecuteWhenScalingNotNeeded.

@Test
void prevalidateTestDoExecuteWhenScalingNotNeeded() throws Exception {
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, ADJUSTMENT_ZERO.longValue());
    context = new StackScalingFlowContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), Map.of(), Map.of(), false, adjustmentTypeWithThreshold);
    UpdateDomainDnsResolverResult payload = new UpdateDomainDnsResolverResult(STACK_ID);
    when(stackUpscaleService.getInstanceCountToCreate(stack, INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO, false)).thenReturn(ADJUSTMENT_ZERO);
    List<CloudResourceStatus> resourceStatuses = List.of(cloudResourceStatus);
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    new AbstractActionTestSupport<>(getPrevalidateAction()).doExecute(context, payload, createVariables(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), Map.of(), NetworkScaleDetails.getEmpty(), adjustmentTypeWithThreshold, VARIANT));
    verify(stackUpscaleService).addInstanceFireEventAndLog(stack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), adjustmentTypeWithThreshold);
    verifyEventForExtendMetadata(resourceStatuses);
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateDomainDnsResolverResult (com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult)8 Test (org.junit.jupiter.api.Test)5 StackScalingFlowContext (com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 AdjustmentTypeWithThreshold (com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold)3 UpscaleStackValidationRequest (com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest)2 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 NetworkScaleDetails (com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails)2 UpdateDomainDnsResolverRequest (com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Bean (org.springframework.context.annotation.Bean)2 UpscaleStackValidationResult (com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)1 StackScaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent)1 DnsResolverType (com.sequenceiq.cloudbreak.domain.stack.DnsResolverType)1 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)1 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)1