Search in sources :

Example 1 with StringFullResponseHandler

use of org.apache.druid.java.util.http.client.response.StringFullResponseHandler in project hive by apache.

the class DruidStorageHandler method fetchKafkaIngestionSpec.

private KafkaSupervisorSpec fetchKafkaIngestionSpec(Table table) {
    // Stop Kafka Ingestion first
    final String overlordAddress = Preconditions.checkNotNull(HiveConf.getVar(getConf(), HiveConf.ConfVars.HIVE_DRUID_OVERLORD_DEFAULT_ADDRESS), "Druid Overlord Address is null");
    String dataSourceName = Preconditions.checkNotNull(DruidStorageHandlerUtils.getTableProperty(table, Constants.DRUID_DATA_SOURCE), "Druid Datasource name is null");
    try {
        StringFullResponseHolder response = RetryUtils.retry(() -> DruidStorageHandlerUtils.getResponseFromCurrentLeader(getHttpClient(), new Request(HttpMethod.GET, new URL(String.format("http://%s/druid/indexer/v1/supervisor/%s", overlordAddress, dataSourceName))), new StringFullResponseHandler(Charset.forName("UTF-8"))), input -> input instanceof IOException, getMaxRetryCount());
        if (response.getStatus().equals(HttpResponseStatus.OK)) {
            return JSON_MAPPER.readValue(response.getContent(), KafkaSupervisorSpec.class);
        // Druid Returns 400 Bad Request when not found.
        } else if (response.getStatus().equals(HttpResponseStatus.NOT_FOUND) || response.getStatus().equals(HttpResponseStatus.BAD_REQUEST)) {
            LOG.debug("No Kafka Supervisor found for datasource[%s]", dataSourceName);
            return null;
        } else {
            throw new IOException(String.format("Unable to fetch Kafka Ingestion Spec from Druid status [%d] full response [%s]", response.getStatus().getCode(), response.getContent()));
        }
    } catch (Exception e) {
        throw new RuntimeException("Exception while fetching kafka ingestion spec from druid", e);
    }
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) StringFullResponseHandler(org.apache.druid.java.util.http.client.response.StringFullResponseHandler) Request(org.apache.druid.java.util.http.client.Request) IOException(java.io.IOException) URL(java.net.URL) SegmentLoadingException(org.apache.druid.segment.loading.SegmentLoadingException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) CallbackFailedException(org.skife.jdbi.v2.exceptions.CallbackFailedException)

Example 2 with StringFullResponseHandler

use of org.apache.druid.java.util.http.client.response.StringFullResponseHandler in project hive by apache.

the class DruidKafkaUtils method updateKafkaIngestionSpec.

