Java 类org.apache.hadoop.hbase.client.Append 实例源码

项目:ditb    文件:ThriftUtilities.java   
public static Append appendFromThrift(TAppend append) throws IOException {
  Append out = new Append(append.getRow());
  for (TColumnValue column : append.getColumns()) {
    out.add(column.getFamily(), column.getQualifier(), column.getValue());
  }

  if (append.isSetAttributes()) {
    addAttributes(out, append.getAttributes());
  }

  if (append.isSetDurability()) {
    out.setDurability(durabilityFromThrift(append.getDurability()));
  }

  if(append.getCellVisibility() != null) {
    out.setCellVisibility(new CellVisibility(append.getCellVisibility().getExpression()));
  }

  return out;
}
项目:ditb    文件:ThriftUtilities.java   
/**
 * From a {@link TAppend} create an {@link Append}.
 * @param tappend the Thrift version of an append.
 * @return an increment that the {@link TAppend} represented.
 */
public static Append appendFromThrift(TAppend tappend) {
  Append append = new Append(tappend.getRow());
  List<ByteBuffer> columns = tappend.getColumns();
  List<ByteBuffer> values = tappend.getValues();

  if (columns.size() != values.size()) {
    throw new IllegalArgumentException(
        "Sizes of columns and values in tappend object are not matching");
  }

  int length = columns.size();

  for (int i = 0; i < length; i++) {
    byte[][] famAndQf = KeyValue.parseColumn(getBytes(columns.get(i)));
    append.add(famAndQf[0], famAndQf[1], getBytes(values.get(i)));
  }
  return append;
}
项目:ditb    文件:AccessController.java   
@Override
public Result preAppendAfterRowLock(final ObserverContext<RegionCoprocessorEnvironment> c,
    final Append append) throws IOException {
  if (append.getAttribute(CHECK_COVERING_PERM) != null) {
    // We had failure with table, cf and q perm checks and now giving a chance for cell
    // perm check
    TableName table = c.getEnvironment().getRegion().getRegionInfo().getTable();
    AuthResult authResult = null;
    if (checkCoveringPermission(OpType.APPEND, c.getEnvironment(), append.getRow(),
        append.getFamilyCellMap(), HConstants.LATEST_TIMESTAMP, Action.WRITE)) {
      authResult = AuthResult.allow(OpType.APPEND.toString(), "Covering cell set",
          getActiveUser(), Action.WRITE, table, append.getFamilyCellMap());
    } else {
      authResult = AuthResult.deny(OpType.APPEND.toString(), "Covering cell set",
          getActiveUser(), Action.WRITE, table, append.getFamilyCellMap());
    }
    logResult(authResult);
    if (authorizationEnabled && !authResult.isAllowed()) {
      throw new AccessDeniedException("Insufficient permissions " +
        authResult.toContextString());
    }
  }
  return null;
}
项目:ditb    文件:TestAccessController.java   
@Test (timeout=180000)
public void testAppend() throws Exception {

  AccessTestAction appendAction = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      byte[] row = TEST_ROW;
      byte[] qualifier = TEST_QUALIFIER;
      Put put = new Put(row);
      put.add(TEST_FAMILY, qualifier, Bytes.toBytes(1));
      Append append = new Append(row);
      append.add(TEST_FAMILY, qualifier, Bytes.toBytes(2));
      try(Connection conn = ConnectionFactory.createConnection(conf);
          Table t = conn.getTable(TEST_TABLE)) {
        t.put(put);
        t.append(append);
      }
      return null;
    }
  };

  verifyAllowed(appendAction, SUPERUSER, USER_ADMIN, USER_OWNER, USER_CREATE, USER_RW,
    USER_GROUP_WRITE);
  verifyDenied(appendAction, USER_RO, USER_NONE, USER_GROUP_CREATE, USER_GROUP_READ,
    USER_GROUP_ADMIN);
}
项目:ditb    文件:TestRegionObserverInterface.java   
@Test (timeout=300000)
public void testAppendHook() throws IOException {
  TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + ".testAppendHook");
  Table table = util.createTable(tableName, new byte[][] {A, B, C});
  try {
    Append app = new Append(Bytes.toBytes(0));
    app.add(A, A, A);

    verifyMethodResult(SimpleRegionObserver.class,
        new String[] {"hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock"},
        tableName,
        new Boolean[] {false, false, false}
        );

    table.append(app);

    verifyMethodResult(SimpleRegionObserver.class,
        new String[] {"hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock"},
        tableName,
        new Boolean[] {true, true, true}
        );
  } finally {
    util.deleteTable(tableName);
    table.close();
  }
}
项目:ditb    文件:TestHRegion.java   
@Test
public void testAppendWithReadOnlyTable() throws Exception {
  byte[] TABLE = Bytes.toBytes("readOnlyTable");
  this.region = initHRegion(TABLE, getName(), CONF, true, Bytes.toBytes("somefamily"));
  boolean exceptionCaught = false;
  Append append = new Append(Bytes.toBytes("somerow"));
  append.setDurability(Durability.SKIP_WAL);
  append.add(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"),
      Bytes.toBytes("somevalue"));
  try {
    region.append(append);
  } catch (IOException e) {
    exceptionCaught = true;
  } finally {
    HRegion.closeHRegion(this.region);
    this.region = null;
  }
  assertTrue(exceptionCaught == true);
}
项目:ColumnManagerForHBase    文件:Repository.java   
NavigableMap<byte[], NavigableMap<byte[], byte[]>> getFamilyQualifierToAliasMap(
        MTableDescriptor mTableDescriptor, Mutation mutation)
        throws IOException {
  NavigableMap<byte[], NavigableMap<byte[], byte[]>> familyQualifierToAliasMap
          = new TreeMap<>(Bytes.BYTES_COMPARATOR);
  Class<?> mutationClass = mutation.getClass();
  if (Append.class.isAssignableFrom(mutationClass)) {
    familyQualifierToAliasMap
            = getFamilyQualifierToAliasMap(mTableDescriptor, (Append)mutation);
  } else if (Increment.class.isAssignableFrom(mutationClass)) {
    familyQualifierToAliasMap
            = getFamilyQualifierToAliasMap(mTableDescriptor, (Increment)mutation);
  } else if (Delete.class.isAssignableFrom(mutationClass)
          || Put.class.isAssignableFrom(mutationClass)
          || RowMutations.class.isAssignableFrom(mutationClass)) {
    // ignore: familyQualifierToAliasMap not passed to alias-processing for these mutation-types
  }
  return familyQualifierToAliasMap;
}
项目:ColumnManagerForHBase    文件:Repository.java   
NavigableMap<byte[], NavigableMap<byte[], byte[]>> getFamilyQualifierToAliasMap(
        MTableDescriptor mTableDescriptor, Append append)
        throws IOException {
  NavigableMap<byte[], NavigableMap<byte[], byte[]>> familyQualifierToAliasMap
          = new TreeMap<>(Bytes.BYTES_COMPARATOR);
  for (Entry<byte[], List<Cell>> familyToCellsMap : append.getFamilyCellMap().entrySet()) {
    byte[] colFamily = familyToCellsMap.getKey();
    List<Cell> cellList = familyToCellsMap.getValue();
    if (mTableDescriptor.getMColumnDescriptor(colFamily).columnAliasesEnabled()) {
      familyQualifierToAliasMap.put (colFamily,
              getQualifierToAliasMap(mTableDescriptor.getTableName(),
                      colFamily, cellList, true));
    }
  }
  return familyQualifierToAliasMap;
}
项目:ColumnManagerForHBase    文件:Repository.java   
Row convertQualifiersToAliases(MTableDescriptor mTableDescriptor, final Row originalRow,
        NavigableMap<byte[], NavigableMap<byte[], byte[]>> familyQualifierToAliasMap,
        int intForUniqueSignature)
        throws IOException {
  // Append, Delete, Get, Increment, Mutation, Put, RowMutations
  Class<?> originalRowClass = originalRow.getClass();
  if (Append.class.isAssignableFrom(originalRowClass)) {
    return convertQualifiersToAliases(
            mTableDescriptor, (Append)originalRow, familyQualifierToAliasMap);
  } else if (Delete.class.isAssignableFrom(originalRowClass)) {
    return convertQualifiersToAliases(mTableDescriptor, (Delete)originalRow);
  } else if (Get.class.isAssignableFrom(originalRowClass)) {
    return convertQualifiersToAliases(
            mTableDescriptor, (Get)originalRow, familyQualifierToAliasMap);
  } else if (Increment.class.isAssignableFrom(originalRowClass)) {
    return convertQualifiersToAliases(
            mTableDescriptor, (Increment)originalRow, familyQualifierToAliasMap);
  } else if (Put.class.isAssignableFrom(originalRowClass)) {
    return convertQualifiersToAliases(mTableDescriptor, (Put)originalRow);
  } else if (RowMutations.class.isAssignableFrom(originalRowClass)) {
    return convertQualifiersToAliases(mTableDescriptor, (RowMutations)originalRow);
  }
  return null;
}
项目:ColumnManagerForHBase    文件:TestColumnAliasing.java   
private void testBatchProcessing(Table table) throws IOException, InterruptedException {
  List<Row> actions = new LinkedList<>();
  actions.add(new Append(ROW_ID_02)
          .add(CF01, COLQUALIFIER03, Bytes.toBytes("appendedStringViaBatch")));
  actions.add(new Delete(ROW_ID_03).addColumn(CF01, COLQUALIFIER04));
  actions.add(new Increment(ROW_ID_02).addColumn(CF01, COLQUALIFIER05, 14));
  actions.add(new Put(ROW_ID_05).
          addColumn(CF01, COLQUALIFIER04, TABLE_PUT_WITH_LIST).
          addColumn(CF02, COLQUALIFIER02, TABLE_PUT_WITH_LIST));
  actions.add(new Get(ROW_ID_01).addColumn(CF01, COLQUALIFIER02));
  Object[] returnedObjects = new Object[actions.size()];
  table.batch(actions, returnedObjects);
  int index = 0;
  for (Object returnedObject : returnedObjects) {
    assertTrue("Table#batch action failed for " + actions.get(index).getClass().getSimpleName(),
            returnedObject != null);
    if (Get.class.isAssignableFrom(actions.get(index).getClass())) {
      Result resultFromGet = (Result)returnedObject;
      assertTrue("Table#batch Get action returned unexpected Result: expected <"
              + Bytes.toString(TABLE_PUT_WITH_LIST) + ">, returned <"
              + Bytes.toString(resultFromGet.getValue(CF01, COLQUALIFIER02)) + ">",
              Bytes.equals(TABLE_PUT_WITH_LIST, resultFromGet.getValue(CF01, COLQUALIFIER02)));
    }
    index++;
  }
}
项目:LCIndex-HBase-0.94.16    文件:RegionCoprocessorHost.java   
/**
 * @param append append object
 * @return result to return to client if default operation should be
 * bypassed, null otherwise
 * @throws IOException if an error occurred on the coprocessor
 */
