Search in sources :

Example 96 with Get

use of org.apache.hadoop.hbase.client.Get in project hbase by apache.

the class TestQuotaThrottle method doGets.

private long doGets(int maxOps, final Table... tables) throws Exception {
    int count = 0;
    try {
        while (count < maxOps) {
            Get get = new Get(Bytes.toBytes("row-" + count));
            for (final Table table : tables) {
                table.get(get);
            }
            count += tables.length;
        }
    } catch (ThrottlingException e) {
        LOG.error("get failed after nRetries=" + count, e);
    }
    return count;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get)

Example 97 with Get

use of org.apache.hadoop.hbase.client.Get in project hbase by apache.

the class TestProtobufUtil method testGet.

/**
   * Test basic Get conversions.
   *
   * @throws IOException
   */
@Test
public void testGet() throws IOException {
    ClientProtos.Get.Builder getBuilder = ClientProtos.Get.newBuilder();
    getBuilder.setRow(ByteString.copyFromUtf8("row"));
    Column.Builder columnBuilder = Column.newBuilder();
    columnBuilder.setFamily(ByteString.copyFromUtf8("f1"));
    columnBuilder.addQualifier(ByteString.copyFromUtf8("c1"));
    columnBuilder.addQualifier(ByteString.copyFromUtf8("c2"));
    getBuilder.addColumn(columnBuilder.build());
    columnBuilder.clear();
    columnBuilder.setFamily(ByteString.copyFromUtf8("f2"));
    getBuilder.addColumn(columnBuilder.build());
    getBuilder.setLoadColumnFamiliesOnDemand(true);
    ClientProtos.Get proto = getBuilder.build();
    // default fields
    assertEquals(1, proto.getMaxVersions());
    assertEquals(true, proto.getCacheBlocks());
    // set the default value for equal comparison
    getBuilder = ClientProtos.Get.newBuilder(proto);
    getBuilder.setMaxVersions(1);
    getBuilder.setCacheBlocks(true);
    Get get = ProtobufUtil.toGet(proto);
    assertEquals(getBuilder.build(), ProtobufUtil.toGet(get));
}
Also used : Column(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.Column) Get(org.apache.hadoop.hbase.client.Get) ClientProtos(org.apache.hadoop.hbase.protobuf.generated.ClientProtos) Test(org.junit.Test)

Example 98 with Get

use of org.apache.hadoop.hbase.client.Get in project hbase by apache.

the class TestVisibilityLabelsReplication method verifyGet.

protected void verifyGet(final byte[] row, final String visString, final int expected, final boolean nullExpected, final String... auths) throws IOException, InterruptedException {
    PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {

        public Void run() throws Exception {
            try (Connection connection = ConnectionFactory.createConnection(conf1);
                Table table2 = connection.getTable(TABLE_NAME)) {
                CellScanner cellScanner;
                Cell current;
                Get get = new Get(row);
                get.setAuthorizations(new Authorizations(auths));
                Result result = table2.get(get);
                cellScanner = result.cellScanner();
                boolean advance = cellScanner.advance();
                if (nullExpected) {
                    assertTrue(!advance);
                    return null;
                }
                current = cellScanner.current();
                assertArrayEquals(CellUtil.cloneRow(current), row);
                for (Tag tag : TestCoprocessorForTagsAtSink.tags) {
                    LOG.info("The tag type is " + tag.getType());
                }
                assertEquals(expected, TestCoprocessorForTagsAtSink.tags.size());
                Tag tag = TestCoprocessorForTagsAtSink.tags.get(1);
                if (tag.getType() != NON_VIS_TAG_TYPE) {
                    assertEquals(TagType.VISIBILITY_EXP_SERIALIZATION_FORMAT_TAG_TYPE, tag.getType());
                }
                tag = TestCoprocessorForTagsAtSink.tags.get(0);
                boolean foundNonVisTag = false;
                for (Tag t : TestCoprocessorForTagsAtSink.tags) {
                    if (t.getType() == NON_VIS_TAG_TYPE) {
                        assertEquals(TEMP, TagUtil.getValueAsString(t));
                        foundNonVisTag = true;
                        break;
                    }
                }
                doAssert(row, visString);
                assertTrue(foundNonVisTag);
                return null;
            }
        }
    };
    USER1.runAs(scanAction);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get) Connection(org.apache.hadoop.hbase.client.Connection) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) Tag(org.apache.hadoop.hbase.Tag) CellScanner(org.apache.hadoop.hbase.CellScanner) Cell(org.apache.hadoop.hbase.Cell) Result(org.apache.hadoop.hbase.client.Result)

