use of org.apache.druid.java.util.common.IAE in project druid by druid-io.
the class MetadataStoreRoleProvider method getRoles.
@Override
public Set<String> getRoles(String authorizerPrefix, AuthenticationResult authenticationResult) {
Set<String> roleNames = new HashSet<>();
Map<String, BasicAuthorizerUser> userMap = cacheManager.getUserMap(authorizerPrefix);
if (userMap == null) {
throw new IAE("Could not load userMap for authorizer [%s]", authorizerPrefix);
}
BasicAuthorizerUser user = userMap.get(authenticationResult.getIdentity());
if (user != null) {
roleNames.addAll(user.getRoles());
}
return roleNames;
}
use of org.apache.druid.java.util.common.IAE in project druid by druid-io.
the class RangerDruidAccessRequest method authorize.
@Override
public Access authorize(AuthenticationResult authenticationResult, Resource resource, Action action) {
if (authenticationResult == null) {
throw new IAE("authenticationResult is null where it should never be.");
}
Set<String> userGroups = null;
if (useUgi) {
UserGroupInformation ugi = UserGroupInformation.createRemoteUser(authenticationResult.getIdentity());
String[] groups = ugi != null ? ugi.getGroupNames() : null;
if (groups != null && groups.length > 0) {
userGroups = new HashSet<>(Arrays.asList(groups));
}
}
RangerDruidResource rangerDruidResource = new RangerDruidResource(resource);
RangerDruidAccessRequest request = new RangerDruidAccessRequest(rangerDruidResource, authenticationResult.getIdentity(), userGroups, action);
RangerAccessResult result = rangerPlugin.isAccessAllowed(request);
if (log.isDebugEnabled()) {
log.debug("==> authorize: %s, allowed: %s", request.toString(), result != null ? result.getIsAllowed() : null);
}
if (result != null && result.getIsAllowed()) {
return new Access(true);
}
return new Access(false);
}
use of org.apache.druid.java.util.common.IAE in project druid by druid-io.
the class JsonIterator method init.
private void init() {
try {
if (inputStream == null) {
throw new UnsupportedOperationException();
} else {
jp = objectMapper.getFactory().createParser(inputStream);
}
final JsonToken nextToken = jp.nextToken();
if (nextToken != JsonToken.START_ARRAY) {
throw new IAE("First token should be START_ARRAY, but it is actually [%s]", jp.getCurrentToken());
} else {
jp.nextToken();
objectCodec = jp.getCodec();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.apache.druid.java.util.common.IAE in project druid by druid-io.
the class BitmapBenchmarkUtils method toOffheap.
public static ImmutableBitmap toOffheap(ImmutableBitmap bitmap) throws IOException {
if (bitmap instanceof WrappedImmutableConciseBitmap) {
final WrappedImmutableConciseBitmap conciseBitmap = (WrappedImmutableConciseBitmap) bitmap;
final byte[] bytes = conciseBitmap.getBitmap().toBytes();
final ByteBuffer buf = ByteBuffer.allocateDirect(bytes.length).put(bytes);
buf.rewind();
return new WrappedImmutableConciseBitmap(new ImmutableConciseSet(buf.asIntBuffer()));
} else if (bitmap instanceof WrappedImmutableRoaringBitmap) {
final WrappedImmutableRoaringBitmap roaringBitmap = (WrappedImmutableRoaringBitmap) bitmap;
final ByteArrayOutputStream out = new ByteArrayOutputStream();
roaringBitmap.getBitmap().serialize(new DataOutputStream(out));
final byte[] bytes = out.toByteArray();
final ByteBuffer buf = ByteBuffer.allocateDirect(bytes.length);
buf.put(bytes);
buf.rewind();
return new WrappedImmutableRoaringBitmap(new ImmutableRoaringBitmap(buf.asReadOnlyBuffer()));
} else {
throw new IAE("Unsupported bitmap type [%s]", bitmap.getClass().getSimpleName());
}
}
use of org.apache.druid.java.util.common.IAE in project druid by druid-io.
the class BitmapBenchmarkWithVaryingOrder method setup.
@Setup(Level.Trial)
public void setup() throws IOException {
switch(type) {
case "concise":
bitmapFactory = new ConciseBitmapFactory();
break;
case "roaring":
bitmapFactory = new RoaringBitmapFactory();
break;
default:
throw new IAE("Unknown bitmap type[%s]", type);
}
bitmaps = new ArrayList<>(numBitmaps);
// Bitmaps usually have a short circuit to early return an empty bitmap if it finds no intersection
// during an AND operation. We want to let them iterate all bitmaps instead, so add some bits that
// will be set for all bitmaps we create.
final int[] knownTrue = new int[minIntersect];
for (int i = 0; i < knownTrue.length; ++i) {
knownTrue[i] = RANDOM.nextInt(bitmapLength);
}
for (int i = 0; i < numBitmaps; ++i) {
// the later the bitmap is created, the higher its density is.
final int bitCount = (int) (i * 0.1);
IntSet ints = new IntOpenHashSet(bitCount);
for (int j = 0; j < bitCount; j++) {
int offset;
do {
offset = RANDOM.nextInt(bitmapLength);
} while (ints.contains(offset));
ints.add(offset);
}
final MutableBitmap mutableBitmap = bitmapFactory.makeEmptyMutableBitmap();
ints.iterator().forEachRemaining((IntConsumer) mutableBitmap::add);
for (int k : knownTrue) {
mutableBitmap.add(k);
}
bitmaps.add(BitmapBenchmarkUtils.toOffheap(bitmapFactory.makeImmutableBitmap(mutableBitmap)));
}
reverseBitmaps = Lists.reverse(bitmaps);
}
Aggregations