public Result preAppend(Append append)
    throws IOException {
  boolean bypass = false;
  Result result = null;
  ObserverContext<RegionCoprocessorEnvironment> ctx = null;
  for (RegionEnvironment env: coprocessors) {
    if (env.getInstance() instanceof RegionObserver) {
      ctx = ObserverContext.createAndPrepare(env, ctx);
      try {
        result = ((RegionObserver)env.getInstance()).preAppend(ctx, append);
      } catch (Throwable e) {
        handleCoprocessorThrowable(env, e);
      }
      bypass |= ctx.shouldBypass();
      if (ctx.shouldComplete()) {
        break;
      }
    }
  }
  return bypass ? result : null;
}
项目:LCIndex-HBase-0.94.16    文件:RegionCoprocessorHost.java   
/**
 * @param append Append object
 * @param result the result returned by postAppend
 * @throws IOException if an error occurred on the coprocessor
 */
public void postAppend(final Append append, Result result)
    throws IOException {
  ObserverContext<RegionCoprocessorEnvironment> ctx = null;
  for (RegionEnvironment env: coprocessors) {
    if (env.getInstance() instanceof RegionObserver) {
      ctx = ObserverContext.createAndPrepare(env, ctx);
      try {
        ((RegionObserver)env.getInstance()).postAppend(ctx, append, result);
      } catch (Throwable e) {
        handleCoprocessorThrowable(env, e);
      }
      if (ctx.shouldComplete()) {
        break;
      }
    }
  }
}
项目:LCIndex-HBase-0.94.16    文件:TestHRegion.java   
public void testAppendWithReadOnlyTable() throws Exception {
  byte[] TABLE = Bytes.toBytes("readOnlyTable");
  this.region = initHRegion(TABLE, getName(), conf, true, Bytes.toBytes("somefamily"));
  boolean exceptionCaught = false;
  Append append = new Append(Bytes.toBytes("somerow"));
  append.add(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"), 
      Bytes.toBytes("somevalue"));
  try {
    region.append(append, false);
  } catch (IOException e) {
    exceptionCaught = true;
  } finally {
    HRegion.closeHRegion(this.region);
    this.region = null;
  }
  assertTrue(exceptionCaught == true);
}
项目:cloud-bigtable-client    文件:BatchExecutor.java   
ListenableFuture<? extends GeneratedMessage> issueRequest(Row row) {
  if (row instanceof Put) {
    return issuePutRequest((Put) row);
  } else if (row instanceof Delete) {
    return issueDeleteRequest((Delete) row);
  } else if (row instanceof Append) {
    return issueAppendRequest((Append) row);
  } else if (row instanceof Increment) {
    return issueIncrementRequest((Increment) row);
  } else if (row instanceof Get) {
    return issueGetRequest((Get) row);
  } else if (row instanceof RowMutations) {
    return issueRowMutationsRequest((RowMutations) row);
  }

  LOG.error("Encountered unknown action type %s", row.getClass());
  return Futures.immediateFailedFuture(
      new IllegalArgumentException("Encountered unknown action type: " + row.getClass()));
}
项目:cloud-bigtable-client    文件:TestAppend.java   
@Test
public void testAppendToEmptyCell() throws Exception {
  // Initialize
  Table table = getConnection().getTable(TABLE_NAME);
  byte[] rowKey = dataHelper.randomData("rowKey-");
  byte[] qualifier = dataHelper.randomData("qualifier-");
  byte[] value = dataHelper.randomData("value1-");

  // Put then append
  Append append = new Append(rowKey).add(COLUMN_FAMILY, qualifier, value);
  table.append(append);

  // Test result
  Get get = new Get(rowKey).addColumn(COLUMN_FAMILY, qualifier);
  get.setMaxVersions(5);
  Result result = table.get(get);
  Assert.assertEquals("There should be one version now", 1, result.size());
  Cell cell = result.getColumnLatestCell(COLUMN_FAMILY, qualifier);
  Assert.assertArrayEquals("Expect append value is entire value", value, CellUtil.cloneValue(cell));
}
项目:cloud-bigtable-client    文件:TestAppend.java   
@Test
public void testAppendNoResult() throws Exception {
  // Initialize
  Table table = getConnection().getTable(TABLE_NAME);
  byte[] rowKey = dataHelper.randomData("rowKey-");
  byte[] qual = dataHelper.randomData("qualifier-");
  byte[] value1 = dataHelper.randomData("value-");
  byte[] value2 = dataHelper.randomData("value-");

  // Put then append
  Put put = new Put(rowKey).addColumn(COLUMN_FAMILY, qual, value1);
  table.put(put);
  Append append = new Append(rowKey).add(COLUMN_FAMILY, qual, value2);
  append.setReturnResults(false);
  Result result = table.append(append);
  Assert.assertNull("Should not return result", result);
}
项目:pbase    文件:AccessController.java   
@Override
public Result preAppendAfterRowLock(final ObserverContext<RegionCoprocessorEnvironment> c,
    final Append append) throws IOException {
  if (append.getAttribute(CHECK_COVERING_PERM) != null) {
    // We had failure with table, cf and q perm checks and now giving a chance for cell
    // perm check
    TableName table = c.getEnvironment().getRegion().getRegionInfo().getTable();
    AuthResult authResult = null;
    if (checkCoveringPermission(OpType.APPEND, c.getEnvironment(), append.getRow(),
        append.getFamilyCellMap(), HConstants.LATEST_TIMESTAMP, Action.WRITE)) {
      authResult = AuthResult.allow(OpType.APPEND.toString(), "Covering cell set",
          getActiveUser(), Action.WRITE, table, append.getFamilyCellMap());
    } else {
      authResult = AuthResult.deny(OpType.APPEND.toString(), "Covering cell set",
          getActiveUser(), Action.WRITE, table, append.getFamilyCellMap());
    }
    logResult(authResult);
    if (!authResult.isAllowed()) {
      throw new AccessDeniedException("Insufficient permissions " + authResult.toContextString());
    }
  }
  return null;
}
项目:pbase    文件:TestAccessController.java   
@Test
public void testAppend() throws Exception {

  AccessTestAction appendAction = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      byte[] row = TEST_ROW;
      byte[] qualifier = TEST_QUALIFIER;
      Put put = new Put(row);
      put.add(TEST_FAMILY, qualifier, Bytes.toBytes(1));
      Append append = new Append(row);
      append.add(TEST_FAMILY, qualifier, Bytes.toBytes(2));
      Table t = new HTable(conf, TEST_TABLE.getTableName());
      try {
        t.put(put);
        t.append(append);
      } finally {
        t.close();
      }
      return null;
    }
  };

  verifyAllowed(appendAction, SUPERUSER, USER_ADMIN, USER_OWNER, USER_CREATE, USER_RW);
  verifyDenied(appendAction, USER_RO, USER_NONE);
}
项目:pbase    文件:TestRegionObserverInterface.java   
@Test (timeout=300000)
public void testAppendHook() throws IOException {
  TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + ".testAppendHook");
  Table table = util.createTable(tableName, new byte[][] {A, B, C});
  try {
    Append app = new Append(Bytes.toBytes(0));
    app.add(A, A, A);

    verifyMethodResult(SimpleRegionObserver.class,
        new String[] {"hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock"},
        tableName,
        new Boolean[] {false, false, false}
        );

    table.append(app);

    verifyMethodResult(SimpleRegionObserver.class,
        new String[] {"hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock"},
        tableName,
        new Boolean[] {true, true, true}
        );
  } finally {
    util.deleteTable(tableName);
    table.close();
  }
}
项目:pbase    文件:MultiThreadedUpdaterWithACL.java   
@Override
public Object run() throws Exception {
  try {
    if (table == null) {
      table = new HTable(conf, tableName);
    }
    if (m instanceof Increment) {
      table.increment((Increment) m);
    } else if (m instanceof Append) {
      table.append((Append) m);
    } else if (m instanceof Put) {
      table.checkAndPut(row, cf, q, v, (Put) m);
    } else if (m instanceof Delete) {
      table.checkAndDelete(row, cf, q, v, (Delete) m);
    } else {
      throw new IllegalArgumentException("unsupported mutation "
          + m.getClass().getSimpleName());
    }
    totalOpTimeMs.addAndGet(System.currentTimeMillis() - start);
  } catch (IOException e) {
    recordFailure(m, keyBase, start, e);
  }
  return null;
}
项目:pbase    文件:TestHRegion.java   
@Test
public void testAppendWithReadOnlyTable() throws Exception {
  byte[] TABLE = Bytes.toBytes("readOnlyTable");
  this.region = initHRegion(TABLE, getName(), CONF, true, Bytes.toBytes("somefamily"));
  boolean exceptionCaught = false;
  Append append = new Append(Bytes.toBytes("somerow"));
  append.setDurability(Durability.SKIP_WAL);
  append.add(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"),
      Bytes.toBytes("somevalue"));
  try {
    region.append(append);
  } catch (IOException e) {
    exceptionCaught = true;
  } finally {
    HRegion.closeHRegion(this.region);
    this.region = null;
  }
  assertTrue(exceptionCaught == true);
}
项目:HIndex    文件:ThriftUtilities.java   
public static Append appendFromThrift(TAppend append) throws IOException {
  Append out = new Append(append.getRow());
  for (TColumnValue column : append.getColumns()) {
    out.add(column.getFamily(), column.getQualifier(), column.getValue());
  }

  if (append.isSetAttributes()) {
    addAttributes(out, append.getAttributes());
  }

  if (append.isSetDurability()) {
    out.setDurability(durabilityFromThrift(append.getDurability()));
  }

  if(append.getCellVisibility() != null) {
    out.setCellVisibility(new CellVisibility(append.getCellVisibility().getExpression()));
  }

  return out;
}
项目:HIndex    文件:RegionCoprocessorHost.java   
/**
 * @param append append object
 * @return result to return to client if default operation should be
 * bypassed, null otherwise
 * @throws IOException if an error occurred on the coprocessor
 */
