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

The following examples show how to use org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil#getRemoteException() . 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: HRegionServer.java    From hbase with Apache License 2.0 6 votes vote down vote up
void reportProcedureDone(ReportProcedureDoneRequest request) throws IOException {
  RegionServerStatusService.BlockingInterface rss;
  // TODO: juggling class state with an instance variable, outside of a synchronized block :'(
  for (;;) {
    rss = rssStub;
    if (rss != null) {
      break;
    }
    createRegionServerStatusStub();
  }
  try {
    rss.reportProcedureDone(null, request);
  } catch (ServiceException se) {
    if (rssStub == rss) {
      rssStub = null;
    }
    throw ProtobufUtil.getRemoteException(se);
  }
}
 
Example 2
Source File: TestGenerateDelegationToken.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
  try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
      Table table = conn.getTable(TableName.META_TABLE_NAME)) {
    CoprocessorRpcChannel rpcChannel = table.coprocessorService(HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    WhoAmIResponse response = service.whoAmI(null, WhoAmIRequest.getDefaultInstance());
    assertEquals(USERNAME, response.getUsername());
    assertEquals(AuthenticationMethod.TOKEN.name(), response.getAuthMethod());
    try {
      service.getAuthenticationToken(null, GetAuthenticationTokenRequest.getDefaultInstance());
    } catch (ServiceException e) {
      IOException ioe = ProtobufUtil.getRemoteException(e);
      assertThat(ioe, instanceOf(AccessDeniedException.class));
      assertThat(ioe.getMessage(),
        containsString("Token generation only allowed for Kerberos authenticated clients"));
    }
  }
}
 
Example 3
Source File: HRegionServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected void tryRegionServerReport(long reportStartTime, long reportEndTime)
    throws IOException {
  RegionServerStatusService.BlockingInterface rss = rssStub;
  if (rss == null) {
    // the current server could be stopping.
    return;
  }
  ClusterStatusProtos.ServerLoad sl = buildServerLoad(reportStartTime, reportEndTime);
  try {
    RegionServerReportRequest.Builder request = RegionServerReportRequest.newBuilder();
    request.setServer(ProtobufUtil.toServerName(this.serverName));
    request.setLoad(sl);
    rss.regionServerReport(null, request.build());
  } catch (ServiceException se) {
    IOException ioe = ProtobufUtil.getRemoteException(se);
    if (ioe instanceof YouAreDeadException) {
      // This will be caught and handled as a fatal error in run()
      throw ioe;
    }
    if (rssStub == rss) {
      rssStub = null;
    }
    // Couldn't connect to the master, get location from zk and reconnect
    // Method blocks until new master is found or we are stopped
    createRegionServerStatusStub(true);
  }
}
 
Example 4
Source File: HRegionServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Reports the given map of Regions and their size on the filesystem to the active Master.
 *
 * @param regionSizeStore The store containing region sizes
 * @return false if FileSystemUtilizationChore should pause reporting to master. true otherwise
 */
public boolean reportRegionSizesForQuotas(RegionSizeStore regionSizeStore) {
  RegionServerStatusService.BlockingInterface rss = rssStub;
  if (rss == null) {
    // the current server could be stopping.
    LOG.trace("Skipping Region size report to HMaster as stub is null");
    return true;
  }
  try {
    buildReportAndSend(rss, regionSizeStore);
  } catch (ServiceException se) {
    IOException ioe = ProtobufUtil.getRemoteException(se);
    if (ioe instanceof PleaseHoldException) {
      LOG.trace("Failed to report region sizes to Master because it is initializing."
          + " This will be retried.", ioe);
      // The Master is coming up. Will retry the report later. Avoid re-creating the stub.
      return true;
    }
    if (rssStub == rss) {
      rssStub = null;
    }
    createRegionServerStatusStub(true);
    if (ioe instanceof DoNotRetryIOException) {
      DoNotRetryIOException doNotRetryEx = (DoNotRetryIOException) ioe;
      if (doNotRetryEx.getCause() != null) {
        Throwable t = doNotRetryEx.getCause();
        if (t instanceof UnsupportedOperationException) {
          LOG.debug("master doesn't support ReportRegionSpaceUse, pause before retrying");
          return false;
        }
      }
    }
    LOG.debug("Failed to report region sizes to Master. This will be retried.", ioe);
  }
  return true;
}
 
