Search in sources :

Example 36 with UpgradeV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeService method checkForSdxUpgradeResponse.

private SdxUpgradeResponse checkForSdxUpgradeResponse(String userCrn, SdxUpgradeRequest upgradeSdxClusterRequest, String clusterName, String accountId) {
    UpgradeV4Response upgradeV4Response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> stackV4Endpoint.checkForClusterUpgradeByName(WORKSPACE_ID, clusterName, sdxUpgradeClusterConverter.sdxUpgradeRequestToUpgradeV4Request(upgradeSdxClusterRequest), accountId));
    UpgradeV4Response filteredUpgradeV4Response = filterSdxUpgradeResponse(accountId, clusterName, upgradeSdxClusterRequest, upgradeV4Response);
    return sdxUpgradeClusterConverter.upgradeResponseToSdxUpgradeResponse(filteredUpgradeV4Response);
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)

Example 37 with UpgradeV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method testCheckForUpgradeByCrnWhenDisabledAndPatchUpdatesNotAvailable.

@Test
@DisplayName("Test checkForUpgradeByCrn() when Runtime Upgrade is disabled and patch updates are not available")
public void testCheckForUpgradeByCrnWhenDisabledAndPatchUpdatesNotAvailable() {
    ImageInfoV4Response currentImageInfo = new ImageInfoV4Response();
    currentImageInfo.setImageId(IMAGE_ID);
    currentImageInfo.setCreated(1);
    currentImageInfo.setComponentVersions(creatImageComponentVersions(MATCHING_TARGET_RUNTIME, MATCHING_TARGET_RUNTIME));
    ImageInfoV4Response imageInfo = new ImageInfoV4Response();
    imageInfo.setImageId(IMAGE_ID);
    imageInfo.setCreated(1);
    imageInfo.setComponentVersions(creatImageComponentVersions("7.2.0", "7.2.0"));
    ImageInfoV4Response imageInfo2 = new ImageInfoV4Response();
    imageInfo2.setImageId(IMAGE_ID_LAST);
    imageInfo2.setCreated(2);
    imageInfo2.setComponentVersions(creatImageComponentVersions("7.3.0", "7.3.0"));
    List<ImageInfoV4Response> candidates = List.of(imageInfo, imageInfo2);
    response.setCurrent(currentImageInfo);
    response.setUpgradeCandidates(candidates);
    SdxUpgradeResponse expectedResponse = new SdxUpgradeResponse(response.getCurrent(), candidates, response.getReason(), response.getFlowIdentifier());
    when(sdxService.getByCrn(anyString(), anyString())).thenReturn(sdxCluster);
    when(entitlementService.runtimeUpgradeEnabled(any())).thenReturn(false);
    when(stackV4Endpoint.checkForClusterUpgradeByName(anyLong(), anyString(), any(), anyString())).thenReturn(response);
    ArgumentCaptor<UpgradeV4Response> upgradeV4ResponseCaptor = ArgumentCaptor.forClass(UpgradeV4Response.class);
    when(sdxUpgradeClusterConverter.upgradeResponseToSdxUpgradeResponse(upgradeV4ResponseCaptor.capture())).thenReturn(expectedResponse);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    SdxUpgradeResponse actualResponse = underTest.checkForUpgradeByCrn(USER_CRN, STACK_CRN, new SdxUpgradeRequest(), ACCOUNT_ID);
    UpgradeV4Response capturedUpgradeV4Response = upgradeV4ResponseCaptor.getValue();
    assertEquals(expectedResponse, actualResponse);
    assertEquals(0, capturedUpgradeV4Response.getUpgradeCandidates().size());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) SdxUpgradeResponse(com.sequenceiq.sdx.api.model.SdxUpgradeResponse) SdxUpgradeRequest(com.sequenceiq.sdx.api.model.SdxUpgradeRequest) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 38 with UpgradeV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method setUp.

