Java 类org.apache.hadoop.hdfs.protocolPB.PBHelper 实例源码

项目:hadoop    文件:TestBlockToken.java   
@Override
public GetReplicaVisibleLengthResponseProto answer(
    InvocationOnMock invocation) throws IOException {
  Object args[] = invocation.getArguments();
  assertEquals(2, args.length);
  GetReplicaVisibleLengthRequestProto req = 
      (GetReplicaVisibleLengthRequestProto) args[1];
  Set<TokenIdentifier> tokenIds = UserGroupInformation.getCurrentUser()
      .getTokenIdentifiers();
  assertEquals("Only one BlockTokenIdentifier expected", 1, tokenIds.size());
  long result = 0;
  for (TokenIdentifier tokenId : tokenIds) {
    BlockTokenIdentifier id = (BlockTokenIdentifier) tokenId;
    LOG.info("Got: " + id.toString());
    assertTrue("Received BlockTokenIdentifier is wrong", ident.equals(id));
    sm.checkAccess(id, null, PBHelper.convert(req.getBlock()),
        BlockTokenSecretManager.AccessMode.WRITE);
    result = id.getBlockId();
  }
  return GetReplicaVisibleLengthResponseProto.newBuilder()
      .setLength(result).build();
}
项目:hadoop    文件:DataTransferSaslUtil.java   
/**
 * Reads a SASL negotiation message and negotiation cipher options. 
 * 
 * @param in stream to read
 * @param cipherOptions list to store negotiation cipher options
 * @return byte[] SASL negotiation message
 * @throws IOException for any error
 */
public static byte[] readSaslMessageAndNegotiationCipherOptions(
    InputStream in, List<CipherOption> cipherOptions) throws IOException {
  DataTransferEncryptorMessageProto proto =
      DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in));
  if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) {
    throw new InvalidEncryptionKeyException(proto.getMessage());
  } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) {
    throw new IOException(proto.getMessage());
  } else {
    List<CipherOptionProto> optionProtos = proto.getCipherOptionList();
    if (optionProtos != null) {
      for (CipherOptionProto optionProto : optionProtos) {
        cipherOptions.add(PBHelper.convert(optionProto));
      }
    }
    return proto.getPayload().toByteArray();
  }
}
项目:hadoop    文件:DataTransferSaslUtil.java   
/**
 * Send SASL message and negotiated cipher option to client.
 * 
 * @param out stream to receive message
 * @param payload to send
 * @param option negotiated cipher option
 * @throws IOException for any error
 */
public static void sendSaslMessageAndNegotiatedCipherOption(
    OutputStream out, byte[] payload, CipherOption option) 
        throws IOException {
  DataTransferEncryptorMessageProto.Builder builder =
      DataTransferEncryptorMessageProto.newBuilder();

  builder.setStatus(DataTransferEncryptorStatus.SUCCESS);
  if (payload != null) {
    builder.setPayload(ByteString.copyFrom(payload));
  }
  if (option != null) {
    builder.addCipherOption(PBHelper.convert(option));
  }

  DataTransferEncryptorMessageProto proto = builder.build();
  proto.writeDelimitedTo(out);
  out.flush();
}
项目:hadoop    文件:DataTransferSaslUtil.java   
/**
 * Send a SASL negotiation message and negotiation cipher options to server.
 * 
 * @param out stream to receive message
 * @param payload to send
 * @param options cipher options to negotiate
 * @throws IOException for any error
 */
public static void sendSaslMessageAndNegotiationCipherOptions(
    OutputStream out, byte[] payload, List<CipherOption> options)
        throws IOException {
  DataTransferEncryptorMessageProto.Builder builder =
      DataTransferEncryptorMessageProto.newBuilder();

  builder.setStatus(DataTransferEncryptorStatus.SUCCESS);
  if (payload != null) {
    builder.setPayload(ByteString.copyFrom(payload));
  }
  if (options != null) {
    builder.addAllCipherOption(PBHelper.convertCipherOptions(options));
  }

  DataTransferEncryptorMessageProto proto = builder.build();
  proto.writeDelimitedTo(out);
  out.flush();
}
项目:hadoop    文件:DataTransferSaslUtil.java   
/**
 * Read SASL message and negotiated cipher option from server.
 * 
 * @param in stream to read
 * @return SaslResponseWithNegotiatedCipherOption SASL message and 
 * negotiated cipher option
 * @throws IOException for any error
 */
