Search in sources :

Example 11 with SdxUpgradeRequest

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

the class SdxUpgradeControllerTest method testUpgradeClusterByNameWhenRequestIsDryRunAndRuntimeIsDisabled.

@Test
void testUpgradeClusterByNameWhenRequestIsDryRunAndRuntimeIsDisabled() {
    SdxUpgradeResponse sdxUpgradeResponse = new SdxUpgradeResponse();
    sdxUpgradeResponse.setReason("No image available to upgrade");
    SdxUpgradeRequest request = new SdxUpgradeRequest();
    request.setDryRun(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)

Example 12 with SdxUpgradeRequest

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

the class SdxUpgradeControllerTest method testUpgradeClusterByNameWhenRequestIsEmptyAndRuntimeIsEnabled.

@Test
void testUpgradeClusterByNameWhenRequestIsEmptyAndRuntimeIsEnabled() {
    SdxUpgradeRequest request = new SdxUpgradeRequest();
    doAs(USER_CRN, () -> underTest.upgradeClusterByName(CLUSTER_NAME, request));
    verify(sdxRuntimeUpgradeService).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 13 with SdxUpgradeRequest

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

the class SdxUpgradeControllerTest method testUpgradeClusterByNameWhenRequestIsShowImagesAndRuntimeIsDisabledShouldNotSetLockComponent.

@Test
@DisplayName("when show images is requested and runtime upgrade is enabled it should not set the lock components flag")
void testUpgradeClusterByNameWhenRequestIsShowImagesAndRuntimeIsDisabledShouldNotSetLockComponent() {
    SdxUpgradeRequest request = new SdxUpgradeRequest();
    request.setShowAvailableImages(SdxUpgradeShowAvailableImages.SHOW);
    SdxUpgradeResponse sdxUpgradeResponse = new SdxUpgradeResponse();
    sdxUpgradeResponse.setReason("No image available to upgrade");
    when(sdxRuntimeUpgradeService.checkForUpgradeByName(USER_CRN, CLUSTER_NAME, request, ACCOUNT_ID)).thenReturn(sdxUpgradeResponse);
    SdxUpgradeResponse response = doAs(USER_CRN, () -> underTest.upgradeClusterByName(CLUSTER_NAME, request));
    verify(sdxRuntimeUpgradeService, times(1)).checkForUpgradeByName(any(), any(), upgradeRequestArgumentCaptor.capture(), anyString());
    SdxUpgradeRequest capturedRequest = upgradeRequestArgumentCaptor.getValue();
    assertNull(capturedRequest.getLockComponents());
    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) DisplayName(org.junit.jupiter.api.DisplayName)

Example 14 with SdxUpgradeRequest

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

the class SdxRuntimeUpgradeService method filterBySdxUpgradeRequestParams.

private UpgradeV4Response filterBySdxUpgradeRequestParams(SdxUpgradeRequest upgradeSdxClusterRequest, UpgradeV4Response upgradeV4Response) {
    UpgradeV4Response filteredUpgradeResponse = new UpgradeV4Response(upgradeV4Response.getCurrent(), upgradeV4Response.getUpgradeCandidates(), upgradeV4Response.getReason());
    if (CollectionUtils.isNotEmpty(filteredUpgradeResponse.getUpgradeCandidates())) {
        List<ImageInfoV4Response> upgradeCandidates = filteredUpgradeResponse.getUpgradeCandidates();
        if (SdxUpgradeShowAvailableImages.LATEST_ONLY == upgradeSdxClusterRequest.getShowAvailableImages()) {
            Map<String, Optional<ImageInfoV4Response>> latestImageByRuntime = upgradeCandidates.stream().collect(Collectors.groupingBy(imageInfoV4Response -> imageInfoV4Response.getComponentVersions().getCdp(), Collectors.maxBy(Comparator.comparingLong(ImageInfoV4Response::getCreated))));
            List<ImageInfoV4Response> latestImages = latestImageByRuntime.values().stream().flatMap(Optional::stream).collect(Collectors.toList());
            filteredUpgradeResponse.setUpgradeCandidates(latestImages);
            LOGGER.debug("Filtering for latest image per runtimes {}", latestImageByRuntime.keySet());
        } else if (upgradeSdxClusterRequest.isDryRun()) {
            ImageInfoV4Response latestImage = upgradeCandidates.stream().max(ImageInfoV4Response.creationBasedComparator()).orElseThrow();
            filteredUpgradeResponse.setUpgradeCandidates(List.of(latestImage));
            LOGGER.debug("Choosing latest image with id {} as dry-run is specified", latestImage.getImageId());
        } else {
            filteredUpgradeResponse.setUpgradeCandidates(upgradeCandidates);
        }
    }
    return filteredUpgradeResponse;
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxUpgradeResponse(com.sequenceiq.sdx.api.model.SdxUpgradeResponse) SdxUpgradeShowAvailableImages(com.sequenceiq.sdx.api.model.SdxUpgradeShowAvailableImages) ImageComponentVersions(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions) PaywallAccessChecker(com.sequenceiq.cloudbreak.auth.PaywallAccessChecker) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) SdxReactorFlowManager(com.sequenceiq.datalake.flow.SdxReactorFlowManager) LoggerFactory(org.slf4j.LoggerFactory) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) 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) Map(java.util.Map) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxService(com.sequenceiq.datalake.service.sdx.SdxService) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) StackV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.StackV4Endpoint) Logger(org.slf4j.Logger) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Collectors(java.util.stream.Collectors) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Objects(java.util.Objects) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) SdxUpgradeReplaceVms(com.sequenceiq.sdx.api.model.SdxUpgradeReplaceVms) SdxUpgradeRequest(com.sequenceiq.sdx.api.model.SdxUpgradeRequest) ClouderaManagerLicenseProvider(com.sequenceiq.cloudbreak.auth.ClouderaManagerLicenseProvider) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) Optional(java.util.Optional) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)

Example 15 with SdxUpgradeRequest

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

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