Search in sources :

Example 1 with SdxUpgradeRequest

use of com.sequenceiq.sdx.api.model.SdxUpgradeRequest in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method testCheckForUpgradeByCrnWhenDisabledAndRequestRuntimeParamIsWrong.

@Test
@DisplayName("Test checkForUpgradeByCrn() when Runtime Upgrade is disabled and request runtime param is wrong")
public void testCheckForUpgradeByCrnWhenDisabledAndRequestRuntimeParamIsWrong() {
    SdxUpgradeRequest sdxUpgradeRequest = new SdxUpgradeRequest();
    sdxUpgradeRequest.setRuntime("7.2.0");
    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, sdxUpgradeRequest, ACCOUNT_ID);
    UpgradeV4Response capturedUpgradeV4Response = upgradeV4ResponseCaptor.getValue();
    assertEquals(expectedResponse, actualResponse);
    assertEquals(0, capturedUpgradeV4Response.getUpgradeCandidates().size());
    assertTrue(capturedUpgradeV4Response.getReason().contains("it is not possible to upgrade from [7.0.2] to [7.2.0] runtime"));
}
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 2 with SdxUpgradeRequest

use of com.sequenceiq.sdx.api.model.SdxUpgradeRequest in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method testCheckForUpgradeByCrnWhenDisabledAndRequestImageIdParamIsWrong.

@Test
@DisplayName("Test checkForUpgradeByCrn() when Runtime Upgrade is disabled and request imageid param is wrong")
public void testCheckForUpgradeByCrnWhenDisabledAndRequestImageIdParamIsWrong() {
    SdxUpgradeRequest sdxUpgradeRequest = new SdxUpgradeRequest();
    sdxUpgradeRequest.setImageId(IMAGE_ID_LAST);
    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, sdxUpgradeRequest, ACCOUNT_ID);
    UpgradeV4Response capturedUpgradeV4Response = upgradeV4ResponseCaptor.getValue();
    assertEquals(expectedResponse, actualResponse);
    assertEquals(0, capturedUpgradeV4Response.getUpgradeCandidates().size());
    assertTrue(capturedUpgradeV4Response.getReason().contains("The version of target runtime has to be the same as the current one"));
}
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 3 with SdxUpgradeRequest

use of com.sequenceiq.sdx.api.model.SdxUpgradeRequest in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method testShowAvailableImagesShouldReturnAllUpgradeCandidates.

@Test
public void testShowAvailableImagesShouldReturnAllUpgradeCandidates() {
    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.SHOW);
    underTest.filterSdxUpgradeResponse(ACCOUNT_ID, sdxCluster.getClusterName(), sdxUpgradeRequest, upgradeV4Response);
    assertEquals(3, upgradeV4Response.getUpgradeCandidates().size());
    assertTrue(upgradeV4Response.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 1)));
    assertTrue(upgradeV4Response.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 2)));
    assertTrue(upgradeV4Response.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)

Example 4 with SdxUpgradeRequest

use of com.sequenceiq.sdx.api.model.SdxUpgradeRequest in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method testCheckForUpgradeByCrnWhenDisabledAndPatchUpdatesAvailable.

@Test
@DisplayName("Test checkForUpgradeByCrn() when Runtime Upgrade is disabled and patch updates are available")
public void testCheckForUpgradeByCrnWhenDisabledAndPatchUpdatesAvailable() {
    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(MATCHING_TARGET_RUNTIME, MATCHING_TARGET_RUNTIME));
    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);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    ArgumentCaptor<UpgradeV4Response> upgradeV4ResponseCaptor = ArgumentCaptor.forClass(UpgradeV4Response.class);
    when(sdxUpgradeClusterConverter.upgradeResponseToSdxUpgradeResponse(upgradeV4ResponseCaptor.capture())).thenReturn(expectedResponse);
    SdxUpgradeResponse actualResponse = underTest.checkForUpgradeByCrn(USER_CRN, STACK_CRN, new SdxUpgradeRequest(), ACCOUNT_ID);
    UpgradeV4Response capturedUpgradeV4Response = upgradeV4ResponseCaptor.getValue();
    assertEquals(expectedResponse, actualResponse);
    assertTrue(StringUtils.isEmpty(capturedUpgradeV4Response.getReason()));
    assertEquals(1, capturedUpgradeV4Response.getUpgradeCandidates().size());
    assertEquals(MATCHING_TARGET_RUNTIME, capturedUpgradeV4Response.getUpgradeCandidates().get(0).getComponentVersions().getCdp());
}
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 5 with SdxUpgradeRequest

use of com.sequenceiq.sdx.api.model.SdxUpgradeRequest in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method getFullSdxUpgradeRequest.

private SdxUpgradeRequest getFullSdxUpgradeRequest() {
    SdxUpgradeRequest sdxUpgradeRequest = new SdxUpgradeRequest();
    sdxUpgradeRequest.setImageId(IMAGE_ID);
    sdxUpgradeRequest.setRuntime(MATCHING_TARGET_RUNTIME);
    return sdxUpgradeRequest;
}
Also used : SdxUpgradeRequest(com.sequenceiq.sdx.api.model.SdxUpgradeRequest)

Aggregations

SdxUpgradeRequest (com.sequenceiq.sdx.api.model.SdxUpgradeRequest)27 Test (org.junit.jupiter.api.Test)19 SdxUpgradeResponse (com.sequenceiq.sdx.api.model.SdxUpgradeResponse)18 DisplayName (org.junit.jupiter.api.DisplayName)9 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)7 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)7 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)6 StackV4Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint)3 ImageComponentVersions (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions)3 ClouderaManagerLicenseProvider (com.sequenceiq.cloudbreak.auth.ClouderaManagerLicenseProvider)3 JsonCMLicense (com.sequenceiq.cloudbreak.auth.JsonCMLicense)3 PaywallAccessChecker (com.sequenceiq.cloudbreak.auth.PaywallAccessChecker)3 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)3 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)3 RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)3 CloudbreakMessagesService (com.sequenceiq.cloudbreak.message.CloudbreakMessagesService)3 SdxUpgradeClusterConverter (com.sequenceiq.datalake.controller.sdx.SdxUpgradeClusterConverter)3 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)3 SdxReactorFlowManager (com.sequenceiq.datalake.flow.SdxReactorFlowManager)3 SdxService (com.sequenceiq.datalake.service.sdx.SdxService)3