Search in sources :

Example 1 with SdxUpgradeResponse

use of com.sequenceiq.sdx.api.model.SdxUpgradeResponse 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 SdxUpgradeResponse

use of com.sequenceiq.sdx.api.model.SdxUpgradeResponse 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 SdxUpgradeResponse

use of com.sequenceiq.sdx.api.model.SdxUpgradeResponse 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 4 with SdxUpgradeResponse

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

the class SdxRuntimeUpgradeServiceTest method testTriggerRuntimeUpgradeByNameWhenNotEnabledAndNoPatchUpgrades.

@Test
public void testTriggerRuntimeUpgradeByNameWhenNotEnabledAndNoPatchUpgrades() {
    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(), List.of(), "Something went wrong", response.getFlowIdentifier());
    when(entitlementService.runtimeUpgradeEnabled(any())).thenReturn(false);
    when(stackV4Endpoint.checkForClusterUpgradeByName(anyLong(), anyString(), any(), anyString())).thenReturn(response);
    when(sdxUpgradeClusterConverter.upgradeResponseToSdxUpgradeResponse(any(UpgradeV4Response.class))).thenReturn(expectedResponse);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    BadRequestException exception = assertThrows(BadRequestException.class, () -> underTest.triggerUpgradeByName(USER_CRN, STACK_NAME, sdxUpgradeRequest, ACCOUNT_ID));
    assertTrue(exception.getMessage().contains("Something went wrong"));
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) SdxUpgradeResponse(com.sequenceiq.sdx.api.model.SdxUpgradeResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) Test(org.junit.jupiter.api.Test)

Example 5 with SdxUpgradeResponse

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

the class SdxRuntimeUpgradeServiceTest method testCheckForUpgradeByCrnWhenDisabledAndNoCurrentImage.

@Test
@DisplayName("Test checkForUpgradeByCrn() when Runtime Upgrade is disabled and no current image information is provided in upgrade response")
public void testCheckForUpgradeByCrnWhenDisabledAndNoCurrentImage() {
    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());
    List<ImageInfoV4Response> candidates = List.of(imageInfo, lastImageInfo);
    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, sdxUpgradeRequest, ACCOUNT_ID);
    UpgradeV4Response capturedUpgradeV4Response = upgradeV4ResponseCaptor.getValue();
    assertEquals(actualResponse, expectedResponse);
    assertTrue(capturedUpgradeV4Response.getReason().contains("No information about current image, cannot filter patch upgrade candidates based on it"));
    assertTrue(capturedUpgradeV4Response.getUpgradeCandidates().isEmpty());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) SdxUpgradeResponse(com.sequenceiq.sdx.api.model.SdxUpgradeResponse) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

SdxUpgradeResponse (com.sequenceiq.sdx.api.model.SdxUpgradeResponse)22 SdxUpgradeRequest (com.sequenceiq.sdx.api.model.SdxUpgradeRequest)15 Test (org.junit.jupiter.api.Test)15 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)9 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)8 DisplayName (org.junit.jupiter.api.DisplayName)8 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 SdxClusterDetailResponse (com.sequenceiq.sdx.api.model.SdxClusterDetailResponse)2 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1