Search in sources :

Example 86 with ISE

use of org.apache.druid.java.util.common.ISE in project druid by druid-io.

the class DruidMeta method prepare.

@Override
public StatementHandle prepare(final ConnectionHandle ch, final String sql, final long maxRowCount) {
    try {
        final StatementHandle statement = createStatement(ch);
        final DruidStatement druidStatement;
        try {
            druidStatement = getDruidStatement(statement);
        } catch (NoSuchStatementException e) {
            throw logFailure(new ISE(e, e.getMessage()));
        }
        final DruidConnection druidConnection = getDruidConnection(statement.connectionId);
        AuthenticationResult authenticationResult = authenticateConnection(druidConnection);
        if (authenticationResult == null) {
            throw logFailure(new ForbiddenException("Authentication failed."), "Authentication failed for statement[%s]", druidStatement.getStatementId());
        }
        statement.signature = druidStatement.prepare(sql, maxRowCount, authenticationResult).getSignature();
        LOG.debug("Successfully prepared statement[%s] for execution", druidStatement.getStatementId());
        return statement;
    } catch (NoSuchConnectionException e) {
        throw e;
    } catch (Throwable t) {
        throw errorHandler.sanitize(t);
    }
}
Also used : ForbiddenException(org.apache.druid.server.security.ForbiddenException) NoSuchConnectionException(org.apache.calcite.avatica.NoSuchConnectionException) NoSuchStatementException(org.apache.calcite.avatica.NoSuchStatementException) ISE(org.apache.druid.java.util.common.ISE) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult)

Example 87 with ISE

use of org.apache.druid.java.util.common.ISE in project druid by druid-io.

the class DruidKerberosUtil method authenticateIfRequired.

