use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerConfigServiceTest method testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenServiceTypeNotFound.
@Test
public void testGetRoleConfigValueByServiceTypeShouldReturnOptionalEmptyWhenServiceTypeNotFound() 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("SPARK", "SPARK-ROLE"));
when(servicesResourceApi.readServices(eq(TEST_CLUSTER_NAME), any())).thenReturn(createApiServiceList(services));
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());
verifyNoInteractions(roleConfigGroupsResourceApi);
verifyNoInteractions(roleConfigGroupsResourceApi);
}
use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerConfigServiceTest method testGetRoleConfigValueByServiceTypeShouldReturnTheConfigValue.
@Test
public void testGetRoleConfigValueByServiceTypeShouldReturnTheConfigValue() 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(CONFIG_VALUE, null)));
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(CONFIG_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);
}
use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerConfigService method getRoleConfigValueByServiceType.
public Optional<String> getRoleConfigValueByServiceType(ApiClient apiClient, String clusterName, String roleType, String serviceType, String configName) {
LOGGER.debug("Looking for configuration: {} for cluster {}, roleType {}, and serviceType {}", configName, clusterName, roleType, serviceType);
RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(apiClient);
ServicesResourceApi servicesResourceApi = clouderaManagerApiFactory.getServicesResourceApi(apiClient);
try {
String serviceName = getServiceNameValue(clusterName, serviceType, servicesResourceApi);
String roleConfigGroupName = getRoleConfigGroupNameByTypeAndServiceName(roleType, clusterName, serviceName, roleConfigGroupsResourceApi);
ApiConfigList roleConfig = roleConfigGroupsResourceApi.readConfig(clusterName, roleConfigGroupName, serviceName, "full");
return roleConfig.getItems().stream().filter(apiConfig -> configName.equals(apiConfig.getName())).map(apiConfig -> Optional.ofNullable(apiConfig.getValue()).orElse(apiConfig.getDefault())).findFirst();
} catch (ApiException | NotFoundException e) {
LOGGER.debug("Failed to get configuration: {} for cluster {}, roleType {}, and serviceType {}", configName, clusterName, roleType, serviceType, e);
return Optional.empty();
}
}
use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerClientActions method checkCmHdfsNamenodeRoleConfigGroups.
public DistroXTestDto checkCmHdfsNamenodeRoleConfigGroups(DistroXTestDto testDto, String user, String password, Set<String> mountPoints) {
String serverIp = testDto.getResponse().getCluster().getServerIp();
ApiClient apiClient = getCmApiClientWithTimeoutDisabled(serverIp, testDto.getName(), V_43, user, password);
// CHECKSTYLE:OFF
RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = new RoleConfigGroupsResourceApi(apiClient);
// CHECKSTYLE:ON
try {
ApiConfigList hdfsConfigs = roleConfigGroupsResourceApi.readConfig(testDto.getName(), "hdfs-NAMENODE-BASE", "hdfs", "summary");
hdfsConfigs.getItems().forEach(config -> {
String hdfsConfigName = config.getName();
String mappingsFromHdfsConfig = config.getValue();
if ("dfs_name_dir_list".equalsIgnoreCase(hdfsConfigName)) {
if (mountPoints.stream().anyMatch(mappingsFromHdfsConfig::startsWith)) {
LOGGER.error("{} contains ephemeral volume mapping '{}'!", hdfsConfigName, mappingsFromHdfsConfig);
throw new TestFailException(String.format("%s contains ephemeral volume mapping '%s'!", hdfsConfigName, mappingsFromHdfsConfig));
} else {
Log.log(LOGGER, format(" '%s' does not contain the ephemeral mapping '%s', as expected. ", hdfsConfigName, mappingsFromHdfsConfig));
}
}
});
if (hdfsConfigs.getItems().isEmpty()) {
LOGGER.error("Namenode mappings are NOT exist!");
throw new TestFailException("Namenode 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 read config at: '{}'!", apiClient.getBasePath());
throw new TestFailException("Can't read config at: " + apiClient.getBasePath(), e);
}
return testDto;
}
use of com.cloudera.api.swagger.RoleConfigGroupsResourceApi in project cloudbreak by hortonworks.
the class ClouderaManagerClientActions method checkCmYarnNodemanagerRoleConfigGroups.
private DistroXTestDto checkCmYarnNodemanagerRoleConfigGroups(ApiClient apiClient, DistroXTestDto testDto, String user, String password) {
// CHECKSTYLE:OFF
RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = new RoleConfigGroupsResourceApi(apiClient);
// CHECKSTYLE:ON
try {
ApiConfigList knoxConfigs = roleConfigGroupsResourceApi.readConfig(testDto.getName(), "yarn-NODEMANAGER-BASE", "yarn", "full");
knoxConfigs.getItems().stream().forEach(knoxConfig -> {
String knoxConfigName = knoxConfig.getName();
String mappingsFromKnoxConfig = knoxConfig.getValue();
if ("yarn_nodemanager_local_dirs".equalsIgnoreCase(knoxConfigName)) {
if (!mappingsFromKnoxConfig.startsWith("/hadoopfs/ephfs")) {
LOGGER.error("{} does not contains the expected '/hadoopfs/ephfs...' mapping!", knoxConfigName);
throw new TestFailException(String.format("%s does not contains the expected '/hadoopfs/ephfs...' mapping!", knoxConfigName));
} else {
Log.log(LOGGER, format(" '%s' contains the expected '%s' mapping. ", knoxConfigName, mappingsFromKnoxConfig));
}
}
});
if (knoxConfigs.getItems().isEmpty()) {
LOGGER.error("Nodemanager mappings are NOT exist!");
throw new TestFailException("Nodemanager 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 role configs at: '{}'!", apiClient.getBasePath());
throw new TestFailException("Can't get role configs at: " + apiClient.getBasePath(), e);
}
return testDto;
}
Aggregations