Search in sources :

Example 1 with ApiClient

use of com.cloudera.api.swagger.client.ApiClient 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 2 with ApiClient

use of com.cloudera.api.swagger.client.ApiClient in project tbd-studio-se by Talend.

the class HadoopCMConfigurator method createClient.

private ApiClient createClient(Builder build) throws CertificateEncodingException {
    ApiClient cmClient = Configuration.getDefaultApiClient();
    StringBuffer sb = new StringBuffer(build.url.toString());
    if (!sb.toString().endsWith("/")) {
        sb.append("/");
    }
    sb.append("api");
    cmClient.setBasePath(sb.toString());
    cmClient.setUsername(build.user);
    cmClient.setPassword(build.password);
    // trust manager can be null for non https connection
    if (build.tms != null) {
        StringBuffer caCerts = new StringBuffer();
        for (TrustManager tm : build.tms) {
            if (tm instanceof X509TrustManager) {
                X509TrustManager xtm = (X509TrustManager) tm;
                buildCaCerts(caCerts, xtm);
            }
        }
        if (caCerts.length() > 0) {
            cmClient.setSslCaCert(new ByteArrayInputStream(caCerts.toString().getBytes()));
        }
    }
    return cmClient;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) X509TrustManager(javax.net.ssl.X509TrustManager) ApiClient(com.cloudera.api.swagger.client.ApiClient) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Aggregations

ApiClient (com.cloudera.api.swagger.client.ApiClient)2 RolesResourceApi (com.cloudera.api.swagger.RolesResourceApi)1 ServicesResourceApi (com.cloudera.api.swagger.ServicesResourceApi)1 ApiException (com.cloudera.api.swagger.client.ApiException)1 ApiConfigList (com.cloudera.api.swagger.model.ApiConfigList)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 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TrustManager (javax.net.ssl.TrustManager)1 X509TrustManager (javax.net.ssl.X509TrustManager)1 DiscoveryApiClient (org.apache.knox.gateway.topology.discovery.cm.DiscoveryApiClient)1