Search in sources :

Example 51 with IAE

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;
}
Also used : BasicAuthorizerUser(org.apache.druid.security.basic.authorization.entity.BasicAuthorizerUser) IAE(org.apache.druid.java.util.common.IAE) HashSet(java.util.HashSet)

Example 52 with IAE

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);
}
Also used : Access(org.apache.druid.server.security.Access) RangerAccessResult(org.apache.ranger.plugin.policyengine.RangerAccessResult) IAE(org.apache.druid.java.util.common.IAE) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 53 with IAE

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);
    }
}
Also used : JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) IAE(org.apache.druid.java.util.common.IAE)

Example 54 with IAE

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());
    }
}
Also used : ImmutableConciseSet(org.apache.druid.extendedset.intset.ImmutableConciseSet) WrappedImmutableConciseBitmap(org.apache.druid.collections.bitmap.WrappedImmutableConciseBitmap) DataOutputStream(java.io.DataOutputStream) WrappedImmutableRoaringBitmap(org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap) ImmutableRoaringBitmap(org.roaringbitmap.buffer.ImmutableRoaringBitmap) WrappedImmutableRoaringBitmap(org.apache.druid.collections.bitmap.WrappedImmutableRoaringBitmap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAE(org.apache.druid.java.util.common.IAE) ByteBuffer(java.nio.ByteBuffer)

Example 55 with IAE

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);
}
Also used : IntOpenHashSet(it.unimi.dsi.fastutil.ints.IntOpenHashSet) ConciseBitmapFactory(org.apache.druid.collections.bitmap.ConciseBitmapFactory) IntSet(it.unimi.dsi.fastutil.ints.IntSet) MutableBitmap(org.apache.druid.collections.bitmap.MutableBitmap) IAE(org.apache.druid.java.util.common.IAE) RoaringBitmapFactory(org.apache.druid.collections.bitmap.RoaringBitmapFactory) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

IAE (org.apache.druid.java.util.common.IAE)115 ISE (org.apache.druid.java.util.common.ISE)23 IOException (java.io.IOException)20 ByteBuffer (java.nio.ByteBuffer)19 ArrayList (java.util.ArrayList)16 List (java.util.List)14 Expr (org.apache.druid.math.expr.Expr)14 Nullable (javax.annotation.Nullable)12 ColumnType (org.apache.druid.segment.column.ColumnType)10 HashSet (java.util.HashSet)8 Map (java.util.Map)8 Interval (org.joda.time.Interval)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 HashMap (java.util.HashMap)7 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)7 File (java.io.File)6 Iterables (com.google.common.collect.Iterables)5 Arrays (java.util.Arrays)5 Test (org.junit.Test)5 ImmutableMap (com.google.common.collect.ImmutableMap)4