static void updateKafkaIngestionSpec(String overlordAddress, KafkaSupervisorSpec spec) {
    try {
        String task = JSON_MAPPER.writeValueAsString(spec);
        CONSOLE.printInfo("submitting kafka Spec {}", task);
        LOG.info("submitting kafka Supervisor Spec {}", task);
        StringFullResponseHolder response = DruidStorageHandlerUtils.getResponseFromCurrentLeader(DruidStorageHandler.getHttpClient(), new Request(HttpMethod.POST, new URL(String.format("http://%s/druid/indexer/v1/supervisor", overlordAddress))).setContent("application/json", JSON_MAPPER.writeValueAsBytes(spec)), new StringFullResponseHandler(Charset.forName("UTF-8")));
        if (response.getStatus().equals(HttpResponseStatus.OK)) {
            String msg = String.format("Kafka Supervisor for [%s] Submitted Successfully to druid.", spec.getDataSchema().getDataSource());
            LOG.info(msg);
            CONSOLE.printInfo(msg);
        } else {
            throw new IOException(String.format("Unable to update Kafka Ingestion for Druid status [%d] full response [%s]", response.getStatus().getCode(), response.getContent()));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) StringFullResponseHandler(org.apache.druid.java.util.http.client.response.StringFullResponseHandler) Request(org.apache.druid.java.util.http.client.Request) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException)

Example 3 with StringFullResponseHandler

use of org.apache.druid.java.util.http.client.response.StringFullResponseHandler in project hive by apache.

the class DruidStorageHandler method checkLoadStatus.

/**
 * This function checks the load status of Druid segments by polling druid coordinator.
 * @param segments List of druid segments to check for
 */
private void checkLoadStatus(List<DataSegment> segments) {
    final String coordinatorAddress = HiveConf.getVar(getConf(), HiveConf.ConfVars.HIVE_DRUID_COORDINATOR_DEFAULT_ADDRESS);
    int maxTries = getMaxRetryCount();
    LOG.debug("checking load status from coordinator {}", coordinatorAddress);
    String coordinatorResponse;
    try {
        coordinatorResponse = RetryUtils.retry(() -> DruidStorageHandlerUtils.getResponseFromCurrentLeader(getHttpClient(), new Request(HttpMethod.GET, new URL(String.format("http://%s/status", coordinatorAddress))), new StringFullResponseHandler(Charset.forName("UTF-8"))).getContent(), input -> input instanceof IOException, maxTries);
    } catch (Exception e) {
        CONSOLE.printInfo("Will skip waiting for data loading, coordinator unavailable");
        return;
    }
    if (Strings.isNullOrEmpty(coordinatorResponse)) {
        CONSOLE.printInfo("Will skip waiting for data loading empty response from coordinator");
    }
    CONSOLE.printInfo(String.format("Waiting for the loading of [%s] segments", segments.size()));
    long passiveWaitTimeMs = HiveConf.getLongVar(getConf(), HiveConf.ConfVars.HIVE_DRUID_PASSIVE_WAIT_TIME);
    Set<URL> urlsOfUnloadedSegments = segments.stream().map(dataSegment -> {
        try {
            // Need to make sure that we are using segment identifier
            return new URL(String.format("http://%s/druid/coordinator/v1/datasources/%s/segments/%s", coordinatorAddress, dataSegment.getDataSource(), dataSegment.getId().toString()));
        } catch (MalformedURLException e) {
            Throwables.propagate(e);
        }
        return null;
    }).collect(Collectors.toSet());
    int numRetries = 0;
    while (numRetries++ < maxTries && !urlsOfUnloadedSegments.isEmpty()) {
        urlsOfUnloadedSegments = ImmutableSet.copyOf(Sets.filter(urlsOfUnloadedSegments, input -> {
            try {
                String result = DruidStorageHandlerUtils.getResponseFromCurrentLeader(getHttpClient(), new Request(HttpMethod.GET, input), new StringFullResponseHandler(Charset.forName("UTF-8"))).getContent();
                LOG.debug("Checking segment [{}] response is [{}]", input, result);
                return Strings.isNullOrEmpty(result);
            } catch (InterruptedException | ExecutionException e) {
                LOG.error(String.format("Error while checking URL [%s]", input), e);
                return true;
            }
        }));
        try {
            if (!urlsOfUnloadedSegments.isEmpty()) {
                Thread.sleep(passiveWaitTimeMs);
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    if (!urlsOfUnloadedSegments.isEmpty()) {
        // We are not Throwing an exception since it might be a transient issue that is blocking loading
        CONSOLE.printError(String.format("Wait time exhausted and we have [%s] out of [%s] segments not loaded yet", urlsOfUnloadedSegments.size(), segments.size()));
    }
}
Also used : FileSystem(org.apache.hadoop.fs.FileSystem) HttpMethod(org.jboss.netty.handler.codec.http.HttpMethod) IndexSpec(org.apache.druid.segment.IndexSpec) StringFullResponseHandler(org.apache.druid.java.util.http.client.response.StringFullResponseHandler) StringUtils(org.apache.commons.lang3.StringUtils) HdfsDataSegmentPusherConfig(org.apache.druid.storage.hdfs.HdfsDataSegmentPusherConfig) TableScanDesc(org.apache.hadoop.hive.ql.plan.TableScanDesc) AbstractSerDe(org.apache.hadoop.hive.serde2.AbstractSerDe) Pair(org.apache.druid.java.util.common.Pair) DruidRecordWriter(org.apache.hadoop.hive.druid.io.DruidRecordWriter) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) HiveStorageHandler(org.apache.hadoop.hive.ql.metadata.HiveStorageHandler) DruidSerDe(org.apache.hadoop.hive.druid.serde.DruidSerDe) PostgreSQLConnector(org.apache.druid.metadata.storage.postgresql.PostgreSQLConnector) KerberosHttpClient(org.apache.hadoop.hive.druid.security.KerberosHttpClient) Set(java.util.Set) DimensionSchema(org.apache.druid.data.input.impl.DimensionSchema) PostgreSQLConnectorConfig(org.apache.druid.metadata.storage.postgresql.PostgreSQLConnectorConfig) LockType(org.apache.hadoop.hive.metastore.api.LockType) DataSegmentPusher(org.apache.druid.segment.loading.DataSegmentPusher) TypeInfoUtils(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils) HttpClient(org.apache.druid.java.util.http.client.HttpClient) MetadataStorageConnectorConfig(org.apache.druid.metadata.MetadataStorageConnectorConfig) SegmentLoadingException(org.apache.druid.segment.loading.SegmentLoadingException) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) RetryUtils(org.apache.druid.java.util.common.RetryUtils) Constants(org.apache.hadoop.hive.conf.Constants) Nullable(javax.annotation.Nullable) DruidQueryBasedInputFormat(org.apache.hadoop.hive.druid.io.DruidQueryBasedInputFormat) Properties(java.util.Properties) GranularitySpec(org.apache.druid.segment.indexing.granularity.GranularitySpec) Throwables(com.google.common.base.Throwables) EnvironmentContext(org.apache.hadoop.hive.metastore.api.EnvironmentContext) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) IOException(java.io.IOException) OperatorDesc(org.apache.hadoop.hive.ql.plan.OperatorDesc) Table(org.apache.hadoop.hive.metastore.api.Table) ShutdownHookManager(org.apache.hive.common.util.ShutdownHookManager) StorageHandlerInfo(org.apache.hadoop.hive.ql.metadata.StorageHandlerInfo) ExecutionException(java.util.concurrent.ExecutionException) HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) Preconditions(com.google.common.base.Preconditions) HiveAuthorizationProvider(org.apache.hadoop.hive.ql.security.authorization.HiveAuthorizationProvider) DataSchema(org.apache.druid.segment.indexing.DataSchema) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) TableDesc(org.apache.hadoop.hive.ql.plan.TableDesc) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) URL(java.net.URL) DruidConstants(org.apache.hadoop.hive.druid.conf.DruidConstants) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) DerbyConnector(org.apache.druid.metadata.storage.derby.DerbyConnector) InputFormat(org.apache.hadoop.mapred.InputFormat) Path(org.apache.hadoop.fs.Path) URI(java.net.URI) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DerbyMetadataStorage(org.apache.druid.metadata.storage.derby.DerbyMetadataStorage) OutputFormat(org.apache.hadoop.mapred.OutputFormat) MetaStoreUtils(org.apache.hadoop.hive.metastore.utils.MetaStoreUtils) DefaultHiveAuthorizationProvider(org.apache.hadoop.hive.ql.security.authorization.DefaultHiveAuthorizationProvider) ImmutableSet(com.google.common.collect.ImmutableSet) MetadataStorageTablesConfig(org.apache.druid.metadata.MetadataStorageTablesConfig) WriteEntity(org.apache.hadoop.hive.ql.hooks.WriteEntity) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) Collection(java.util.Collection) HiveMetaHook(org.apache.hadoop.hive.metastore.HiveMetaHook) InputRowParser(org.apache.druid.data.input.impl.InputRowParser) DefaultHiveMetaHook(org.apache.hadoop.hive.metastore.DefaultHiveMetaHook) SessionState(org.apache.hadoop.hive.ql.session.SessionState) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) HttpClientInit(org.apache.druid.java.util.http.client.HttpClientInit) HiveCustomStorageHandlerUtils(org.apache.hadoop.hive.ql.security.authorization.HiveCustomStorageHandlerUtils) List(java.util.List) DataSegment(org.apache.druid.timeline.DataSegment) KafkaSupervisorSpec(org.apache.hadoop.hive.druid.json.KafkaSupervisorSpec) JSON_MAPPER(org.apache.hadoop.hive.druid.DruidStorageHandlerUtils.JSON_MAPPER) PostgreSQLTablesConfig(org.apache.druid.metadata.storage.postgresql.PostgreSQLTablesConfig) Supplier(com.google.common.base.Supplier) HdfsDataSegmentPusher(org.apache.druid.storage.hdfs.HdfsDataSegmentPusher) KafkaSupervisorReport(org.apache.hadoop.hive.druid.json.KafkaSupervisorReport) BaseQuery(org.apache.druid.query.BaseQuery) Utilities(org.apache.hadoop.hive.ql.exec.Utilities) ImmutableList(com.google.common.collect.ImmutableList) Query(org.apache.druid.query.Query) Charset(java.nio.charset.Charset) Request(org.apache.druid.java.util.http.client.Request) Suppliers(com.google.common.base.Suppliers) TableName(org.apache.hadoop.hive.common.TableName) SQLMetadataConnector(org.apache.druid.metadata.SQLMetadataConnector) Period(org.joda.time.Period) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) Logger(org.slf4j.Logger) HttpClientConfig(org.apache.druid.java.util.http.client.HttpClientConfig) MalformedURLException(java.net.MalformedURLException) MySQLConnector(org.apache.druid.metadata.storage.mysql.MySQLConnector) MySQLConnectorConfig(org.apache.druid.metadata.storage.mysql.MySQLConnectorConfig) HiveConf(org.apache.hadoop.hive.conf.HiveConf) DateTime(org.joda.time.DateTime) Maps(com.google.common.collect.Maps) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) JobConf(org.apache.hadoop.mapred.JobConf) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) DruidOutputFormat(org.apache.hadoop.hive.druid.io.DruidOutputFormat) CallbackFailedException(org.skife.jdbi.v2.exceptions.CallbackFailedException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) Collections(java.util.Collections) StringFullResponseHandler(org.apache.druid.java.util.http.client.response.StringFullResponseHandler) MalformedURLException(java.net.MalformedURLException) Request(org.apache.druid.java.util.http.client.Request) IOException(java.io.IOException) URL(java.net.URL) SegmentLoadingException(org.apache.druid.segment.loading.SegmentLoadingException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) CallbackFailedException(org.skife.jdbi.v2.exceptions.CallbackFailedException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with StringFullResponseHandler

use of org.apache.druid.java.util.http.client.response.StringFullResponseHandler in project hive by apache.

the class DruidStorageHandler method fetchKafkaSupervisorReport.

/**
 * Fetches kafka supervisor status report from druid overlord. This method will return null if can not fetch report
 *
 * @param table object.
 * @return kafka supervisor report or null when druid overlord is unreachable.
 */
@Nullable
private KafkaSupervisorReport fetchKafkaSupervisorReport(Table table) {
    final String overlordAddress = Preconditions.checkNotNull(HiveConf.getVar(getConf(), HiveConf.ConfVars.HIVE_DRUID_OVERLORD_DEFAULT_ADDRESS), "Druid Overlord Address is null");
    final String dataSourceName = Preconditions.checkNotNull(DruidStorageHandlerUtils.getTableProperty(table, Constants.DRUID_DATA_SOURCE), "Druid Datasource name is null");
    try {
        StringFullResponseHolder response = RetryUtils.retry(() -> DruidStorageHandlerUtils.getResponseFromCurrentLeader(getHttpClient(), new Request(HttpMethod.GET, new URL(String.format("http://%s/druid/indexer/v1/supervisor/%s/status", overlordAddress, dataSourceName))), new StringFullResponseHandler(Charset.forName("UTF-8"))), input -> input instanceof IOException, getMaxRetryCount());
        if (response.getStatus().equals(HttpResponseStatus.OK)) {
            return DruidStorageHandlerUtils.JSON_MAPPER.readValue(response.getContent(), KafkaSupervisorReport.class);
        // Druid Returns 400 Bad Request when not found.
        } else if (response.getStatus().equals(HttpResponseStatus.NOT_FOUND) || response.getStatus().equals(HttpResponseStatus.BAD_REQUEST)) {
            LOG.info("No Kafka Supervisor found for datasource[%s]", dataSourceName);
            return null;
        } else {
            LOG.error("Unable to fetch Kafka Supervisor status [%d] full response [%s]", response.getStatus().getCode(), response.getContent());
            return null;
        }
    } catch (Exception e) {
        LOG.error("Exception while fetching kafka ingestion spec from druid", e);
        return null;
    }
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) StringFullResponseHandler(org.apache.druid.java.util.http.client.response.StringFullResponseHandler) Request(org.apache.druid.java.util.http.client.Request) IOException(java.io.IOException) URL(java.net.URL) SegmentLoadingException(org.apache.druid.segment.loading.SegmentLoadingException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) CallbackFailedException(org.skife.jdbi.v2.exceptions.CallbackFailedException) Nullable(javax.annotation.Nullable)

Aggregations

IOException (java.io.IOException)4 URL (java.net.URL)4 Request (org.apache.druid.java.util.http.client.Request)4 StringFullResponseHandler (org.apache.druid.java.util.http.client.response.StringFullResponseHandler)4 StringFullResponseHolder (org.apache.druid.java.util.http.client.response.StringFullResponseHolder)4 MalformedURLException (java.net.MalformedURLException)3 URISyntaxException (java.net.URISyntaxException)3 ExecutionException (java.util.concurrent.ExecutionException)3 SegmentLoadingException (org.apache.druid.segment.loading.SegmentLoadingException)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3 CallbackFailedException (org.skife.jdbi.v2.exceptions.CallbackFailedException)3 Nullable (javax.annotation.Nullable)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 Supplier (com.google.common.base.Supplier)1 Suppliers (com.google.common.base.Suppliers)1 Throwables (com.google.common.base.Throwables)1 ImmutableList (com.google.common.collect.ImmutableList)1