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;
}
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;
}
Aggregations