Java 类com.google.protobuf.ZeroCopyLiteralByteString 实例源码

项目:c5    文件:CellSetModel.java   
@Override
public byte[] createProtobufOutput() {
  CellSet.Builder builder = CellSet.newBuilder();
  for (RowModel row: getRows()) {
    CellSet.Row.Builder rowBuilder = CellSet.Row.newBuilder();
    rowBuilder.setKey(ZeroCopyLiteralByteString.wrap(row.getKey()));
    for (CellModel cell: row.getCells()) {
      Cell.Builder cellBuilder = Cell.newBuilder();
      cellBuilder.setColumn(ZeroCopyLiteralByteString.wrap(cell.getColumn()));
      cellBuilder.setData(ZeroCopyLiteralByteString.wrap(cell.getValue()));
      if (cell.hasUserTimestamp()) {
        cellBuilder.setTimestamp(cell.getTimestamp());
      }
      rowBuilder.addValues(cellBuilder);
    }
    builder.addRows(rowBuilder);
  }
  return builder.build().toByteArray();
}
项目:c5    文件:HRegionServer.java   
/**
 * Roll the WAL writer of the region server.
 * @param controller the RPC controller
 * @param request the request
 * @throws ServiceException
 */
@Override
public RollWALWriterResponse rollWALWriter(final RpcController controller,
    final RollWALWriterRequest request) throws ServiceException {
  try {
    requestCount.increment();
    HLog wal = this.getWAL();
    byte[][] regionsToFlush = wal.rollWriter(true);
    RollWALWriterResponse.Builder builder = RollWALWriterResponse.newBuilder();
    if (regionsToFlush != null) {
      for (byte[] region: regionsToFlush) {
        builder.addRegionToFlush(ZeroCopyLiteralByteString.wrap(region));
      }
    }
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
项目:c5    文件:TestCoprocessorEndpoint.java   
private Map<byte [], Long> sum(final HTable table, final byte [] family,
    final byte [] qualifier, final byte [] start, final byte [] end)
throws ServiceException, Throwable {
  return table.coprocessorService(ColumnAggregationProtos.ColumnAggregationService.class,
      start, end,
    new Batch.Call<ColumnAggregationProtos.ColumnAggregationService, Long>() {
      @Override
      public Long call(ColumnAggregationProtos.ColumnAggregationService instance)
      throws IOException {
        BlockingRpcCallback<ColumnAggregationProtos.SumResponse> rpcCallback =
            new BlockingRpcCallback<ColumnAggregationProtos.SumResponse>();
        ColumnAggregationProtos.SumRequest.Builder builder =
          ColumnAggregationProtos.SumRequest.newBuilder();
        builder.setFamily(ZeroCopyLiteralByteString.wrap(family));
        if (qualifier != null && qualifier.length > 0) {
          builder.setQualifier(ZeroCopyLiteralByteString.wrap(qualifier));
        }
        instance.sum(null, builder.build(), rpcCallback);
        return rpcCallback.get().getSum();
      }
    });
}
项目:c5    文件:RequestConverter.java   
/**
 * Create a new protocol buffer GetRequest to get a row, all columns in a family.
 * If there is no such row, return the closest row before it.
 *
 * @param regionName the name of the region to get
 * @param row the row to get
 * @param family the column family to get
 * should return the immediate row before
 * @return a protocol buffer GetReuqest
 */
public static GetRequest buildGetRowOrBeforeRequest(
    final byte[] regionName, final byte[] row, final byte[] family) {
  GetRequest.Builder builder = GetRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);

  Column.Builder columnBuilder = Column.newBuilder();
  columnBuilder.setFamily(ZeroCopyLiteralByteString.wrap(family));
  ClientProtos.Get.Builder getBuilder =
    ClientProtos.Get.newBuilder();
  getBuilder.setRow(ZeroCopyLiteralByteString.wrap(row));
  getBuilder.addColumn(columnBuilder.build());
  getBuilder.setClosestRowBefore(true);
  builder.setGet(getBuilder.build());
  return builder.build();
}
项目:c5    文件:RequestConverter.java   
/**
 * Create a protocol buffer MutateRequest for a client increment
 *
 * @param regionName
 * @param row
 * @param family
 * @param qualifier
 * @param amount
 * @param durability
 * @return a mutate request
 */
public static MutateRequest buildMutateRequest(
    final byte[] regionName, final byte[] row, final byte[] family,
    final byte [] qualifier, final long amount, final Durability durability) {
  MutateRequest.Builder builder = MutateRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);

  MutationProto.Builder mutateBuilder = MutationProto.newBuilder();
  mutateBuilder.setRow(ZeroCopyLiteralByteString.wrap(row));
  mutateBuilder.setMutateType(MutationType.INCREMENT);
  mutateBuilder.setDurability(ProtobufUtil.toDurability(durability));
  ColumnValue.Builder columnBuilder = ColumnValue.newBuilder();
  columnBuilder.setFamily(ZeroCopyLiteralByteString.wrap(family));
  QualifierValue.Builder valueBuilder = QualifierValue.newBuilder();
  valueBuilder.setValue(ZeroCopyLiteralByteString.wrap(Bytes.toBytes(amount)));
  valueBuilder.setQualifier(ZeroCopyLiteralByteString.wrap(qualifier));
  columnBuilder.addQualifierValue(valueBuilder.build());
  mutateBuilder.addColumnValue(columnBuilder.build());
  builder.setMutation(mutateBuilder.build());
  return builder.build();
}
项目:c5    文件:RequestConverter.java   
/**
 * Create a protocol buffer bulk load request
 *
 * @param familyPaths
 * @param regionName
 * @param assignSeqNum
 * @return a bulk load request
 */