public Result preAppend(final Append append) throws IOException {
  boolean bypass = false;
  Result result = null;
  ObserverContext<RegionCoprocessorEnvironment> ctx = null;
  for (RegionEnvironment env: coprocessors) {
    if (env.getInstance() instanceof RegionObserver) {
      ctx = ObserverContext.createAndPrepare(env, ctx);
      Thread currentThread = Thread.currentThread();
      ClassLoader cl = currentThread.getContextClassLoader();
      try {
        currentThread.setContextClassLoader(env.getClassLoader());
        result = ((RegionObserver)env.getInstance()).preAppend(ctx, append);
      } catch (Throwable e) {
        handleCoprocessorThrowable(env, e);
      } finally {
        currentThread.setContextClassLoader(cl);
      }
      bypass |= ctx.shouldBypass();
      if (ctx.shouldComplete()) {
        break;
      }
    }
  }
  return bypass ? result : null;
}
项目:HIndex    文件:RegionCoprocessorHost.java   
/**
 * @param append Append object
 * @param result the result returned by the append
 * @throws IOException if an error occurred on the coprocessor
 */
public void postAppend(final Append append, final Result result) throws IOException {
  ObserverContext<RegionCoprocessorEnvironment> ctx = null;
  for (RegionEnvironment env: coprocessors) {
    if (env.getInstance() instanceof RegionObserver) {
      ctx = ObserverContext.createAndPrepare(env, ctx);
      Thread currentThread = Thread.currentThread();
      ClassLoader cl = currentThread.getContextClassLoader();
      try {
        currentThread.setContextClassLoader(env.getClassLoader());
        ((RegionObserver)env.getInstance()).postAppend(ctx, append, result);
      } catch (Throwable e) {
        handleCoprocessorThrowable(env, e);
      } finally {
        currentThread.setContextClassLoader(cl);
      }
      if (ctx.shouldComplete()) {
        break;
      }
    }
  }
}
项目:HIndex    文件:TestAccessController.java   
@Test
public void testAppend() throws Exception {

  AccessTestAction appendAction = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      byte[] row = TEST_ROW;
      byte[] qualifier = TEST_QUALIFIER;
      Put put = new Put(row);
      put.add(TEST_FAMILY, qualifier, Bytes.toBytes(1));
      Append append = new Append(row);
      append.add(TEST_FAMILY, qualifier, Bytes.toBytes(2));
      HTable t = new HTable(conf, TEST_TABLE.getTableName());
      try {
        t.put(put);
        t.append(append);
      } finally {
        t.close();
      }
      return null;
    }
  };

  verifyAllowed(appendAction, SUPERUSER, USER_ADMIN, USER_OWNER, USER_CREATE, USER_RW);
  verifyDenied(appendAction, USER_RO, USER_NONE);
}
项目:HIndex    文件:MultiThreadedUpdaterWithACL.java   
@Override
public Object run() throws Exception {
  try {
    if (table == null) {
      table = new HTable(conf, tableName);
    }
    if (m instanceof Increment) {
      table.increment((Increment) m);
    } else if (m instanceof Append) {
      table.append((Append) m);
    } else if (m instanceof Put) {
      table.checkAndPut(row, cf, q, v, (Put) m);
    } else if (m instanceof Delete) {
      table.checkAndDelete(row, cf, q, v, (Delete) m);
    } else {
      throw new IllegalArgumentException("unsupported mutation "
          + m.getClass().getSimpleName());
    }
    totalOpTimeMs.addAndGet(System.currentTimeMillis() - start);
  } catch (IOException e) {
    recordFailure(m, keyBase, start, e);
  }
  return null;
}
项目:HIndex    文件:TestHRegion.java   
@Test
public void testAppendWithReadOnlyTable() throws Exception {
  byte[] TABLE = Bytes.toBytes("readOnlyTable");
  this.region = initHRegion(TABLE, getName(), CONF, true, Bytes.toBytes("somefamily"));
  boolean exceptionCaught = false;
  Append append = new Append(Bytes.toBytes("somerow"));
  append.setDurability(Durability.SKIP_WAL);
  append.add(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"),
      Bytes.toBytes("somevalue"));
  try {
    region.append(append);
  } catch (IOException e) {
    exceptionCaught = true;
  } finally {
    HRegion.closeHRegion(this.region);
    this.region = null;
  }
  assertTrue(exceptionCaught == true);
}
项目:IRIndex    文件:TestAccessController.java   
@Test
public void testAppend() throws Exception {

  PrivilegedExceptionAction appendAction = new PrivilegedExceptionAction() {
    public Object run() throws Exception {
      byte[] row = Bytes.toBytes("random_row");
      byte[] qualifier = Bytes.toBytes("q");
      Put put = new Put(row);
      put.add(TEST_FAMILY, qualifier, Bytes.toBytes(1));
      Append append = new Append(row);
      append.add(TEST_FAMILY, qualifier, Bytes.toBytes(2));
      HTable t = new HTable(conf, TEST_TABLE);
      try {
        t.put(put);
        t.append(append);
      } finally {
        t.close();
      }
      return null;
    }
  };

  verifyAllowed(appendAction, SUPERUSER, USER_ADMIN, USER_OWNER, USER_RW);
  verifyDenied(appendAction, USER_CREATE, USER_RO, USER_NONE);
}
项目:IRIndex    文件:RegionCoprocessorHost.java   
/**
 * @param append append object
 * @return result to return to client if default operation should be
 * bypassed, null otherwise
 * @throws IOException if an error occurred on the coprocessor
 */
