Search in sources :

Example 6 with JsonCMLicense

use of com.sequenceiq.cloudbreak.auth.JsonCMLicense in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method testTriggerUpgradeWhenPaywallProbeFailsShouldThrowBadRequest.

@Test
public void testTriggerUpgradeWhenPaywallProbeFailsShouldThrowBadRequest() {
    when(sdxService.getByCrn(anyString(), anyString())).thenReturn(sdxCluster);
    when(stackV4Endpoint.checkForClusterUpgradeByName(anyLong(), anyString(), any(), anyString())).thenReturn(response);
    when(sdxUpgradeClusterConverter.upgradeResponseToSdxUpgradeResponse(any(UpgradeV4Response.class))).thenReturn(sdxUpgradeResponse);
    when(entitlementService.runtimeUpgradeEnabled(any())).thenReturn(true);
    when(entitlementService.isInternalRepositoryForUpgradeAllowed(any())).thenReturn(false);
    when(clouderaManagerLicenseProvider.getLicense(any())).thenReturn(new JsonCMLicense());
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    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());
    response.setUpgradeCandidates(List.of(imageInfo, lastImageInfo));
    sdxUpgradeResponse.setUpgradeCandidates(List.of(imageInfo, lastImageInfo));
    sdxUpgradeRequest.setLockComponents(false);
    sdxUpgradeRequest.setImageId(null);
    sdxUpgradeRequest.setReplaceVms(REPAIR_AFTER_UPGRADE);
    doThrow(new BadRequestException("The Cloudera Manager license is not valid to authenticate to paywall, " + "please contact a Cloudera administrator to update it.")).when(paywallAccessChecker).checkPaywallAccess(any(JsonCMLicense.class), anyString());
    try {
        ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerUpgradeByCrn(USER_CRN, STACK_CRN, sdxUpgradeRequest, ACCOUNT_ID));
    } catch (BadRequestException e) {
        String errorMessage = "The Cloudera Manager license is not valid to authenticate to paywall, " + "please contact a Cloudera administrator to update it.";
        assertEquals(errorMessage, e.getMessage());
    }
    verify(sdxReactorFlowManager, times(0)).triggerDatalakeRuntimeUpgradeFlow(sdxCluster, IMAGE_ID_LAST, REPAIR_AFTER_UPGRADE, SKIP_BACKUP);
    verify(sdxReactorFlowManager, times(0)).triggerDatalakeRuntimeUpgradeFlow(sdxCluster, IMAGE_ID, REPAIR_AFTER_UPGRADE, SKIP_BACKUP);
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) Test(org.junit.jupiter.api.Test)

Example 7 with JsonCMLicense

use of com.sequenceiq.cloudbreak.auth.JsonCMLicense in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeServiceTest method testTriggerUpgradeWithInvalidPaywallLicenseShouldThrowBadRequest.

