Search in sources :

Example 1 with HOST_GROUP_WITH_ADJUSTMENT

use of com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_ADJUSTMENT in project cloudbreak by hortonworks.

the class StackUpscaleActions method updateDomainDnsResolverAction.

@Bean(name = "UPDATE_DOMAIN_DNS_RESOLVER_STATE")
public Action<?, ?> updateDomainDnsResolverAction() {
    return new AbstractStackUpscaleAction<>(StackScaleTriggerEvent.class) {

        @Override
        protected void prepareExecution(StackScaleTriggerEvent payload, Map<Object, Object> variables) {
            variables.put(HOST_GROUP_WITH_ADJUSTMENT, payload.getHostGroupsWithAdjustment());
            variables.put(HOST_GROUP_WITH_HOSTNAMES, payload.getHostGroupsWithHostNames());
            variables.put(REPAIR, payload.isRepair());
            if (payload.getTriggeredStackVariant() != null) {
                variables.put(TRIGGERED_VARIANT, payload.getTriggeredStackVariant());
            }
            variables.put(NETWORK_SCALE_DETAILS, payload.getNetworkScaleDetails());
            variables.put(ADJUSTMENT_WITH_THRESHOLD, payload.getAdjustmentTypeWithThreshold());
        }

        @Override
        protected void doExecute(StackScalingFlowContext context, StackScaleTriggerEvent payload, Map<Object, Object> variables) {
            if (context.isRepair()) {
                LOGGER.debug("We do not need to update domainDnsResolver in case of repair activity, since it matters only in case of upscale activity.");
                sendEvent(context, new UpdateDomainDnsResolverResult(context.getStack().getId()));
            } else {
                sendEvent(context, new UpdateDomainDnsResolverRequest(context.getStack().getId()));
            }
        }

        @Override
        protected Object getFailurePayload(StackScaleTriggerEvent payload, Optional<StackScalingFlowContext> flowContext, Exception ex) {
            return new StackFailureEvent(EventSelectorUtil.failureSelector(UpdateDomainDnsResolverResult.class), payload.getResourceId(), ex);
        }
    };
}
Also used : StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) UpdateDomainDnsResolverRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest) Optional(java.util.Optional) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) Map(java.util.Map) HashMap(java.util.HashMap) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) Bean(org.springframework.context.annotation.Bean)

Example 2 with HOST_GROUP_WITH_ADJUSTMENT

use of com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_ADJUSTMENT in project cloudbreak by hortonworks.

the class StackUpscaleActionsTest method prevalidateTestCreateContextWhenTriggeredVariantNotSet.

@Test
void prevalidateTestCreateContextWhenTriggeredVariantNotSet() {
    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, null);
    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.assertNull(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 3 with HOST_GROUP_WITH_ADJUSTMENT

use of com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_ADJUSTMENT in project cloudbreak by hortonworks.

the class AbstractStackUpscaleAction method createFlowContext.

@Override
protected StackScalingFlowContext createFlowContext(FlowParameters flowParameters, StateContext<StackUpscaleState, StackUpscaleEvent> stateContext, P payload) {
    Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    stack.setResources(new HashSet<>(resourceService.getAllByStackId(payload.getResourceId())));
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(getTriggeredVariantOrStackVariant(variables, stack)).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(Crn.safeFromString(stack.getResourceCrn()).getAccountId()).withTenantId(stack.getTenant().getId()).build();
    CloudCredential cloudCredential = stackUtil.getCloudCredential(stack);
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    if (payload instanceof StackScaleTriggerEvent) {
        StackScaleTriggerEvent stackScaleTriggerEvent = (StackScaleTriggerEvent) payload;
        boolean repair = stackScaleTriggerEvent.isRepair();
        Map<String, Set<String>> hostgroupsWithHostnames = stackScaleTriggerEvent.getHostGroupsWithHostNames();
        Map<String, Integer> hostGroupsWithAdjustment = stackScaleTriggerEvent.getHostGroupsWithAdjustment();
        Map<String, Set<Long>> hostGroupsWithPrivateIds = stackScaleTriggerEvent.getHostGroupsWithPrivateIds();
        NetworkScaleDetails networkScaleDetails = stackScaleTriggerEvent.getNetworkScaleDetails();
        AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = stackScaleTriggerEvent.getAdjustmentTypeWithThreshold();
        variables.put(REPAIR, repair);
        variables.put(HOST_GROUP_WITH_ADJUSTMENT, hostGroupsWithAdjustment);
        variables.put(HOST_GROUP_WITH_HOSTNAMES, hostgroupsWithHostnames);
        variables.put(NETWORK_SCALE_DETAILS, networkScaleDetails);
        variables.put(ADJUSTMENT_WITH_THRESHOLD, adjustmentTypeWithThreshold);
        return new StackScalingFlowContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, hostGroupsWithAdjustment, hostGroupsWithPrivateIds, hostgroupsWithHostnames, repair, networkScaleDetails, adjustmentTypeWithThreshold);
    } else {
        Map<String, Integer> hostGroupWithAdjustment = getHostGroupWithAdjustment(variables);
        Map<String, Set<String>> hostgroupWithHostnames = getHostGroupWithHostnames(variables);
        NetworkScaleDetails stackNetworkScaleDetails = getStackNetworkScaleDetails(variables);
        AdjustmentTypeWithThreshold adjustmentWithThreshold = getAdjustmentWithThreshold(variables);
        return new StackScalingFlowContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, hostGroupWithAdjustment, null, hostgroupWithHostnames, isRepair(variables), stackNetworkScaleDetails, adjustmentWithThreshold);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) NetworkScaleDetails(com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 4 with HOST_GROUP_WITH_ADJUSTMENT

use of com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_ADJUSTMENT 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 5 with HOST_GROUP_WITH_ADJUSTMENT

use of com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_ADJUSTMENT 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)

Aggregations

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