use of com.cloudera.api.swagger.RolesResourceApi in project knox by apache.
the class ClouderaManagerServiceDiscovery method discoverCluster.
private ClouderaManagerCluster discoverCluster(DiscoveryApiClient client, String clusterName, Collection<String> includedServices) throws ApiException {
ServicesResourceApi servicesResourceApi = new ServicesResourceApi(client);
RolesResourceApi rolesResourceApi = new RolesResourceApi(client);
log.discoveringCluster(clusterName);
repository.registerCluster(client.getConfig());
Set<ServiceModel> serviceModels = new HashSet<>();
List<ApiService> serviceList = getClusterServices(client.getConfig(), servicesResourceApi);
if (serviceList != null) {
/*
Since Cloudera Manager does not have a service for itself, we will add a skeleton CM
service so that we can add CM service to topology when auto-discovery is
turned on and CM service is selected in the descriptor
*/
final ApiService cmService = new ApiService();
cmService.setName(CM_SERVICE_TYPE.toLowerCase(Locale.ROOT));
cmService.setType(CM_SERVICE_TYPE);
serviceList.add(cmService);
for (ApiService service : serviceList) {
final List<ServiceModelGenerator> modelGenerators = serviceModelGenerators.get(service.getType());
if (shouldSkipServiceDiscovery(modelGenerators, includedServices)) {
log.skipServiceDiscovery(service.getName(), service.getType());
continue;
}
log.discoveringService(service.getName(), service.getType());
ApiServiceConfig serviceConfig = null;
/* no reason to check service config for CM service */
if (!CM_SERVICE_TYPE.equals(service.getType())) {
serviceConfig = getServiceConfig(client.getConfig(), servicesResourceApi, service);
}
ApiRoleList roleList = getRoles(client.getConfig(), rolesResourceApi, clusterName, service);
if (roleList != null) {
for (ApiRole role : roleList.getItems()) {
String roleName = role.getName();
log.discoveringServiceRole(roleName, role.getType());
ApiConfigList roleConfig = null;
/* no reason to check role config for CM service */
if (!CM_SERVICE_TYPE.equals(service.getType())) {
roleConfig = getRoleConfig(client.getConfig(), rolesResourceApi, service, role);
}
if (modelGenerators != null) {
for (ServiceModelGenerator serviceModelGenerator : modelGenerators) {
ServiceModelGeneratorHandleResponse response = serviceModelGenerator.handles(service, serviceConfig, role, roleConfig);
if (response.handled()) {
serviceModelGenerator.setApiClient(client);
ServiceModel serviceModel = serviceModelGenerator.generateService(service, serviceConfig, role, roleConfig);
serviceModels.add(serviceModel);
} else if (!response.getConfigurationIssues().isEmpty()) {
log.serviceRoleHasConfigurationIssues(roleName, String.join(";", response.getConfigurationIssues()));
}
}
}
log.discoveredServiceRole(roleName, role.getType());
}
}
log.discoveredService(service.getName(), service.getType());
}
ClouderaManagerCluster cluster = new ClouderaManagerCluster(clusterName);
cluster.addServiceModels(serviceModels);
return cluster;
}
return null;
}
use of com.cloudera.api.swagger.RolesResourceApi in project knox by apache.
the class PollingConfigurationAnalyzer method getCurrentServiceConfiguration.
/**
* Get the current configuration for the specified service.
*
* @param address The address of the ClouderaManager instance.
* @param clusterName The name of the cluster.
* @param service The name of the service.
*
* @return A ServiceConfigurationModel object with the configuration properties associated with the specified
* service.
*/
protected ServiceConfigurationModel getCurrentServiceConfiguration(final String address, final String clusterName, final String service) {
ServiceConfigurationModel currentConfig = null;
log.gettingCurrentClusterConfiguration(service, clusterName, address);
ApiClient apiClient = getApiClient(configCache.getDiscoveryConfig(address, clusterName));
ServicesResourceApi api = new ServicesResourceApi(apiClient);
try {
ApiServiceConfig svcConfig = api.readServiceConfig(clusterName, service, "full");
Map<ApiRole, ApiConfigList> roleConfigs = new HashMap<>();
RolesResourceApi rolesApi = (new RolesResourceApi(apiClient));
ApiRoleList roles = rolesApi.readRoles(clusterName, service, "", "full");
for (ApiRole role : roles.getItems()) {
ApiConfigList config = rolesApi.readRoleConfig(clusterName, role.getName(), service, "full");
roleConfigs.put(role, config);
}
currentConfig = new ServiceConfigurationModel(svcConfig, roleConfigs);
} catch (ApiException e) {
log.clouderaManagerConfigurationAPIError(e);
}
return currentConfig;
}
Aggregations