public static BulkLoadHFileRequest buildBulkLoadHFileRequest(
    final List<Pair<byte[], String>> familyPaths,
    final byte[] regionName, boolean assignSeqNum) {
  BulkLoadHFileRequest.Builder builder = BulkLoadHFileRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);
  FamilyPath.Builder familyPathBuilder = FamilyPath.newBuilder();
  for (Pair<byte[], String> familyPath: familyPaths) {
    familyPathBuilder.setFamily(ZeroCopyLiteralByteString.wrap(familyPath.getFirst()));
    familyPathBuilder.setPath(familyPath.getSecond());
    builder.addFamilyPath(familyPathBuilder.build());
  }
  builder.setAssignSeqNum(assignSeqNum);
  return builder.build();
}
项目:c5    文件:ProtobufUtil.java   
public static MutationProto toMutation(final MutationType type, final Mutation mutation,
    MutationProto.Builder builder)
throws IOException {
  builder = getMutationBuilderAndSetCommonFields(type, mutation, builder);
  ColumnValue.Builder columnBuilder = ColumnValue.newBuilder();
  QualifierValue.Builder valueBuilder = QualifierValue.newBuilder();
  for (Map.Entry<byte[],List<Cell>> family: mutation.getFamilyCellMap().entrySet()) {
    columnBuilder.clear();
    columnBuilder.setFamily(ZeroCopyLiteralByteString.wrap(family.getKey()));
    for (Cell cell: family.getValue()) {
      KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
      valueBuilder.setQualifier(ZeroCopyLiteralByteString.wrap(
          kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength()));
      valueBuilder.setValue(ZeroCopyLiteralByteString.wrap(
          kv.getValueArray(), kv.getValueOffset(), kv.getValueLength()));
      valueBuilder.setTimestamp(kv.getTimestamp());
      if (type == MutationType.DELETE) {
        KeyValue.Type keyValueType = KeyValue.Type.codeToType(kv.getType());
        valueBuilder.setDeleteType(toDeleteType(keyValueType));
      }
      columnBuilder.addQualifierValue(valueBuilder.build());
    }
    builder.addColumnValue(columnBuilder.build());
  }
  return builder.build();
}
项目:c5    文件:ProtobufUtil.java   
/**
 * Code shared by {@link #toMutation(MutationType, Mutation)} and
 * {@link #toMutationNoData(MutationType, Mutation)}
 * @param type
 * @param mutation
 * @return A partly-filled out protobuf'd Mutation.
 */
private static MutationProto.Builder getMutationBuilderAndSetCommonFields(final MutationType type,
    final Mutation mutation, MutationProto.Builder builder) {
  builder.setRow(ZeroCopyLiteralByteString.wrap(mutation.getRow()));
  builder.setMutateType(type);
  builder.setDurability(toDurability(mutation.getDurability()));
  builder.setTimestamp(mutation.getTimeStamp());
  Map<String, byte[]> attributes = mutation.getAttributesMap();
  if (!attributes.isEmpty()) {
    NameBytesPair.Builder attributeBuilder = NameBytesPair.newBuilder();
    for (Map.Entry<String, byte[]> attribute: attributes.entrySet()) {
      attributeBuilder.setName(attribute.getKey());
      attributeBuilder.setValue(ZeroCopyLiteralByteString.wrap(attribute.getValue()));
      builder.addAttribute(attributeBuilder.build());
    }
  }
  return builder;
}
项目:c5    文件:ProtobufUtil.java   
public static CellProtos.Cell toCell(final Cell kv) {
  // Doing this is going to kill us if we do it for all data passed.
  // St.Ack 20121205
  CellProtos.Cell.Builder kvbuilder = CellProtos.Cell.newBuilder();
  kvbuilder.setRow(ZeroCopyLiteralByteString.wrap(kv.getRowArray(), kv.getRowOffset(),
    kv.getRowLength()));
  kvbuilder.setFamily(ZeroCopyLiteralByteString.wrap(kv.getFamilyArray(),
    kv.getFamilyOffset(), kv.getFamilyLength()));
  kvbuilder.setQualifier(ZeroCopyLiteralByteString.wrap(kv.getQualifierArray(),
    kv.getQualifierOffset(), kv.getQualifierLength()));
  kvbuilder.setCellType(CellProtos.CellType.valueOf(kv.getTypeByte()));
  kvbuilder.setTimestamp(kv.getTimestamp());
  kvbuilder.setValue(ZeroCopyLiteralByteString.wrap(kv.getValueArray(), kv.getValueOffset(),
    kv.getValueLength()));
  return kvbuilder.build();
}
项目:c5    文件:ProtobufUtil.java   
public static CompactionDescriptor toCompactionDescriptor(HRegionInfo info, byte[] family,
    List<Path> inputPaths, List<Path> outputPaths, Path storeDir) {
  // compaction descriptor contains relative paths.
  // input / output paths are relative to the store dir
  // store dir is relative to region dir
  CompactionDescriptor.Builder builder = CompactionDescriptor.newBuilder()
      .setTableName(ZeroCopyLiteralByteString.wrap(info.getTableName()))
      .setEncodedRegionName(ZeroCopyLiteralByteString.wrap(info.getEncodedNameAsBytes()))
      .setFamilyName(ZeroCopyLiteralByteString.wrap(family))
      .setStoreHomeDir(storeDir.getName()); //make relative
  for (Path inputPath : inputPaths) {
    builder.addCompactionInput(inputPath.getName()); //relative path
  }
  for (Path outputPath : outputPaths) {
    builder.addCompactionOutput(outputPath.getName());
  }
  return builder.build();
}
项目:c5    文件:ZKUtil.java   
/**
 * @param regionLastFlushedSequenceId the flushed sequence id of a region which is the min of its
 *          store max seq ids
 * @param storeSequenceIds column family to sequence Id map
 * @return Serialized protobuf of <code>RegionSequenceIds</code> with pb magic prefix prepended
 *         suitable for use to filter wal edits in distributedLogReplay mode
 */
