Java Code Examples for org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil#handleRemoteException()

The following examples show how to use org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil#handleRemoteException() . 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: ClientTokenUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Obtain and return an authentication token for the current user.
 * @param conn The HBase cluster connection
 * @throws IOException if a remote error or serialization problem occurs.
 * @return the authentication token instance
 */
@InterfaceAudience.Private
static Token<AuthenticationTokenIdentifier> obtainToken(
    Connection conn) throws IOException {
  Table meta = null;
  try {
    injectFault();

    meta = conn.getTable(TableName.META_TABLE_NAME);
    CoprocessorRpcChannel rpcChannel = meta.coprocessorService(
            HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    AuthenticationProtos.GetAuthenticationTokenResponse response =
            service.getAuthenticationToken(null,
        AuthenticationProtos.GetAuthenticationTokenRequest.getDefaultInstance());

    return toToken(response.getToken());
  } catch (ServiceException se) {
    throw ProtobufUtil.handleRemoteException(se);
  } finally {
    if (meta != null) {
      meta.close();
    }
  }
}
 
Example 2
Source File: AbstractTestIPC.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testAsyncRemoteError() throws IOException {
  AbstractRpcClient<?> client = createRpcClient(CONF);
  RpcServer rpcServer = createRpcServer(null, "testRpcServer",
      Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(
          SERVICE, null)), new InetSocketAddress("localhost", 0), CONF,
      new FifoRpcScheduler(CONF, 1));
  try {
    rpcServer.start();
    Interface stub = newStub(client, rpcServer.getListenerAddress());
    BlockingRpcCallback<EmptyResponseProto> callback = new BlockingRpcCallback<>();
    HBaseRpcController pcrc = new HBaseRpcControllerImpl();
    stub.error(pcrc, EmptyRequestProto.getDefaultInstance(), callback);
    assertNull(callback.get());
    assertTrue(pcrc.failed());
    LOG.info("Caught expected exception: " + pcrc.getFailed());
    IOException ioe = ProtobufUtil.handleRemoteException(pcrc.getFailed());
    assertTrue(ioe instanceof DoNotRetryIOException);
    assertTrue(ioe.getMessage().contains("server error!"));
  } finally {
    client.close();
    rpcServer.stop();
  }
}
 
Example 3
Source File: AbstractTestIPC.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoteError() throws IOException, ServiceException {
  RpcServer rpcServer = createRpcServer(null, "testRpcServer",
      Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(
          SERVICE, null)), new InetSocketAddress("localhost", 0), CONF,
      new FifoRpcScheduler(CONF, 1));
  try (AbstractRpcClient<?> client = createRpcClient(CONF)) {
    rpcServer.start();
    BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress());
    stub.error(null, EmptyRequestProto.getDefaultInstance());
  } catch (ServiceException e) {
    LOG.info("Caught expected exception: " + e);
    IOException ioe = ProtobufUtil.handleRemoteException(e);
    assertTrue(ioe instanceof DoNotRetryIOException);
    assertTrue(ioe.getMessage().contains("server error!"));
  } finally {
    rpcServer.stop();
  }
}
 
Example 4
Source File: SnapshotTestingUtils.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Expect the snapshot to throw an error when checking if the snapshot is
 * complete
 *
 * @param master master to check
 * @param snapshot the {@link SnapshotDescription} request to pass to the master
 * @param clazz expected exception from the master
 */
public static void expectSnapshotDoneException(HMaster master,
    IsSnapshotDoneRequest snapshot,
    Class<? extends HBaseSnapshotException> clazz) {
  try {
    master.getMasterRpcServices().isSnapshotDone(null, snapshot);
    Assert.fail("didn't fail to lookup a snapshot");
  } catch (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException se) {
    try {
      throw ProtobufUtil.handleRemoteException(se);
    } catch (HBaseSnapshotException e) {
      assertEquals("Threw wrong snapshot exception!", clazz, e.getClass());
    } catch (Throwable t) {
      Assert.fail("Threw an unexpected exception:" + t);
    }
  }
}
 
Example 5
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Move given set of servers and tables to the specified target RegionServer group.
 * @param servers set of servers to move
 * @param tables set of tables to move
 * @param targetGroup the target group name
 * @throws IOException if moving the server and tables fail
 */
