Search in sources :

Example 11 with TreeMap

use of java.util.TreeMap in project hbase by apache.

the class AccessControlLists method loadAll.

/**
   * Loads all of the permission grants stored in a region of the {@code _acl_}
   * table.
   *
   * @param aclRegion
   * @return a map of the permissions for this table.
   * @throws IOException
   */
static Map<byte[], ListMultimap<String, TablePermission>> loadAll(Region aclRegion) throws IOException {
    if (!isAclRegion(aclRegion)) {
        throw new IOException("Can only load permissions from " + ACL_TABLE_NAME);
    }
    Map<byte[], ListMultimap<String, TablePermission>> allPerms = new TreeMap<>(Bytes.BYTES_RAWCOMPARATOR);
    // do a full scan of _acl_ table
    Scan scan = new Scan();
    scan.addFamily(ACL_LIST_FAMILY);
    InternalScanner iScanner = null;
    try {
        iScanner = aclRegion.getScanner(scan);
        while (true) {
            List<Cell> row = new ArrayList<>();
            boolean hasNext = iScanner.next(row);
            ListMultimap<String, TablePermission> perms = ArrayListMultimap.create();
            byte[] entry = null;
            for (Cell kv : row) {
                if (entry == null) {
                    entry = CellUtil.cloneRow(kv);
                }
                Pair<String, TablePermission> permissionsOfUserOnTable = parsePermissionRecord(entry, kv);
                if (permissionsOfUserOnTable != null) {
                    String username = permissionsOfUserOnTable.getFirst();
                    TablePermission permissions = permissionsOfUserOnTable.getSecond();
                    perms.put(username, permissions);
                }
            }
            if (entry != null) {
                allPerms.put(entry, perms);
            }
            if (!hasNext) {
                break;
            }
        }
    } finally {
        if (iScanner != null) {
            iScanner.close();
        }
    }
    return allPerms;
}
Also used : InternalScanner(org.apache.hadoop.hbase.regionserver.InternalScanner) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TreeMap(java.util.TreeMap) Scan(org.apache.hadoop.hbase.client.Scan) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) Cell(org.apache.hadoop.hbase.Cell)

Example 12 with TreeMap

use of java.util.TreeMap in project hbase by apache.

the class AccessControlLists method loadAll.

/**
   * Load all permissions from the region server holding {@code _acl_},
   * primarily intended for testing purposes.
   */
static Map<byte[], ListMultimap<String, TablePermission>> loadAll(Configuration conf) throws IOException {
    Map<byte[], ListMultimap<String, TablePermission>> allPerms = new TreeMap<>(Bytes.BYTES_RAWCOMPARATOR);
    // do a full scan of _acl_, filtering on only first table region rows
    Scan scan = new Scan();
    scan.addFamily(ACL_LIST_FAMILY);
    ResultScanner scanner = null;
    // TODO: Pass in a Connection rather than create one each time.
    try (Connection connection = ConnectionFactory.createConnection(conf)) {
        try (Table table = connection.getTable(ACL_TABLE_NAME)) {
            scanner = table.getScanner(scan);
            try {
                for (Result row : scanner) {
                    ListMultimap<String, TablePermission> resultPerms = parsePermissions(row.getRow(), row);
                    allPerms.put(row.getRow(), resultPerms);
                }
            } finally {
                if (scanner != null)
                    scanner.close();
            }
        }
    }
    return allPerms;
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Table(org.apache.hadoop.hbase.client.Table) Connection(org.apache.hadoop.hbase.client.Connection) Scan(org.apache.hadoop.hbase.client.Scan) TreeMap(java.util.TreeMap) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) Result(org.apache.hadoop.hbase.client.Result)

Example 13 with TreeMap

use of java.util.TreeMap in project hadoop by apache.

the class TestRLESparseResourceAllocation method testMergesubtractTestNonNegative.

