use of com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount in project cloudbreak by hortonworks.
the class StackUpgradeOperationsTest method testCheckForClusterUpgradeShouldNotValidateUpgradeableDataHubsWhenDataHubUpgradeEntitlementIsGranted.
@Test
void testCheckForClusterUpgradeShouldNotValidateUpgradeableDataHubsWhenDataHubUpgradeEntitlementIsGranted() {
Stack stack = createStack(StackType.DATALAKE);
StackViewV4Responses stackViewV4Responses = new StackViewV4Responses();
UpgradeV4Request request = createUpgradeRequest(null);
UpgradeV4Response upgradeResponseToReturn = createUpgradeResponse();
UpgradeV4Response expectedResponse = createUpgradeResponse();
expectedResponse.setReason("There are attached Data Hub clusters in incorrect state");
when(instanceGroupService.getByStackAndFetchTemplates(STACK_ID)).thenReturn(Collections.emptySet());
when(upgradeService.isOsUpgrade(request)).thenReturn(false);
StackInstanceCount instanceCount = mock(StackInstanceCount.class);
when(instanceCount.getInstanceCount()).thenReturn(INSTANCE_COUNT);
when(instanceMetaDataService.countByStackId(STACK_ID)).thenReturn(instanceCount);
when(limitConfiguration.getUpgradeNodeCountLimit()).thenReturn(NODE_LIMIT);
when(clusterUpgradeAvailabilityService.checkForUpgradesByName(stack, false, true, request.getInternalUpgradeSettings())).thenReturn(upgradeResponseToReturn);
when(entitlementService.runtimeUpgradeEnabled(ACCOUNT_ID)).thenReturn(true);
when(entitlementService.datahubRuntimeUpgradeEnabled(ACCOUNT_ID)).thenReturn(true);
when(stackOperations.listByEnvironmentCrn(eq(WORKSPACE_ID), eq(ENVIRONMENT_CRN), any())).thenReturn(stackViewV4Responses);
when(upgradePreconditionService.checkForRunningAttachedClusters(stackViewV4Responses, stack)).thenReturn("There are attached Data Hub clusters in incorrect state");
UpgradeV4Response actual = underTest.checkForClusterUpgrade(ACCOUNT_ID, stack, WORKSPACE_ID, request);
assertEquals(expectedResponse, actual);
verify(instanceGroupService).getByStackAndFetchTemplates(STACK_ID);
verify(upgradeService).isOsUpgrade(request);
verify(instanceGroupService).getByStackAndFetchTemplates(STACK_ID);
verify(limitConfiguration).getUpgradeNodeCountLimit();
verify(clusterUpgradeAvailabilityService).checkForUpgradesByName(stack, false, true, request.getInternalUpgradeSettings());
verify(clusterUpgradeAvailabilityService).filterUpgradeOptions(ACCOUNT_ID, upgradeResponseToReturn, request, true);
verify(entitlementService).runtimeUpgradeEnabled(ACCOUNT_ID);
verify(stackOperations).listByEnvironmentCrn(eq(WORKSPACE_ID), eq(ENVIRONMENT_CRN), any());
verify(upgradePreconditionService).checkForRunningAttachedClusters(stackViewV4Responses, stack);
verify(upgradePreconditionService, times(0)).checkForNonUpgradeableAttachedClusters(stackViewV4Responses);
verifyNoInteractions(clusterDBValidationService);
}
use of com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount in project cloudbreak by hortonworks.
the class StackUpgradeOperationsTest method testCheckForClusterUpgradeShouldReturnUpgradeCandidatesWhenTheUpgradeIsRuntimeUpgradeAndTheStackTypeIsDataLakeAndReplaceVmEnabled.
@Test
void testCheckForClusterUpgradeShouldReturnUpgradeCandidatesWhenTheUpgradeIsRuntimeUpgradeAndTheStackTypeIsDataLakeAndReplaceVmEnabled() {
Stack stack = createStack(StackType.DATALAKE);
StackViewV4Responses stackViewV4Responses = new StackViewV4Responses();
UpgradeV4Request request = createUpgradeRequest(null);
UpgradeV4Response upgradeResponse = createUpgradeResponse();
when(instanceGroupService.getByStackAndFetchTemplates(STACK_ID)).thenReturn(Collections.emptySet());
when(upgradeService.isOsUpgrade(request)).thenReturn(false);
StackInstanceCount instanceCount = mock(StackInstanceCount.class);
when(instanceCount.getInstanceCount()).thenReturn(INSTANCE_COUNT);
when(instanceMetaDataService.countByStackId(STACK_ID)).thenReturn(instanceCount);
when(limitConfiguration.getUpgradeNodeCountLimit()).thenReturn(NODE_LIMIT);
when(clusterUpgradeAvailabilityService.checkForUpgradesByName(stack, false, true, request.getInternalUpgradeSettings())).thenReturn(upgradeResponse);
when(entitlementService.runtimeUpgradeEnabled(ACCOUNT_ID)).thenReturn(true);
when(stackOperations.listByEnvironmentCrn(eq(WORKSPACE_ID), eq(ENVIRONMENT_CRN), any())).thenReturn(stackViewV4Responses);
UpgradeV4Response actual = underTest.checkForClusterUpgrade(ACCOUNT_ID, stack, WORKSPACE_ID, request);
assertEquals(upgradeResponse, actual);
verify(instanceGroupService).getByStackAndFetchTemplates(STACK_ID);
verify(upgradeService).isOsUpgrade(request);
verify(instanceGroupService).getByStackAndFetchTemplates(STACK_ID);
verify(limitConfiguration).getUpgradeNodeCountLimit();
verify(clusterUpgradeAvailabilityService).checkForUpgradesByName(stack, false, true, request.getInternalUpgradeSettings());
verify(clusterUpgradeAvailabilityService).filterUpgradeOptions(ACCOUNT_ID, upgradeResponse, request, true);
verify(entitlementService).runtimeUpgradeEnabled(ACCOUNT_ID);
verify(stackOperations).listByEnvironmentCrn(eq(WORKSPACE_ID), eq(ENVIRONMENT_CRN), any());
verify(upgradePreconditionService).checkForRunningAttachedClusters(stackViewV4Responses, stack);
verify(upgradePreconditionService).checkForNonUpgradeableAttachedClusters(stackViewV4Responses);
verifyNoInteractions(clusterDBValidationService);
}
use of com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount in project cloudbreak by hortonworks.
the class StackUpgradeOperationsTest method testCheckForClusterUpgradeShouldReturnUpgradeCandidatesWhenTheUpgradeIsRuntimeUpgradeAndTheStackTypeIsWorkloadAndReplaceVmEnabled.
@Test
void testCheckForClusterUpgradeShouldReturnUpgradeCandidatesWhenTheUpgradeIsRuntimeUpgradeAndTheStackTypeIsWorkloadAndReplaceVmEnabled() {
Stack stack = createStack(StackType.WORKLOAD);
UpgradeV4Request request = createUpgradeRequest(true);
UpgradeV4Response upgradeResponse = createUpgradeResponse();
when(instanceGroupService.getByStackAndFetchTemplates(STACK_ID)).thenReturn(Collections.emptySet());
when(upgradeService.isOsUpgrade(request)).thenReturn(false);
StackInstanceCount instanceCount = mock(StackInstanceCount.class);
when(instanceCount.getInstanceCount()).thenReturn(INSTANCE_COUNT);
when(instanceMetaDataService.countByStackId(STACK_ID)).thenReturn(instanceCount);
when(limitConfiguration.getUpgradeNodeCountLimit()).thenReturn(NODE_LIMIT);
when(clusterUpgradeAvailabilityService.checkForUpgradesByName(stack, false, true, request.getInternalUpgradeSettings())).thenReturn(upgradeResponse);
when(entitlementService.runtimeUpgradeEnabled(ACCOUNT_ID)).thenReturn(true);
UpgradeV4Response actual = underTest.checkForClusterUpgrade(ACCOUNT_ID, stack, WORKSPACE_ID, request);
assertEquals(upgradeResponse, actual);
verify(instanceGroupService).getByStackAndFetchTemplates(STACK_ID);
verify(upgradeService).isOsUpgrade(request);
verify(instanceGroupService).getByStackAndFetchTemplates(STACK_ID);
verify(limitConfiguration).getUpgradeNodeCountLimit();
verify(clusterUpgradeAvailabilityService).checkForUpgradesByName(stack, false, true, request.getInternalUpgradeSettings());
verify(clusterUpgradeAvailabilityService).filterUpgradeOptions(ACCOUNT_ID, upgradeResponse, request, false);
verify(entitlementService).runtimeUpgradeEnabled(ACCOUNT_ID);
verifyNoInteractions(upgradePreconditionService);
verifyNoInteractions(clusterDBValidationService);
verifyNoInteractions(stackOperations);
}
use of com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount in project cloudbreak by hortonworks.
the class StackUpgradeOperations method checkForClusterUpgrade.
public UpgradeV4Response checkForClusterUpgrade(String accountId, @NotNull Stack stack, Long workspaceId, UpgradeV4Request request) {
MDCBuilder.buildMdcContext(stack);
stack.setInstanceGroups(instanceGroupService.getByStackAndFetchTemplates(stack.getId()));
boolean osUpgrade = upgradeService.isOsUpgrade(request);
boolean replaceVms = determineReplaceVmsParameter(stack, request.getReplaceVms());
if (replaceVms) {
StackInstanceCount stackInstanceCount = instanceMetaDataService.countByStackId(stack.getId());
Integer upgradeNodeCountLimit = limitConfiguration.getUpgradeNodeCountLimit();
LOGGER.debug("Instance count: {} and limit: [{}]", stackInstanceCount == null ? "null" : stackInstanceCount.asString(), upgradeNodeCountLimit);
if (stackInstanceCount != null && stackInstanceCount.getInstanceCount() > upgradeNodeCountLimit) {
throw new BadRequestException(String.format("There are %s nodes in the cluster. Upgrade has a limit of %s nodes, above the limit it is unstable. " + "Please downscale the cluster below the limit and retry the upgrade.", stackInstanceCount.getInstanceCount(), upgradeNodeCountLimit));
}
}
UpgradeV4Response upgradeResponse = clusterUpgradeAvailabilityService.checkForUpgradesByName(stack, osUpgrade, replaceVms, request.getInternalUpgradeSettings());
if (CollectionUtils.isNotEmpty(upgradeResponse.getUpgradeCandidates())) {
clusterUpgradeAvailabilityService.filterUpgradeOptions(accountId, upgradeResponse, request, stack.isDatalake());
}
validateAttachedDataHubsForDataLake(accountId, workspaceId, stack, upgradeResponse);
LOGGER.debug("Upgrade response after validations: {}", upgradeResponse);
return upgradeResponse;
}
use of com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount in project cloudbreak by hortonworks.
the class StackUpgradeOperationsTest method throwsBadRequestIfClusterHasMoreNodesThanTheLimit.
@Test
void throwsBadRequestIfClusterHasMoreNodesThanTheLimit() {
UpgradeV4Request request = createUpgradeRequest(true);
StackInstanceCount stackInstanceCount = mock(StackInstanceCount.class);
when(stackInstanceCount.getInstanceCount()).thenReturn(201);
when(limitConfiguration.getUpgradeNodeCountLimit()).thenReturn(200);
when(instanceMetaDataService.countByStackId(any())).thenReturn(stackInstanceCount);
BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.checkForClusterUpgrade("accId", new Stack(), WORKSPACE_ID, request));
assertEquals("There are 201 nodes in the cluster. Upgrade has a limit of 200 nodes, above the limit it is unstable. " + "Please downscale the cluster below the limit and retry the upgrade.", exception.getMessage());
}
Aggregations