Search in sources :

Example 6 with UpgradeV4Request

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

the class UpgradeConverterTest method testConvertRequestWhenInternal.

@Test
public void testConvertRequestWhenInternal() {
    // GIVEN
    DistroXUpgradeV1Request source = new DistroXUpgradeV1Request();
    // WHEN
    UpgradeV4Request result = underTest.convert(source, new InternalUpgradeSettings(true, true, true));
    // THEN
    assertTrue(result.getInternalUpgradeSettings().isSkipValidations());
}
Also used : InternalUpgradeSettings(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.InternalUpgradeSettings) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) DistroXUpgradeV1Request(com.sequenceiq.distrox.api.v1.distrox.model.upgrade.DistroXUpgradeV1Request) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with UpgradeV4Request

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

the class DistroXUpgradeAvailabilityServiceTest method testCheckForUpgradeWhenDataHubUpgradeIsDisabledAnNoMaintenanceUpgradeCandidatesAreAvaiable.

@Test
@DisplayName("this test simulates that a Data Hub runtime upgrade entitlement is disabled" + " and all the image candidates are filtered for maintenance upgrade so empty response should be returned")
public void testCheckForUpgradeWhenDataHubUpgradeIsDisabledAnNoMaintenanceUpgradeCandidatesAreAvaiable() {
    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.2.0");
    ImageInfoV4Response image2 = createImageResponse(8L, "7.3.0");
    ImageInfoV4Response image3 = createImageResponse(6L, "7.4.0");
    response.setUpgradeCandidates(List.of(image1, image2, image3));
    response.setCurrent(current);
    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);
    UpgradeV4Response result = underTest.checkForUpgrade(CLUSTER, WORKSPACE_ID, request, USER_CRN);
    String expectedMessage = "No image is available for maintenance upgrade, CDP version: 7.1.0";
    assertEquals(0, result.getUpgradeCandidates().size());
    assertEquals(expectedMessage, result.getReason());
}
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) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 8 with UpgradeV4Request

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

the class DistroXUpgradeAvailabilityServiceTest method testReturnLatestOnlyForDryRun.

@Test
public void testReturnLatestOnlyForDryRun() {
    UpgradeV4Request request = new UpgradeV4Request();
    request.setDryRun(Boolean.TRUE);
    UpgradeV4Response response = new UpgradeV4Response();
    ImageInfoV4Response image1 = new ImageInfoV4Response();
    image1.setCreated(1L);
    ImageInfoV4Response image2 = new ImageInfoV4Response();
    image2.setCreated(8L);
    ImageInfoV4Response image3 = new ImageInfoV4Response();
    image3.setCreated(5L);
    response.setUpgradeCandidates(List.of(image1, image2, image3));
    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);
    assertEquals(1, result.getUpgradeCandidates().size());
    assertEquals(8L, result.getUpgradeCandidates().get(0).getCreated());
}
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) Test(org.junit.jupiter.api.Test)

Example 9 with UpgradeV4Request

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

the class DistroXUpgradeAvailabilityServiceTest method testReturnAllCandidates.

@Test
public void testReturnAllCandidates() {
    UpgradeV4Request request = new UpgradeV4Request();
    UpgradeV4Response response = new UpgradeV4Response();
    response.setUpgradeCandidates(List.of(mock(ImageInfoV4Response.class), mock(ImageInfoV4Response.class)));
    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);
    assertEquals(response.getUpgradeCandidates(), result.getUpgradeCandidates());
}
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) Test(org.junit.jupiter.api.Test)

Example 10 with UpgradeV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request 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())));
}
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) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) 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