Search in sources :

Example 1 with EntitlementService

use of com.sequenceiq.cloudbreak.auth.altus.EntitlementService 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.getCluster(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 2 with EntitlementService

use of com.sequenceiq.cloudbreak.auth.altus.EntitlementService in project cloudbreak by hortonworks.

the class DistroXUpgradeAvailabilityServiceTest method testCheckForUpgradeWhenDataHubUpgradeIsGaAndOneMaintenanceUpgradeCandidateIsAvaiable.

@Test
@DisplayName("this test simulates that a Data Hub blueprint is GA for upgrade " + " and there 3 image candidates for upgrade")
public void testCheckForUpgradeWhenDataHubUpgradeIsGaAndOneMaintenanceUpgradeCandidateIsAvaiable() {
    Cluster datalakeCluster = TestUtil.cluster();
    datalakeCluster.setRangerRazEnabled(false);
    UpgradeV4Request request = new UpgradeV4Request();
    UpgradeV4Response response = new UpgradeV4Response();
    ImageInfoV4Response current = createImageResponse(1L, "7.1.0");
    ImageInfoV4Response image1 = createImageResponse(2L, "7.1.0");
    ImageInfoV4Response image2 = createImageResponse(8L, "7.2.0");
    ImageInfoV4Response image3 = createImageResponse(6L, "7.3.0");
    response.setUpgradeCandidates(List.of(image1, image2, image3));
    response.setCurrent(current);
    stack.getCluster().getBlueprint().setBlueprintUpgradeOption(BlueprintUpgradeOption.GA);
    when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WORKSPACE_ID)).thenReturn(stack);
    when(stackUpgradeOperations.checkForClusterUpgrade(ACCOUNT_ID, stack, WORKSPACE_ID, request)).thenReturn(response);
    UpgradeV4Response result = underTest.checkForUpgrade(CLUSTER, WORKSPACE_ID, request, USER_CRN);
    verify(entitlementService, times(1)).datahubRuntimeUpgradeEnabled(ACCOUNT_ID);
    assertEquals(3, result.getUpgradeCandidates().size());
    assertTrue(result.getUpgradeCandidates().stream().anyMatch(img -> img.getCreated() == 2L && "7.1.0".equals(img.getComponentVersions().getCdp())));
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) 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) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TestUtil (com.sequenceiq.cloudbreak.TestUtil)2 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)2 UpgradeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)2 ImageComponentVersions (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions)2 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)2 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)2 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)2 BlueprintUpgradeOption (com.sequenceiq.cloudbreak.domain.BlueprintUpgradeOption)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)2 ClusterView (com.sequenceiq.cloudbreak.domain.view.ClusterView)2 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)2 ClusterService (com.sequenceiq.cloudbreak.service.cluster.ClusterService)2 RuntimeVersionService (com.sequenceiq.cloudbreak.service.stack.RuntimeVersionService)2 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)2 StackViewService (com.sequenceiq.cloudbreak.service.stack.StackViewService)2 UpgradeShowAvailableImages (com.sequenceiq.common.model.UpgradeShowAvailableImages)2