@Test public void testSetAzureCloudIdentityMappingSameConfig() throws ApiException { when(clouderaManagerApiFactory.getClustersResourceApi(any())).thenReturn(clustersResourceApi); when(clouderaManagerApiFactory.getRolesResourceApi(any())).thenReturn(rolesResourceApi); setupCluster(); setupRangerUserSyncRole(); setupExistingAzureUserMapping("user01=val01;user02=val02"); setupRoleRefreshRequired(false); Optional<ApiCommand> apiCommand = underTest.setAzureCloudIdentityMapping("stackCrn", Map.of("user01", "val01", "user02", "val02")); assertTrue(apiCommand.isEmpty()); ArgumentCaptor<ApiConfigList> apiConfigListCaptor = ArgumentCaptor.forClass(ApiConfigList.class); verify(rolesResourceApi, never()).updateRoleConfig(eq(CLUSTER), eq(RANGER_USER_SYNC_ROLE), anyString(), anyString(), apiConfigListCaptor.capture()); verify(roleCommandsResourceApi, never()).refreshCommand(any(), any(), any()); }
public Optional<ApiCommand> setAzureCloudIdentityMapping(String stackCrn, Map<String, String> requestedAzureUserMapping) throws ApiException { ApiClient client = clouderaManagerProxiedClientFactory.getProxiedClouderaManagerClient(stackCrn); String clusterName = getClusterName(client); String rangerUserSyncRoleName = getRangerUserSyncRoleName(client, clusterName); RolesResourceApi rolesResourceApi = clouderaManagerApiFactory.getRolesResourceApi(client); Map<String, String> existingMappingStr = getExistingAzureUserMapping(rolesResourceApi, clusterName, rangerUserSyncRoleName); boolean operationRequired = !existingMappingStr.equals(requestedAzureUserMapping) || isRoleStale(rolesResourceApi, clusterName, rangerUserSyncRoleName); if (!operationRequired) { LOGGER.info("Existing azure cloud mappings are the same, nothing to do"); return Optional.empty(); } else { LOGGER.info("Existing azure cloud mappings are different (or role is stale), setting mapping and trigerring role refresh"); ApiConfigList configList = new ApiConfigList(); configList.addItemsItem(newCloudIdentityConfig(AZURE_USER_MAPPING, requestedAzureUserMapping)); rolesResourceApi.updateRoleConfig(clusterName, rangerUserSyncRoleName, RANGER_SERVICE_NAME, "Updating Azure Cloud Identity Mapping through Cloudbreak", configList); ApiCommand command = triggerRoleRefresh(client, clusterName, RANGER_SERVICE_NAME, rangerUserSyncRoleName); return Optional.of(command); } }
ClouderaManagerRangerUtil { public Optional<ApiCommand> setAzureCloudIdentityMapping(String stackCrn, Map<String, String> requestedAzureUserMapping) throws ApiException { ApiClient client = clouderaManagerProxiedClientFactory.getProxiedClouderaManagerClient(stackCrn); String clusterName = getClusterName(client); String rangerUserSyncRoleName = getRangerUserSyncRoleName(client, clusterName); RolesResourceApi rolesResourceApi = clouderaManagerApiFactory.getRolesResourceApi(client); Map<String, String> existingMappingStr = getExistingAzureUserMapping(rolesResourceApi, clusterName, rangerUserSyncRoleName); boolean operationRequired = !existingMappingStr.equals(requestedAzureUserMapping) || isRoleStale(rolesResourceApi, clusterName, rangerUserSyncRoleName); if (!operationRequired) { LOGGER.info("Existing azure cloud mappings are the same, nothing to do"); return Optional.empty(); } else { LOGGER.info("Existing azure cloud mappings are different (or role is stale), setting mapping and trigerring role refresh"); ApiConfigList configList = new ApiConfigList(); configList.addItemsItem(newCloudIdentityConfig(AZURE_USER_MAPPING, requestedAzureUserMapping)); rolesResourceApi.updateRoleConfig(clusterName, rangerUserSyncRoleName, RANGER_SERVICE_NAME, "Updating Azure Cloud Identity Mapping through Cloudbreak", configList); ApiCommand command = triggerRoleRefresh(client, clusterName, RANGER_SERVICE_NAME, rangerUserSyncRoleName); return Optional.of(command); } } }
ClouderaManagerRangerUtil { public Optional<ApiCommand> setAzureCloudIdentityMapping(String stackCrn, Map<String, String> requestedAzureUserMapping) throws ApiException { ApiClient client = clouderaManagerProxiedClientFactory.getProxiedClouderaManagerClient(stackCrn); String clusterName = getClusterName(client); String rangerUserSyncRoleName = getRangerUserSyncRoleName(client, clusterName); RolesResourceApi rolesResourceApi = clouderaManagerApiFactory.getRolesResourceApi(client); Map<String, String> existingMappingStr = getExistingAzureUserMapping(rolesResourceApi, clusterName, rangerUserSyncRoleName); boolean operationRequired = !existingMappingStr.equals(requestedAzureUserMapping) || isRoleStale(rolesResourceApi, clusterName, rangerUserSyncRoleName); if (!operationRequired) { LOGGER.info("Existing azure cloud mappings are the same, nothing to do"); return Optional.empty(); } else { LOGGER.info("Existing azure cloud mappings are different (or role is stale), setting mapping and trigerring role refresh"); ApiConfigList configList = new ApiConfigList(); configList.addItemsItem(newCloudIdentityConfig(AZURE_USER_MAPPING, requestedAzureUserMapping)); rolesResourceApi.updateRoleConfig(clusterName, rangerUserSyncRoleName, RANGER_SERVICE_NAME, "Updating Azure Cloud Identity Mapping through Cloudbreak", configList); ApiCommand command = triggerRoleRefresh(client, clusterName, RANGER_SERVICE_NAME, rangerUserSyncRoleName); return Optional.of(command); } }  }
ClouderaManagerRangerUtil { public Optional<ApiCommand> setAzureCloudIdentityMapping(String stackCrn, Map<String, String> requestedAzureUserMapping) throws ApiException { ApiClient client = clouderaManagerProxiedClientFactory.getProxiedClouderaManagerClient(stackCrn); String clusterName = getClusterName(client); String rangerUserSyncRoleName = getRangerUserSyncRoleName(client, clusterName); RolesResourceApi rolesResourceApi = clouderaManagerApiFactory.getRolesResourceApi(client); Map<String, String> existingMappingStr = getExistingAzureUserMapping(rolesResourceApi, clusterName, rangerUserSyncRoleName); boolean operationRequired = !existingMappingStr.equals(requestedAzureUserMapping) || isRoleStale(rolesResourceApi, clusterName, rangerUserSyncRoleName); if (!operationRequired) { LOGGER.info("Existing azure cloud mappings are the same, nothing to do"); return Optional.empty(); } else { LOGGER.info("Existing azure cloud mappings are different (or role is stale), setting mapping and trigerring role refresh"); ApiConfigList configList = new ApiConfigList(); configList.addItemsItem(newCloudIdentityConfig(AZURE_USER_MAPPING, requestedAzureUserMapping)); rolesResourceApi.updateRoleConfig(clusterName, rangerUserSyncRoleName, RANGER_SERVICE_NAME, "Updating Azure Cloud Identity Mapping through Cloudbreak", configList); ApiCommand command = triggerRoleRefresh(client, clusterName, RANGER_SERVICE_NAME, rangerUserSyncRoleName); return Optional.of(command); } }  boolean isCloudIdMappingSupported(String stackCrn); Optional<ApiCommand> setAzureCloudIdentityMapping(String stackCrn, Map<String, String> requestedAzureUserMapping); ApiCommand getApiCommand(String stackCrn, long commandId); }
ClouderaManagerRangerUtil { public Optional<ApiCommand> setAzureCloudIdentityMapping(String stackCrn, Map<String, String> requestedAzureUserMapping) throws ApiException { ApiClient client = clouderaManagerProxiedClientFactory.getProxiedClouderaManagerClient(stackCrn); String clusterName = getClusterName(client); String rangerUserSyncRoleName = getRangerUserSyncRoleName(client, clusterName); RolesResourceApi rolesResourceApi = clouderaManagerApiFactory.getRolesResourceApi(client); Map<String, String> existingMappingStr = getExistingAzureUserMapping(rolesResourceApi, clusterName, rangerUserSyncRoleName); boolean operationRequired = !existingMappingStr.equals(requestedAzureUserMapping) || isRoleStale(rolesResourceApi, clusterName, rangerUserSyncRoleName); if (!operationRequired) { LOGGER.info("Existing azure cloud mappings are the same, nothing to do"); return Optional.empty(); } else { LOGGER.info("Existing azure cloud mappings are different (or role is stale), setting mapping and trigerring role refresh"); ApiConfigList configList = new ApiConfigList(); configList.addItemsItem(newCloudIdentityConfig(AZURE_USER_MAPPING, requestedAzureUserMapping)); rolesResourceApi.updateRoleConfig(clusterName, rangerUserSyncRoleName, RANGER_SERVICE_NAME, "Updating Azure Cloud Identity Mapping through Cloudbreak", configList); ApiCommand command = triggerRoleRefresh(client, clusterName, RANGER_SERVICE_NAME, rangerUserSyncRoleName); return Optional.of(command); } }  boolean isCloudIdMappingSupported(String stackCrn); Optional<ApiCommand> setAzureCloudIdentityMapping(String stackCrn, Map<String, String> requestedAzureUserMapping); ApiCommand getApiCommand(String stackCrn, long commandId);  }