Search in sources :

Example 36 with ExploreException

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);
    }
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) IOException(java.io.IOException) URL(java.net.URL) ExploreException(co.cask.cdap.explore.service.ExploreException)

Example 37 with ExploreException

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));
}
Also used : HashMap(java.util.HashMap) HttpResponse(co.cask.common.http.HttpResponse) ExploreException(co.cask.cdap.explore.service.ExploreException)

Example 38 with ExploreException

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));
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) ExploreException(co.cask.cdap.explore.service.ExploreException)

Example 39 with ExploreException

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);
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) ExploreException(co.cask.cdap.explore.service.ExploreException)

Example 40 with ExploreException

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);
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) HttpResponse(co.cask.common.http.HttpResponse) ExploreException(co.cask.cdap.explore.service.ExploreException)

Aggregations

ExploreException (co.cask.cdap.explore.service.ExploreException)41 QueryHandle (co.cask.cdap.proto.QueryHandle)16 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)14 HttpResponse (co.cask.common.http.HttpResponse)12 OperationHandle (org.apache.hive.service.cli.OperationHandle)12 SessionHandle (org.apache.hive.service.cli.SessionHandle)12 SQLException (java.sql.SQLException)11 IOException (java.io.IOException)9 HandleNotFoundException (co.cask.cdap.explore.service.HandleNotFoundException)6 TableNotFoundException (co.cask.cdap.explore.service.TableNotFoundException)4 Path (javax.ws.rs.Path)4 QueryStatus (co.cask.cdap.proto.QueryStatus)3 FileNotFoundException (java.io.FileNotFoundException)3 TException (org.apache.thrift.TException)3 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)2 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 HBaseDDLExecutor (co.cask.cdap.spi.hbase.HBaseDDLExecutor)2 ImmutableList (com.google.common.collect.ImmutableList)2 JsonObject (com.google.gson.JsonObject)2 HashMap (java.util.HashMap)2