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