@Test
public void testMergesubtractTestNonNegative() throws PlanningException {
    // starting with default array example
    TreeMap<Long, Resource> a = new TreeMap<>();
    TreeMap<Long, Resource> b = new TreeMap<>();
    setupArrays(a, b);
    RLESparseResourceAllocation rleA = new RLESparseResourceAllocation(a, new DefaultResourceCalculator());
    RLESparseResourceAllocation rleB = new RLESparseResourceAllocation(b, new DefaultResourceCalculator());
    try {
        RLESparseResourceAllocation out = RLESparseResourceAllocation.merge(new DefaultResourceCalculator(), Resource.newInstance(100 * 128 * 1024, 100 * 32), rleA, rleB, RLEOperator.subtractTestNonNegative, 0, 60);
        fail();
    } catch (PlanningException pe) {
    // Expected!
    }
    // NOTE a is empty!! so the subtraction is implicitly considered negative
    // and the test should fail
    a = new TreeMap<>();
    b = new TreeMap<>();
    b.put(11L, Resource.newInstance(5, 6));
    rleA = new RLESparseResourceAllocation(a, new DefaultResourceCalculator());
    rleB = new RLESparseResourceAllocation(b, new DefaultResourceCalculator());
    try {
        RLESparseResourceAllocation out = RLESparseResourceAllocation.merge(new DefaultResourceCalculator(), Resource.newInstance(100 * 128 * 1024, 100 * 32), rleA, rleB, RLEOperator.subtractTestNonNegative, 0, 60);
        fail();
    } catch (PlanningException pe) {
    // Expected!
    }
    // Testing that the subtractTestNonNegative detects problems even if only one
    // of the resource dimensions is "<0"
    a.put(10L, Resource.newInstance(10, 5));
    b.put(11L, Resource.newInstance(5, 6));
    rleA = new RLESparseResourceAllocation(a, new DefaultResourceCalculator());
    rleB = new RLESparseResourceAllocation(b, new DefaultResourceCalculator());
    try {
        RLESparseResourceAllocation out = RLESparseResourceAllocation.merge(new DefaultResourceCalculator(), Resource.newInstance(100 * 128 * 1024, 100 * 32), rleA, rleB, RLEOperator.subtractTestNonNegative, 0, 60);
        fail();
    } catch (PlanningException pe) {
    // Expected!
    }
    // try with reverse setting
    a.put(10L, Resource.newInstance(5, 10));
    b.put(11L, Resource.newInstance(6, 5));
    rleA = new RLESparseResourceAllocation(a, new DefaultResourceCalculator());
    rleB = new RLESparseResourceAllocation(b, new DefaultResourceCalculator());
    try {
        RLESparseResourceAllocation out = RLESparseResourceAllocation.merge(new DefaultResourceCalculator(), Resource.newInstance(100 * 128 * 1024, 100 * 32), rleA, rleB, RLEOperator.subtractTestNonNegative, 0, 60);
        fail();
    } catch (PlanningException pe) {
    // Expected!
    }
    // trying a case that should work
    a.put(10L, Resource.newInstance(10, 6));
    b.put(11L, Resource.newInstance(5, 6));
    rleA = new RLESparseResourceAllocation(a, new DefaultResourceCalculator());
    rleB = new RLESparseResourceAllocation(b, new DefaultResourceCalculator());
    RLESparseResourceAllocation out = RLESparseResourceAllocation.merge(new DefaultResourceCalculator(), Resource.newInstance(100 * 128 * 1024, 100 * 32), rleA, rleB, RLEOperator.subtractTestNonNegative, 0, 60);
}
Also used : DefaultResourceCalculator(org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator) Resource(org.apache.hadoop.yarn.api.records.Resource) PlanningException(org.apache.hadoop.yarn.server.resourcemanager.reservation.exceptions.PlanningException) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 14 with TreeMap

use of java.util.TreeMap in project hadoop by apache.

the class TestRLESparseResourceAllocation method testMergeAdd.

@Test
public void testMergeAdd() throws PlanningException {
    TreeMap<Long, Resource> a = new TreeMap<>();
    TreeMap<Long, Resource> b = new TreeMap<>();
    setupArrays(a, b);
    RLESparseResourceAllocation rleA = new RLESparseResourceAllocation(a, new DefaultResourceCalculator());
    RLESparseResourceAllocation rleB = new RLESparseResourceAllocation(b, new DefaultResourceCalculator());
    RLESparseResourceAllocation out = RLESparseResourceAllocation.merge(new DefaultResourceCalculator(), Resource.newInstance(100 * 128 * 1024, 100 * 32), rleA, rleB, RLEOperator.add, 18, 45);
    System.out.println(out);
    long[] time = { 18, 20, 22, 30, 33, 40, 43, 45 };
    int[] alloc = { 10, 15, 20, 25, 30, 40, 30 };
    validate(out, time, alloc);
}
Also used : DefaultResourceCalculator(org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator) Resource(org.apache.hadoop.yarn.api.records.Resource) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 15 with TreeMap

use of java.util.TreeMap in project hadoop by apache.

the class TestRLESparseResourceAllocation method testMergeMin.

@Test
public void testMergeMin() throws PlanningException {
    TreeMap<Long, Resource> a = new TreeMap<>();
    TreeMap<Long, Resource> b = new TreeMap<>();
    setupArrays(a, b);
    RLESparseResourceAllocation rleA = new RLESparseResourceAllocation(a, new DefaultResourceCalculator());
    RLESparseResourceAllocation rleB = new RLESparseResourceAllocation(b, new DefaultResourceCalculator());
    RLESparseResourceAllocation out = RLESparseResourceAllocation.merge(new DefaultResourceCalculator(), Resource.newInstance(100 * 128 * 1024, 100 * 32), rleA, rleB, RLEOperator.min, 0, 60);
    System.out.println(out);
    long[] time = { 10, 22, 33, 40, 43, 50, 60 };
    int[] alloc = { 5, 10, 15, 20, 10, 0 };
    validate(out, time, alloc);
}
Also used : DefaultResourceCalculator(org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator) Resource(org.apache.hadoop.yarn.api.records.Resource) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Aggregations

TreeMap (java.util.TreeMap)4328 Map (java.util.Map)1215 ArrayList (java.util.ArrayList)908 HashMap (java.util.HashMap)848 Test (org.junit.Test)610 List (java.util.List)530 Before (org.junit.Before)504 IOException (java.io.IOException)390 HashSet (java.util.HashSet)292 File (java.io.File)260 Set (java.util.Set)258 SortedMap (java.util.SortedMap)238 TreeSet (java.util.TreeSet)208 LinkedHashMap (java.util.LinkedHashMap)181 Key (org.apache.accumulo.core.data.Key)156 Value (org.apache.accumulo.core.data.Value)156 Iterator (java.util.Iterator)147 NavigableMap (java.util.NavigableMap)124 Collection (java.util.Collection)111 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)110