public static SaslResponseWithNegotiatedCipherOption
    readSaslMessageAndNegotiatedCipherOption(InputStream in)
        throws IOException {
  DataTransferEncryptorMessageProto proto =
      DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in));
  if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) {
    throw new InvalidEncryptionKeyException(proto.getMessage());
  } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) {
    throw new IOException(proto.getMessage());
  } else {
    byte[] response = proto.getPayload().toByteArray();
    List<CipherOption> options = PBHelper.convertCipherOptionProtos(
        proto.getCipherOptionList());
    CipherOption option = null;
    if (options != null && !options.isEmpty()) {
      option = options.get(0);
    }
    return new SaslResponseWithNegotiatedCipherOption(response, option);
  }
}
项目:hadoop    文件:Sender.java   
@Override
public void transferBlock(final ExtendedBlock blk,
    final Token<BlockTokenIdentifier> blockToken,
    final String clientName,
    final DatanodeInfo[] targets,
    final StorageType[] targetStorageTypes) throws IOException {

  OpTransferBlockProto proto = OpTransferBlockProto.newBuilder()
    .setHeader(DataTransferProtoUtil.buildClientHeader(
        blk, clientName, blockToken))
    .addAllTargets(PBHelper.convert(targets))
    .addAllTargetStorageTypes(PBHelper.convertStorageTypes(targetStorageTypes))
    .build();

  send(out, Op.TRANSFER_BLOCK, proto);
}
项目:hadoop    文件:Sender.java   
@Override
public void requestShortCircuitFds(final ExtendedBlock blk,
    final Token<BlockTokenIdentifier> blockToken,
    SlotId slotId, int maxVersion, boolean supportsReceiptVerification)
      throws IOException {
  OpRequestShortCircuitAccessProto.Builder builder =
      OpRequestShortCircuitAccessProto.newBuilder()
        .setHeader(DataTransferProtoUtil.buildBaseHeader(
          blk, blockToken)).setMaxVersion(maxVersion);
  if (slotId != null) {
    builder.setSlotId(PBHelper.convert(slotId));
  }
  builder.setSupportsReceiptVerification(supportsReceiptVerification);
  OpRequestShortCircuitAccessProto proto = builder.build();
  send(out, Op.REQUEST_SHORT_CIRCUIT_FDS, proto);
}
项目:hadoop    文件:Receiver.java   
/** Receive OP_READ_BLOCK */
private void opReadBlock() throws IOException {
  OpReadBlockProto proto = OpReadBlockProto.parseFrom(vintPrefixed(in));
  TraceScope traceScope = continueTraceSpan(proto.getHeader(),
      proto.getClass().getSimpleName());
  try {
    readBlock(PBHelper.convert(proto.getHeader().getBaseHeader().getBlock()),
      PBHelper.convert(proto.getHeader().getBaseHeader().getToken()),
      proto.getHeader().getClientName(),
      proto.getOffset(),
      proto.getLen(),
      proto.getSendChecksums(),
      (proto.hasCachingStrategy() ?
          getCachingStrategy(proto.getCachingStrategy()) :
        CachingStrategy.newDefaultStrategy()));
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
项目:hadoop    文件:Receiver.java   
/** Receive {@link Op#TRANSFER_BLOCK} */
private void opTransferBlock(DataInputStream in) throws IOException {
  final OpTransferBlockProto proto =
    OpTransferBlockProto.parseFrom(vintPrefixed(in));
  final DatanodeInfo[] targets = PBHelper.convert(proto.getTargetsList());
  TraceScope traceScope = continueTraceSpan(proto.getHeader(),
      proto.getClass().getSimpleName());
  try {
    transferBlock(PBHelper.convert(proto.getHeader().getBaseHeader().getBlock()),
        PBHelper.convert(proto.getHeader().getBaseHeader().getToken()),
        proto.getHeader().getClientName(),
        targets,
        PBHelper.convertStorageTypes(proto.getTargetStorageTypesList(), targets.length));
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
项目:hadoop    文件:Receiver.java   
/** Receive {@link Op#REQUEST_SHORT_CIRCUIT_FDS} */
private void opRequestShortCircuitFds(DataInputStream in) throws IOException {
  final OpRequestShortCircuitAccessProto proto =
    OpRequestShortCircuitAccessProto.parseFrom(vintPrefixed(in));
  SlotId slotId = (proto.hasSlotId()) ? 
      PBHelper.convert(proto.getSlotId()) : null;
  TraceScope traceScope = continueTraceSpan(proto.getHeader(),
      proto.getClass().getSimpleName());
  try {
    requestShortCircuitFds(PBHelper.convert(proto.getHeader().getBlock()),
        PBHelper.convert(proto.getHeader().getToken()),
        slotId, proto.getMaxVersion(),
        proto.getSupportsReceiptVerification());
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
项目:hadoop    文件:DFSClient.java   
/**
 * Infer the checksum type for a replica by sending an OP_READ_BLOCK
 * for the first byte of that replica. This is used for compatibility
 * with older HDFS versions which did not include the checksum type in
 * OpBlockChecksumResponseProto.
 *
 * @param lb the located block
 * @param dn the connected datanode
 * @return the inferred checksum type
 * @throws IOException if an error occurs
 */
private Type inferChecksumTypeByReading(LocatedBlock lb, DatanodeInfo dn)
    throws IOException {
  IOStreamPair pair = connectToDN(dn, dfsClientConf.socketTimeout, lb);

  try {
    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(pair.out,
        HdfsConstants.SMALL_BUFFER_SIZE));
    DataInputStream in = new DataInputStream(pair.in);

    new Sender(out).readBlock(lb.getBlock(), lb.getBlockToken(), clientName,
        0, 1, true, CachingStrategy.newDefaultStrategy());
    final BlockOpResponseProto reply =
        BlockOpResponseProto.parseFrom(PBHelper.vintPrefixed(in));
    String logInfo = "trying to read " + lb.getBlock() + " from datanode " + dn;
    DataTransferProtoUtil.checkBlockOpStatus(reply, logInfo);

    return PBHelper.convert(reply.getReadOpChecksumInfo().getChecksum().getType());
  } finally {
    IOUtils.cleanup(null, pair.in, pair.out);
  }
}
项目:hadoop    文件:FSEditLogOp.java   
@Override
public void writeFields(DataOutputStream out) throws IOException {
  FSImageSerialization.writeLong(inodeId, out);
  FSImageSerialization.writeString(path, out);
  FSImageSerialization.writeShort(replication, out);
  FSImageSerialization.writeLong(mtime, out);
  FSImageSerialization.writeLong(atime, out);
  FSImageSerialization.writeLong(blockSize, out);
  new ArrayWritable(Block.class, blocks).write(out);
  permissions.write(out);

  if (this.opCode == OP_ADD) {
    AclEditLogUtil.write(aclEntries, out);
    XAttrEditLogProto.Builder b = XAttrEditLogProto.newBuilder();
    b.addAllXAttrs(PBHelper.convertXAttrProto(xAttrs));
    b.build().writeDelimitedTo(out);
    FSImageSerialization.writeString(clientName,out);
    FSImageSerialization.writeString(clientMachine,out);
    FSImageSerialization.writeBoolean(overwrite, out);
    FSImageSerialization.writeByte(storagePolicyId, out);
    // write clientId and callId
    writeRpcIds(rpcClientId, rpcCallId, out);
  }
}
项目:hadoop    文件:FSDirectory.java   
/**
 * Set the FileEncryptionInfo for an INode.
 */
void setFileEncryptionInfo(String src, FileEncryptionInfo info)
    throws IOException {
  // Make the PB for the xattr
  final HdfsProtos.PerFileEncryptionInfoProto proto =
      PBHelper.convertPerFileEncInfo(info);
  final byte[] protoBytes = proto.toByteArray();
  final XAttr fileEncryptionAttr =
      XAttrHelper.buildXAttr(CRYPTO_XATTR_FILE_ENCRYPTION_INFO, protoBytes);
  final List<XAttr> xAttrs = Lists.newArrayListWithCapacity(1);
  xAttrs.add(fileEncryptionAttr);

  writeLock();
  try {
    FSDirXAttrOp.unprotectedSetXAttrs(this, src, xAttrs,
                                      EnumSet.of(XAttrSetFlag.CREATE));
  } finally {
    writeUnlock();
  }
}
项目:hadoop    文件:FSImageFormatPBINode.java   
private static XAttrFeatureProto.Builder buildXAttrs(XAttrFeature f,
    final SaverContext.DeduplicationMap<String> stringMap) {
  XAttrFeatureProto.Builder b = XAttrFeatureProto.newBuilder();
  for (XAttr a : f.getXAttrs()) {
    XAttrCompactProto.Builder xAttrCompactBuilder = XAttrCompactProto.
        newBuilder();
    int nsOrd = a.getNameSpace().ordinal();
    Preconditions.checkArgument(nsOrd < 8, "Too many namespaces.");
    int v = ((nsOrd & XATTR_NAMESPACE_MASK) << XATTR_NAMESPACE_OFFSET)
        | ((stringMap.getId(a.getName()) & XATTR_NAME_MASK) <<
            XATTR_NAME_OFFSET);
    v |= (((nsOrd >> 2) & XATTR_NAMESPACE_EXT_MASK) <<
        XATTR_NAMESPACE_EXT_OFFSET);
    xAttrCompactBuilder.setName(v);
    if (a.getValue() != null) {
      xAttrCompactBuilder.setValue(PBHelper.getByteString(a.getValue()));
    }
    b.addXAttrs(xAttrCompactBuilder.build());
  }

  return b;
}
项目:hadoop    文件:FSImageFormatPBINode.java   
private void save(OutputStream out, INodeFile n) throws IOException {
  INodeSection.INodeFile.Builder b = buildINodeFile(n,
      parent.getSaverContext());

  if (n.getBlocks() != null) {
    for (Block block : n.getBlocks()) {
      b.addBlocks(PBHelper.convert(block));
    }
  }

  FileUnderConstructionFeature uc = n.getFileUnderConstructionFeature();
  if (uc != null) {
    INodeSection.FileUnderConstructionFeature f =
        INodeSection.FileUnderConstructionFeature
        .newBuilder().setClientName(uc.getClientName())
        .setClientMachine(uc.getClientMachine()).build();
    b.setFileUC(f);
  }

  INodeSection.INode r = buildINodeCommon(n)
      .setType(INodeSection.INode.Type.FILE).setFile(b).build();
  r.writeDelimitedTo(out);
}
项目:hadoop    文件:QJournalProtocolTranslatorPB.java   
@Override
public void journal(RequestInfo reqInfo,
    long segmentTxId, long firstTxnId, int numTxns,
    byte[] records) throws IOException {
  JournalRequestProto req = JournalRequestProto.newBuilder()
      .setReqInfo(convert(reqInfo))
      .setSegmentTxnId(segmentTxId)
      .setFirstTxnId(firstTxnId)
      .setNumTxns(numTxns)
      .setRecords(PBHelper.getByteString(records))
      .build();
  try {
    rpcProxy.journal(NULL_CONTROLLER, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
项目:hadoop    文件:QJournalProtocolTranslatorPB.java   
@Override
public Boolean canRollBack(String journalId, StorageInfo storage,
    StorageInfo prevStorage, int targetLayoutVersion) throws IOException {
  try {
    CanRollBackResponseProto response = rpcProxy.canRollBack(
        NULL_CONTROLLER,
        CanRollBackRequestProto.newBuilder()
          .setJid(convertJournalId(journalId))
          .setStorage(PBHelper.convert(storage))
          .setPrevStorage(PBHelper.convert(prevStorage))
          .setTargetLayoutVersion(targetLayoutVersion)
          .build());
    return response.getCanRollBack();
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
项目:aliyun-oss-hadoop-fs    文件:QJournalProtocolTranslatorPB.java   
@Override
public Boolean canRollBack(String journalId, StorageInfo storage,
    StorageInfo prevStorage, int targetLayoutVersion) throws IOException {
  try {
    CanRollBackResponseProto response = rpcProxy.canRollBack(
        NULL_CONTROLLER,
        CanRollBackRequestProto.newBuilder()
          .setJid(convertJournalId(journalId))
          .setStorage(PBHelper.convert(storage))
          .setPrevStorage(PBHelper.convert(prevStorage))
          .setTargetLayoutVersion(targetLayoutVersion)
          .build());
    return response.getCanRollBack();
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
项目:big-c    文件:DataTransferSaslUtil.java   
/**
 * Reads a SASL negotiation message and negotiation cipher options. 
 * 
 * @param in stream to read
 * @param cipherOptions list to store negotiation cipher options
 * @return byte[] SASL negotiation message
 * @throws IOException for any error
 */
public static byte[] readSaslMessageAndNegotiationCipherOptions(
    InputStream in, List<CipherOption> cipherOptions) throws IOException {
  DataTransferEncryptorMessageProto proto =
      DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in));
  if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) {
    throw new InvalidEncryptionKeyException(proto.getMessage());
  } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) {
    throw new IOException(proto.getMessage());
  } else {
    List<CipherOptionProto> optionProtos = proto.getCipherOptionList();
    if (optionProtos != null) {
      for (CipherOptionProto optionProto : optionProtos) {
        cipherOptions.add(PBHelper.convert(optionProto));
      }
    }
    return proto.getPayload().toByteArray();
  }
}
项目:big-c    文件:DataTransferSaslUtil.java   
/**
 * Send SASL message and negotiated cipher option to client.
 * 
 * @param out stream to receive message
 * @param payload to send
 * @param option negotiated cipher option
 * @throws IOException for any error
 */
public static void sendSaslMessageAndNegotiatedCipherOption(
    OutputStream out, byte[] payload, CipherOption option) 
        throws IOException {
  DataTransferEncryptorMessageProto.Builder builder =
      DataTransferEncryptorMessageProto.newBuilder();

  builder.setStatus(DataTransferEncryptorStatus.SUCCESS);
  if (payload != null) {
    builder.setPayload(ByteString.copyFrom(payload));
  }
  if (option != null) {
    builder.addCipherOption(PBHelper.convert(option));
  }

  DataTransferEncryptorMessageProto proto = builder.build();
  proto.writeDelimitedTo(out);
  out.flush();
}
项目:big-c    文件:DataTransferSaslUtil.java   
/**
 * Send a SASL negotiation message and negotiation cipher options to server.
 * 
 * @param out stream to receive message
 * @param payload to send
 * @param options cipher options to negotiate
 * @throws IOException for any error
 */
public static void sendSaslMessageAndNegotiationCipherOptions(
    OutputStream out, byte[] payload, List<CipherOption> options)
        throws IOException {
  DataTransferEncryptorMessageProto.Builder builder =
      DataTransferEncryptorMessageProto.newBuilder();

  builder.setStatus(DataTransferEncryptorStatus.SUCCESS);
  if (payload != null) {
    builder.setPayload(ByteString.copyFrom(payload));
  }
  if (options != null) {
    builder.addAllCipherOption(PBHelper.convertCipherOptions(options));
  }

  DataTransferEncryptorMessageProto proto = builder.build();
  proto.writeDelimitedTo(out);
  out.flush();
}
项目:big-c    文件:DataTransferSaslUtil.java   
/**
 * Read SASL message and negotiated cipher option from server.
 * 
 * @param in stream to read
 * @return SaslResponseWithNegotiatedCipherOption SASL message and 
 * negotiated cipher option
 * @throws IOException for any error
 */
public static SaslResponseWithNegotiatedCipherOption
    readSaslMessageAndNegotiatedCipherOption(InputStream in)
        throws IOException {
  DataTransferEncryptorMessageProto proto =
      DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in));
  if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) {
    throw new InvalidEncryptionKeyException(proto.getMessage());
  } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) {
    throw new IOException(proto.getMessage());
  } else {
    byte[] response = proto.getPayload().toByteArray();
    List<CipherOption> options = PBHelper.convertCipherOptionProtos(
        proto.getCipherOptionList());
    CipherOption option = null;
    if (options != null && !options.isEmpty()) {
      option = options.get(0);
    }
    return new SaslResponseWithNegotiatedCipherOption(response, option);
  }
}
项目:big-c    文件:Sender.java   
@Override
public void transferBlock(final ExtendedBlock blk,
    final Token<BlockTokenIdentifier> blockToken,
    final String clientName,
    final DatanodeInfo[] targets,
    final StorageType[] targetStorageTypes) throws IOException {

  OpTransferBlockProto proto = OpTransferBlockProto.newBuilder()
    .setHeader(DataTransferProtoUtil.buildClientHeader(
        blk, clientName, blockToken))
    .addAllTargets(PBHelper.convert(targets))
    .addAllTargetStorageTypes(PBHelper.convertStorageTypes(targetStorageTypes))
    .build();

  send(out, Op.TRANSFER_BLOCK, proto);
}
项目:big-c    文件:Sender.java   
@Override
public void requestShortCircuitFds(final ExtendedBlock blk,
    final Token<BlockTokenIdentifier> blockToken,
    SlotId slotId, int maxVersion, boolean supportsReceiptVerification)
      throws IOException {
  OpRequestShortCircuitAccessProto.Builder builder =
      OpRequestShortCircuitAccessProto.newBuilder()
        .setHeader(DataTransferProtoUtil.buildBaseHeader(
          blk, blockToken)).setMaxVersion(maxVersion);
  if (slotId != null) {
    builder.setSlotId(PBHelper.convert(slotId));
  }
  builder.setSupportsReceiptVerification(supportsReceiptVerification);
  OpRequestShortCircuitAccessProto proto = builder.build();
  send(out, Op.REQUEST_SHORT_CIRCUIT_FDS, proto);
}
项目:big-c    文件:Receiver.java   
/** Receive OP_READ_BLOCK */
private void opReadBlock() throws IOException {
  OpReadBlockProto proto = OpReadBlockProto.parseFrom(vintPrefixed(in));
  TraceScope traceScope = continueTraceSpan(proto.getHeader(),
      proto.getClass().getSimpleName());
  try {
    readBlock(PBHelper.convert(proto.getHeader().getBaseHeader().getBlock()),
      PBHelper.convert(proto.getHeader().getBaseHeader().getToken()),
      proto.getHeader().getClientName(),
      proto.getOffset(),
      proto.getLen(),
      proto.getSendChecksums(),
      (proto.hasCachingStrategy() ?
          getCachingStrategy(proto.getCachingStrategy()) :
        CachingStrategy.newDefaultStrategy()));
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
项目:big-c    文件:Receiver.java   
/** Receive {@link Op#TRANSFER_BLOCK} */
private void opTransferBlock(DataInputStream in) throws IOException {
  final OpTransferBlockProto proto =
    OpTransferBlockProto.parseFrom(vintPrefixed(in));
  final DatanodeInfo[] targets = PBHelper.convert(proto.getTargetsList());
  TraceScope traceScope = continueTraceSpan(proto.getHeader(),
      proto.getClass().getSimpleName());
  try {
    transferBlock(PBHelper.convert(proto.getHeader().getBaseHeader().getBlock()),
        PBHelper.convert(proto.getHeader().getBaseHeader().getToken()),
        proto.getHeader().getClientName(),
        targets,
        PBHelper.convertStorageTypes(proto.getTargetStorageTypesList(), targets.length));
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
项目:big-c    文件:Receiver.java   
/** Receive {@link Op#REQUEST_SHORT_CIRCUIT_FDS} */
private void opRequestShortCircuitFds(DataInputStream in) throws IOException {
  final OpRequestShortCircuitAccessProto proto =
    OpRequestShortCircuitAccessProto.parseFrom(vintPrefixed(in));
  SlotId slotId = (proto.hasSlotId()) ? 
      PBHelper.convert(proto.getSlotId()) : null;
  TraceScope traceScope = continueTraceSpan(proto.getHeader(),
      proto.getClass().getSimpleName());
  try {
    requestShortCircuitFds(PBHelper.convert(proto.getHeader().getBlock()),
        PBHelper.convert(proto.getHeader().getToken()),
        slotId, proto.getMaxVersion(),
        proto.getSupportsReceiptVerification());
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
项目:big-c    文件:DFSClient.java   
/**
 * Infer the checksum type for a replica by sending an OP_READ_BLOCK
 * for the first byte of that replica. This is used for compatibility
 * with older HDFS versions which did not include the checksum type in
 * OpBlockChecksumResponseProto.
 *
 * @param lb the located block
 * @param dn the connected datanode
 * @return the inferred checksum type
 * @throws IOException if an error occurs
 */
private Type inferChecksumTypeByReading(LocatedBlock lb, DatanodeInfo dn)
    throws IOException {
  IOStreamPair pair = connectToDN(dn, dfsClientConf.socketTimeout, lb);

  try {
    DataOutputStream out = new DataOutputStream(new BufferedOutputStream(pair.out,
        HdfsConstants.SMALL_BUFFER_SIZE));
    DataInputStream in = new DataInputStream(pair.in);

    new Sender(out).readBlock(lb.getBlock(), lb.getBlockToken(), clientName,
        0, 1, true, CachingStrategy.newDefaultStrategy());
    final BlockOpResponseProto reply =
        BlockOpResponseProto.parseFrom(PBHelper.vintPrefixed(in));
    String logInfo = "trying to read " + lb.getBlock() + " from datanode " + dn;
    DataTransferProtoUtil.checkBlockOpStatus(reply, logInfo);

    return PBHelper.convert(reply.getReadOpChecksumInfo().getChecksum().getType());
  } finally {
    IOUtils.cleanup(null, pair.in, pair.out);
  }
}
项目:big-c    文件:FSEditLogOp.java   
@Override
public void writeFields(DataOutputStream out) throws IOException {
  FSImageSerialization.writeLong(inodeId, out);
  FSImageSerialization.writeString(path, out);
  FSImageSerialization.writeShort(replication, out);
  FSImageSerialization.writeLong(mtime, out);
  FSImageSerialization.writeLong(atime, out);
  FSImageSerialization.writeLong(blockSize, out);
  new ArrayWritable(Block.class, blocks).write(out);
  permissions.write(out);

  if (this.opCode == OP_ADD) {
    AclEditLogUtil.write(aclEntries, out);
    XAttrEditLogProto.Builder b = XAttrEditLogProto.newBuilder();
    b.addAllXAttrs(PBHelper.convertXAttrProto(xAttrs));
    b.build().writeDelimitedTo(out);
    FSImageSerialization.writeString(clientName,out);
    FSImageSerialization.writeString(clientMachine,out);
    FSImageSerialization.writeBoolean(overwrite, out);
    FSImageSerialization.writeByte(storagePolicyId, out);
    // write clientId and callId
    writeRpcIds(rpcClientId, rpcCallId, out);
  }
}
项目:big-c    文件:FSDirectory.java   
/**
 * Set the FileEncryptionInfo for an INode.
 */
void setFileEncryptionInfo(String src, FileEncryptionInfo info)
    throws IOException {
  // Make the PB for the xattr
  final HdfsProtos.PerFileEncryptionInfoProto proto =
      PBHelper.convertPerFileEncInfo(info);
  final byte[] protoBytes = proto.toByteArray();
  final XAttr fileEncryptionAttr =
      XAttrHelper.buildXAttr(CRYPTO_XATTR_FILE_ENCRYPTION_INFO, protoBytes);
  final List<XAttr> xAttrs = Lists.newArrayListWithCapacity(1);
  xAttrs.add(fileEncryptionAttr);

  writeLock();
  try {
    FSDirXAttrOp.unprotectedSetXAttrs(this, src, xAttrs,
                                      EnumSet.of(XAttrSetFlag.CREATE));
  } finally {
    writeUnlock();
  }
}
项目:big-c    文件:FSImageFormatPBINode.java   
private static XAttrFeatureProto.Builder buildXAttrs(XAttrFeature f,
    final SaverContext.DeduplicationMap<String> stringMap) {
  XAttrFeatureProto.Builder b = XAttrFeatureProto.newBuilder();
  for (XAttr a : f.getXAttrs()) {
    XAttrCompactProto.Builder xAttrCompactBuilder = XAttrCompactProto.
        newBuilder();
    int nsOrd = a.getNameSpace().ordinal();
    Preconditions.checkArgument(nsOrd < 8, "Too many namespaces.");
    int v = ((nsOrd & XATTR_NAMESPACE_MASK) << XATTR_NAMESPACE_OFFSET)
        | ((stringMap.getId(a.getName()) & XATTR_NAME_MASK) <<
            XATTR_NAME_OFFSET);
    v |= (((nsOrd >> 2) & XATTR_NAMESPACE_EXT_MASK) <<
        XATTR_NAMESPACE_EXT_OFFSET);
    xAttrCompactBuilder.setName(v);
    if (a.getValue() != null) {
      xAttrCompactBuilder.setValue(PBHelper.getByteString(a.getValue()));
    }
    b.addXAttrs(xAttrCompactBuilder.build());
  }

  return b;
}
项目:big-c    文件:FSImageFormatPBINode.java   
private void save(OutputStream out, INodeFile n) throws IOException {
  INodeSection.INodeFile.Builder b = buildINodeFile(n,
      parent.getSaverContext());

  if (n.getBlocks() != null) {
    for (Block block : n.getBlocks()) {
      b.addBlocks(PBHelper.convert(block));
    }
  }

  FileUnderConstructionFeature uc = n.getFileUnderConstructionFeature();
  if (uc != null) {
    INodeSection.FileUnderConstructionFeature f =
        INodeSection.FileUnderConstructionFeature
        .newBuilder().setClientName(uc.getClientName())
        .setClientMachine(uc.getClientMachine()).build();
    b.setFileUC(f);
  }

  INodeSection.INode r = buildINodeCommon(n)
      .setType(INodeSection.INode.Type.FILE).setFile(b).build();
  r.writeDelimitedTo(out);
}
项目:big-c    文件:QJournalProtocolTranslatorPB.java   
@Override
public void journal(RequestInfo reqInfo,
    long segmentTxId, long firstTxnId, int numTxns,
    byte[] records) throws IOException {
  JournalRequestProto req = JournalRequestProto.newBuilder()
      .setReqInfo(convert(reqInfo))
      .setSegmentTxnId(segmentTxId)
      .setFirstTxnId(firstTxnId)
      .setNumTxns(numTxns)
      .setRecords(PBHelper.getByteString(records))
      .build();
  try {
    rpcProxy.journal(NULL_CONTROLLER, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
项目:big-c    文件:QJournalProtocolTranslatorPB.java   
@Override
public Boolean canRollBack(String journalId, StorageInfo storage,
    StorageInfo prevStorage, int targetLayoutVersion) throws IOException {
  try {
    CanRollBackResponseProto response = rpcProxy.canRollBack(
        NULL_CONTROLLER,
        CanRollBackRequestProto.newBuilder()
          .setJid(convertJournalId(journalId))
          .setStorage(PBHelper.convert(storage))
          .setPrevStorage(PBHelper.convert(prevStorage))
          .setTargetLayoutVersion(targetLayoutVersion)
          .build());
    return response.getCanRollBack();
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
项目:big-c    文件:TestBlockToken.java   
@Override
public GetReplicaVisibleLengthResponseProto answer(
    InvocationOnMock invocation) throws IOException {
  Object args[] = invocation.getArguments();
  assertEquals(2, args.length);
  GetReplicaVisibleLengthRequestProto req = 
      (GetReplicaVisibleLengthRequestProto) args[1];
  Set<TokenIdentifier> tokenIds = UserGroupInformation.getCurrentUser()
      .getTokenIdentifiers();
  assertEquals("Only one BlockTokenIdentifier expected", 1, tokenIds.size());
  long result = 0;
  for (TokenIdentifier tokenId : tokenIds) {
    BlockTokenIdentifier id = (BlockTokenIdentifier) tokenId;
    LOG.info("Got: " + id.toString());
    assertTrue("Received BlockTokenIdentifier is wrong", ident.equals(id));
    sm.checkAccess(id, null, PBHelper.convert(req.getBlock()),
        BlockTokenSecretManager.AccessMode.WRITE);
    result = id.getBlockId();
  }
  return GetReplicaVisibleLengthResponseProto.newBuilder()
      .setLength(result).build();
}
项目:FlexMap    文件:QJournalProtocolTranslatorPB.java   
@Override
public Boolean canRollBack(String journalId, StorageInfo storage,
    StorageInfo prevStorage, int targetLayoutVersion) throws IOException {
  try {
    CanRollBackResponseProto response = rpcProxy.canRollBack(
        NULL_CONTROLLER,
        CanRollBackRequestProto.newBuilder()
          .setJid(convertJournalId(journalId))
          .setStorage(PBHelper.convert(storage))
          .setPrevStorage(PBHelper.convert(prevStorage))
          .setTargetLayoutVersion(targetLayoutVersion)
          .build());
    return response.getCanRollBack();
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:DataTransferSaslUtil.java   
/**
 * Reads a SASL negotiation message and negotiation cipher options. 
 * 
 * @param in stream to read
 * @param cipherOptions list to store negotiation cipher options
 * @return byte[] SASL negotiation message
 * @throws IOException for any error
 */
public static byte[] readSaslMessageAndNegotiationCipherOptions(
    InputStream in, List<CipherOption> cipherOptions) throws IOException {
  DataTransferEncryptorMessageProto proto =
      DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in));
  if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) {
    throw new InvalidEncryptionKeyException(proto.getMessage());
  } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) {
    throw new IOException(proto.getMessage());
  } else {
    List<CipherOptionProto> optionProtos = proto.getCipherOptionList();
    if (optionProtos != null) {
      for (CipherOptionProto optionProto : optionProtos) {
        cipherOptions.add(PBHelper.convert(optionProto));
      }
    }
    return proto.getPayload().toByteArray();
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:DataTransferSaslUtil.java   
/**
 * Send SASL message and negotiated cipher option to client.
 * 
 * @param out stream to receive message
 * @param payload to send
 * @param option negotiated cipher option
 * @throws IOException for any error
 */
public static void sendSaslMessageAndNegotiatedCipherOption(
    OutputStream out, byte[] payload, CipherOption option) 
        throws IOException {
  DataTransferEncryptorMessageProto.Builder builder =
      DataTransferEncryptorMessageProto.newBuilder();

  builder.setStatus(DataTransferEncryptorStatus.SUCCESS);
  if (payload != null) {
    builder.setPayload(ByteString.copyFrom(payload));
  }
  if (option != null) {
    builder.addCipherOption(PBHelper.convert(option));
  }

  DataTransferEncryptorMessageProto proto = builder.build();
  proto.writeDelimitedTo(out);
  out.flush();
}
项目:hadoop-2.6.0-cdh5.4.3    文件:DataTransferSaslUtil.java   
/**
 * Read SASL message and negotiated cipher option from server.
 * 
 * @param in stream to read
 * @return SaslResponseWithNegotiatedCipherOption SASL message and 
 * negotiated cipher option
 * @throws IOException for any error
 */
public static SaslResponseWithNegotiatedCipherOption
    readSaslMessageAndNegotiatedCipherOption(InputStream in)
        throws IOException {
  DataTransferEncryptorMessageProto proto =
      DataTransferEncryptorMessageProto.parseFrom(vintPrefixed(in));
  if (proto.getStatus() == DataTransferEncryptorStatus.ERROR_UNKNOWN_KEY) {
    throw new InvalidEncryptionKeyException(proto.getMessage());
  } else if (proto.getStatus() == DataTransferEncryptorStatus.ERROR) {
    throw new IOException(proto.getMessage());
  } else {
    byte[] response = proto.getPayload().toByteArray();
    List<CipherOption> options = PBHelper.convertCipherOptionProtos(
        proto.getCipherOptionList());
    CipherOption option = null;
    if (options != null && !options.isEmpty()) {
      option = options.get(0);
    }
    return new SaslResponseWithNegotiatedCipherOption(response, option);
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:Sender.java   
@Override
public void transferBlock(final ExtendedBlock blk,
    final Token<BlockTokenIdentifier> blockToken,
    final String clientName,
    final DatanodeInfo[] targets,
    final StorageType[] targetStorageTypes) throws IOException {

  OpTransferBlockProto proto = OpTransferBlockProto.newBuilder()
    .setHeader(DataTransferProtoUtil.buildClientHeader(
        blk, clientName, blockToken))
    .addAllTargets(PBHelper.convert(targets))
    .addAllTargetStorageTypes(PBHelper.convertStorageTypes(targetStorageTypes))
    .build();

  send(out, Op.TRANSFER_BLOCK, proto);
}