@Test public void testSetAzureCloudIdentityMappingDatalakNotRunning() throws ApiException { when(sdxService.listSdxByEnvCrn(anyString())).thenReturn(List.of(mock(SdxCluster.class))); SdxStatusEntity sdxStatus = mockSdxStatus(DatalakeStatusEnum.PROVISIONING_FAILED); when(sdxStatusService.getActualStatusForSdx(any())).thenReturn(sdxStatus); Map<String, String> userMapping = Map.of("user", "val1"); RangerCloudIdentitySyncStatus status = underTest.setAzureCloudIdentityMapping("env-crn", userMapping); assertEquals(RangerCloudIdentitySyncState.NOT_APPLICABLE, status.getState()); verify(clouderaManagerRangerUtil, never()).setAzureCloudIdentityMapping(eq("stack-crn"), eq(userMapping)); }
private RangerCloudIdentitySyncStatus setAzureCloudIdentityMapping(String envCrn, SdxCluster sdxCluster, Map<String, String> azureUserMapping) { String stackCrn = sdxCluster.getStackCrn(); LOGGER.info("Updating azure cloud id mappings for envCrn = {}, datalake stack crn = {}", envCrn, stackCrn); try { if (!clouderaManagerRangerUtil.isCloudIdMappingSupported(sdxCluster.getStackCrn())) { return newSyncStatus(RangerCloudIdentitySyncState.NOT_APPLICABLE, "The datalake does not support cloud identity sync. Sync request is ignored."); } Optional<ApiCommand> apiCommand = clouderaManagerRangerUtil.setAzureCloudIdentityMapping(stackCrn, azureUserMapping); if (apiCommand.isEmpty()) { return newSyncStatus(RangerCloudIdentitySyncState.SUCCESS, "Sucessfully synced, no role refresh required"); } return toRangerCloudIdentitySyncStatus(apiCommand.get()); } catch (ApiException e) { LOGGER.error("Encountered api exception", e); return newSyncStatus(RangerCloudIdentitySyncState.FAILED, "Encountered cloudera manager api exception"); } }
RangerCloudIdentityService { private RangerCloudIdentitySyncStatus setAzureCloudIdentityMapping(String envCrn, SdxCluster sdxCluster, Map<String, String> azureUserMapping) { String stackCrn = sdxCluster.getStackCrn(); LOGGER.info("Updating azure cloud id mappings for envCrn = {}, datalake stack crn = {}", envCrn, stackCrn); try { if (!clouderaManagerRangerUtil.isCloudIdMappingSupported(sdxCluster.getStackCrn())) { return newSyncStatus(RangerCloudIdentitySyncState.NOT_APPLICABLE, "The datalake does not support cloud identity sync. Sync request is ignored."); } Optional<ApiCommand> apiCommand = clouderaManagerRangerUtil.setAzureCloudIdentityMapping(stackCrn, azureUserMapping); if (apiCommand.isEmpty()) { return newSyncStatus(RangerCloudIdentitySyncState.SUCCESS, "Sucessfully synced, no role refresh required"); } return toRangerCloudIdentitySyncStatus(apiCommand.get()); } catch (ApiException e) { LOGGER.error("Encountered api exception", e); return newSyncStatus(RangerCloudIdentitySyncState.FAILED, "Encountered cloudera manager api exception"); } } }
RangerCloudIdentityService { private RangerCloudIdentitySyncStatus setAzureCloudIdentityMapping(String envCrn, SdxCluster sdxCluster, Map<String, String> azureUserMapping) { String stackCrn = sdxCluster.getStackCrn(); LOGGER.info("Updating azure cloud id mappings for envCrn = {}, datalake stack crn = {}", envCrn, stackCrn); try { if (!clouderaManagerRangerUtil.isCloudIdMappingSupported(sdxCluster.getStackCrn())) { return newSyncStatus(RangerCloudIdentitySyncState.NOT_APPLICABLE, "The datalake does not support cloud identity sync. Sync request is ignored."); } Optional<ApiCommand> apiCommand = clouderaManagerRangerUtil.setAzureCloudIdentityMapping(stackCrn, azureUserMapping); if (apiCommand.isEmpty()) { return newSyncStatus(RangerCloudIdentitySyncState.SUCCESS, "Sucessfully synced, no role refresh required"); } return toRangerCloudIdentitySyncStatus(apiCommand.get()); } catch (ApiException e) { LOGGER.error("Encountered api exception", e); return newSyncStatus(RangerCloudIdentitySyncState.FAILED, "Encountered cloudera manager api exception"); } }  }
RangerCloudIdentityService { private RangerCloudIdentitySyncStatus setAzureCloudIdentityMapping(String envCrn, SdxCluster sdxCluster, Map<String, String> azureUserMapping) { String stackCrn = sdxCluster.getStackCrn(); LOGGER.info("Updating azure cloud id mappings for envCrn = {}, datalake stack crn = {}", envCrn, stackCrn); try { if (!clouderaManagerRangerUtil.isCloudIdMappingSupported(sdxCluster.getStackCrn())) { return newSyncStatus(RangerCloudIdentitySyncState.NOT_APPLICABLE, "The datalake does not support cloud identity sync. Sync request is ignored."); } Optional<ApiCommand> apiCommand = clouderaManagerRangerUtil.setAzureCloudIdentityMapping(stackCrn, azureUserMapping); if (apiCommand.isEmpty()) { return newSyncStatus(RangerCloudIdentitySyncState.SUCCESS, "Sucessfully synced, no role refresh required"); } return toRangerCloudIdentitySyncStatus(apiCommand.get()); } catch (ApiException e) { LOGGER.error("Encountered api exception", e); return newSyncStatus(RangerCloudIdentitySyncState.FAILED, "Encountered cloudera manager api exception"); } }  Optional<RangerCloudIdentitySyncStatus> checkIfUnapplicable(Optional<SdxCluster> sdxCluster); RangerCloudIdentitySyncStatus setAzureCloudIdentityMapping(String envCrn, Map<String, String> azureUserMapping); RangerCloudIdentitySyncStatus getRangerCloudIdentitySyncStatus(String envCrn, long commandId); }
RangerCloudIdentityService { private RangerCloudIdentitySyncStatus setAzureCloudIdentityMapping(String envCrn, SdxCluster sdxCluster, Map<String, String> azureUserMapping) { String stackCrn = sdxCluster.getStackCrn(); LOGGER.info("Updating azure cloud id mappings for envCrn = {}, datalake stack crn = {}", envCrn, stackCrn); try { if (!clouderaManagerRangerUtil.isCloudIdMappingSupported(sdxCluster.getStackCrn())) { return newSyncStatus(RangerCloudIdentitySyncState.NOT_APPLICABLE, "The datalake does not support cloud identity sync. Sync request is ignored."); } Optional<ApiCommand> apiCommand = clouderaManagerRangerUtil.setAzureCloudIdentityMapping(stackCrn, azureUserMapping); if (apiCommand.isEmpty()) { return newSyncStatus(RangerCloudIdentitySyncState.SUCCESS, "Sucessfully synced, no role refresh required"); } return toRangerCloudIdentitySyncStatus(apiCommand.get()); } catch (ApiException e) { LOGGER.error("Encountered api exception", e); return newSyncStatus(RangerCloudIdentitySyncState.FAILED, "Encountered cloudera manager api exception"); } }  Optional<RangerCloudIdentitySyncStatus> checkIfUnapplicable(Optional<SdxCluster> sdxCluster); RangerCloudIdentitySyncStatus setAzureCloudIdentityMapping(String envCrn, Map<String, String> azureUserMapping); RangerCloudIdentitySyncStatus getRangerCloudIdentitySyncStatus(String envCrn, long commandId);  }