public Result preAppend(Append append)
    throws IOException {
  boolean bypass = false;
  Result result = null;
  ObserverContext<RegionCoprocessorEnvironment> ctx = null;
  for (RegionEnvironment env: coprocessors) {
    if (env.getInstance() instanceof RegionObserver) {
      ctx = ObserverContext.createAndPrepare(env, ctx);
      try {
        result = ((RegionObserver)env.getInstance()).preAppend(ctx, append);
      } catch (Throwable e) {
        handleCoprocessorThrowable(env, e);
      }
      bypass |= ctx.shouldBypass();
      if (ctx.shouldComplete()) {
        break;
      }
    }
  }
  return bypass ? result : null;
}
项目:IRIndex    文件:RegionCoprocessorHost.java   
/**
 * @param append Append object
 * @param result the result returned by postAppend
 * @throws IOException if an error occurred on the coprocessor
 */
public void postAppend(final Append append, Result result)
    throws IOException {
  ObserverContext<RegionCoprocessorEnvironment> ctx = null;
  for (RegionEnvironment env: coprocessors) {
    if (env.getInstance() instanceof RegionObserver) {
      ctx = ObserverContext.createAndPrepare(env, ctx);
      try {
        ((RegionObserver)env.getInstance()).postAppend(ctx, append, result);
      } catch (Throwable e) {
        handleCoprocessorThrowable(env, e);
      }
      if (ctx.shouldComplete()) {
        break;
      }
    }
  }
}
项目:IRIndex    文件:TestHRegion.java   
public void testAppendWithReadOnlyTable() throws Exception {
  byte[] TABLE = Bytes.toBytes("readOnlyTable");
  this.region = initHRegion(TABLE, getName(), conf, true, Bytes.toBytes("somefamily"));
  boolean exceptionCaught = false;
  Append append = new Append(Bytes.toBytes("somerow"));
  append.add(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"), 
      Bytes.toBytes("somevalue"));
  try {
    region.append(append, false);
  } catch (IOException e) {
    exceptionCaught = true;
  } finally {
    HRegion.closeHRegion(this.region);
    this.region = null;
  }
  assertTrue(exceptionCaught == true);
}
项目:hbase    文件:ThriftUtilities.java   
public static Append appendFromThrift(TAppend append) throws IOException {
  Append out = new Append(append.getRow());
  for (TColumnValue column : append.getColumns()) {
    out.addColumn(column.getFamily(), column.getQualifier(), column.getValue());
  }

  if (append.isSetAttributes()) {
    addAttributes(out, append.getAttributes());
  }

  if (append.isSetDurability()) {
    out.setDurability(durabilityFromThrift(append.getDurability()));
  }

  if(append.getCellVisibility() != null) {
    out.setCellVisibility(new CellVisibility(append.getCellVisibility().getExpression()));
  }

  return out;
}
项目:hbase    文件:ThriftUtilities.java   
/**
 * From a {@link TAppend} create an {@link Append}.
 * @param tappend the Thrift version of an append.
 * @return an increment that the {@link TAppend} represented.
 */