public static byte[] regionSequenceIdsToByteArray(final Long regionLastFlushedSequenceId,
    final Map<byte[], Long> storeSequenceIds) {
  ZooKeeperProtos.RegionStoreSequenceIds.Builder regionSequenceIdsBuilder =
      ZooKeeperProtos.RegionStoreSequenceIds.newBuilder();
  ZooKeeperProtos.StoreSequenceId.Builder storeSequenceIdBuilder =
      ZooKeeperProtos.StoreSequenceId.newBuilder();
  if (storeSequenceIds != null) {
    for (Map.Entry<byte[], Long> e : storeSequenceIds.entrySet()){
      byte[] columnFamilyName = e.getKey();
      Long curSeqId = e.getValue();
      storeSequenceIdBuilder.setFamilyName(ZeroCopyLiteralByteString.wrap(columnFamilyName));
      storeSequenceIdBuilder.setSequenceId(curSeqId);
      regionSequenceIdsBuilder.addStoreSequenceId(storeSequenceIdBuilder.build());
      storeSequenceIdBuilder.clear();
    }
  }
  regionSequenceIdsBuilder.setLastFlushedSequenceId(regionLastFlushedSequenceId);
  byte[] result = regionSequenceIdsBuilder.build().toByteArray();
  return ProtobufUtil.prependPBMagic(result);
}
项目:c5    文件:HRegionInfo.java   
/**
 * Convert a HRegionInfo to a RegionInfo
 *
 * @param info the HRegionInfo to convert
 * @return the converted RegionInfo
 */
public static RegionInfo convert(final HRegionInfo info) {
  if (info == null) return null;
  RegionInfo.Builder builder = RegionInfo.newBuilder();
  builder.setTableName(ProtobufUtil.toProtoTableName(info.getTable()));
  builder.setRegionId(info.getRegionId());
  if (info.getStartKey() != null) {
    builder.setStartKey(ZeroCopyLiteralByteString.wrap(info.getStartKey()));
  }
  if (info.getEndKey() != null) {
    builder.setEndKey(ZeroCopyLiteralByteString.wrap(info.getEndKey()));
  }
  builder.setOffline(info.isOffline());
  builder.setSplit(info.isSplit());
  return builder.build();
}
项目:c5    文件:SingleColumnValueFilter.java   
FilterProtos.SingleColumnValueFilter convert() {
  FilterProtos.SingleColumnValueFilter.Builder builder =
    FilterProtos.SingleColumnValueFilter.newBuilder();
  if (this.columnFamily != null) {
    builder.setColumnFamily(ZeroCopyLiteralByteString.wrap(this.columnFamily));
  }
  if (this.columnQualifier != null) {
    builder.setColumnQualifier(ZeroCopyLiteralByteString.wrap(this.columnQualifier));
  }
  HBaseProtos.CompareType compareOp = CompareType.valueOf(this.compareOp.name());
  builder.setCompareOp(compareOp);
  builder.setComparator(ProtobufUtil.toComparator(this.comparator));
  builder.setFilterIfMissing(this.filterIfMissing);
  builder.setLatestVersionOnly(this.latestVersionOnly);

  return builder.build();
}
项目:spliceengine    文件:CoprocessorTxnStore.java   
@Override
    public void elevateTransaction(Txn txn,byte[] newDestinationTable) throws IOException{
        byte[] rowKey=getTransactionRowKey(txn.getTxnId());
        TxnMessage.ElevateRequest elevateRequest=TxnMessage.ElevateRequest.newBuilder()
                .setTxnId(txn.getTxnId())
                .setNewDestinationTable(ZeroCopyLiteralByteString.wrap(Encoding.encodeBytesUnsorted(newDestinationTable))).build();

        try(TxnNetworkLayer table = tableFactory.accessTxnNetwork()){
//            TxnMessage.TxnLifecycleService service=getLifecycleService(table,rowKey);

//            SpliceRpcController controller=new SpliceRpcController();
//            service.elevateTransaction(controller,elevateRequest,new BlockingRpcCallback<TxnMessage.VoidResponse>());
//            dealWithError(controller);
            table.elevate(rowKey,elevateRequest);
            elevations.incrementAndGet();
        }
    }
