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);
}
};
}
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));
}
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);
}
Aggregations