use of com.cloudera.api.swagger.client.ApiException in project tbd-studio-se by Talend.
the class HadoopCMCluster method getHostedServices.
/*
* (non-Javadoc)
*
* @see org.talend.repository.hadoopcluster.configurator.HadoopCluster#getHostedServices()
*/
@Override
public Map<HadoopHostedService, HadoopClusterService> getHostedServices() {
Map<HadoopHostedService, HadoopClusterService> servicesMapping = new HashMap<HadoopHostedService, HadoopClusterService>();
ApiServiceList services;
try {
services = this.serviceAPI.readServices(this.clusterName, DEFAULT_VIEW_NAME);
for (ApiService service : services.getItems()) {
if (HadoopHostedService.isSupport(service.getType())) {
HadoopCMClusterService clusterService = new HadoopCMClusterService(this.clusterName, service.getName(), this.serviceAPI, blacklistParams);
if (clusterService.hasConfigurations()) {
servicesMapping.put(HadoopHostedService.fromString(service.getType()), clusterService);
}
}
}
} catch (ApiException e) {
throw new RuntimeException(e);
}
return servicesMapping;
}
use of com.cloudera.api.swagger.client.ApiException in project tbd-studio-se by Talend.
the class HadoopCMConfigurator method getAllClusters.
/*
* (non-Javadoc)
*
* @see org.talend.repository.hadoopcluster.configurator.HadoopConfigurator#getAllClusters()
*/
@Override
public List<String> getAllClusters() {
List<String> names = new ArrayList<String>();
ApiClusterList clusters;
try {
clusters = clusterAPI.readClusters(null, HadoopCMCluster.DEFAULT_VIEW_NAME);
for (ApiCluster cluster : clusters.getItems()) {
names.add(cluster.getDisplayName() + NAME_SEPARATOR + cluster.getName());
}
} catch (ApiException e) {
throw new RuntimeException(e);
}
return names;
}
use of com.cloudera.api.swagger.client.ApiException in project knox by apache.
the class ClouderaManagerAPIServiceModelGenerator method generateService.
/**
* This method functions differently than others. This method inquires the
* discovery client and uses the CM url used by the driver (which was
* populated by the descriptor).
*
* @param service Service.
* @param serviceConfig Service config.
* @param role Role.
* @param roleConfig Role config.
* @return ServiceModel for given service and role.
* @throws ApiException Exception interacting with CM.
*/
@Override
public ServiceModel generateService(ApiService service, ApiServiceConfig serviceConfig, ApiRole role, ApiConfigList roleConfig) throws ApiException {
final String basePath = getClient().getBasePath();
URI uri;
try {
uri = new URI(basePath);
} catch (URISyntaxException e) {
throw new ApiException(e);
}
final String serviceURL = getModelType() == ServiceModel.Type.API ? String.format(Locale.getDefault(), "%s://%s:%s/api", uri.getScheme(), uri.getHost(), uri.getPort()) : String.format(Locale.getDefault(), "%s://%s:%s", uri.getScheme(), uri.getHost(), uri.getPort());
return new ServiceModel(getModelType(), getService(), getServiceType(), getRoleType(), serviceURL);
}
use of com.cloudera.api.swagger.client.ApiException 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;
}
use of com.cloudera.api.swagger.client.ApiException in project tbd-studio-se by Talend.
the class HadoopCMClusterService method init.
/**
* DOC bchen Comment method "init".
*/
private void init(List<String> blacklistParams) {
confs = new HashMap<>();
try {
File configZipFile = this.serviceAPI.getClientConfig(this.clusterName, this.serviceName);
File directory = new File(System.getProperty("java.io.tmpdir"), "Talend_Hadoop_Wizard_" + serviceName + String.valueOf(new Date().getTime()) + Thread.currentThread().getId());
ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(configZipFile));
ZipEntry configInputZipEntry = null;
while ((configInputZipEntry = zipInputStream.getNextEntry()) != null) {
String configFile = getConfFileName(configInputZipEntry.getName());
if (!configFile.endsWith(SUPPORT_FILE)) {
continue;
}
directory.mkdirs();
File file = new File(directory, configFile);
writeZipIntoFile(zipInputStream, file);
Configuration conf = new Configuration(false);
// build configuration by file
conf.addResource(new Path(file.toURI()));
conf = filterByBlacklist(conf, blacklistParams);
confs.put(configFile, conf);
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ApiException e) {
if (e.getCode() == 400 && e.getResponseBody().contains(IGNORE_ERROR_MSG)) {
Logger.getLogger(this.getClass()).info("service: " + this.serviceName + " " + IGNORE_ERROR_MSG);
} else {
throw new RuntimeException(e);
}
}
}
Aggregations