项目:spliceengine    文件:TXNDecoderUtils.java   
public static TxnMessage.Txn composeValue(Cell destinationTables, IsolationLevel level, long txnId, long beginTs, long parentTs, boolean hasAdditive,
                                          boolean additive, long commitTs, long globalCommitTs, Txn.State state, long kaTime, List<Long> rollbackSubIds) {
    ByteString destTableBuffer = null;
    if(destinationTables!=null){
        destTableBuffer = ZeroCopyLiteralByteString.wrap(CellUtil.cloneValue(destinationTables));
    }
    if (level == null)
        level = Txn.IsolationLevel.SNAPSHOT_ISOLATION;
    TxnMessage.TxnInfo.Builder info = TxnMessage.TxnInfo.newBuilder().setIsolationLevel(level.encode())
            .setTxnId(txnId).setBeginTs(beginTs).setParentTxnid(parentTs);
    if (destTableBuffer !=null)
        info.setDestinationTables(destTableBuffer);
    if(hasAdditive)
        info = info.setIsAdditive(additive);
    return TxnMessage.Txn.newBuilder().setInfo(info.build())
            .setCommitTs(commitTs).setGlobalCommitTs(globalCommitTs).setState(state.getId())
            .setLastKeepAliveTime(kaTime).addAllRollbackSubIds(rollbackSubIds).build();

}
项目:spliceengine    文件:ProtoUtil.java   
public static DDLChange createDropPKConstraint(long txnId, long newConglomId, long oldConglomId,
                                               int[] srcColumnOrdering, int[] targetColumnOrdering,
                                               ColumnInfo[] columInfos, LanguageConnectionContext lcc, BasicUUID tableId) throws StandardException {
    String tableVersion = DataDictionaryUtils.getTableVersion(lcc, tableId);
    return DDLChange.newBuilder().setTxnId(txnId)
            .setDdlChangeType(DDLChangeType.DROP_PRIMARY_KEY)
            .setTentativeDropPKConstraint(
                    TentativeDropPKConstraint.newBuilder()
                            .setNewConglomId(newConglomId)
                            .setOldConglomId(oldConglomId)
                            .setTableVersion(tableVersion)
                            .addAllSrcColumnOrdering(Ints.asList(srcColumnOrdering))
                            .addAllTargetColumnOrdering(Ints.asList(targetColumnOrdering))
                            .setColumnInfos(ZeroCopyLiteralByteString.wrap(DDLUtils.serializeColumnInfoArray(columInfos))
                            )).build();
}
项目:spliceengine    文件:ProtoUtil.java   
public static DDLChange createTentativeAddConstraint (long txnId, long oldConglomId,
                                                      long newConglomId, long indexConglomerateId,
                                                      int[] srcColumnOrdering, int[] targetColumnOrdering, ColumnInfo[] columnInfo, LanguageConnectionContext lcc, BasicUUID tableId) throws StandardException {
    String tableVersion = DataDictionaryUtils.getTableVersion(lcc, tableId);
return DDLChange.newBuilder().setTxnId(txnId)
            .setDdlChangeType(DDLChangeType.ADD_UNIQUE_CONSTRAINT)
            .setTentativeAddConstraint(TentativeAddConstraint.newBuilder()
                            .setNewConglomId(newConglomId)
                            .setOldConglomId(oldConglomId)
                            .setIndexConglomerateId(indexConglomerateId)
                            .setTableVersion(tableVersion)
                   .addAllSrcColumnOrdering((srcColumnOrdering != null ? Ints.asList(srcColumnOrdering) : Ints.asList()))
                    .addAllTargetColumnOrdering((targetColumnOrdering != null ? Ints.asList(targetColumnOrdering) : Ints.asList()))
                            .setColumnInfos(ZeroCopyLiteralByteString.wrap(DDLUtils.serializeColumnInfoArray(columnInfo)))
            ).build();


}
项目:spliceengine    文件:SpliceIndexEndpoint.java   
@Override
public void bulkWrite(RpcController controller,
                      SpliceMessage.BulkWriteRequest request,
                      RpcCallback<SpliceMessage.BulkWriteResponse> done){
    try{
        byte[] bytes=bulkWrites(request.getBytes().toByteArray());
        if(bytes==null||bytes.length<=0)
            LOG.error("No bytes constructed for the result!");

        SpliceMessage.BulkWriteResponse response =SpliceMessage.BulkWriteResponse.newBuilder()
                .setBytes(ZeroCopyLiteralByteString.wrap(bytes)).build();
        done.run(response);
    }catch(IOException e){
        LOG.error("Unexpected exception performing bulk write: ",e);
        controller.setFailed(StringUtils.stringifyException(e));
    }
}
项目:spliceengine    文件:SparkOperationContext.java   
@Override
public OperationContext getClone() throws IOException, ClassNotFoundException{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(this);
    oos.flush();
    oos.close();
    ByteString bs = ZeroCopyLiteralByteString.wrap(baos.toByteArray());

    // Deserialize activation to clone it
    InputStream is = bs.newInput();
    ObjectInputStream ois = new ObjectInputStream(is);
    SparkOperationContext operationContext = (SparkOperationContext) ois.readObject();
    BroadcastedActivation  broadcastedActivation = operationContext.broadcastedActivation;
    BroadcastedActivation.ActivationHolderAndBytes activationHolderAndBytes = broadcastedActivation.readActivationHolder();
    broadcastedActivation.setActivationHolder(activationHolderAndBytes.getActivationHolder());
    operationContext.op = broadcastedActivation.getActivationHolder().getOperationsMap().get(op.resultSetNumber());
    operationContext.activation = operationContext.broadcastedActivation.getActivationHolder().getActivation();
    return operationContext;
}
项目:c5    文件:TableInfoModel.java   
@Override
public byte[] createProtobufOutput() {
  TableInfo.Builder builder = TableInfo.newBuilder();
  builder.setName(name);
  for (TableRegionModel aRegion: regions) {
    TableInfo.Region.Builder regionBuilder = TableInfo.Region.newBuilder();
    regionBuilder.setName(aRegion.getName());
    regionBuilder.setId(aRegion.getId());
    regionBuilder.setStartKey(ZeroCopyLiteralByteString.wrap(aRegion.getStartKey()));
    regionBuilder.setEndKey(ZeroCopyLiteralByteString.wrap(aRegion.getEndKey()));
    regionBuilder.setLocation(aRegion.getLocation());
    builder.addRegions(regionBuilder);
  }
  return builder.build().toByteArray();
}
项目:c5    文件:ScannerModel.java   
@Override
public byte[] createProtobufOutput() {
  Scanner.Builder builder = Scanner.newBuilder();
  if (!Bytes.equals(startRow, HConstants.EMPTY_START_ROW)) {
    builder.setStartRow(ZeroCopyLiteralByteString.wrap(startRow));
  }
  if (!Bytes.equals(endRow, HConstants.EMPTY_START_ROW)) {
    builder.setEndRow(ZeroCopyLiteralByteString.wrap(endRow));
  }
  for (byte[] column: columns) {
    builder.addColumns(ZeroCopyLiteralByteString.wrap(column));
  }
  if (startTime != 0) {
    builder.setStartTime(startTime);
  }
  if (endTime != 0) {
    builder.setEndTime(endTime);
  }
  builder.setBatch(getBatch());
  if (caching > 0) {
    builder.setCaching(caching);
  }
  builder.setMaxVersions(maxVersions);
  if (filter != null) {
    builder.setFilter(filter);
  }
  return builder.build().toByteArray();
}
项目:c5    文件:CellModel.java   
@Override
public byte[] createProtobufOutput() {
  Cell.Builder builder = Cell.newBuilder();
  builder.setColumn(ZeroCopyLiteralByteString.wrap(getColumn()));
  builder.setData(ZeroCopyLiteralByteString.wrap(getValue()));
  if (hasUserTimestamp()) {
    builder.setTimestamp(getTimestamp());
  }
  return builder.build().toByteArray();
}
项目:c5    文件:HLogKey.java   
public WALKey.Builder getBuilder(
    WALCellCodec.ByteStringCompressor compressor) throws IOException {
  WALKey.Builder builder = WALKey.newBuilder();
  if (compressionContext == null) {
    builder.setEncodedRegionName(ZeroCopyLiteralByteString.wrap(this.encodedRegionName));
    builder.setTableName(ZeroCopyLiteralByteString.wrap(this.tablename.getName()));
  } else {
    builder.setEncodedRegionName(
        compressor.compress(this.encodedRegionName, compressionContext.regionDict));
    builder.setTableName(compressor.compress(this.tablename.getName(),
        compressionContext.tableDict));
  }
  builder.setLogSequenceNumber(this.logSeqNum);
  builder.setWriteTime(writeTime);
  HBaseProtos.UUID.Builder uuidBuilder = HBaseProtos.UUID.newBuilder();
  for (UUID clusterId : clusterIds) {
    uuidBuilder.setLeastSigBits(clusterId.getLeastSignificantBits());
    uuidBuilder.setMostSigBits(clusterId.getMostSignificantBits());
    builder.addClusterIds(uuidBuilder.build());
  }
  if (scopes != null) {
    for (Map.Entry<byte[], Integer> e : scopes.entrySet()) {
      ByteString family = (compressionContext == null) ? ZeroCopyLiteralByteString.wrap(e.getKey())
          : compressor.compress(e.getKey(), compressionContext.familyDict);
      builder.addScopes(FamilyScope.newBuilder()
          .setFamily(family).setScopeType(ScopeType.valueOf(e.getValue())));
    }
  }
  return builder;
}
项目:c5    文件:Reference.java   
FSProtos.Reference convert() {
  FSProtos.Reference.Builder builder = FSProtos.Reference.newBuilder();
  builder.setRange(isTopFileRegion(getFileRegion())?
    FSProtos.Reference.Range.TOP: FSProtos.Reference.Range.BOTTOM);
  builder.setSplitkey(ZeroCopyLiteralByteString.wrap(getSplitKey()));
  return builder.build();
}
项目:c5    文件:HFile.java   
/**
 * Write out this instance on the passed in <code>out</code> stream.
 * We write it as a protobuf.
 * @param out
 * @throws IOException
 * @see #read(DataInputStream)
 */
