Search in sources :

Example 1 with ApiException

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;
}
Also used : HadoopHostedService(org.talend.repository.hadoopcluster.configurator.HadoopHostedService) HashMap(java.util.HashMap) ApiService(com.cloudera.api.swagger.model.ApiService) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) HadoopClusterService(org.talend.repository.hadoopcluster.configurator.HadoopClusterService) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 2 with ApiException

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;
}
Also used : ApiClusterList(com.cloudera.api.swagger.model.ApiClusterList) ApiCluster(com.cloudera.api.swagger.model.ApiCluster) ArrayList(java.util.ArrayList) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 3 with ApiException

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);
}
Also used : ServiceModel(org.apache.knox.gateway.topology.discovery.cm.ServiceModel) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 4 with ApiException

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;
}
Also used : ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ApiRole(com.cloudera.api.swagger.model.ApiRole) ApiConfigList(com.cloudera.api.swagger.model.ApiConfigList) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RolesResourceApi(com.cloudera.api.swagger.RolesResourceApi) ApiRoleList(com.cloudera.api.swagger.model.ApiRoleList) ApiClient(com.cloudera.api.swagger.client.ApiClient) DiscoveryApiClient(org.apache.knox.gateway.topology.discovery.cm.DiscoveryApiClient) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 5 with ApiException

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);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ZipInputStream(java.util.zip.ZipInputStream) Configuration(org.apache.hadoop.conf.Configuration) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) File(java.io.File) Date(java.util.Date) FileInputStream(java.io.FileInputStream) ApiException(com.cloudera.api.swagger.client.ApiException)

Aggregations

ApiException (com.cloudera.api.swagger.client.ApiException)7 ArrayList (java.util.ArrayList)3 ApiService (com.cloudera.api.swagger.model.ApiService)2 ApiServiceList (com.cloudera.api.swagger.model.ApiServiceList)2 HashMap (java.util.HashMap)2 EventsResourceApi (com.cloudera.api.swagger.EventsResourceApi)1 RolesResourceApi (com.cloudera.api.swagger.RolesResourceApi)1 ServicesResourceApi (com.cloudera.api.swagger.ServicesResourceApi)1 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 ApiCluster (com.cloudera.api.swagger.model.ApiCluster)1 ApiClusterList (com.cloudera.api.swagger.model.ApiClusterList)1 ApiConfigList (com.cloudera.api.swagger.model.ApiConfigList)1 ApiEvent (com.cloudera.api.swagger.model.ApiEvent)1 ApiEventQueryResult (com.cloudera.api.swagger.model.ApiEventQueryResult)1 ApiRole (com.cloudera.api.swagger.model.ApiRole)1 ApiRoleList (com.cloudera.api.swagger.model.ApiRoleList)1 ApiServiceConfig (com.cloudera.api.swagger.model.ApiServiceConfig)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1