use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.
the class DistroXUpgradeAvailabilityServiceTest method testOnlyReturnCandidatesWithDatalakeVersion.
@Test
public void testOnlyReturnCandidatesWithDatalakeVersion() {
UpgradeV4Request request = new UpgradeV4Request();
request.setShowAvailableImages(UpgradeShowAvailableImages.LATEST_ONLY);
UpgradeV4Response response = new UpgradeV4Response();
ImageInfoV4Response image1 = createImageResponse(2L, "A");
ImageInfoV4Response image2 = createImageResponse(8L, "A");
ImageInfoV4Response image3 = createImageResponse(6L, "A");
ImageInfoV4Response image4 = createImageResponse(1L, "B");
ImageInfoV4Response image5 = createImageResponse(4L, "B");
ImageInfoV4Response image6 = createImageResponse(3L, "B");
ImageInfoV4Response image7 = createImageResponse(9L, "C");
ImageInfoV4Response image8 = createImageResponse(8L, "C");
ImageInfoV4Response image9 = createImageResponse(6L, "C");
response.setUpgradeCandidates(List.of(image1, image2, image3, image4, image5, image6, image7, image8, image9));
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(stackViewService.findDatalakeViewByEnvironmentCrn(stack.getEnvironmentCrn())).thenReturn(Optional.of(stackView));
when(runtimeVersionService.getRuntimeVersion(eq(clusterView.getId()))).thenReturn(Optional.of("C"));
when(entitlementService.datahubRuntimeUpgradeEnabled(ACCOUNT_ID)).thenReturn(true);
UpgradeV4Response result = underTest.checkForUpgrade(CLUSTER, WORKSPACE_ID, request, USER_CRN);
assertEquals(1, result.getUpgradeCandidates().size());
assertTrue(result.getUpgradeCandidates().stream().anyMatch(img -> img.getCreated() == 9L && "C".equals(img.getComponentVersions().getCdp())));
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.
the class DistroXUpgradeAvailabilityServiceTest method testCheckForUpgradeWhenDataHubUpgradeIsDisabledAnMultipleMaintenanceUpgradeCandidatesAreAvaiable.
@Test
@DisplayName("this test simulates that a Data Hub runtime upgrade entitlement is disabled" + " and there are 2 image candidates for maintenance upgrade and the latest should be returned with dry-run")
public void testCheckForUpgradeWhenDataHubUpgradeIsDisabledAnMultipleMaintenanceUpgradeCandidatesAreAvaiable() {
Cluster datalakeCluster = TestUtil.cluster();
datalakeCluster.setRangerRazEnabled(false);
UpgradeV4Request request = new UpgradeV4Request();
request.setDryRun(true);
UpgradeV4Response response = new UpgradeV4Response();
ImageInfoV4Response current = createImageResponse(1L, "7.1.0");
ImageInfoV4Response image1 = createImageResponse(2L, "7.1.0");
ImageInfoV4Response image2 = createImageResponse(3L, "7.1.0");
ImageInfoV4Response image3 = createImageResponse(6L, "7.3.0");
response.setUpgradeCandidates(List.of(image1, image2, image3));
response.setCurrent(current);
StackView stackView = new StackView();
ClusterView clusterView = new ClusterView();
clusterView.setId(1L);
ReflectionTestUtils.setField(stackView, "cluster", clusterView);
stack.setCluster(TestUtil.cluster());
when(runtimeVersionService.getRuntimeVersion(any())).thenReturn(Optional.of("C"));
when(clusterService.getClusterByStackResourceCrn(any())).thenReturn(datalakeCluster);
when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WORKSPACE_ID)).thenReturn(stack);
when(stackUpgradeOperations.checkForClusterUpgrade(ACCOUNT_ID, stack, WORKSPACE_ID, request)).thenReturn(response);
when(entitlementService.datahubRuntimeUpgradeEnabled(ACCOUNT_ID)).thenReturn(false);
when(entitlementService.isDifferentDataHubAndDataLakeVersionAllowed(anyString())).thenReturn(false);
when(stackViewService.findDatalakeViewByEnvironmentCrn(stack.getEnvironmentCrn())).thenReturn(Optional.of(stackView));
when(runtimeVersionService.getRuntimeVersion(eq(clusterView.getId()))).thenReturn(Optional.of("7.1.0"));
UpgradeV4Response result = underTest.checkForUpgrade(CLUSTER, WORKSPACE_ID, request, USER_CRN);
assertEquals(1, result.getUpgradeCandidates().size());
verify(entitlementService, times(2)).datahubRuntimeUpgradeEnabled(ACCOUNT_ID);
assertTrue(result.getUpgradeCandidates().stream().anyMatch(img -> img.getCreated() == 3L && "7.1.0".equals(img.getComponentVersions().getCdp())));
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response 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.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response 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.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response 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);
}
Aggregations