void write(final DataOutputStream out) throws IOException {
  HFileProtos.FileInfoProto.Builder builder = HFileProtos.FileInfoProto.newBuilder();
  for (Map.Entry<byte [], byte[]> e: this.map.entrySet()) {
    HBaseProtos.BytesBytesPair.Builder bbpBuilder = HBaseProtos.BytesBytesPair.newBuilder();
    bbpBuilder.setFirst(ZeroCopyLiteralByteString.wrap(e.getKey()));
    bbpBuilder.setSecond(ZeroCopyLiteralByteString.wrap(e.getValue()));
    builder.addMapEntry(bbpBuilder.build());
  }
  out.write(ProtobufUtil.PB_MAGIC);
  builder.build().writeDelimitedTo(out);
}
项目:c5    文件:TestReplicationSink.java   
private WALEntry createEntry(byte [] table, int row,  KeyValue.Type type, List<Cell> cells) {
  byte[] fam = Bytes.equals(table, TABLE_NAME1) ? FAM_NAME1 : FAM_NAME2;
  byte[] rowBytes = Bytes.toBytes(row);
  // Just make sure we don't get the same ts for two consecutive rows with
  // same key
  try {
    Thread.sleep(1);
  } catch (InterruptedException e) {
    LOG.info("Was interrupted while sleep, meh", e);
  }
  final long now = System.currentTimeMillis();
  KeyValue kv = null;
  if(type.getCode() == KeyValue.Type.Put.getCode()) {
    kv = new KeyValue(rowBytes, fam, fam, now,
        KeyValue.Type.Put, Bytes.toBytes(row));
  } else if (type.getCode() == KeyValue.Type.DeleteColumn.getCode()) {
      kv = new KeyValue(rowBytes, fam, fam,
          now, KeyValue.Type.DeleteColumn);
  } else if (type.getCode() == KeyValue.Type.DeleteFamily.getCode()) {
      kv = new KeyValue(rowBytes, fam, null,
          now, KeyValue.Type.DeleteFamily);
  }
  WALEntry.Builder builder = WALEntry.newBuilder();
  builder.setAssociatedCellCount(1);
  WALKey.Builder keyBuilder = WALKey.newBuilder();
  UUID.Builder uuidBuilder = UUID.newBuilder();
  uuidBuilder.setLeastSigBits(HConstants.DEFAULT_CLUSTER_ID.getLeastSignificantBits());
  uuidBuilder.setMostSigBits(HConstants.DEFAULT_CLUSTER_ID.getMostSignificantBits());
  keyBuilder.setClusterId(uuidBuilder.build());
  keyBuilder.setTableName(ZeroCopyLiteralByteString.wrap(table));
  keyBuilder.setWriteTime(now);
  keyBuilder.setEncodedRegionName(ZeroCopyLiteralByteString.wrap(HConstants.EMPTY_BYTE_ARRAY));
  keyBuilder.setLogSequenceNumber(-1);
  builder.setKey(keyBuilder.build());
  cells.add(kv);

  return builder.build();
}
项目:c5    文件:TestProtobufUtil.java   
@Test
public void testException() throws IOException {
  NameBytesPair.Builder builder = NameBytesPair.newBuilder();
  final String omg = "OMG!!!";
  builder.setName("java.io.IOException");
  builder.setValue(ZeroCopyLiteralByteString.wrap(Bytes.toBytes(omg)));
  Throwable t = ProtobufUtil.toException(builder.build());
  assertEquals(omg, t.getMessage());
  builder.clear();
  builder.setName("org.apache.hadoop.ipc.RemoteException");
  builder.setValue(ZeroCopyLiteralByteString.wrap(Bytes.toBytes(omg)));
  t = ProtobufUtil.toException(builder.build());
  assertEquals(omg, t.getMessage());
}
项目:c5    文件:TestProtobufUtil.java   
/**
 * Test Increment Mutate conversions.
 *
 * @throws IOException
 */
