Search in sources :

Example 1 with JsonCMLicense

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

the class DistroXUpgradeService 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 2 with JsonCMLicense

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

the class SdxRuntimeUpgradeServiceTest method testTriggerUpgradeWithValidPaywallLicense.

@Test
public void testTriggerUpgradeWithValidPaywallLicense() {
    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);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerUpgradeByCrn(USER_CRN, STACK_CRN, sdxUpgradeRequest, ACCOUNT_ID));
    verify(sdxReactorFlowManager, times(1)).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) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) Test(org.junit.jupiter.api.Test)

Example 3 with JsonCMLicense

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

the class TelemetryConfigServiceTest method testCreateTelemetryConfigs.

@Test
public void testCreateTelemetryConfigs() throws Exception {
    // GIVEN
    UserManagementProto.Account account = UserManagementProto.Account.newBuilder().setClouderaManagerLicenseKey("myLicense").build();
    JsonCMLicense license = new JsonCMLicense();
    license.setName("myname");
    license.setUuid("myuuid");
    Stack stack = createStack();
    given(stackService.getStackById(STACK_ID)).willReturn(stack);
    given(entitlementService.useDataBusCNameEndpointEnabled(anyString())).willReturn(false);
    given(dataBusEndpointProvider.getDataBusEndpoint(anyString(), anyBoolean())).willReturn("myendpoint");
    given(vmLogsService.getVmLogs()).willReturn(List.of(new VmLog()));
    given(telemetryCommonConfigService.createTelemetryCommonConfigs(any(), any(), any())).willReturn(new TelemetryCommonConfigView.Builder().build());
    given(cmLicenseParser.parseLicense(anyString())).willReturn(Optional.of(license));
    given(umsClient.getAccountDetails(anyString(), any(), any())).willReturn(account);
    given(fluentConfigService.createFluentConfigs(any(), anyBoolean(), anyBoolean(), isNull(), any())).willReturn(new FluentConfigView.Builder().build());
    given(nodeStatusConfigService.createNodeStatusConfig(isNull(), isNull(), anyBoolean())).willReturn(new NodeStatusConfigView.Builder().build());
    given(monitoringConfigService.createMonitoringConfig(isNull(), any(), isNull(), isNull(), anyBoolean())).willReturn(new MonitoringConfigView.Builder().build());
    // WHEN
    Map<String, SaltPillarProperties> result = underTest.createTelemetryConfigs(STACK_ID, Set.of(TelemetryComponentType.CDP_TELEMETRY));
    // THEN
    verify(fluentConfigService, times(1)).createFluentConfigs(any(), anyBoolean(), anyBoolean(), isNull(), any());
    assertNotNull(result.get("telemetry").getProperties().get("cloudera-manager"));
    assertNotNull(result.get("telemetry").getProperties().get("telemetry"));
}
Also used : VmLog(com.sequenceiq.common.api.telemetry.model.VmLog) UserManagementProto(com.cloudera.thunderhead.service.usermanagement.UserManagementProto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JsonCMLicense(com.sequenceiq.cloudbreak.auth.JsonCMLicense) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 4 with JsonCMLicense

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

the class DistroXUpgradeServiceTest method testTriggerFlowWithPaywallCheck.

@Test
public void testTriggerFlowWithPaywallCheck() {
    UpgradeV4Request request = new UpgradeV4Request();
    UpgradeV4Response response = new UpgradeV4Response();
    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);
    UpgradeV4Response result = underTest.triggerUpgrade(CLUSTER, WS_ID, USER_CRN, request);
    verify(paywallAccessChecker).checkPaywallAccess(any(), any());
    assertEquals(flowIdentifier, result.getFlowIdentifier());
    assertTrue(result.getReason().contains(imageInfoV4Response.getImageId()));
    StackImageChangeV4Request imageChangeV4Request = imageChangeRequestArgumentCaptor.getValue();
    assertEquals(imageInfoV4Response.getImageId(), imageChangeV4Request.getImageId());
    assertEquals(imageInfoV4Response.getImageCatalogName(), imageChangeV4Request.getImageCatalogName());
}
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 5 with JsonCMLicense

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

the class DistroXUpgradeServiceTest method testTriggerFlowWhenReplaceVmsParamIsFalse.

@Test
public void testTriggerFlowWhenReplaceVmsParamIsFalse() {
    // GIVEN
    UpgradeV4Request request = new UpgradeV4Request();
    UpgradeV4Response response = new UpgradeV4Response();
    response.setReplaceVms(false);
    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