@BeforeEach
public void setUp() {
    response = new UpgradeV4Response();
    sdxUpgradeResponse = new SdxUpgradeResponse();
    sdxCluster = getValidSdxCluster();
    sdxUpgradeRequest = getFullSdxUpgradeRequest();
    ReflectionTestUtils.setField(underTest, "paywallUrl", "https://archive.coudera.com/p/cdp-public/");
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) SdxUpgradeResponse(com.sequenceiq.sdx.api.model.SdxUpgradeResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 39 with UpgradeV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method testDryRunShouldReturnOneUpgradeCandidate.

@Test
public void testDryRunShouldReturnOneUpgradeCandidate() {
    ImageInfoV4Response imageInfo = new ImageInfoV4Response();
    imageInfo.setImageId(IMAGE_ID);
    imageInfo.setCreated(1);
    imageInfo.setComponentVersions(creatExpectedPackageVersions());
    ImageInfoV4Response lastImageInfo = new ImageInfoV4Response();
    lastImageInfo.setImageId(IMAGE_ID_LAST);
    lastImageInfo.setCreated(2);
    lastImageInfo.setComponentVersions(creatExpectedPackageVersions());
    UpgradeV4Response upgradeV4Response = new UpgradeV4Response();
    upgradeV4Response.setUpgradeCandidates(List.of(imageInfo, lastImageInfo));
    sdxUpgradeRequest.setDryRun(true);
    when(entitlementService.runtimeUpgradeEnabled(any())).thenReturn(true);
    UpgradeV4Response actualUpgradeResponse = underTest.filterSdxUpgradeResponse(ACCOUNT_ID, sdxCluster.getClusterName(), sdxUpgradeRequest, upgradeV4Response);
    assertEquals(1, actualUpgradeResponse.getUpgradeCandidates().size());
    assertEquals(IMAGE_ID_LAST, actualUpgradeResponse.getUpgradeCandidates().get(0).getImageId());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) Test(org.junit.jupiter.api.Test)

Example 40 with UpgradeV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method testShowLatestOnlyShouldReturnLatestUpgradeCandidatesPerRuntime.

@Test
public void testShowLatestOnlyShouldReturnLatestUpgradeCandidatesPerRuntime() {
    when(entitlementService.runtimeUpgradeEnabled(any())).thenReturn(true);
    ImageComponentVersions imageComponentVersionsFor702 = new ImageComponentVersions();
    imageComponentVersionsFor702.setCm(V_7_0_2);
    imageComponentVersionsFor702.setCdp(V_7_0_2);
    ImageComponentVersions imageComponentVersionsFor703 = new ImageComponentVersions();
    imageComponentVersionsFor703.setCm(V_7_0_3);
    imageComponentVersionsFor703.setCdp(V_7_0_3);
    ImageInfoV4Response imageInfo1 = new ImageInfoV4Response();
    imageInfo1.setImageId(IMAGE_ID + 1);
    imageInfo1.setCreated(1);
    imageInfo1.setComponentVersions(imageComponentVersionsFor702);
    ImageInfoV4Response imageInfo2 = new ImageInfoV4Response();
    imageInfo2.setImageId(IMAGE_ID + 2);
    imageInfo2.setCreated(2);
    imageInfo2.setComponentVersions(imageComponentVersionsFor702);
    ImageInfoV4Response imageInfo3 = new ImageInfoV4Response();
    imageInfo3.setImageId(IMAGE_ID + 3);
    imageInfo3.setCreated(3);
    imageInfo3.setComponentVersions(imageComponentVersionsFor703);
    UpgradeV4Response upgradeV4Response = new UpgradeV4Response();
    upgradeV4Response.setUpgradeCandidates(List.of(imageInfo1, imageInfo2, imageInfo3));
    sdxUpgradeRequest.setShowAvailableImages(SdxUpgradeShowAvailableImages.LATEST_ONLY);
    UpgradeV4Response actualResponse = underTest.filterSdxUpgradeResponse(ACCOUNT_ID, sdxCluster.getClusterName(), sdxUpgradeRequest, upgradeV4Response);
    assertEquals(2, actualResponse.getUpgradeCandidates().size());
    assertFalse(actualResponse.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 1)));
    assertTrue(actualResponse.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 2)));
    assertTrue(actualResponse.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 3)));
}
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) BeforeEach(org.junit.jupiter.api.BeforeEach) RestClientFactory(com.sequenceiq.cloudbreak.client.RestClientFactory) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxUpgradeResponse(com.sequenceiq.sdx.api.model.SdxUpgradeResponse) SdxUpgradeShowAvailableImages(com.sequenceiq.sdx.api.model.SdxUpgradeShowAvailableImages) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions) PaywallAccessChecker(com.sequenceiq.cloudbreak.auth.PaywallAccessChecker) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape) Mock(org.mockito.Mock) SdxReactorFlowManager(com.sequenceiq.datalake.flow.SdxReactorFlowManager) StringUtils(org.apache.commons.lang3.StringUtils) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) ArrayList(java.util.ArrayList) Mockito.doThrow(org.mockito.Mockito.doThrow) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) SdxUpgradeClusterConverter(com.sequenceiq.datalake.controller.sdx.SdxUpgradeClusterConverter) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SdxService(com.sequenceiq.datalake.service.sdx.SdxService) InjectMocks(org.mockito.InjectMocks) RegionAwareInternalCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGenerator) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) StackV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint) 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) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SdxUpgradeReplaceVms(com.sequenceiq.sdx.api.model.SdxUpgradeReplaceVms) SdxUpgradeRequest(com.sequenceiq.sdx.api.model.SdxUpgradeRequest) ClouderaManagerLicenseProvider(com.sequenceiq.cloudbreak.auth.ClouderaManagerLicenseProvider) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions) Test(org.junit.jupiter.api.Test)

Aggregations

UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)69 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)43 Test (org.junit.jupiter.api.Test)41 UpgradeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)40 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)21 Test (org.junit.Test)16 DisplayName (org.junit.jupiter.api.DisplayName)16 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)13 ImageComponentVersions (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions)10 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)10 ImageFilterResult (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)9 CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)9 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)9 ImageFilterParams (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams)9 List (java.util.List)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 InjectMocks (org.mockito.InjectMocks)8 Mock (org.mockito.Mock)8