public static void authenticateIfRequired(String internalClientPrincipal, String internalClientKeytab) {
    if (!Strings.isNullOrEmpty(internalClientPrincipal) && !Strings.isNullOrEmpty(internalClientKeytab)) {
        Configuration conf = new Configuration();
        conf.setClassLoader(DruidKerberosModule.class.getClassLoader());
        conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
        UserGroupInformation.setConfiguration(conf);
        try {
            // login for the first time.
            if (UserGroupInformation.getCurrentUser().hasKerberosCredentials() == false || !UserGroupInformation.getCurrentUser().getUserName().equals(internalClientPrincipal)) {
                log.info("trying to authenticate user [%s] with keytab [%s]", internalClientPrincipal, internalClientKeytab);
                UserGroupInformation.loginUserFromKeytab(internalClientPrincipal, internalClientKeytab);
                return;
            }
            // try to relogin in case the TGT expired
            if (UserGroupInformation.isLoginKeytabBased()) {
                log.info("Re-Login from key tab [%s] with principal [%s]", internalClientKeytab, internalClientPrincipal);
                UserGroupInformation.getLoginUser().checkTGTAndReloginFromKeytab();
                return;
            } else if (UserGroupInformation.isLoginTicketBased()) {
                log.info("Re-Login from Ticket cache");
                UserGroupInformation.getLoginUser().reloginFromTicketCache();
                return;
            }
        } catch (IOException e) {
            throw new ISE(e, "Failed to authenticate user principal [%s] with keytab [%s]", internalClientPrincipal, internalClientKeytab);
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ISE(org.apache.druid.java.util.common.ISE) IOException(java.io.IOException)

Example 88 with ISE

use of org.apache.druid.java.util.common.ISE in project druid by druid-io.

the class JdbcCacheGenerator method generateCache.

@Override
@Nullable
public CacheScheduler.VersionedCache generateCache(final JdbcExtractionNamespace namespace, final CacheScheduler.EntryImpl<JdbcExtractionNamespace> entryId, final String lastVersion, final CacheScheduler scheduler) {
    final long lastCheck = lastVersion == null ? JodaUtils.MIN_INSTANT : Long.parseLong(lastVersion);
    final Long lastDBUpdate;
    final long dbQueryStart;
    try {
        lastDBUpdate = lastUpdates(entryId, namespace);
        if (lastDBUpdate != null && lastDBUpdate <= lastCheck) {
            return null;
        }
    } catch (UnableToObtainConnectionException e) {
        if (e.getMessage().contains(NO_SUITABLE_DRIVER_FOUND_ERROR)) {
            throw new ISE(e, JDBC_DRIVER_JAR_FILES_MISSING_ERROR);
        } else {
            throw e;
        }
    }
    dbQueryStart = System.currentTimeMillis();
    LOG.debug("Updating %s", entryId);
    final String newVersion;
    if (lastDBUpdate != null) {
        newVersion = lastDBUpdate.toString();
    } else {
        newVersion = StringUtils.format("%d", dbQueryStart);
    }
    final CacheScheduler.VersionedCache versionedCache = scheduler.createVersionedCache(entryId, newVersion);
    final long startNs = System.nanoTime();
    try (Handle handle = getHandle(entryId, namespace);
        ResultIterator<Pair<String, String>> pairs = getLookupPairs(handle, namespace)) {
        final Map<String, String> cache = versionedCache.getCache();
        final MapPopulator.PopulateResult populateResult = MapPopulator.populateAndWarnAtByteLimit(pairs, cache, (long) (MAX_MEMORY * namespace.getMaxHeapPercentage() / 100.0), null == entryId ? null : entryId.toString());
        final long duration = System.nanoTime() - startNs;
        LOG.info("Finished loading %,d values (%d bytes) for [%s] in %,d ns", populateResult.getEntries(), populateResult.getBytes(), entryId, duration);
        return versionedCache;
    } catch (UnableToObtainConnectionException e) {
        if (e.getMessage().contains(NO_SUITABLE_DRIVER_FOUND_ERROR)) {
            throw new ISE(e, JDBC_DRIVER_JAR_FILES_MISSING_ERROR);
        } else {
            throw e;
        }
    } catch (Throwable t) {
        try {
            versionedCache.close();
        } catch (Exception e) {
            t.addSuppressed(e);
        }
        throw t;
    }
}
Also used : UnableToObtainConnectionException(org.skife.jdbi.v2.exceptions.UnableToObtainConnectionException) Handle(org.skife.jdbi.v2.Handle) UnableToObtainConnectionException(org.skife.jdbi.v2.exceptions.UnableToObtainConnectionException) ISE(org.apache.druid.java.util.common.ISE) CacheScheduler(org.apache.druid.server.lookup.namespace.cache.CacheScheduler) Pair(org.apache.druid.java.util.common.Pair) MapPopulator(org.apache.druid.data.input.MapPopulator) Nullable(javax.annotation.Nullable)

Example 89 with ISE

use of org.apache.druid.java.util.common.ISE in project druid by druid-io.

the class SegmentMetadataUpdateAction method perform.

@Override
public Void perform(Task task, TaskActionToolbox toolbox) {
    TaskLocks.checkLockCoversSegments(task, toolbox.getTaskLockbox(), segments);
    try {
        toolbox.getTaskLockbox().doInCriticalSection(task, segments.stream().map(DataSegment::getInterval).collect(Collectors.toList()), CriticalAction.builder().onValidLocks(() -> {
            toolbox.getIndexerMetadataStorageCoordinator().updateSegmentMetadata(segments);
            return null;
        }).onInvalidLocks(() -> {
            throw new ISE("Some locks for task[%s] are already revoked", task.getId());
        }).build());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // Emit metrics
    final ServiceMetricEvent.Builder metricBuilder = new ServiceMetricEvent.Builder();
    IndexTaskUtils.setTaskDimensions(metricBuilder, task);
    for (DataSegment segment : segments) {
        metricBuilder.setDimension(DruidMetrics.INTERVAL, segment.getInterval().toString());
        toolbox.getEmitter().emit(metricBuilder.build("segment/moved/bytes", segment.getSize()));
    }
    return null;
}
Also used : ISE(org.apache.druid.java.util.common.ISE) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) DataSegment(org.apache.druid.timeline.DataSegment)

Example 90 with ISE

use of org.apache.druid.java.util.common.ISE in project druid by druid-io.

the class SegmentTransactionalInsertAction method checkWithSegmentLock.

private void checkWithSegmentLock() {
    final Map<Interval, List<DataSegment>> oldSegmentsMap = groupSegmentsByIntervalAndSort(segmentsToBeOverwritten);
    final Map<Interval, List<DataSegment>> newSegmentsMap = groupSegmentsByIntervalAndSort(segments);
    oldSegmentsMap.values().forEach(TaskLockHelper::verifyRootPartitionIsAdjacentAndAtomicUpdateGroupIsFull);
    newSegmentsMap.values().forEach(TaskLockHelper::verifyRootPartitionIsAdjacentAndAtomicUpdateGroupIsFull);
    oldSegmentsMap.forEach((interval, oldSegmentsPerInterval) -> {
        final List<DataSegment> newSegmentsPerInterval = Preconditions.checkNotNull(newSegmentsMap.get(interval), "segments of interval[%s]", interval);
        // These lists are already sorted in groupSegmentsByIntervalAndSort().
        final int oldStartRootPartitionId = oldSegmentsPerInterval.get(0).getStartRootPartitionId();
        final int oldEndRootPartitionId = oldSegmentsPerInterval.get(oldSegmentsPerInterval.size() - 1).getEndRootPartitionId();
        final int newStartRootPartitionId = newSegmentsPerInterval.get(0).getStartRootPartitionId();
        final int newEndRootPartitionId = newSegmentsPerInterval.get(newSegmentsPerInterval.size() - 1).getEndRootPartitionId();
        if (oldStartRootPartitionId != newStartRootPartitionId || oldEndRootPartitionId != newEndRootPartitionId) {
            throw new ISE("Root partition range[%d, %d] of new segments doesn't match to root partition range[%d, %d] of old segments", newStartRootPartitionId, newEndRootPartitionId, oldStartRootPartitionId, oldEndRootPartitionId);
        }
        newSegmentsPerInterval.forEach(eachNewSegment -> oldSegmentsPerInterval.forEach(eachOldSegment -> {
            if (eachNewSegment.getMinorVersion() <= eachOldSegment.getMinorVersion()) {
                throw new ISE("New segment[%s] have a smaller minor version than old segment[%s]", eachNewSegment, eachOldSegment);
            }
        }));
    });
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) DruidMetrics(org.apache.druid.query.DruidMetrics) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CriticalAction(org.apache.druid.indexing.overlord.CriticalAction) Interval(org.joda.time.Interval) DataSourceMetadata(org.apache.druid.indexing.overlord.DataSourceMetadata) Task(org.apache.druid.indexing.common.task.Task) Map(java.util.Map) TaskLock(org.apache.druid.indexing.common.TaskLock) TaskLockHelper(org.apache.druid.indexing.common.task.TaskLockHelper) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Nullable(javax.annotation.Nullable) ImmutableSet(com.google.common.collect.ImmutableSet) SegmentPublishResult(org.apache.druid.indexing.overlord.SegmentPublishResult) ServiceMetricEvent(org.apache.druid.java.util.emitter.service.ServiceMetricEvent) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) Collectors(java.util.stream.Collectors) LockGranularity(org.apache.druid.indexing.common.LockGranularity) List(java.util.List) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) SegmentUtils(org.apache.druid.segment.SegmentUtils) DataSegment(org.apache.druid.timeline.DataSegment) IndexTaskUtils(org.apache.druid.indexing.common.task.IndexTaskUtils) Preconditions(com.google.common.base.Preconditions) TaskLockHelper(org.apache.druid.indexing.common.task.TaskLockHelper) ArrayList(java.util.ArrayList) List(java.util.List) ISE(org.apache.druid.java.util.common.ISE) DataSegment(org.apache.druid.timeline.DataSegment) Interval(org.joda.time.Interval)

Aggregations

ISE (org.apache.druid.java.util.common.ISE)354 IOException (java.io.IOException)95 ArrayList (java.util.ArrayList)90 Map (java.util.Map)68 List (java.util.List)60 File (java.io.File)48 Interval (org.joda.time.Interval)48 DataSegment (org.apache.druid.timeline.DataSegment)44 HashMap (java.util.HashMap)43 Nullable (javax.annotation.Nullable)43 URL (java.net.URL)36 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)33 Request (org.apache.druid.java.util.http.client.Request)30 ExecutionException (java.util.concurrent.ExecutionException)29 ImmutableMap (com.google.common.collect.ImmutableMap)28 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)28 VisibleForTesting (com.google.common.annotations.VisibleForTesting)27 Collectors (java.util.stream.Collectors)27 IAE (org.apache.druid.java.util.common.IAE)27 ImmutableList (com.google.common.collect.ImmutableList)26