use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold 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.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class StackUpscaleService method upscale.
public List<CloudResourceStatus> upscale(AuthenticatedContext ac, UpscaleStackRequest<UpscaleStackResult> request, CloudConnector<?> connector) throws QuotaExceededException {
CloudStack cloudStack = request.getCloudStack();
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = request.getAdjustmentWithThreshold();
try {
return connector.resources().upscale(ac, cloudStack, request.getResourceList(), adjustmentTypeWithThreshold);
} catch (QuotaExceededException quotaExceededException) {
return handleQuotaExceptionAndRetryUpscale(request, connector, ac, cloudStack, adjustmentTypeWithThreshold, quotaExceededException);
}
}
use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class GcpResourceConnectorTest method testUpscaleWhenEverythingIsFine.
@Test
public void testUpscaleWhenEverythingIsFine() throws QuotaExceededException {
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudStack cloudStack = mock(CloudStack.class);
Network network = mock(Network.class);
CloudContext cloudContext = mock(CloudContext.class);
ResourceBuilderContext resourceBuilderContext = mock(ResourceBuilderContext.class);
ResourceContextBuilder resourceContextBuilder = mock(ResourceContextBuilder.class);
List<CloudResource> cloudResourceList = List.of(cloudResource("test-5", GCP_ATTACHED_DISKSET));
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudStack.getNetwork()).thenReturn(network);
when(cloudContext.getPlatform()).thenReturn(platform("GCP"));
when(cloudContext.getVariant()).thenReturn(GcpConstants.GCP_VARIANT);
when(contextBuilders.get(any(Platform.class))).thenReturn(resourceContextBuilder);
when(resourceContextBuilder.contextInit(any(CloudContext.class), any(AuthenticatedContext.class), any(Network.class), anyList(), anyBoolean())).thenReturn(resourceBuilderContext);
when(networkResourceService.getNetworkResources(any(Variant.class), anyList())).thenReturn(new ArrayList<>());
doNothing().when(resourceBuilderContext).addNetworkResources(anyCollection());
when(groupResourceService.getGroupResources(any(Variant.class), anyCollection())).thenReturn(List.of(cloudResource("test-1", GCP_INSTANCE)));
Group master = group("master");
master.getInstances().get(0).putParameter(CloudInstance.FQDN, "fqdn");
when(cloudStack.getGroups()).thenReturn(List.of(master));
doNothing().when(resourceBuilderContext).addComputeResources(anyLong(), anyList());
when(computeResourceService.buildResourcesForUpscale(any(ResourceBuilderContext.class), any(AuthenticatedContext.class), any(CloudStack.class), anyCollection(), any())).thenReturn(List.of());
underTest.upscale(authenticatedContext, cloudStack, cloudResourceList, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, 0L));
verify(contextBuilders, times(1)).get(any(Platform.class));
verify(networkResourceService, times(1)).getNetworkResources(any(Variant.class), anyList());
verify(groupResourceService, times(1)).getGroupResources(any(Variant.class), anyList());
verify(resourceBuilderContext, times(1)).addComputeResources(anyLong(), anyList());
verify(computeResourceService, times(1)).buildResourcesForUpscale(any(ResourceBuilderContext.class), any(AuthenticatedContext.class), any(CloudStack.class), anyCollection(), any());
}
use of com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold 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.common.api.adjustment.AdjustmentTypeWithThreshold in project cloudbreak by hortonworks.
the class StackUpscaleActionsTest method prevalidateTestDoExecuteWhenScalingNeededAndNotAllowed.
@Test
void prevalidateTestDoExecuteWhenScalingNeededAndNotAllowed() throws Exception {
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_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), Map.of(), NetworkScaleDetails.getEmpty(), adjustmentTypeWithThreshold, VARIANT));
verify(stackUpscaleService).addInstanceFireEventAndLog(stack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT), adjustmentTypeWithThreshold);
verifyEventForExtendMetadata(resourceStatuses);
}
Aggregations