use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.
the class DistroXUpgradeAvailabilityServiceTest method testCheckForUpgradeWhenDataLakeAndDataHubIsOnTheSameVersionAndUpgradeIsAvailable.
@Test
@DisplayName("this test simulates when the Data Lake and Data Hub version is the same (7.1.0)" + "and the only upgrade options for Data Hub is newer than the DL (7.2.0,7.3.0,7.4.0). this will NOT be filtered" + "since the different Data Hub version entitlement is enabled")
public void testCheckForUpgradeWhenDataLakeAndDataHubIsOnTheSameVersionAndUpgradeIsAvailable() {
UpgradeV4Request request = new UpgradeV4Request();
UpgradeV4Response response = new UpgradeV4Response();
ImageInfoV4Response image1 = createImageResponse(2L, "7.2.0");
ImageInfoV4Response image2 = createImageResponse(8L, "7.3.0");
ImageInfoV4Response image3 = createImageResponse(6L, "7.4.0");
response.setUpgradeCandidates(List.of(image1, image2, image3));
StackView stackView = new StackView();
ClusterView clusterView = new ClusterView();
clusterView.setId(1L);
ReflectionTestUtils.setField(stackView, "cluster", clusterView);
when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WORKSPACE_ID)).thenReturn(stack);
when(stackUpgradeOperations.checkForClusterUpgrade(ACCOUNT_ID, stack, WORKSPACE_ID, request)).thenReturn(response);
when(entitlementService.isDifferentDataHubAndDataLakeVersionAllowed(anyString())).thenReturn(true);
UpgradeV4Response result = underTest.checkForUpgrade(CLUSTER, WORKSPACE_ID, request, USER_CRN);
assertEquals(3, result.getUpgradeCandidates().size());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request 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());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.
the class StackUpgradeOperationsTest method testCheckForClusterUpgradeShouldReturnCompositeErrorWhenBothAttachedDataHubValidationsFail.
@Test
void testCheckForClusterUpgradeShouldReturnCompositeErrorWhenBothAttachedDataHubValidationsFail() {
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 that are non-upgradeable 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(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");
when(upgradePreconditionService.checkForNonUpgradeableAttachedClusters(stackViewV4Responses)).thenReturn("There are attached Data Hub clusters that are non-upgradeable");
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).checkForNonUpgradeableAttachedClusters(stackViewV4Responses);
verifyNoInteractions(clusterDBValidationService);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.
the class StackUpgradeOperationsTest method createUpgradeRequest.
private UpgradeV4Request createUpgradeRequest(Boolean replaceVm) {
UpgradeV4Request upgradeRequest = new UpgradeV4Request();
upgradeRequest.setReplaceVms(replaceVm);
upgradeRequest.setInternalUpgradeSettings(new InternalUpgradeSettings(true, true, true));
return upgradeRequest;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.
the class DistroXUpgradeV1ControllerTest method testUpgradeCalledWithCrn.
@Test
public void testUpgradeCalledWithCrn() {
DistroXUpgradeV1Request distroxUpgradeRequest = new DistroXUpgradeV1Request();
UpgradeV4Request upgradeV4Request = new UpgradeV4Request();
upgradeV4Request.setDryRun(Boolean.FALSE);
when(upgradeAvailabilityService.isRuntimeUpgradeEnabledByAccountId(ACCOUNT_ID)).thenReturn(true);
when(upgradeAvailabilityService.isOsUpgradeEnabledByAccountId(ACCOUNT_ID)).thenReturn(true);
when(upgradeConverter.convert(distroxUpgradeRequest, new InternalUpgradeSettings(false, true, true))).thenReturn(upgradeV4Request);
UpgradeV4Response upgradeV4Response = new UpgradeV4Response();
when(upgradeService.triggerUpgrade(NameOrCrn.ofCrn(CLUSTER_NAME), WORKSPACE_ID, USER_CRN, upgradeV4Request)).thenReturn(upgradeV4Response);
when(upgradeConverter.convert(upgradeV4Response)).thenReturn(new DistroXUpgradeV1Response());
ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.upgradeClusterByCrn(CLUSTER_NAME, distroxUpgradeRequest));
verify(upgradeService).triggerUpgrade(NameOrCrn.ofCrn(CLUSTER_NAME), WORKSPACE_ID, USER_CRN, upgradeV4Request);
}
Aggregations