Search in sources :

Example 11 with UpgradeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request 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())));
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ClusterView(com.sequenceiq.cloudbreak.domain.view.ClusterView) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) BeforeEach(org.junit.jupiter.api.BeforeEach) ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TestUtil(com.sequenceiq.cloudbreak.TestUtil) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) UpgradeShowAvailableImages(com.sequenceiq.common.model.UpgradeShowAvailableImages) Mockito.lenient(org.mockito.Mockito.lenient) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) BlueprintUpgradeOption(com.sequenceiq.cloudbreak.domain.BlueprintUpgradeOption) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) InjectMocks(org.mockito.InjectMocks) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) RuntimeVersionService(com.sequenceiq.cloudbreak.service.stack.RuntimeVersionService) StackUpgradeOperations(com.sequenceiq.distrox.v1.distrox.StackUpgradeOperations) StackViewService(com.sequenceiq.cloudbreak.service.stack.StackViewService) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Mockito.verify(org.mockito.Mockito.verify) DisplayName(org.junit.jupiter.api.DisplayName) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) Test(org.junit.jupiter.api.Test) Mockito.never(org.mockito.Mockito.never) List(java.util.List) ClusterView(com.sequenceiq.cloudbreak.domain.view.ClusterView) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with UpgradeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request 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);
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) StackInstanceCount(com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) StackViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 13 with UpgradeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request 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);
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) StackInstanceCount(com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) StackViewV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Responses) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 14 with UpgradeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request 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);
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) StackInstanceCount(com.sequenceiq.cloudbreak.domain.projection.StackInstanceCount) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 15 with UpgradeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request in project cloudbreak by hortonworks.

the class StackUpgradeOperationsTest method testCheckForClusterUpgradeShouldReturnUpgradeCandidatesWhenTheUpgradeIsRuntimeUpgradeAndTheStackTypeIsWorkloadAndReplaceVmDisabled.

@Test
void testCheckForClusterUpgradeShouldReturnUpgradeCandidatesWhenTheUpgradeIsRuntimeUpgradeAndTheStackTypeIsWorkloadAndReplaceVmDisabled() {
    Stack stack = createStack(StackType.WORKLOAD);
    UpgradeV4Request request = createUpgradeRequest(null);
    UpgradeV4Response upgradeResponse = new UpgradeV4Response();
    upgradeResponse.setUpgradeCandidates(List.of(new ImageInfoV4Response()));
    when(instanceGroupService.getByStackAndFetchTemplates(STACK_ID)).thenReturn(Collections.emptySet());
    when(upgradeService.isOsUpgrade(request)).thenReturn(false);
    when(upgradePreconditionService.notUsingEphemeralVolume(stack)).thenReturn(false);
    when(clusterUpgradeAvailabilityService.checkForUpgradesByName(stack, false, false, 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(upgradePreconditionService).notUsingEphemeralVolume(stack);
    verify(clusterUpgradeAvailabilityService).checkForUpgradesByName(stack, false, false, request.getInternalUpgradeSettings());
    verify(clusterUpgradeAvailabilityService).filterUpgradeOptions(ACCOUNT_ID, upgradeResponse, request, false);
    verify(entitlementService).runtimeUpgradeEnabled(ACCOUNT_ID);
    verifyNoInteractions(stackOperations);
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

UpgradeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)54 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)44 Test (org.junit.jupiter.api.Test)42 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)35 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)14 InternalUpgradeSettings (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.InternalUpgradeSettings)10 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)9 DisplayName (org.junit.jupiter.api.DisplayName)9 ClusterView (com.sequenceiq.cloudbreak.domain.view.ClusterView)7 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)7 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)7 DistroXUpgradeV1Request (com.sequenceiq.distrox.api.v1.distrox.model.upgrade.DistroXUpgradeV1Request)7 Test (org.junit.Test)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)6 ImageComponentVersions (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions)6 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)6 BlueprintUpgradeOption (com.sequenceiq.cloudbreak.domain.BlueprintUpgradeOption)6 List (java.util.List)6