Example 5
Source File: HRegionServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
private RegionServerStartupResponse reportForDuty() throws IOException {
  if (this.masterless) return RegionServerStartupResponse.getDefaultInstance();
  ServerName masterServerName = createRegionServerStatusStub(true);
  RegionServerStatusService.BlockingInterface rss = rssStub;
  if (masterServerName == null || rss == null) return null;
  RegionServerStartupResponse result = null;
  try {
    rpcServices.requestCount.reset();
    rpcServices.rpcGetRequestCount.reset();
    rpcServices.rpcScanRequestCount.reset();
    rpcServices.rpcMultiRequestCount.reset();
    rpcServices.rpcMutateRequestCount.reset();
    LOG.info("reportForDuty to master=" + masterServerName + " with port="
      + rpcServices.isa.getPort() + ", startcode=" + this.startcode);
    long now = EnvironmentEdgeManager.currentTime();
    int port = rpcServices.isa.getPort();
    RegionServerStartupRequest.Builder request = RegionServerStartupRequest.newBuilder();
    if (!StringUtils.isBlank(useThisHostnameInstead)) {
      request.setUseThisHostnameInstead(useThisHostnameInstead);
    }
    request.setPort(port);
    request.setServerStartCode(this.startcode);
    request.setServerCurrentTime(now);
    result = rss.regionServerStartup(null, request.build());
  } catch (ServiceException se) {
    IOException ioe = ProtobufUtil.getRemoteException(se);
    if (ioe instanceof ClockOutOfSyncException) {
      LOG.error(HBaseMarkers.FATAL, "Master rejected startup because clock is out of sync",
          ioe);
      // Re-throw IOE will cause RS to abort
      throw ioe;
    } else if (ioe instanceof ServerNotRunningYetException) {
      LOG.debug("Master is not running yet");
    } else {
      LOG.warn("error telling master we are up", se);
    }
    rssStub = null;
  }
  return result;
}
 
Example 6
Source File: HRegionServer.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public boolean reportFileArchivalForQuotas(TableName tableName,
    Collection<Entry<String, Long>> archivedFiles) {
  RegionServerStatusService.BlockingInterface rss = rssStub;
  if (rss == null || rsSpaceQuotaManager == null) {
    // the current server could be stopping.
    LOG.trace("Skipping file archival reporting to HMaster as stub is null");
    return false;
  }
  try {
    RegionServerStatusProtos.FileArchiveNotificationRequest request =
        rsSpaceQuotaManager.buildFileArchiveRequest(tableName, archivedFiles);
    rss.reportFileArchival(null, request);
  } catch (ServiceException se) {
    IOException ioe = ProtobufUtil.getRemoteException(se);
    if (ioe instanceof PleaseHoldException) {
      if (LOG.isTraceEnabled()) {
        LOG.trace("Failed to report file archival(s) to Master because it is initializing."
            + " This will be retried.", ioe);
      }
      // The Master is coming up. Will retry the report later. Avoid re-creating the stub.
      return false;
    }
    if (rssStub == rss) {
      rssStub = null;
    }
    // re-create the stub if we failed to report the archival
    createRegionServerStatusStub(true);
    LOG.debug("Failed to report file archival(s) to Master. This will be retried.", ioe);
    return false;
  }
  return true;
}
 
Example 7
Source File: HRegionServer.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public boolean reportRegionStateTransition(final RegionStateTransitionContext context) {
  if (TEST_SKIP_REPORTING_TRANSITION) {
    return skipReportingTransition(context);
  }
  final ReportRegionStateTransitionRequest request =
      createReportRegionStateTransitionRequest(context);

  // Time to pause if master says 'please hold'. Make configurable if needed.
  final long initPauseTime = 1000;
  int tries = 0;
  long pauseTime;
  // Keep looping till we get an error. We want to send reports even though server is going down.
  // Only go down if clusterConnection is null. It is set to null almost as last thing as the
  // HRegionServer does down.
  while (this.asyncClusterConnection != null && !this.asyncClusterConnection.isClosed()) {
    RegionServerStatusService.BlockingInterface rss = rssStub;
    try {
      if (rss == null) {
        createRegionServerStatusStub();
        continue;
      }
      ReportRegionStateTransitionResponse response =
        rss.reportRegionStateTransition(null, request);
      if (response.hasErrorMessage()) {
        LOG.info("TRANSITION FAILED " + request + ": " + response.getErrorMessage());
        break;
      }
      // Log if we had to retry else don't log unless TRACE. We want to
      // know if were successful after an attempt showed in logs as failed.
      if (tries > 0 || LOG.isTraceEnabled()) {
        LOG.info("TRANSITION REPORTED " + request);
      }
      // NOTE: Return mid-method!!!
      return true;
    } catch (ServiceException se) {
      IOException ioe = ProtobufUtil.getRemoteException(se);
      boolean pause =
          ioe instanceof ServerNotRunningYetException || ioe instanceof PleaseHoldException
              || ioe instanceof CallQueueTooBigException;
      if (pause) {
        // Do backoff else we flood the Master with requests.
        pauseTime = ConnectionUtils.getPauseTime(initPauseTime, tries);
      } else {
        pauseTime = initPauseTime; // Reset.
      }
      LOG.info("Failed report transition " +
        TextFormat.shortDebugString(request) + "; retry (#" + tries + ")" +
          (pause?
              " after " + pauseTime + "ms delay (Master is coming online...).":
              " immediately."),
          ioe);
      if (pause) Threads.sleep(pauseTime);
      tries++;
      if (rssStub == rss) {
        rssStub = null;
      }
    }
  }
  return false;
}