Example 99 with Get

use of org.apache.hadoop.hbase.client.Get in project hbase by apache.

the class TestCellACLWithMultipleVersions method testDeleteWithFutureTimestamp.

@Test
public void testDeleteWithFutureTimestamp() throws Exception {
    // Store two values, one in the future
    verifyAllowed(new AccessTestAction() {

        @Override
        public Object run() throws Exception {
            try (Connection connection = ConnectionFactory.createConnection(conf)) {
                try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
                    // Store a read write ACL without a timestamp, server will use current time
                    Put p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q2, ONE);
                    Map<String, Permission> readAndWritePerms = prepareCellPermissions(usersAndGroups, Action.READ, Action.WRITE);
                    p.setACL(readAndWritePerms);
                    t.put(p);
                    p = new Put(TEST_ROW).addColumn(TEST_FAMILY2, TEST_Q2, ONE);
                    p.setACL(readAndWritePerms);
                    t.put(p);
                    LOG.info("Stored at current time");
                    // Store read only ACL at a future time
                    p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, EnvironmentEdgeManager.currentTime() + 1000000, ZERO);
                    p.setACL(prepareCellPermissions(new String[] { USER_OTHER.getShortName(), AuthUtil.toGroupEntry(GROUP) }, Action.READ));
                    t.put(p);
                }
            }
            return null;
        }
    }, USER_OWNER);
    // Confirm stores are visible
    AccessTestAction getQ1 = new AccessTestAction() {

        @Override
        public Object run() throws Exception {
            Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1);
            try (Connection connection = ConnectionFactory.createConnection(conf)) {
                try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
                    return t.get(get).listCells();
                }
            }
        }
    };
    AccessTestAction getQ2 = new AccessTestAction() {

        @Override
        public Object run() throws Exception {
            Get get = new Get(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q2);
            try (Connection connection = ConnectionFactory.createConnection(conf)) {
                try (Table t = connection.getTable(TEST_TABLE.getTableName())) {
                    return t.get(get).listCells();
                }
            }
        }
    };
    verifyAllowed(getQ1, USER_OWNER, USER_OTHER, GROUP_USER);
    verifyAllowed(getQ2, USER_OWNER, USER_OTHER, GROUP_USER);
    // Issue a DELETE for the family, should succeed because the future ACL is
    // not considered
    AccessTestAction deleteFamily1 = getDeleteFamilyAction(TEST_FAMILY1);
    AccessTestAction deleteFamily2 = getDeleteFamilyAction(TEST_FAMILY2);
    verifyAllowed(deleteFamily1, USER_OTHER);
    verifyAllowed(deleteFamily2, GROUP_USER);
    // The future put should still exist
    verifyAllowed(getQ1, USER_OWNER, USER_OTHER, GROUP_USER);
    // The other put should be covered by the tombstone
    verifyIfNull(getQ2, USER_OTHER, GROUP_USER);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get) Connection(org.apache.hadoop.hbase.client.Connection) HashMap(java.util.HashMap) Map(java.util.Map) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 100 with Get

use of org.apache.hadoop.hbase.client.Get in project hbase by apache.