public void moveServersAndTables(Set<Address> servers, Set<TableName> tables, String targetGroup)
  throws IOException {
  MoveServersAndTablesRequest.Builder builder =
    MoveServersAndTablesRequest.newBuilder().setTargetGroup(targetGroup);
  for (Address el : servers) {
    builder.addServers(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostname())
      .setPort(el.getPort()).build());
  }
  for (TableName tableName : tables) {
    builder.addTableName(ProtobufUtil.toProtoTableName(tableName));
    if (!admin.tableExists(tableName)) {
      throw new TableNotFoundException(tableName);
    }
  }
  try {
    stub.moveServersAndTables(null, builder.build());
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 6
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Lists current set of RegionServer groups.
 */
public List<RSGroupInfo> listRSGroups() throws IOException {
  try {
    List<RSGroupProtos.RSGroupInfo> resp = stub
      .listRSGroupInfos(null, ListRSGroupInfosRequest.getDefaultInstance()).getRSGroupInfoList();
    List<RSGroupInfo> result = new ArrayList<>(resp.size());
    for (RSGroupProtos.RSGroupInfo entry : resp) {
      result.add(ProtobufUtil.toGroupInfo(entry));
    }
    return result;
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 7
Source File: AbstractTestIPC.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testTimeout() throws IOException {
  RpcServer rpcServer = createRpcServer(null, "testRpcServer",
      Lists.newArrayList(new RpcServer.BlockingServiceAndInterface(
          SERVICE, null)), new InetSocketAddress("localhost", 0), CONF,
      new FifoRpcScheduler(CONF, 1));
  try (AbstractRpcClient<?> client = createRpcClient(CONF)) {
    rpcServer.start();
    BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress());
    HBaseRpcController pcrc = new HBaseRpcControllerImpl();
    int ms = 1000;
    int timeout = 100;
    for (int i = 0; i < 10; i++) {
      pcrc.reset();
      pcrc.setCallTimeout(timeout);
      long startTime = System.nanoTime();
      try {
        stub.pause(pcrc, PauseRequestProto.newBuilder().setMs(ms).build());
      } catch (ServiceException e) {
        long waitTime = (System.nanoTime() - startTime) / 1000000;
        // expected
        LOG.info("Caught expected exception: " + e);
        IOException ioe = ProtobufUtil.handleRemoteException(e);
        assertTrue(ioe.getCause() instanceof CallTimeoutException);
        // confirm that we got exception before the actual pause.
        assertTrue(waitTime < ms);
      }
    }
  } finally {
    rpcServer.stop();
  }
}
 
Example 8
Source File: TestHMasterRPCException.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testRPCException() throws IOException, InterruptedException, KeeperException {
  ServerName sm = master.getServerName();
  boolean fakeZNodeDelete = false;
  for (int i = 0; i < 20; i++) {
    try {
      BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0);
      MasterProtos.MasterService.BlockingInterface stub =
          MasterProtos.MasterService.newBlockingStub(channel);
      assertTrue(stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance())
          .getIsMasterRunning());
      return;
    } catch (ServiceException ex) {
      IOException ie = ProtobufUtil.handleRemoteException(ex);
      // No SocketTimeoutException here. RpcServer is already started after the construction of
      // HMaster.
      assertTrue(ie.getMessage().startsWith(
        "org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet"));
      LOG.info("Expected exception: ", ie);
      if (!fakeZNodeDelete) {
        testUtil.getZooKeeperWatcher().getRecoverableZooKeeper()
            .delete(testUtil.getZooKeeperWatcher().getZNodePaths().masterAddressZNode, -1);
        fakeZNodeDelete = true;
      }
    }
    Thread.sleep(1000);
  }
}
 
Example 9
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Remove decommissioned servers from rsgroup. 1. Sometimes we may find the server aborted due to
 * some hardware failure and we must offline the server for repairing. Or we need to move some
 * servers to join other clusters. So we need to remove these servers from the rsgroup. 2.
 * Dead/recovering/live servers will be disallowed.
 * @param servers set of servers to remove
 */
