use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerClientActions method checkCmKnoxIDBrokerRoleConfigGroups.
public SdxInternalTestDto checkCmKnoxIDBrokerRoleConfigGroups(SdxInternalTestDto testDto, String user, String password) {
String serverFqdn = testDto.getResponse().getStackV4Response().getCluster().getServerFqdn();
ApiClient apiClient = getCmApiClient(serverFqdn, testDto.getName(), V_43, user, password);
// CHECKSTYLE:OFF
RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = new RoleConfigGroupsResourceApi(apiClient);
// CHECKSTYLE:ON
try {
ApiConfigList knoxConfigs = roleConfigGroupsResourceApi.readConfig(testDto.getName(), "knox-IDBROKER-BASE", "knox", "full");
knoxConfigs.getItems().stream().forEach(knoxConfig -> {
String knoxConfigName = knoxConfig.getName();
String mappingsFromKnoxConfig = knoxConfig.getValue();
if (String.join("_", "idbroker", cloudProvider, "group", "mapping").equalsIgnoreCase(knoxConfigName)) {
if (!mappingsFromKnoxConfig.contains("_c_cm_admins_")) {
LOGGER.error("{} does not contains the expected 'CM Admins' mapping!", knoxConfigName);
throw new TestFailException(String.format("%s does not contains the expected 'CM Admins' mapping!", knoxConfigName));
} else {
Log.log(LOGGER, format(" '%s' contains the expected '%s' mapping. ", knoxConfigName, mappingsFromKnoxConfig));
}
} else if (String.join("_", "idbroker", cloudProvider, "user", "mapping").equalsIgnoreCase(knoxConfigName)) {
if (!mappingsFromKnoxConfig.contains("hive")) {
LOGGER.error("{} does not contains the expected 'Hive' mapping!", knoxConfigName);
throw new TestFailException(String.format("%s does not contains the expected 'Hive' mapping!", knoxConfigName));
} else {
Log.log(LOGGER, format(" '%s' contains the expected ['%s'] mappings. ", knoxConfigName, mappingsFromKnoxConfig));
}
}
});
if (knoxConfigs.getItems().isEmpty()) {
LOGGER.error("IDBroker mappings are NOT exist!");
throw new TestFailException("IDBroker mappings are NOT exist!");
}
} catch (ApiException e) {
LOGGER.error("Exception when calling RoleConfigGroupsResourceApi#readConfig. Response: {}", e.getResponseBody(), e);
String message = format("Exception when calling RoleConfigGroupsResourceApi#readConfig at %s. Response: %s", apiClient.getBasePath(), e.getResponseBody());
throw new TestFailException(message, e);
} catch (Exception e) {
LOGGER.error("Can't get users' list at: '{}'!", apiClient.getBasePath());
throw new TestFailException("Can't get users' list at: " + apiClient.getBasePath(), e);
}
return testDto;
}
use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerCommunicator method getRoleConfigPropertiesFromCM.
public Map<String, ApiConfig> getRoleConfigPropertiesFromCM(Cluster cluster, String serviceName, String roleGroupRef, Set roleConfigPropertyNames) {
LOGGER.debug("Retrieving roleConfigProperties for cluster '{}', service '{}', roleGroupRef '{}'", cluster.getStackCrn(), serviceName, roleGroupRef);
HttpClientConfig httpClientConfig = tlsHttpClientConfigurationService.buildTLSClientConfig(cluster.getStackCrn(), cluster.getClusterManager().getHost(), cluster.getTunnel());
ClusterManager cm = cluster.getClusterManager();
String user = secretService.get(cm.getUser());
String pass = secretService.get(cm.getPass());
Map<String, ApiConfig> roleConfigProperties = requestLogging.logResponseTime(() -> {
try {
ApiClient client = clouderaManagerApiClientProvider.getV31Client(Integer.valueOf(cm.getPort()), user, pass, httpClientConfig);
client.getHttpClient().interceptors().add(cmOkHttpTracingInterceptor);
client.getHttpClient().interceptors().add(cmRequestIdProviderInterceptor);
RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(client);
return roleConfigGroupsResourceApi.readConfig(cluster.getStackName(), roleGroupRef, serviceName, DataView.FULL.name()).getItems().stream().filter(apiConfig -> roleConfigPropertyNames.contains(apiConfig.getName())).collect(Collectors.toMap(ApiConfig::getName, apiConfig -> apiConfig));
} catch (Exception ex) {
throw new RuntimeException(String.format("Error retrieving roleConfigProperties for cluster '%s', service '%s', roleGroupRef '%s'", cluster.getStackCrn(), serviceName, roleGroupRef), ex);
}
}, String.format("getRoleConfigPropertiesFromCM for cluster crn '%s'", cluster.getStackCrn()));
LOGGER.debug("Retrieved roleConfigPropertyValues for cluster '{}', service '{}', roleGroupRef '{}', roleConfigProperties '{}", cluster.getStackCrn(), serviceName, roleGroupRef, roleConfigProperties.values().stream().map(apiConfig -> String.format("ApiConfig Name '%s, Value '%s', Default '%s", apiConfig.getName(), apiConfig.getValue(), apiConfig.getDefault())).collect(Collectors.toSet()));
return roleConfigProperties;
}
use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerConfigServiceTest method testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenRoleTypeNotFound.
@Test
public void testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenRoleTypeNotFound() throws ApiException {
RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = Mockito.mock(RoleConfigGroupsResourceApi.class);
ServicesResourceApi servicesResourceApi = Mockito.mock(ServicesResourceApi.class);
when(clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(API_CLIENT)).thenReturn(roleConfigGroupsResourceApi);
when(clouderaManagerApiFactory.getServicesResourceApi(API_CLIENT)).thenReturn(servicesResourceApi);
List<ApiService> services = List.of(createApiService(NIFI_SERVICE, NIFI_SERVICE_TYPE), createApiService("SPARK", "SPARK-ROLE"));
when(servicesResourceApi.readServices(eq(TEST_CLUSTER_NAME), any())).thenReturn(createApiServiceList(services));
ApiRoleConfigGroupList configGroupList = createApiRoleConfigGroups(List.of(createConfigGroup("SPARK-GROUP", "SPARK-ROLE")));
when(roleConfigGroupsResourceApi.readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE)).thenReturn(configGroupList);
Optional<String> actual = underTest.getRoleConfigValueByServiceType(API_CLIENT, TEST_CLUSTER_NAME, NIFI_ROLE, NIFI_SERVICE_TYPE, CONFIG_NAME);
assertEquals(Optional.empty(), actual);
verify(clouderaManagerApiFactory).getRoleConfigGroupsResourceApi(API_CLIENT);
verify(clouderaManagerApiFactory).getServicesResourceApi(API_CLIENT);
verify(servicesResourceApi).readServices(eq(TEST_CLUSTER_NAME), any());
verify(roleConfigGroupsResourceApi, times(1)).readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE);
}
use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerConfigServiceTest method testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenTheConfigNotFound.
@Test
public void testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenTheConfigNotFound() throws ApiException {
RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = Mockito.mock(RoleConfigGroupsResourceApi.class);
ServicesResourceApi servicesResourceApi = Mockito.mock(ServicesResourceApi.class);
when(clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(API_CLIENT)).thenReturn(roleConfigGroupsResourceApi);
when(clouderaManagerApiFactory.getServicesResourceApi(API_CLIENT)).thenReturn(servicesResourceApi);
List<ApiService> services = List.of(createApiService(NIFI_SERVICE, NIFI_SERVICE_TYPE), createApiService("SPARK", "SPARK-ROLE"));
when(servicesResourceApi.readServices(eq(TEST_CLUSTER_NAME), any())).thenReturn(createApiServiceList(services));
ApiRoleConfigGroupList configGroupList = createApiRoleConfigGroups(List.of(createConfigGroup(NIFI_CONFIG_GROUP, NIFI_ROLE), createConfigGroup("SPARK-GROUP", "SPARK-ROLE")));
when(roleConfigGroupsResourceApi.readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE)).thenReturn(configGroupList);
ApiConfigList roleConfig = createApiConfigList(Collections.emptyList());
when(roleConfigGroupsResourceApi.readConfig(TEST_CLUSTER_NAME, NIFI_CONFIG_GROUP, NIFI_SERVICE, CONFIG_VIEW)).thenReturn(roleConfig);
Optional<String> actual = underTest.getRoleConfigValueByServiceType(API_CLIENT, TEST_CLUSTER_NAME, NIFI_ROLE, NIFI_SERVICE_TYPE, CONFIG_NAME);
assertEquals(Optional.empty(), actual);
verify(clouderaManagerApiFactory).getRoleConfigGroupsResourceApi(API_CLIENT);
verify(clouderaManagerApiFactory).getServicesResourceApi(API_CLIENT);
verify(servicesResourceApi).readServices(eq(TEST_CLUSTER_NAME), any());
verify(roleConfigGroupsResourceApi).readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE);
verify(roleConfigGroupsResourceApi).readConfig(TEST_CLUSTER_NAME, NIFI_CONFIG_GROUP, NIFI_SERVICE, CONFIG_VIEW);
}
use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerConfigServiceTest method testGetRoleConfigValueByServiceTypeShouldReturnTheConfigValueWhenTheValueIsNullAndDefaultValuePresent.
@Test
public void testGetRoleConfigValueByServiceTypeShouldReturnTheConfigValueWhenTheValueIsNullAndDefaultValuePresent() throws ApiException {
RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = Mockito.mock(RoleConfigGroupsResourceApi.class);
ServicesResourceApi servicesResourceApi = Mockito.mock(ServicesResourceApi.class);
when(clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(API_CLIENT)).thenReturn(roleConfigGroupsResourceApi);
when(clouderaManagerApiFactory.getServicesResourceApi(API_CLIENT)).thenReturn(servicesResourceApi);
List<ApiService> services = List.of(createApiService(NIFI_SERVICE, NIFI_SERVICE_TYPE), createApiService("SPARK", "SPARK-ROLE"));
when(servicesResourceApi.readServices(eq(TEST_CLUSTER_NAME), any())).thenReturn(createApiServiceList(services));
ApiRoleConfigGroupList configGroupList = createApiRoleConfigGroups(List.of(createConfigGroup(NIFI_CONFIG_GROUP, NIFI_ROLE), createConfigGroup("SPARK-GROUP", "SPARK-ROLE")));
when(roleConfigGroupsResourceApi.readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE)).thenReturn(configGroupList);
ApiConfigList roleConfig = createApiConfigList(List.of(createConfig(null, DEFAULT_VALUE)));
when(roleConfigGroupsResourceApi.readConfig(TEST_CLUSTER_NAME, NIFI_CONFIG_GROUP, NIFI_SERVICE, CONFIG_VIEW)).thenReturn(roleConfig);
Optional<String> actual = underTest.getRoleConfigValueByServiceType(API_CLIENT, TEST_CLUSTER_NAME, NIFI_ROLE, NIFI_SERVICE_TYPE, CONFIG_NAME);
assertEquals(Optional.of(DEFAULT_VALUE), actual);
verify(clouderaManagerApiFactory).getRoleConfigGroupsResourceApi(API_CLIENT);
verify(clouderaManagerApiFactory).getServicesResourceApi(API_CLIENT);
verify(servicesResourceApi).readServices(eq(TEST_CLUSTER_NAME), any());
verify(roleConfigGroupsResourceApi).readRoleConfigGroups(TEST_CLUSTER_NAME, NIFI_SERVICE);
verify(roleConfigGroupsResourceApi).readConfig(TEST_CLUSTER_NAME, NIFI_CONFIG_GROUP, NIFI_SERVICE, CONFIG_VIEW);
}
Aggregations