@Test
public void testIncrement() throws IOException {
  MutationProto.Builder mutateBuilder = MutationProto.newBuilder();
  mutateBuilder.setRow(ByteString.copyFromUtf8("row"));
  mutateBuilder.setMutateType(MutationType.INCREMENT);
  ColumnValue.Builder valueBuilder = ColumnValue.newBuilder();
  valueBuilder.setFamily(ByteString.copyFromUtf8("f1"));
  QualifierValue.Builder qualifierBuilder = QualifierValue.newBuilder();
  qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c1"));
  qualifierBuilder.setValue(ZeroCopyLiteralByteString.wrap(Bytes.toBytes(11L)));
  valueBuilder.addQualifierValue(qualifierBuilder.build());
  qualifierBuilder.setQualifier(ByteString.copyFromUtf8("c2"));
  qualifierBuilder.setValue(ZeroCopyLiteralByteString.wrap(Bytes.toBytes(22L)));
  valueBuilder.addQualifierValue(qualifierBuilder.build());
  mutateBuilder.addColumnValue(valueBuilder.build());

  MutationProto proto = mutateBuilder.build();
  // default fields
  assertEquals(MutationProto.Durability.USE_DEFAULT, proto.getDurability());

  // set the default value for equal comparison
  mutateBuilder = MutationProto.newBuilder(proto);
  mutateBuilder.setDurability(MutationProto.Durability.USE_DEFAULT);

  Increment increment = ProtobufUtil.toIncrement(proto, null);
  assertEquals(mutateBuilder.build(),
    ProtobufUtil.toMutation(increment, MutationProto.newBuilder()));
}
项目:c5    文件:TestRowProcessorEndpoint.java   
@Override
public IncCounterProcessorRequest getRequestData() throws IOException {
  IncCounterProcessorRequest.Builder builder = IncCounterProcessorRequest.newBuilder();
  builder.setCounter(counter);
  builder.setRow(ZeroCopyLiteralByteString.wrap(row));
  return builder.build();
}
项目:c5    文件:TestRowProcessorEndpoint.java   
@Override
public FriendsOfFriendsProcessorRequest getRequestData() throws IOException {
  FriendsOfFriendsProcessorRequest.Builder builder =
      FriendsOfFriendsProcessorRequest.newBuilder();
  builder.setPerson(ZeroCopyLiteralByteString.wrap(person));
  builder.setRow(ZeroCopyLiteralByteString.wrap(row));
  builder.addAllResult(result);
  FriendsOfFriendsProcessorRequest f = builder.build();
  return f;
}
项目:c5    文件:TestRowProcessorEndpoint.java   
@Override
public RowSwapProcessorRequest getRequestData() throws IOException {
  RowSwapProcessorRequest.Builder builder = RowSwapProcessorRequest.newBuilder();
  builder.setRow1(ZeroCopyLiteralByteString.wrap(row1));
  builder.setRow2(ZeroCopyLiteralByteString.wrap(row2));
  return builder.build();
}
项目:c5    文件:TestPriorityRpc.java   
@Test
public void testQosFunctionForMeta() throws IOException {
  qosFunction = regionServer.getQosFunction();
  RequestHeader.Builder headerBuilder = RequestHeader.newBuilder();
  //create a rpc request that has references to hbase:meta region and also
  //uses one of the known argument classes (known argument classes are
  //listed in HRegionServer.QosFunction.knownArgumentClasses)
  headerBuilder.setMethodName("foo");

  GetRequest.Builder getRequestBuilder = GetRequest.newBuilder();
  RegionSpecifier.Builder regionSpecifierBuilder = RegionSpecifier.newBuilder();
  regionSpecifierBuilder.setType(RegionSpecifierType.REGION_NAME);
  ByteString name = ZeroCopyLiteralByteString.wrap(HRegionInfo.FIRST_META_REGIONINFO.getRegionName());
  regionSpecifierBuilder.setValue(name);
  RegionSpecifier regionSpecifier = regionSpecifierBuilder.build();
  getRequestBuilder.setRegion(regionSpecifier);
  Get.Builder getBuilder = Get.newBuilder();
  getBuilder.setRow(ZeroCopyLiteralByteString.wrap("somerow".getBytes()));
  getRequestBuilder.setGet(getBuilder.build());
  GetRequest getRequest = getRequestBuilder.build();
  RequestHeader header = headerBuilder.build();
  HRegion mockRegion = Mockito.mock(HRegion.class);
  HRegionServer mockRS = Mockito.mock(HRegionServer.class);
  HRegionInfo mockRegionInfo = Mockito.mock(HRegionInfo.class);
  Mockito.when(mockRS.getRegion((RegionSpecifier)Mockito.any())).thenReturn(mockRegion);
  Mockito.when(mockRegion.getRegionInfo()).thenReturn(mockRegionInfo);
  Mockito.when(mockRegionInfo.isMetaTable()).thenReturn(true);
  qosFunction.setRegionServer(mockRS);
  assertTrue (qosFunction.apply(new Pair<RequestHeader, Message>(header, getRequest)) ==
    HConstants.HIGH_QOS);
}
项目:c5    文件:RequestConverter.java   
/**
 * Create a protocol buffer GetStoreFileRequest for a given region name
 *
 * @param regionName the name of the region to get info
 * @param family the family to get store file list
 * @return a protocol buffer GetStoreFileRequest
 */