@Test
public void testTriggerUpgradeWithInvalidPaywallLicenseShouldThrowBadRequest() {
    when(sdxService.getByCrn(anyString(), anyString())).thenReturn(sdxCluster);
    when(stackV4Endpoint.checkForClusterUpgradeByName(anyLong(), anyString(), any(), anyString())).thenReturn(response);
    when(sdxUpgradeClusterConverter.upgradeResponseToSdxUpgradeResponse(any(UpgradeV4Response.class))).thenReturn(sdxUpgradeResponse);
    when(entitlementService.runtimeUpgradeEnabled(any())).thenReturn(true);
    when(entitlementService.isInternalRepositoryForUpgradeAllowed(any())).thenReturn(false);
    when(clouderaManagerLicenseProvider.getLicense(any())).thenReturn(new JsonCMLicense());
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    doThrow(new BadRequestException("The Cloudera Manager license is not valid to authenticate to paywall, " + "please contact a Cloudera administrator to update it.")).when(paywallAccessChecker).checkPaywallAccess(any(JsonCMLicense.class), anyString());
    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());
    response.setUpgradeCandidates(List.of(imageInfo, lastImageInfo));
    sdxUpgradeResponse.setUpgradeCandidates(List.of(imageInfo, lastImageInfo));
    sdxUpgradeRequest.setLockComponents(false);
    sdxUpgradeRequest.setImageId(null);
    sdxUpgradeRequest.setReplaceVms(REPAIR_AFTER_UPGRADE);
    try {
        ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerUpgradeByCrn(USER_CRN, STACK_CRN, sdxUpgradeRequest, ACCOUNT_ID));
    } catch (BadRequestException e) {
        String errorMessage = "The Cloudera Manager license is not valid to authenticate to paywall, " + "please contact a Cloudera administrator to update it.";
        assertEquals(errorMessage, e.getMessage());
    }
    verify(sdxReactorFlowManager, times(0)).triggerDatalakeRuntimeUpgradeFlow(sdxCluster, IMAGE_ID_LAST, REPAIR_AFTER_UPGRADE, SKIP_BACKUP);
    verify(sdxReactorFlowManager, times(0)).triggerDatalakeRuntimeUpgradeFlow(sdxCluster, IMAGE_ID, REPAIR_AFTER_UPGRADE, SKIP_BACKUP);
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) Test(org.junit.jupiter.api.Test)

Example 8 with JsonCMLicense

use of com.sequenceiq.cloudbreak.auth.JsonCMLicense in project cloudbreak by hortonworks.

the class SdxRuntimeUpgradeService method verifyCMLicenseValidity.

private void verifyCMLicenseValidity(String userCrn) {
    LOGGER.info("Verify if the CM license is valid to authenticate to {}", paywallUrl);
    JsonCMLicense license = clouderaManagerLicenseProvider.getLicense(userCrn);
    paywallAccessChecker.checkPaywallAccess(license, paywallUrl);
}
Also used : JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense)

Example 9 with JsonCMLicense

use of com.sequenceiq.cloudbreak.auth.JsonCMLicense in project cloudbreak by hortonworks.

the class DistroXUpgradeServiceTest method testTriggerFlowWithoutTurnOffReplaceVmsParam.

@Test
public void testTriggerFlowWithoutTurnOffReplaceVmsParam() {
    // GIVEN
    UpgradeV4Request request = createRequest(true);
    UpgradeV4Response response = new UpgradeV4Response();
    response.setReplaceVms(true);
    response.setUpgradeCandidates(List.of(mock(ImageInfoV4Response.class)));
    when(upgradeAvailabilityService.checkForUpgrade(CLUSTER, WS_ID, request, USER_CRN)).thenReturn(response);
    when(entitlementService.isInternalRepositoryForUpgradeAllowed(ACCOUNT_ID)).thenReturn(Boolean.FALSE);
    when(clouderaManagerLicenseProvider.getLicense(any())).thenReturn(new JsonCMLicense());
    ImageInfoV4Response imageInfoV4Response = new ImageInfoV4Response();
    imageInfoV4Response.setImageId("imgId");
    imageInfoV4Response.setImageCatalogName("catalogName");
    when(imageSelector.determineImageId(request, response.getUpgradeCandidates())).thenReturn(imageInfoV4Response);
    ArgumentCaptor<StackImageChangeV4Request> imageChangeRequestArgumentCaptor = ArgumentCaptor.forClass(StackImageChangeV4Request.class);
    ImageChangeDto imageChangeDto = new ImageChangeDto(STACK_ID, imageInfoV4Response.getImageId());
    when(stackCommonService.createImageChangeDto(eq(CLUSTER), eq(WS_ID), imageChangeRequestArgumentCaptor.capture())).thenReturn(imageChangeDto);
    when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WS_ID)).thenReturn(stack);
    when(lockedComponentService.isComponentsLocked(stack, imageInfoV4Response.getImageId())).thenReturn(true);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "asdf");
    when(reactorFlowManager.triggerDistroXUpgrade(eq(STACK_ID), eq(imageChangeDto), anyBoolean(), anyBoolean(), anyString())).thenReturn(flowIdentifier);
    // WHEN
    UpgradeV4Response result = underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request);
    // THEN
    verify(reactorFlowManager).triggerDistroXUpgrade(STACK_ID, imageChangeDto, true, true, "variant");
    assertTrue(result.isReplaceVms());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) Test(org.junit.jupiter.api.Test)

