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);
}
}
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);
}
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();
}
}
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;
}
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);
}
}
Aggregations