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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations