Search in sources :

Example 16 with SdxUpgradeRequest

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

Example 17 with SdxUpgradeRequest

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

the class SdxUpgradeControllerTest method testUpgradeClusterByNameRuntimeIsSetAndDisabled.

@Test
void testUpgradeClusterByNameRuntimeIsSetAndDisabled() {
    SdxUpgradeRequest request = new SdxUpgradeRequest();
    request.setRuntime("7.1.0");
    doThrow(new BadRequestException("Runtime upgrade feature is not enabled")).when(sdxRuntimeUpgradeService).triggerUpgradeByName(USER_CRN, CLUSTER_NAME, request, Crn.fromString(USER_CRN).getAccountId());
    BadRequestException exception = doAs(USER_CRN, () -> Assertions.assertThrows(BadRequestException.class, () -> underTest.upgradeClusterByName(CLUSTER_NAME, request)));
    assertEquals("Runtime upgrade feature is not enabled", exception.getMessage());
}
Also used : SdxUpgradeRequest(com.sequenceiq.sdx.api.model.SdxUpgradeRequest) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 18 with SdxUpgradeRequest

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

the class SdxUpgradeControllerTest method testUpgradeClusterByNameWhenRequestIsEmptyAndRuntimeIsDisabled.

@Test
void testUpgradeClusterByNameWhenRequestIsEmptyAndRuntimeIsDisabled() {
    SdxUpgradeRequest request = new SdxUpgradeRequest();
    doAs(USER_CRN, () -> underTest.upgradeClusterByName(CLUSTER_NAME, request));
    verify(sdxRuntimeUpgradeService, times(1)).triggerUpgradeByName(USER_CRN, CLUSTER_NAME, request, Crn.fromString(USER_CRN).getAccountId());
}
Also used : SdxUpgradeRequest(com.sequenceiq.sdx.api.model.SdxUpgradeRequest) Test(org.junit.jupiter.api.Test)

Example 19 with SdxUpgradeRequest

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

the class SdxUpgradeControllerTest method testUpgradeClusterByNameWhenImageIsSetAndRuntimeIsEnabled.

@Test
void testUpgradeClusterByNameWhenImageIsSetAndRuntimeIsEnabled() {
    SdxUpgradeRequest request = new SdxUpgradeRequest();
    request.setImageId("imageId");
    SdxUpgradeResponse sdxUpgradeResponse = new SdxUpgradeResponse();
    sdxUpgradeResponse.setReason("No image available to upgrade");
    when(sdxRuntimeUpgradeService.triggerUpgradeByName(USER_CRN, CLUSTER_NAME, request, Crn.fromString(USER_CRN).getAccountId())).thenReturn(sdxUpgradeResponse);
    SdxUpgradeResponse response = doAs(USER_CRN, () -> underTest.upgradeClusterByName(CLUSTER_NAME, request));
    verify(sdxRuntimeUpgradeService, times(0)).checkForUpgradeByName(any(), any(), any(), anyString());
    verify(sdxRuntimeUpgradeService).triggerUpgradeByName(USER_CRN, CLUSTER_NAME, request, Crn.fromString(USER_CRN).getAccountId());
    assertEquals("No image available to upgrade", response.getReason());
}
Also used : SdxUpgradeResponse(com.sequenceiq.sdx.api.model.SdxUpgradeResponse) SdxUpgradeRequest(com.sequenceiq.sdx.api.model.SdxUpgradeRequest) Test(org.junit.jupiter.api.Test)

Example 20 with SdxUpgradeRequest

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

the class SdxUpgradeControllerTest method testUpgradeClusterByNameWhenRequestIsDryRunAndLockComponents.

@Test
void testUpgradeClusterByNameWhenRequestIsDryRunAndLockComponents() {
    SdxUpgradeResponse sdxUpgradeResponse = new SdxUpgradeResponse();
    sdxUpgradeResponse.setReason("No image available to upgrade");
    SdxUpgradeRequest request = new SdxUpgradeRequest();
    request.setDryRun(true);
    request.setLockComponents(true);
    when(sdxRuntimeUpgradeService.checkForUpgradeByName(eq(USER_CRN), eq(CLUSTER_NAME), eq(request), anyString())).thenReturn(sdxUpgradeResponse);
    SdxUpgradeResponse response = doAs(USER_CRN, () -> underTest.upgradeClusterByName(CLUSTER_NAME, request));
    verify(sdxRuntimeUpgradeService, times(1)).checkForUpgradeByName(eq(USER_CRN), eq(CLUSTER_NAME), eq(request), anyString());
    assertEquals("No image available to upgrade", response.getReason());
}
Also used : SdxUpgradeResponse(com.sequenceiq.sdx.api.model.SdxUpgradeResponse) SdxUpgradeRequest(com.sequenceiq.sdx.api.model.SdxUpgradeRequest) Test(org.junit.jupiter.api.Test)

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