Example 10 with JsonCMLicense

use of com.sequenceiq.cloudbreak.auth.JsonCMLicense in project cloudbreak by hortonworks.

the class DistroXUpgradeServiceTest method testTriggerFlowWithTurnOffReplaceVmsParam.

@Test
public void testTriggerFlowWithTurnOffReplaceVmsParam() {
    // GIVEN
    UpgradeV4Request request = new UpgradeV4Request();
    UpgradeV4Response response = new UpgradeV4Response();
    response.setReplaceVms(true);
    response.setUpgradeCandidates(List.of(mock(ImageInfoV4Response.class)));
    when(upgradeAvailabilityService.checkForUpgrade(CLUSTER, WS_ID, request, USER_CRN)).thenReturn(response);
    when(entitlementService.isInternalRepositoryForUpgradeAllowed(ACCOUNT_ID)).thenReturn(Boolean.FALSE);
    when(clouderaManagerLicenseProvider.getLicense(any())).thenReturn(new JsonCMLicense());
    ImageInfoV4Response imageInfoV4Response = new ImageInfoV4Response();
    imageInfoV4Response.setImageId("imgId");
    imageInfoV4Response.setImageCatalogName("catalogName");
    when(imageSelector.determineImageId(request, response.getUpgradeCandidates())).thenReturn(imageInfoV4Response);
    ArgumentCaptor<StackImageChangeV4Request> imageChangeRequestArgumentCaptor = ArgumentCaptor.forClass(StackImageChangeV4Request.class);
    ImageChangeDto imageChangeDto = new ImageChangeDto(STACK_ID, imageInfoV4Response.getImageId());
    when(stackCommonService.createImageChangeDto(eq(CLUSTER), eq(WS_ID), imageChangeRequestArgumentCaptor.capture())).thenReturn(imageChangeDto);
    when(stackService.getByNameOrCrnInWorkspace(CLUSTER, WS_ID)).thenReturn(stack);
    when(lockedComponentService.isComponentsLocked(stack, imageInfoV4Response.getImageId())).thenReturn(LOCK_COMPONENTS);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW_CHAIN, "asdf");
    when(reactorFlowManager.triggerDistroXUpgrade(eq(STACK_ID), eq(imageChangeDto), anyBoolean(), eq(LOCK_COMPONENTS), anyString())).thenReturn(flowIdentifier);
    // WHEN
    UpgradeV4Response result = underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request);
    // THEN
    verify(reactorFlowManager).triggerDistroXUpgrade(STACK_ID, imageChangeDto, false, LOCK_COMPONENTS, "variant");
    assertFalse(result.isReplaceVms());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageChangeDto(com.sequenceiq.cloudbreak.service.image.ImageChangeDto) StackImageChangeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request) UpgradeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) Test(org.junit.jupiter.api.Test)

Aggregations

JsonCMLicense (com.sequenceiq.cloudbreak.auth.JsonCMLicense)10 Test (org.junit.jupiter.api.Test)8 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)7 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)7 StackImageChangeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackImageChangeV4Request)4 UpgradeV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.upgrade.UpgradeV4Request)4 ImageChangeDto (com.sequenceiq.cloudbreak.service.image.ImageChangeDto)4 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)1 SaltPillarProperties (com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties)1 VmLog (com.sequenceiq.common.api.telemetry.model.VmLog)1 Stack (com.sequenceiq.freeipa.entity.Stack)1