public static Append appendFromThrift(TAppend tappend) {
  Append append = new Append(tappend.getRow());
  List<ByteBuffer> columns = tappend.getColumns();
  List<ByteBuffer> values = tappend.getValues();

  if (columns.size() != values.size()) {
    throw new IllegalArgumentException(
        "Sizes of columns and values in tappend object are not matching");
  }

  int length = columns.size();

  for (int i = 0; i < length; i++) {
    byte[][] famAndQf = CellUtil.parseColumn(getBytes(columns.get(i)));
    append.addColumn(famAndQf[0], famAndQf[1], getBytes(values.get(i)));
  }
  return append;
}
项目:hbase    文件:AccessController.java   
@Override
public Result preAppendAfterRowLock(final ObserverContext<RegionCoprocessorEnvironment> c,
    final Append append) throws IOException {
  if (append.getAttribute(CHECK_COVERING_PERM) != null) {
    // We had failure with table, cf and q perm checks and now giving a chance for cell
    // perm check
    TableName table = c.getEnvironment().getRegion().getRegionInfo().getTable();
    AuthResult authResult = null;
    User user = getActiveUser(c);
    if (checkCoveringPermission(user, OpType.APPEND, c.getEnvironment(), append.getRow(),
        append.getFamilyCellMap(), append.getTimeRange().getMax(), Action.WRITE)) {
      authResult = AuthResult.allow(OpType.APPEND.toString(),
          "Covering cell set", user, Action.WRITE, table, append.getFamilyCellMap());
    } else {
      authResult = AuthResult.deny(OpType.APPEND.toString(),
          "Covering cell set", user, Action.WRITE, table, append.getFamilyCellMap());
    }
    AccessChecker.logResult(authResult);
    if (authorizationEnabled && !authResult.isAllowed()) {
      throw new AccessDeniedException("Insufficient permissions " +
        authResult.toContextString());
    }
  }
  return null;
}
项目:hbase    文件:HRegion.java   
/**
 * Do coprocessor pre-increment or pre-append call.
 * @return Result returned out of the coprocessor, which means bypass all further processing and
 *  return the proffered Result instead, or null which means proceed.
 */