public void removeServers(Set<Address> servers) throws IOException {
  Set<HBaseProtos.ServerName> hostPorts = Sets.newHashSet();
  for (Address el : servers) {
    hostPorts.add(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostname())
      .setPort(el.getPort()).build());
  }
  RemoveServersRequest request =
    RemoveServersRequest.newBuilder().addAllServers(hostPorts).build();
  try {
    stub.removeServers(null, request);
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 10
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve the RSGroupInfo a server is affiliated to
 * @param hostPort HostPort to get RSGroupInfo for
 */
public RSGroupInfo getRSGroupOfServer(Address hostPort) throws IOException {
  GetRSGroupInfoOfServerRequest request =
    GetRSGroupInfoOfServerRequest.newBuilder().setServer(HBaseProtos.ServerName.newBuilder()
      .setHostName(hostPort.getHostname()).setPort(hostPort.getPort()).build()).build();
  try {
    GetRSGroupInfoOfServerResponse resp = stub.getRSGroupInfoOfServer(null, request);
    if (resp.hasRSGroupInfo()) {
      return ProtobufUtil.toGroupInfo(resp.getRSGroupInfo());
    }
    return null;
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 11
Source File: EntityLock.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Sends rpc to the master to request lock.
 * The lock request is queued with other lock requests.
 * Call {@link #await()} to wait on lock.
 * Always call {@link #unlock()} after calling the below, even after error.
 */
public void requestLock() throws IOException {
  if (procId == null) {
    try {
      procId = stub.requestLock(null, lockRequest).getProcId();
    } catch (Exception e) {
      throw ProtobufUtil.handleRemoteException(e);
    }
    worker.start();
  } else {
    LOG.info("Lock already queued : " + toString());
  }
}
 
Example 12
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Balance regions in the given RegionServer group.
 * @return boolean Whether balance ran or not
 */
public boolean balanceRSGroup(String groupName) throws IOException {
  BalanceRSGroupRequest request =
    BalanceRSGroupRequest.newBuilder().setRSGroupName(groupName).build();
  try {
    return stub.balanceRSGroup(null, request).getBalanceRan();
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 13
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Removes RegionServer group associated with the given name.
 */
public void removeRSGroup(String name) throws IOException {
  RemoveRSGroupRequest request = RemoveRSGroupRequest.newBuilder().setRSGroupName(name).build();
  try {
    stub.removeRSGroup(null, request);
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 14
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new RegionServer group with the given name.
 */
public void addRSGroup(String groupName) throws IOException {
  AddRSGroupRequest request = AddRSGroupRequest.newBuilder().setRSGroupName(groupName).build();
  try {
    stub.addRSGroup(null, request);
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 15
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Move given set of tables to the specified target RegionServer group. This will unassign all of
 * a table's region so it can be reassigned to the correct group.
 */
public void moveTables(Set<TableName> tables, String targetGroup) throws IOException {
  MoveTablesRequest.Builder builder = MoveTablesRequest.newBuilder().setTargetGroup(targetGroup);
  for (TableName tableName : tables) {
    builder.addTableName(ProtobufUtil.toProtoTableName(tableName));
    if (!admin.tableExists(tableName)) {
      throw new TableNotFoundException(tableName);
    }
  }
  try {
    stub.moveTables(null, builder.build());
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 16
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Move given set of servers to the specified target RegionServer group.
 */
public void moveServers(Set<Address> servers, String targetGroup) throws IOException {
  Set<HBaseProtos.ServerName> hostPorts = Sets.newHashSet();
  for (Address el : servers) {
    hostPorts.add(HBaseProtos.ServerName.newBuilder().setHostName(el.getHostname())
      .setPort(el.getPort()).build());
  }
  MoveServersRequest request =
    MoveServersRequest.newBuilder().setTargetGroup(targetGroup).addAllServers(hostPorts).build();
  try {
    stub.moveServers(null, request);
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 17
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Gets {@code RSGroupInfo} for the given table's group.
 */
public RSGroupInfo getRSGroupInfoOfTable(TableName tableName) throws IOException {
  GetRSGroupInfoOfTableRequest request = GetRSGroupInfoOfTableRequest.newBuilder()
    .setTableName(ProtobufUtil.toProtoTableName(tableName)).build();
  try {
    GetRSGroupInfoOfTableResponse resp = stub.getRSGroupInfoOfTable(null, request);
    if (resp.hasRSGroupInfo()) {
      return ProtobufUtil.toGroupInfo(resp.getRSGroupInfo());
    }
    return null;
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 18
Source File: RSGroupAdminClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Gets {@code RSGroupInfo} for given group name.
 */
public RSGroupInfo getRSGroupInfo(String groupName) throws IOException {
  try {
    GetRSGroupInfoResponse resp = stub.getRSGroupInfo(null,
      GetRSGroupInfoRequest.newBuilder().setRSGroupName(groupName).build());
    if (resp.hasRSGroupInfo()) {
      return ProtobufUtil.toGroupInfo(resp.getRSGroupInfo());
    }
    return null;
  } catch (ServiceException e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}
 
Example 19
Source File: EntityLock.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void unlock() throws IOException {
  Threads.shutdown(worker.shutdown());
  try {
    stub.lockHeartbeat(null,
      LockHeartbeatRequest.newBuilder().setProcId(procId).setKeepAlive(false).build());
  } catch (Exception e) {
    throw ProtobufUtil.handleRemoteException(e);
  }
}