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