private Result doCoprocessorPreCall(final Operation op, final Mutation mutation)
throws IOException {
  Result result = null;
  if (this.coprocessorHost != null) {
    switch(op) {
      case INCREMENT:
        result = this.coprocessorHost.preIncrementAfterRowLock((Increment)mutation);
        break;
      case APPEND:
        result = this.coprocessorHost.preAppendAfterRowLock((Append)mutation);
        break;
      default: throw new UnsupportedOperationException(op.toString());
    }
  }
  return result;
}
项目:hbase    文件:RegionCoprocessorHost.java   
/**
 * Supports Coprocessor 'bypass'.
 * @param append append object
 * @return result to return to client if default operation should be bypassed, null otherwise
 * @throws IOException if an error occurred on the coprocessor
 */
public Result preAppend(final Append append) throws IOException {
  boolean bypassable = true;
  Result defaultResult = null;
  if (this.coprocEnvironments.isEmpty()) {
    return defaultResult;
  }
  return execOperationWithResult(
    new ObserverOperationWithResult<RegionObserver, Result>(regionObserverGetter, defaultResult,
          bypassable) {
        @Override
        public Result call(RegionObserver observer) throws IOException {
          return observer.preAppend(this, append);
        }
      });
}
项目:hbase    文件:RegionCoprocessorHost.java   
/**
 * Supports Coprocessor 'bypass'.
 * @param append append object
 * @return result to return to client if default operation should be bypassed, null otherwise
 * @throws IOException if an error occurred on the coprocessor
 */
