Search in sources :

Example 51 with Append

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

the class TestSpaceQuotaBasicFunctioning method testNoWritesWithAppend.

@Test
public void testNoWritesWithAppend() throws Exception {
    Append a = new Append(Bytes.toBytes("to_reject"));
    a.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), Bytes.toBytes("reject"));
    helper.writeUntilViolationAndVerifyViolation(SpaceViolationPolicy.NO_WRITES, a);
}
Also used : Append(org.apache.hadoop.hbase.client.Append) Test(org.junit.Test)

Example 52 with Append

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

the class TestRegionServerMetrics method testAppend.

@Test
public void testAppend() throws Exception {
    doNPuts(1, false);
    for (int count = 0; count < 73; count++) {
        Append append = new Append(row);
        append.addColumn(cf, qualifier, Bytes.toBytes(",Test"));
        table.append(append);
    }
    metricsRegionServer.getRegionServerWrapper().forceRecompute();
    assertCounter("appendNumOps", 73);
}
Also used : Append(org.apache.hadoop.hbase.client.Append) Test(org.junit.Test)

Example 53 with Append

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

the class TestVisibilityLabels method testLabelsWithAppend.

@Test
public void testLabelsWithAppend() throws Throwable {
    TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
    try (Table table = TEST_UTIL.createTable(tableName, fam)) {
        byte[] row1 = Bytes.toBytes("row1");
        byte[] val = Bytes.toBytes("a");
        Put put = new Put(row1);
        put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, val);
        put.setCellVisibility(new CellVisibility(SECRET + " & " + CONFIDENTIAL));
        table.put(put);
        Get get = new Get(row1);
        get.setAuthorizations(new Authorizations(SECRET));
        Result result = table.get(get);
        assertTrue(result.isEmpty());
        Append append = new Append(row1);
        append.addColumn(fam, qual, Bytes.toBytes("b"));
        table.append(append);
        result = table.get(get);
        assertTrue(result.isEmpty());
        append = new Append(row1);
        append.addColumn(fam, qual, Bytes.toBytes("c"));
        append.setCellVisibility(new CellVisibility(SECRET));
        table.append(append);
        result = table.get(get);
        assertTrue(!result.isEmpty());
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) Append(org.apache.hadoop.hbase.client.Append) Get(org.apache.hadoop.hbase.client.Get) Put(org.apache.hadoop.hbase.client.Put) Result(org.apache.hadoop.hbase.client.Result) RegionActionResult(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionActionResult) Test(org.junit.Test)

Example 54 with Append

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

the class TestVisibilityWithCheckAuths method testLabelsWithAppend.

@Test
public void testLabelsWithAppend() throws Throwable {
    PrivilegedExceptionAction<VisibilityLabelsResponse> action = new PrivilegedExceptionAction<VisibilityLabelsResponse>() {

        @Override
        public VisibilityLabelsResponse run() throws Exception {
            try (Connection conn = ConnectionFactory.createConnection(conf)) {
                return VisibilityClient.setAuths(conn, new String[] { TOPSECRET }, USER.getShortName());
            } catch (Throwable e) {
            }
            return null;
        }
    };
    SUPERUSER.runAs(action);
    final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
    try (Table table = TEST_UTIL.createTable(tableName, fam)) {
        final byte[] row1 = Bytes.toBytes("row1");
        final byte[] val = Bytes.toBytes("a");
        PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {

            @Override
            public Void run() throws Exception {
                try (Connection connection = ConnectionFactory.createConnection(conf);
                    Table table = connection.getTable(tableName)) {
                    Put put = new Put(row1);
                    put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, val);
                    put.setCellVisibility(new CellVisibility(TOPSECRET));
                    table.put(put);
                }
                return null;
            }
        };
        USER.runAs(actiona);
        actiona = new PrivilegedExceptionAction<Void>() {

            @Override
            public Void run() throws Exception {
                try (Connection connection = ConnectionFactory.createConnection(conf);
                    Table table = connection.getTable(tableName)) {
                    Append append = new Append(row1);
                    append.addColumn(fam, qual, Bytes.toBytes("b"));
                    table.append(append);
                }
                return null;
            }
        };
        USER.runAs(actiona);
        actiona = new PrivilegedExceptionAction<Void>() {

            @Override
            public Void run() throws Exception {
                try (Connection connection = ConnectionFactory.createConnection(conf);
                    Table table = connection.getTable(tableName)) {
                    Append append = new Append(row1);
                    append.addColumn(fam, qual, Bytes.toBytes("c"));
                    append.setCellVisibility(new CellVisibility(PUBLIC));
                    table.append(append);
                    Assert.fail("Testcase should fail with AccesDeniedException");
                } catch (Throwable t) {
                    assertTrue(t.getMessage().contains("AccessDeniedException"));
                }
                return null;
            }
        };
        USER.runAs(actiona);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Connection(org.apache.hadoop.hbase.client.Connection) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Put(org.apache.hadoop.hbase.client.Put) IOException(java.io.IOException) TableName(org.apache.hadoop.hbase.TableName) Append(org.apache.hadoop.hbase.client.Append) VisibilityLabelsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse) Test(org.junit.Test)

Example 55 with Append

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

the class ThriftHBaseServiceHandler method append.

@Override
public List<TCell> append(TAppend tappend) throws IOError, TException {
    if (tappend.getRow().length == 0 || tappend.getTable().length == 0) {
        throw new TException("Must supply a table and a row key; can't append");
    }
    Table table = null;
    try {
        table = getTable(tappend.getTable());
        Append append = ThriftUtilities.appendFromThrift(tappend);
        Result result = table.append(append);
        return ThriftUtilities.cellFromHBase(result.rawCells());
    } catch (IOException e) {
        LOG.warn(e.getMessage(), e);
        throw getIOError(e);
    } finally {
        closeTable(table);
    }
}
Also used : TException(org.apache.thrift.TException) Table(org.apache.hadoop.hbase.client.Table) TAppend(org.apache.hadoop.hbase.thrift.generated.TAppend) Append(org.apache.hadoop.hbase.client.Append) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) TRowResult(org.apache.hadoop.hbase.thrift.generated.TRowResult)

Aggregations

Append (org.apache.hadoop.hbase.client.Append)62 Test (org.junit.Test)31 Result (org.apache.hadoop.hbase.client.Result)26 Increment (org.apache.hadoop.hbase.client.Increment)25 Put (org.apache.hadoop.hbase.client.Put)23 IOException (java.io.IOException)17 Get (org.apache.hadoop.hbase.client.Get)17 Delete (org.apache.hadoop.hbase.client.Delete)16 Table (org.apache.hadoop.hbase.client.Table)15 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)10 TableName (org.apache.hadoop.hbase.TableName)10 RowMutations (org.apache.hadoop.hbase.client.RowMutations)10 Cell (org.apache.hadoop.hbase.Cell)9 CheckAndMutateResult (org.apache.hadoop.hbase.client.CheckAndMutateResult)8 Mutation (org.apache.hadoop.hbase.client.Mutation)7 ArrayList (java.util.ArrayList)5 CheckAndMutate (org.apache.hadoop.hbase.client.CheckAndMutate)5 MutationProto (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto)5 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)5 List (java.util.List)4