use of com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult in project cloudbreak by hortonworks.
the class StackUpscaleActions method addInstances.
@Bean(name = "ADD_INSTANCES_STATE")
public Action<?, ?> addInstances() {
return new AbstractStackUpscaleAction<>(UpscaleStackValidationResult.class) {
@Override
protected void doExecute(StackScalingFlowContext context, UpscaleStackValidationResult payload, Map<Object, Object> variables) {
sendEvent(context);
}
@Override
protected Selectable createRequest(StackScalingFlowContext context) {
Map<String, Integer> hostGroupWithInstanceCountToCreate = getHostGroupsWithInstanceCountToCreate(context);
Stack updatedStack = instanceMetaDataService.saveInstanceAndGetUpdatedStack(context.getStack(), hostGroupWithInstanceCountToCreate, context.getHostgroupWithHostnames(), true, context.isRepair(), context.getStackNetworkScaleDetails());
List<CloudResource> resources = context.getStack().getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
CloudStack updatedCloudStack = cloudStackConverter.convert(updatedStack);
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = context.getAdjustmentTypeWithThreshold();
if (adjustmentTypeWithThreshold == null) {
Integer exactNumber = hostGroupWithInstanceCountToCreate.values().stream().reduce(0, Integer::sum);
adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, exactNumber.longValue());
}
LOGGER.info("Adjustment type with threshold for upscale request: {}", adjustmentTypeWithThreshold);
return new UpscaleStackRequest<UpscaleStackResult>(context.getCloudContext(), context.getCloudCredential(), updatedCloudStack, resources, adjustmentTypeWithThreshold);
}
};
}
use of com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult 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.UpscaleStackValidationResult in project cloudbreak by hortonworks.
the class UpscaleValidationHandler method accept.
@Override
public void accept(Event<UpscaleStackValidationRequest> upscaleStackValidationRequestEvent) {
LOGGER.debug("Received event: {}", upscaleStackValidationRequestEvent);
UpscaleStackValidationRequest<UpscaleStackValidationResult> request = upscaleStackValidationRequestEvent.getData();
CloudContext cloudContext = request.getCloudContext();
try {
CloudConnector<?> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
connector.setup().scalingPrerequisites(ac, request.getCloudStack(), true);
UpscaleStackValidationResult result = new UpscaleStackValidationResult(request.getResourceId());
request.getResult().onNext(result);
eventBus.notify(result.selector(), new Event<>(upscaleStackValidationRequestEvent.getHeaders(), result));
LOGGER.debug("Upscale validation successfully finished for {}", cloudContext);
} catch (Exception e) {
UpscaleStackValidationResult result = new UpscaleStackValidationResult(e.getMessage(), e, request.getResourceId());
request.getResult().onNext(result);
eventBus.notify(CloudPlatformResult.failureSelector(UpscaleStackValidationResult.class), new Event<>(upscaleStackValidationRequestEvent.getHeaders(), result));
}
}
Aggregations