org.apache.hadoop.ipc.ProtobufHelper Java Examples

The following examples show how to use org.apache.hadoop.ipc.ProtobufHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QJournalProtocolTranslatorPB.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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);
  }
}
 
Example #2
Source File: JournalProtocolTranslatorPB.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void journal(JournalInfo journalInfo, long epoch, long firstTxnId,
    int numTxns, byte[] records) throws IOException {
  JournalRequestProto req = JournalRequestProto.newBuilder()
      .setJournalInfo(PBHelper.convert(journalInfo))
      .setEpoch(epoch)
      .setFirstTxnId(firstTxnId)
      .setNumTxns(numTxns)
      .setRecords(PBHelper.getByteString(records))
      .build();
  try {
    rpcProxy.journal(NULL_CONTROLLER, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #3
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public LocatedBlock addBlock(String src, String clientName,
    ExtendedBlock previous, DatanodeInfo[] excludeNodes, long fileId,
    String[] favoredNodes)
    throws AccessControlException, FileNotFoundException,
    NotReplicatedYetException, SafeModeException, UnresolvedLinkException,
    IOException {
  AddBlockRequestProto.Builder req = AddBlockRequestProto.newBuilder()
      .setSrc(src).setClientName(clientName).setFileId(fileId);
  if (previous != null) 
    req.setPrevious(PBHelper.convert(previous)); 
  if (excludeNodes != null) 
    req.addAllExcludeNodes(PBHelper.convert(excludeNodes));
  if (favoredNodes != null) {
    req.addAllFavoredNodes(Arrays.asList(favoredNodes));
  }
  try {
    return PBHelper.convert(rpcProxy.addBlock(null, req.build()).getBlock());
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #4
Source File: TraceAdminProtocolTranslatorPB.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public SpanReceiverInfo[] listSpanReceivers() throws IOException {
  ArrayList<SpanReceiverInfo> infos = new ArrayList<SpanReceiverInfo>(1);
  try {
    ListSpanReceiversRequestProto req =
        ListSpanReceiversRequestProto.newBuilder().build();
    ListSpanReceiversResponseProto resp =
        rpcProxy.listSpanReceivers(null, req);
    for (SpanReceiverListInfo info : resp.getDescriptionsList()) {
      infos.add(new SpanReceiverInfo(info.getId(), info.getClassName()));
    }
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
  return infos.toArray(new SpanReceiverInfo[infos.size()]);
}
 
Example #5
Source File: HAServiceProtocolClientSideTranslatorPB.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public HAServiceStatus getServiceStatus() throws IOException {
  GetServiceStatusResponseProto status;
  try {
    status = rpcProxy.getServiceStatus(NULL_CONTROLLER,
        GET_SERVICE_STATUS_REQ);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
  
  HAServiceStatus ret = new HAServiceStatus(
      convert(status.getState()));
  if (status.getReadyToBecomeActive()) {
    ret.setReadyToBecomeActive();
  } else {
    ret.setNotReadyToBecomeActive(status.getNotReadyReason());
  }
  return ret;
}
 
Example #6
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void updatePipeline(String clientName, ExtendedBlock oldBlock,
    ExtendedBlock newBlock, DatanodeID[] newNodes, String[] storageIDs) throws IOException {
  UpdatePipelineRequestProto req = UpdatePipelineRequestProto.newBuilder()
      .setClientName(clientName)
      .setOldBlock(PBHelper.convert(oldBlock))
      .setNewBlock(PBHelper.convert(newBlock))
      .addAllNewNodes(Arrays.asList(PBHelper.convert(newNodes)))
      .addAllStorageIDs(storageIDs == null ? null : Arrays.asList(storageIDs))
      .build();
  try {
    rpcProxy.updatePipeline(null, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #7
Source File: DatanodeProtocolClientSideTranslatorPB.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void blockReceivedAndDeleted(DatanodeRegistration registration,
    String poolId, StorageReceivedDeletedBlocks[] receivedAndDeletedBlocks)
    throws IOException {
  BlockReceivedAndDeletedRequestProto.Builder builder = 
      BlockReceivedAndDeletedRequestProto.newBuilder()
      .setRegistration(PBHelper.convert(registration))
      .setBlockPoolId(poolId);
  for (StorageReceivedDeletedBlocks storageBlock : receivedAndDeletedBlocks) {
    StorageReceivedDeletedBlocksProto.Builder repBuilder = 
        StorageReceivedDeletedBlocksProto.newBuilder();
    repBuilder.setStorageUuid(storageBlock.getStorage().getStorageID());  // Set for wire compatibility.
    repBuilder.setStorage(PBHelper.convert(storageBlock.getStorage()));
    for (ReceivedDeletedBlockInfo rdBlock : storageBlock.getBlocks()) {
      repBuilder.addBlocks(PBHelper.convert(rdBlock));
    }
    builder.addBlocks(repBuilder.build());
  }
  try {
    rpcProxy.blockReceivedAndDeleted(NULL_CONTROLLER, builder.build());
  } catch (ServiceException se) {
    throw ProtobufHelper.getRemoteException(se);
  }
}
 
Example #8
Source File: TraceAdminProtocolTranslatorPB.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public long addSpanReceiver(SpanReceiverInfo info) throws IOException {
  try {
    AddSpanReceiverRequestProto.Builder bld =
        AddSpanReceiverRequestProto.newBuilder();
    bld.setClassName(info.getClassName());
    for (ConfigurationPair configPair : info.configPairs) {
      ConfigPair tuple = ConfigPair.newBuilder().
          setKey(configPair.getKey()).
          setValue(configPair.getValue()).build();
      bld.addConfig(tuple);
    }
    AddSpanReceiverResponseProto resp =
        rpcProxy.addSpanReceiver(null, bld.build());
    return resp.getId();
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #9
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public BatchedEntries<EncryptionZone> listEncryptionZones(long id)
    throws IOException {
  final ListEncryptionZonesRequestProto req =
    ListEncryptionZonesRequestProto.newBuilder()
        .setId(id)
        .build();
  try {
    EncryptionZonesProtos.ListEncryptionZonesResponseProto response =
        rpcProxy.listEncryptionZones(null, req);
    List<EncryptionZone> elements =
        Lists.newArrayListWithCapacity(response.getZonesCount());
    for (EncryptionZoneProto p : response.getZonesList()) {
      elements.add(PBHelper.convert(p));
    }
    return new BatchedListEntries<EncryptionZone>(elements,
        response.getHasMore());
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #10
Source File: InterDatanodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public ReplicaRecoveryInfo initReplicaRecovery(RecoveringBlock rBlock)
    throws IOException {
  InitReplicaRecoveryRequestProto req = InitReplicaRecoveryRequestProto
      .newBuilder().setBlock(PBHelper.convert(rBlock)).build();
  InitReplicaRecoveryResponseProto resp;
  try {
    resp = rpcProxy.initReplicaRecovery(NULL_CONTROLLER, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
  if (!resp.getReplicaFound()) {
    // No replica found on the remote node.
    return null;
  } else {
    if (!resp.hasBlock() || !resp.hasState()) {
      throw new IOException("Replica was found but missing fields. " +
          "Req: " + req + "\n" +
          "Resp: " + resp);
    }
  }
  
  BlockProto b = resp.getBlock();
  return new ReplicaRecoveryInfo(b.getBlockId(), b.getNumBytes(),
      b.getGenStamp(), PBHelper.convert(resp.getState()));
}
 
Example #11
Source File: StorageContainerDatanodeProtocolClientSideTranslatorPB.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to wrap the request and send the message.
 */
private SCMDatanodeResponse submitRequest(Type type,
    Consumer<SCMDatanodeRequest.Builder> builderConsumer) throws IOException {
  final SCMDatanodeResponse response;
  try {
    Builder builder = SCMDatanodeRequest.newBuilder()
        .setCmdType(type);
    builderConsumer.accept(builder);
    SCMDatanodeRequest wrapper = builder.build();

    response = rpcProxy.submitRequest(NULL_RPC_CONTROLLER, wrapper);
  } catch (ServiceException ex) {
    throw ProtobufHelper.getRemoteException(ex);
  }
  return response;
}
 
Example #12
Source File: ClientDatanodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public BlockLocalPathInfo getBlockLocalPathInfo(ExtendedBlock block,
    Token<BlockTokenIdentifier> token) throws IOException {
  GetBlockLocalPathInfoRequestProto req =
      GetBlockLocalPathInfoRequestProto.newBuilder()
      .setBlock(PBHelper.convert(block))
      .setToken(PBHelper.convert(token)).build();
  GetBlockLocalPathInfoResponseProto resp;
  try {
    resp = rpcProxy.getBlockLocalPathInfo(NULL_CONTROLLER, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
  return new BlockLocalPathInfo(PBHelper.convert(resp.getBlock()),
      resp.getLocalPath(), resp.getLocalMetaPath());
}
 
Example #13
Source File: Hadoop3OmTransport.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
@Override
public OMResponse submitRequest(OMRequest payload) throws IOException {
  try {
    OMResponse omResponse =
        rpcProxy.submitRequest(NULL_RPC_CONTROLLER, payload);

    if (omResponse.hasLeaderOMNodeId() && omFailoverProxyProvider != null) {
      String leaderOmId = omResponse.getLeaderOMNodeId();

      // Failover to the OM node returned by OMResponse leaderOMNodeId if
      // current proxy is not pointing to that node.
      omFailoverProxyProvider.performFailoverIfRequired(leaderOmId);
    }
    return omResponse;
  } catch (ServiceException e) {
    OMNotLeaderException notLeaderException = getNotLeaderException(e);
    if (notLeaderException == null) {
      throw ProtobufHelper.getRemoteException(e);
    }
    throw new IOException("Could not determine or connect to OM Leader.");
  }
}
 
Example #14
Source File: SCMSecurityProtocolClientSideTranslatorPB.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to wrap the request and send the message.
 */
private SCMSecurityResponse submitRequest(
    SCMSecurityProtocolProtos.Type type,
    Consumer<Builder> builderConsumer) throws IOException {
  final SCMSecurityResponse response;
  try {

    Builder builder = SCMSecurityRequest.newBuilder()
        .setCmdType(type)
        .setTraceID(TracingUtil.exportCurrentSpan());
    builderConsumer.accept(builder);
    SCMSecurityRequest wrapper = builder.build();

    response = rpcProxy.submitRequest(NULL_RPC_CONTROLLER, wrapper);
  } catch (ServiceException ex) {
    throw ProtobufHelper.getRemoteException(ex);
  }
  return response;
}
 
Example #15
Source File: StorageContainerLocationProtocolClientSideTranslatorPB.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to wrap the request and send the message.
 */
private ScmContainerLocationResponse submitRequest(
    StorageContainerLocationProtocolProtos.Type type,
    Consumer<Builder> builderConsumer) throws IOException {
  final ScmContainerLocationResponse response;
  try {

    Builder builder = ScmContainerLocationRequest.newBuilder()
        .setCmdType(type)
        .setTraceID(TracingUtil.exportCurrentSpan());
    builderConsumer.accept(builder);
    ScmContainerLocationRequest wrapper = builder.build();

    response = submitRpcRequest(wrapper);
  } catch (ServiceException ex) {
    throw ProtobufHelper.getRemoteException(ex);
  }
  return response;
}
 
Example #16
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteSnapshot(String snapshotRoot, String snapshotName)
    throws IOException {
  DeleteSnapshotRequestProto req = DeleteSnapshotRequestProto.newBuilder()
      .setSnapshotRoot(snapshotRoot).setSnapshotName(snapshotName).build();
  try {
    rpcProxy.deleteSnapshot(null, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #17
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void removeAcl(String src) throws IOException {
  RemoveAclRequestProto req = RemoveAclRequestProto.newBuilder()
      .setSrc(src).build();
  try {
    rpcProxy.removeAcl(null, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #18
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void reportBadBlocks(LocatedBlock[] blocks) throws IOException {
  ReportBadBlocksRequestProto req = ReportBadBlocksRequestProto.newBuilder()
      .addAllBlocks(Arrays.asList(PBHelper.convertLocatedBlock(blocks)))
      .build();
  try {
    rpcProxy.reportBadBlocks(null, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #19
Source File: QJournalProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public NewEpochResponseProto newEpoch(String jid, NamespaceInfo nsInfo,
    long epoch) throws IOException {
  try {
    NewEpochRequestProto req = NewEpochRequestProto.newBuilder()
      .setJid(convertJournalId(jid))
      .setNsInfo(PBHelper.convert(nsInfo))
      .setEpoch(epoch)
      .build();
    return rpcProxy.newEpoch(NULL_CONTROLLER, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #20
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void allowSnapshot(String snapshotRoot) throws IOException {
  AllowSnapshotRequestProto req = AllowSnapshotRequestProto.newBuilder()
      .setSnapshotRoot(snapshotRoot).build();
  try {
    rpcProxy.allowSnapshot(null, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #21
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public long rollEdits() throws AccessControlException, IOException {
  try {
    RollEditsResponseProto resp = rpcProxy.rollEdits(null,
        VOID_ROLLEDITS_REQUEST);
    return resp.getNewSegmentTxId();
  } catch (ServiceException se) {
    throw ProtobufHelper.getRemoteException(se);
  }
}
 
Example #22
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void refreshNodes() throws IOException {
  try {
    rpcProxy.refreshNodes(null, VOID_REFRESH_NODES_REQUEST);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #23
Source File: QJournalProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public GetEditLogManifestResponseProto getEditLogManifest(String jid,
    long sinceTxId, boolean inProgressOk)
    throws IOException {
  try {
    return rpcProxy.getEditLogManifest(NULL_CONTROLLER,
        GetEditLogManifestRequestProto.newBuilder()
          .setJid(convertJournalId(jid))
          .setSinceTxId(sinceTxId)
          .setInProgressOk(inProgressOk)
          .build());
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #24
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void setPermission(String src, FsPermission permission)
    throws AccessControlException, FileNotFoundException, SafeModeException,
    UnresolvedLinkException, IOException {
  SetPermissionRequestProto req = SetPermissionRequestProto.newBuilder()
      .setSrc(src)
      .setPermission(PBHelper.convert(permission))
      .build();
  try {
    rpcProxy.setPermission(null, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #25
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public boolean setReplication(String src, short replication)
    throws AccessControlException, DSQuotaExceededException,
    FileNotFoundException, SafeModeException, UnresolvedLinkException,
    IOException {
  SetReplicationRequestProto req = SetReplicationRequestProto.newBuilder()
      .setSrc(src)
      .setReplication(replication)
      .build();
  try {
    return rpcProxy.setReplication(null, req).getResult();
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #26
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public BatchedEntries<CachePoolEntry> listCachePools(String prevKey)
    throws IOException {
  try {
    return new BatchedCachePoolEntries(
      rpcProxy.listCachePools(null,
        ListCachePoolsRequestProto.newBuilder().
          setPrevPoolName(prevKey).build()));
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #27
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public AclStatus getAclStatus(String src) throws IOException {
  GetAclStatusRequestProto req = GetAclStatusRequestProto.newBuilder()
      .setSrc(src).build();
  try {
    return PBHelper.convert(rpcProxy.getAclStatus(null, req));
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #28
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelDelegationToken(Token<DelegationTokenIdentifier> token)
    throws IOException {
  CancelDelegationTokenRequestProto req = CancelDelegationTokenRequestProto
      .newBuilder()
      .setToken(PBHelper.convert(token))
      .build();
  try {
    rpcProxy.cancelDelegationToken(null, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #29
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public String getLinkTarget(String path) throws AccessControlException,
    FileNotFoundException, IOException {
  GetLinkTargetRequestProto req = GetLinkTargetRequestProto.newBuilder()
      .setPath(path).build();
  try {
    GetLinkTargetResponseProto rsp = rpcProxy.getLinkTarget(null, req);
    return rsp.hasTargetPath() ? rsp.getTargetPath() : null;
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #30
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void modifyCachePool(CachePoolInfo req) throws IOException {
  ModifyCachePoolRequestProto.Builder builder = 
      ModifyCachePoolRequestProto.newBuilder();
  builder.setInfo(PBHelper.convert(req));
  try {
    rpcProxy.modifyCachePool(null, builder.build());
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}