public Result preAppendAfterRowLock(final Append append) throws IOException {
  boolean bypassable = true;
  Result defaultResult = null;
  if (this.coprocEnvironments.isEmpty()) {
    return defaultResult;
  }
  return execOperationWithResult(
      new ObserverOperationWithResult<RegionObserver, Result>(regionObserverGetter,
          defaultResult, bypassable) {
        @Override
        public Result call(RegionObserver observer) throws IOException {
          return observer.preAppendAfterRowLock(this, append);
        }
      });
}
项目:hbase    文件:TestAccessController.java   
@Test (timeout=180000)
public void testAppend() throws Exception {

  AccessTestAction appendAction = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      byte[] row = TEST_ROW;
      byte[] qualifier = TEST_QUALIFIER;
      Put put = new Put(row);
      put.addColumn(TEST_FAMILY, qualifier, Bytes.toBytes(1));
      Append append = new Append(row);
      append.addColumn(TEST_FAMILY, qualifier, Bytes.toBytes(2));
      try(Connection conn = ConnectionFactory.createConnection(conf);
          Table t = conn.getTable(TEST_TABLE)) {
        t.put(put);
        t.append(append);
      }
      return null;
    }
  };

  verifyAllowed(appendAction, SUPERUSER, USER_ADMIN, USER_OWNER, USER_CREATE, USER_RW,
    USER_GROUP_WRITE);
  verifyDenied(appendAction, USER_RO, USER_NONE, USER_GROUP_CREATE, USER_GROUP_READ,
    USER_GROUP_ADMIN);
}
项目:hbase    文件:TestRegionObserverInterface.java   
@Test
public void testAppendHook() throws IOException {
  final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
  Table table = util.createTable(tableName, new byte[][] { A, B, C });
  try {
    Append app = new Append(Bytes.toBytes(0));
    app.addColumn(A, A, A);

    verifyMethodResult(SimpleRegionObserver.class,
      new String[] { "hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock" }, tableName,
      new Boolean[] { false, false, false });

    table.append(app);

    verifyMethodResult(SimpleRegionObserver.class,
      new String[] { "hadPreAppend", "hadPostAppend", "hadPreAppendAfterRowLock" }, tableName,
      new Boolean[] { true, true, true });
  } finally {
    util.deleteTable(tableName);
    table.close();
  }
}
项目:hbase    文件:TestAppendTimeRange.java   
@Override
public Result preAppend(final ObserverContext<RegionCoprocessorEnvironment> e,
    final Append append) throws IOException {
  NavigableMap<byte [], List<Cell>> map = append.getFamilyCellMap();
  for (Map.Entry<byte [], List<Cell>> entry : map.entrySet()) {
    for (Cell cell : entry.getValue()) {
      String appendStr = Bytes.toString(cell.getValueArray(), cell.getValueOffset(),
          cell.getValueLength());
      if (appendStr.equals("b")) {
        tr10 = append.getTimeRange();
      } else if (appendStr.equals("c") && !append.getTimeRange().isAllTime()) {
        tr2 = append.getTimeRange();
      }
    }
  }
  return null;
}