use of co.cask.cdap.explore.service.ExploreException in project cdap by caskdata.
the class ExploreHttpClient method doRequest.
private HttpResponse doRequest(String resource, HttpMethod requestMethod, @Nullable Map<String, String> headers, @Nullable String body) throws ExploreException {
Map<String, String> newHeaders = addSecurityHeaders(headers);
String resolvedUrl = resolve(resource);
try {
URL url = new URL(resolvedUrl);
HttpRequest.Builder builder = HttpRequest.builder(requestMethod, url).addHeaders(newHeaders);
if (body != null) {
builder.withBody(body);
}
return HttpRequests.execute(builder.build(), createRequestConfig());
} catch (IOException e) {
throw new ExploreException(String.format("Error connecting to Explore Service at %s while doing %s with headers %s and body %s", resolvedUrl, requestMethod, newHeaders == null ? "null" : Joiner.on(",").withKeyValueSeparator("=").join(newHeaders), body == null ? "null" : body), e);
}
}
use of co.cask.cdap.explore.service.ExploreException in project cdap by caskdata.
the class ExploreHttpClient method doDropPartition.
protected QueryHandle doDropPartition(DatasetId datasetInstance, DatasetSpecification spec, PartitionKey key) throws ExploreException {
Map<String, String> args = new HashMap<>();
PartitionedFileSetArguments.setOutputPartitionKey(args, key);
String tableName = ExploreProperties.getExploreTableName(spec.getProperties());
String databaseName = ExploreProperties.getExploreDatabaseName(spec.getProperties());
if (tableName != null) {
args.put(ExploreProperties.PROPERTY_EXPLORE_TABLE_NAME, tableName);
}
if (databaseName != null) {
args.put(ExploreProperties.PROPERTY_EXPLORE_DATABASE_NAME, databaseName);
}
HttpResponse response = doPost(String.format("namespaces/%s/data/explore/datasets/%s/deletePartition", datasetInstance.getNamespace(), datasetInstance.getEntityName()), GSON.toJson(args), null);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
}
throw new ExploreException(String.format("Cannot drop partition with key %s from dataset %s. Reason: %s", key, datasetInstance.toString(), response));
}
use of co.cask.cdap.explore.service.ExploreException in project cdap by caskdata.
the class ExploreHttpClient method doDisableExploreDataset.
protected QueryHandle doDisableExploreDataset(DatasetId datasetInstance, DatasetSpecification spec) throws ExploreException {
String body = spec == null ? null : GSON.toJson(new DisableExploreParameters(spec));
String endpoint = spec == null ? "disable" : "disable-internal";
HttpResponse response = doPost(String.format("namespaces/%s/data/explore/datasets/%s/%s", datasetInstance.getNamespace(), datasetInstance.getEntityName(), endpoint), body, null);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
}
throw new ExploreException(String.format("Cannot disable explore on dataset %s. Reason: %s", datasetInstance.toString(), response));
}
use of co.cask.cdap.explore.service.ExploreException in project cdap by caskdata.
the class ExploreHttpClient method execute.
@Override
public QueryHandle execute(NamespaceId namespace, String statement, @Nullable Map<String, String> additionalSessionConf) throws ExploreException {
Map<String, String> bodyMap = additionalSessionConf == null ? ImmutableMap.of("query", statement) : ImmutableMap.<String, String>builder().put("query", statement).putAll(additionalSessionConf).build();
HttpResponse response = doPost(String.format("namespaces/%s/data/explore/queries", namespace.getEntityName()), GSON.toJson(bodyMap), null);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
}
throw new ExploreException("Cannot execute query. Reason: " + response);
}
use of co.cask.cdap.explore.service.ExploreException in project cdap by caskdata.
the class ExploreHttpClient method getActiveQueryCount.
@Override
public int getActiveQueryCount(NamespaceId namespace) throws ExploreException {
String resource = String.format("namespaces/%s/data/explore/queries/count", namespace.getEntityName());
HttpResponse response = doGet(resource);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
Map<String, String> mapResponse = parseJson(response, new TypeToken<Map<String, String>>() {
}.getType());
return Integer.parseInt(mapResponse.get("count"));
}
throw new ExploreException("Cannot get list of queries. Reason: " + response);
}
Aggregations