Search in sources :

Example 6 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by apache.

the class BsonRecordReader method writeString.

private void writeString(String readString, final MapOrListWriterImpl writer, String fieldName, boolean isList) {
    int length;
    byte[] strBytes;
    try {
        strBytes = readString.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new DrillRuntimeException("Unable to read string value for field: " + fieldName, e);
    }
    length = strBytes.length;
    ensure(length);
    workBuf.setBytes(0, strBytes);
    final VarCharHolder vh = new VarCharHolder();
    vh.buffer = workBuf;
    vh.start = 0;
    vh.end = length;
    if (isList == false) {
        writer.varChar(fieldName).write(vh);
    } else {
        writer.list.varChar().write(vh);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder)

Example 7 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by apache.

the class InboundImpersonationManager method replaceUserOnSession.

/**
   * Check if the current session user, as a proxy user, is authorized to impersonate the given target user
   * based on the system's impersonation policies.
   *
   * @param targetName target user name
   * @param session    user session
   */
public void replaceUserOnSession(final String targetName, final UserSession session) {
    final String policiesString = session.getOptions().getOption(ExecConstants.IMPERSONATION_POLICY_VALIDATOR);
    if (!policiesString.equals(this.policiesString)) {
        try {
            impersonationPolicies = deserializeImpersonationPolicies(policiesString);
            this.policiesString = policiesString;
        } catch (final IOException e) {
            // This never happens. Impersonation policies must have been validated.
            logger.warn("Impersonation policies must have been validated.");
            throw new DrillRuntimeException("Failure while checking for impersonation policies.", e);
        }
    }
    final String proxyName = session.getCredentials().getUserName();
    if (!hasImpersonationPrivileges(proxyName, targetName, impersonationPolicies)) {
        throw UserException.permissionError().message("Proxy user '%s' is not authorized to impersonate target user '%s'.", proxyName, targetName).build(logger);
    }
    // replace session's user credentials
    final UserCredentials newCredentials = UserCredentials.newBuilder().setUserName(targetName).build();
    session.replaceUserCredentials(this, newCredentials);
}
Also used : UserCredentials(org.apache.drill.exec.proto.UserBitShared.UserCredentials) IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 8 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by apache.

the class BuildTimeScan method loadExcept.

/**
   * loads all the prescanned resources from classpath
   * (except for the target location in case it already exists)
   * @return the result of the previous scan
   */
private static ScanResult loadExcept(URL ignored) {
    Set<URL> preScanned = ClassPathScanner.forResource(REGISTRY_FILE, false);
    ScanResult result = null;
    for (URL u : preScanned) {
        if (ignored != null && u.toString().startsWith(ignored.toString())) {
            continue;
        }
        try (InputStream reflections = u.openStream()) {
            ScanResult ref = reader.readValue(reflections);
            if (result == null) {
                result = ref;
            } else {
                result = result.merge(ref);
            }
        } catch (IOException e) {
            throw new DrillRuntimeException("can't read function registry at " + u, e);
        }
    }
    if (result != null) {
        if (logger.isInfoEnabled()) {
            StringBuilder sb = new StringBuilder();
            sb.append(format("Loaded prescanned packages %s from locations:\n", result.getScannedPackages()));
            for (URL u : preScanned) {
                sb.append('\t');
                sb.append(u.toExternalForm());
                sb.append('\n');
            }
        }
        logger.info(format("Loaded prescanned packages %s from locations %s", result.getScannedPackages(), preScanned));
        return result;
    } else {
        return ClassPathScanner.emptyResult();
    }
}
Also used : ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) InputStream(java.io.InputStream) IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) URL(java.net.URL)

Example 9 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by apache.

the class ZookeeperClient method get.

/**
   * Returns the value corresponding to the given key, null otherwise.
   *
   * If the flag consistent is set, the check is consistent as it is made against Zookeeper directly. Otherwise,
   * the check is eventually consistent.
   *
   * If consistency flag is set to true and version holder is not null, passes version holder to get data change version.
   * Data change version is retrieved from {@link Stat} object, it increases each time znode data change is performed.
   * Link to Zookeeper documentation - https://zookeeper.apache.org/doc/r3.2.2/zookeeperProgrammers.html#sc_zkDataModel_znodes
   *
   * @param path  target path
   * @param consistent consistency check
   * @param version version holder
   */
public byte[] get(final String path, final boolean consistent, final DataChangeVersion version) {
    Preconditions.checkNotNull(path, "path is required");
    final String target = PathUtils.join(root, path);
    if (consistent) {
        try {
            if (version != null) {
                Stat stat = new Stat();
                final byte[] bytes = curator.getData().storingStatIn(stat).forPath(target);
                version.setVersion(stat.getVersion());
                return bytes;
            }
            return curator.getData().forPath(target);
        } catch (final Exception ex) {
            throw new DrillRuntimeException(String.format("error retrieving value for [%s]", path), ex);
        }
    } else {
        final ChildData data = getCache().getCurrentData(target);
        if (data != null) {
            return data.getData();
        }
    }
    return null;
}
Also used : Stat(org.apache.zookeeper.data.Stat) ChildData(org.apache.curator.framework.recipes.cache.ChildData) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) KeeperException(org.apache.zookeeper.KeeperException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException)

Example 10 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by apache.

the class ZkEphemeralStore method put.

@Override
public V put(final String key, final V value) {
    final InstanceSerializer<V> serializer = config.getSerializer();
    try {
        final byte[] old = getClient().get(key);
        final byte[] bytes = serializer.serialize(value);
        getClient().put(key, bytes);
        if (old == null) {
            return null;
        }
        return serializer.deserialize(old);
    } catch (final IOException e) {
        throw new DrillRuntimeException(String.format("unable to de/serialize value of type %s", value.getClass()), e);
    }
}
Also used : IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Aggregations

DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)69 IOException (java.io.IOException)32 VersionMismatchException (org.apache.drill.exec.exception.VersionMismatchException)9 Stopwatch (com.google.common.base.Stopwatch)7 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)7 UserException (org.apache.drill.common.exceptions.UserException)6 KeeperException (org.apache.zookeeper.KeeperException)6 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)6 NoSuchElementException (java.util.NoSuchElementException)5 Path (org.apache.hadoop.fs.Path)5 Bson (org.bson.conversions.Bson)4 Registry (org.apache.drill.exec.proto.UserBitShared.Registry)3 ValueVector (org.apache.drill.exec.vector.ValueVector)3 Admin (org.apache.hadoop.hbase.client.Admin)3 Document (org.bson.Document)3 File (java.io.File)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URI (java.net.URI)2 RexNode (org.apache.calcite.rex.RexNode)2 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)2