public static GetStoreFileRequest
    buildGetStoreFileRequest(final byte[] regionName, final byte[] family) {
  GetStoreFileRequest.Builder builder = GetStoreFileRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);
  builder.addFamily(ZeroCopyLiteralByteString.wrap(family));
  return builder.build();
}
项目:c5    文件:RequestConverter.java   
/**
 * Create a SplitRegionRequest for a given region name
 *
 * @param regionName the name of the region to split
 * @param splitPoint the split point
 * @return a SplitRegionRequest
 */
public static SplitRegionRequest buildSplitRegionRequest(
    final byte[] regionName, final byte[] splitPoint) {
  SplitRegionRequest.Builder builder = SplitRegionRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);
  if (splitPoint != null) {
    builder.setSplitPoint(ZeroCopyLiteralByteString.wrap(splitPoint));
  }
  return builder.build();
}
项目:c5    文件:RequestConverter.java   
/**
 * Create a  CompactRegionRequest for a given region name
 *
 * @param regionName the name of the region to get info
 * @param major indicator if it is a major compaction
 * @return a CompactRegionRequest
 */
public static CompactRegionRequest buildCompactRegionRequest(
    final byte[] regionName, final boolean major, final byte [] family) {
  CompactRegionRequest.Builder builder = CompactRegionRequest.newBuilder();
  RegionSpecifier region = buildRegionSpecifier(
    RegionSpecifierType.REGION_NAME, regionName);
  builder.setRegion(region);
  builder.setMajor(major);
  if (family != null) {
    builder.setFamily(ZeroCopyLiteralByteString.wrap(family));
  }
  return builder.build();
}
项目:c5    文件:RequestConverter.java   
/**
 * Convert a byte array to a protocol buffer RegionSpecifier
 *
 * @param type the region specifier type
 * @param value the region specifier byte array value
 * @return a protocol buffer RegionSpecifier
 */
