Search in sources :

Example 36 with HadoopException

use of org.apache.ranger.plugin.client.HadoopException in project ranger by apache.

the class ElasticsearchClient method getElasticsearchResourceResponse.

private <T> T getElasticsearchResourceResponse(ClientResponse response, Type type) {
    T resource = null;
    try {
        if (response != null && response.getStatus() == HttpStatus.SC_OK) {
            String jsonString = response.getEntity(String.class);
            Gson gson = new GsonBuilder().setPrettyPrinting().create();
            resource = gson.fromJson(jsonString, type);
        } else {
            String msgDesc = "Unable to get a valid response for " + "expected mime type : [" + MediaType.APPLICATION_JSON + "], elasticsearchUrl: " + elasticsearchUrl + " - got null response.";
            LOG.error(msgDesc);
            HadoopException hdpException = new HadoopException(msgDesc);
            hdpException.generateResponseDataMap(false, msgDesc, msgDesc + DEFAULT_ERROR_MESSAGE, null, null);
            throw hdpException;
        }
    } catch (HadoopException he) {
        throw he;
    } catch (Throwable t) {
        String msgDesc = "Exception while getting elasticsearch resource response, elasticsearchUrl: " + elasticsearchUrl;
        HadoopException hdpException = new HadoopException(msgDesc, t);
        LOG.error(msgDesc, t);
        hdpException.generateResponseDataMap(false, BaseClient.getMessage(t), msgDesc + DEFAULT_ERROR_MESSAGE, null, null);
        throw hdpException;
    } finally {
        if (response != null) {
            response.close();
        }
    }
    return resource;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) HadoopException(org.apache.ranger.plugin.client.HadoopException)

Example 37 with HadoopException

use of org.apache.ranger.plugin.client.HadoopException in project ranger by apache.

the class ElasticsearchClient method getElasticsearchClient.

public static ElasticsearchClient getElasticsearchClient(String serviceName, Map<String, String> configs) {
    ElasticsearchClient elasticsearchClient = null;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Getting elasticsearchClient for datasource: " + serviceName);
    }
    if (MapUtils.isEmpty(configs)) {
        String msgDesc = "Could not connect elasticsearch as connection configMap is empty.";
        LOG.error(msgDesc);
        HadoopException hdpException = new HadoopException(msgDesc);
        hdpException.generateResponseDataMap(false, msgDesc, msgDesc + DEFAULT_ERROR_MESSAGE, null, null);
        throw hdpException;
    } else {
        elasticsearchClient = new ElasticsearchClient(serviceName, configs);
    }
    return elasticsearchClient;
}
Also used : HadoopException(org.apache.ranger.plugin.client.HadoopException)

Aggregations

HadoopException (org.apache.ranger.plugin.client.HadoopException)37 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)9 SQLException (java.sql.SQLException)9 SQLTimeoutException (java.sql.SQLTimeoutException)8 ResultSet (java.sql.ResultSet)7 Statement (java.sql.Statement)7 Gson (com.google.gson.Gson)6 GsonBuilder (com.google.gson.GsonBuilder)6 PrivilegedAction (java.security.PrivilegedAction)6 Client (com.sun.jersey.api.client.Client)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)5 WebResource (com.sun.jersey.api.client.WebResource)5 BaseClient (org.apache.ranger.plugin.client.BaseClient)5 List (java.util.List)3 Subject (javax.security.auth.Subject)3 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 Driver (java.sql.Driver)2