the class TestCellACLWithMultipleVersions method testCellPermissionwithVersions.

@Test
public void testCellPermissionwithVersions() throws Exception {
    // store two sets of values, one store with a cell level ACL, and one
    // without
    final Map<String, Permission> writePerms = prepareCellPermissions(usersAndGroups, Action.WRITE);
    final Map<String, Permission> readPerms = prepareCellPermissions(usersAndGroups, Action.READ);
    verifyAllowed(new AccessTestAction() {

        @Override
        public Object run() throws Exception {
            try (Connection connection = ConnectionFactory.createConnection(conf);
                Table t = connection.getTable(TEST_TABLE.getTableName())) {
                Put p;
                // with ro ACL
                p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
                p.setACL(writePerms);
                t.put(p);
                // with ro ACL
                p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
                p.setACL(readPerms);
                t.put(p);
                p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
                p.setACL(writePerms);
                t.put(p);
                p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
                p.setACL(readPerms);
                t.put(p);
                p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
                p.setACL(writePerms);
                t.put(p);
            }
            return null;
        }
    }, USER_OWNER);
    /* ---- Gets ---- */
    AccessTestAction getQ1 = new AccessTestAction() {

        @Override
        public Object run() throws Exception {
            Get get = new Get(TEST_ROW);
            get.setMaxVersions(10);
            try (Connection connection = ConnectionFactory.createConnection(conf);
                Table t = connection.getTable(TEST_TABLE.getTableName())) {
                return t.get(get).listCells();
            }
        }
    };
    AccessTestAction get2 = new AccessTestAction() {

        @Override
        public Object run() throws Exception {
            Get get = new Get(TEST_ROW);
            get.setMaxVersions(10);
            try (Connection connection = ConnectionFactory.createConnection(conf);
                Table t = connection.getTable(TEST_TABLE.getTableName())) {
                return t.get(get).listCells();
            }
        }
    };
    // Confirm special read access set at cell level
    verifyAllowed(GROUP_USER, getQ1, 2);
    verifyAllowed(USER_OTHER, getQ1, 2);
    // store two sets of values, one store with a cell level ACL, and one
    // without
    verifyAllowed(new AccessTestAction() {

        @Override
        public Object run() throws Exception {
            try (Connection connection = ConnectionFactory.createConnection(conf);
                Table t = connection.getTable(TEST_TABLE.getTableName())) {
                Put p;
                p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
                p.setACL(writePerms);
                t.put(p);
                p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
                p.setACL(readPerms);
                t.put(p);
                p = new Put(TEST_ROW).addColumn(TEST_FAMILY1, TEST_Q1, ZERO);
                p.setACL(writePerms);
                t.put(p);
            }
            return null;
        }
    }, USER_OWNER);
    // Confirm special read access set at cell level
    verifyAllowed(USER_OTHER, get2, 1);
    verifyAllowed(GROUP_USER, get2, 1);
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Get(org.apache.hadoop.hbase.client.Get) Connection(org.apache.hadoop.hbase.client.Connection) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Aggregations

Get (org.apache.hadoop.hbase.client.Get)377 Result (org.apache.hadoop.hbase.client.Result)269 Test (org.junit.Test)169 Put (org.apache.hadoop.hbase.client.Put)114 Table (org.apache.hadoop.hbase.client.Table)107 Cell (org.apache.hadoop.hbase.Cell)84 IOException (java.io.IOException)58 Connection (org.apache.hadoop.hbase.client.Connection)48 TableName (org.apache.hadoop.hbase.TableName)45 Delete (org.apache.hadoop.hbase.client.Delete)41 ArrayList (java.util.ArrayList)38 Scan (org.apache.hadoop.hbase.client.Scan)33 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)32 Configuration (org.apache.hadoop.conf.Configuration)31 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)23 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)23 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)23 Map (java.util.Map)22 KeyValue (org.apache.hadoop.hbase.KeyValue)21 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)21