public static RegionSpecifier buildRegionSpecifier(
    final RegionSpecifierType type, final byte[] value) {
  RegionSpecifier.Builder regionBuilder = RegionSpecifier.newBuilder();
  regionBuilder.setValue(ZeroCopyLiteralByteString.wrap(value));
  regionBuilder.setType(type);
  return regionBuilder.build();
}
项目:c5    文件:RequestConverter.java   
/**
 * Create a protocol buffer Condition
 *
 * @param row
 * @param family
 * @param qualifier
 * @param comparator
 * @param compareType
 * @return a Condition
 * @throws IOException
 */
private static Condition buildCondition(final byte[] row,
    final byte[] family, final byte [] qualifier,
    final ByteArrayComparable comparator,
    final CompareType compareType) throws IOException {
  Condition.Builder builder = Condition.newBuilder();
  builder.setRow(ZeroCopyLiteralByteString.wrap(row));
  builder.setFamily(ZeroCopyLiteralByteString.wrap(family));
  builder.setQualifier(ZeroCopyLiteralByteString.wrap(qualifier));
  builder.setComparator(ProtobufUtil.toComparator(comparator));
  builder.setCompareType(compareType);
  return builder.build();
}
项目:c5    文件:RequestConverter.java   
/**
 * Create a protocol buffer DeleteColumnRequest
 *
 * @param tableName
 * @param columnName
 * @return a DeleteColumnRequest
 */
public static DeleteColumnRequest buildDeleteColumnRequest(
    final TableName tableName, final byte [] columnName) {
  DeleteColumnRequest.Builder builder = DeleteColumnRequest.newBuilder();
  builder.setTableName(ProtobufUtil.toProtoTableName((tableName)));
  builder.setColumnName(ZeroCopyLiteralByteString.wrap(columnName));
  return builder.build();
}
项目:c5    文件:RequestConverter.java   
/**
 * Creates a protocol buffer CreateTableRequest
 *
 * @param hTableDesc
 * @param splitKeys
 * @return a CreateTableRequest
 */
public static CreateTableRequest buildCreateTableRequest(
    final HTableDescriptor hTableDesc, final byte [][] splitKeys) {
  CreateTableRequest.Builder builder = CreateTableRequest.newBuilder();
  builder.setTableSchema(hTableDesc.convert());
  if (splitKeys != null) {
    for (byte [] splitKey : splitKeys) {
      builder.addSplitKeys(ZeroCopyLiteralByteString.wrap(splitKey));
    }
  }
  return builder.build();
}
项目:c5    文件:RequestConverter.java   
/**
 * Create a request to grant user permissions.
 *
 * @param username the short user name who to grant permissions
 * @param tableName optional table name the permissions apply
 * @param family optional column family
 * @param qualifier optional qualifier
 * @param actions the permissions to be granted
 * @return A {@link AccessControlProtos} GrantRequest
 */
public static AccessControlProtos.GrantRequest buildGrantRequest(
    String username, TableName tableName, byte[] family, byte[] qualifier,
    AccessControlProtos.Permission.Action... actions) {
  AccessControlProtos.Permission.Builder ret =
      AccessControlProtos.Permission.newBuilder();
  AccessControlProtos.TablePermission.Builder permissionBuilder =
      AccessControlProtos.TablePermission.newBuilder();
  for (AccessControlProtos.Permission.Action a : actions) {
    permissionBuilder.addAction(a);
  }
  if (tableName == null) {
    throw new NullPointerException("TableName cannot be null");
  }
  permissionBuilder.setTableName(ProtobufUtil.toProtoTableName(tableName));

  if (family != null) {
    permissionBuilder.setFamily(ZeroCopyLiteralByteString.wrap(family));
  }
  if (qualifier != null) {
    permissionBuilder.setQualifier(ZeroCopyLiteralByteString.wrap(qualifier));
  }
  ret.setType(AccessControlProtos.Permission.Type.Table)
     .setTablePermission(permissionBuilder);
  return AccessControlProtos.GrantRequest.newBuilder()
    .setUserPermission(
        AccessControlProtos.UserPermission.newBuilder()
            .setUser(ByteString.copyFromUtf8(username))
            .setPermission(ret)
    ).build();
}