Esempio n. 1
0
  private void doHealthChecks() throws InterruptedException {
    while (shouldRun) {
      HAServiceStatus status = null;
      boolean healthy = false;
      try {
        status = proxy.getServiceStatus();
        proxy.monitorHealth();
        healthy = true;
      } catch (HealthCheckFailedException e) {
        LOG.warn("Service health check failed for " + targetToMonitor + ": " + e.getMessage());
        enterState(State.SERVICE_UNHEALTHY);
      } catch (Throwable t) {
        LOG.warn(
            "Transport-level exception trying to monitor health of "
                + targetToMonitor
                + ": "
                + t.getLocalizedMessage());
        RPC.stopProxy(proxy);
        proxy = null;
        enterState(State.SERVICE_NOT_RESPONDING);
        Thread.sleep(sleepAfterDisconnectMillis);
        return;
      }

      if (status != null) {
        setLastServiceStatus(status);
      }
      if (healthy) {
        enterState(State.SERVICE_HEALTHY);
      }

      Thread.sleep(checkIntervalMillis);
    }
  }
  @Before
  public void configure() throws IOException {
    admin = mock(ResourceManagerAdministrationProtocol.class);

    haadmin = mock(HAServiceProtocol.class);
    when(haadmin.getServiceStatus())
        .thenReturn(new HAServiceStatus(HAServiceProtocol.HAServiceState.INITIALIZING));

    final HAServiceTarget haServiceTarget = mock(HAServiceTarget.class);
    when(haServiceTarget.getProxy(any(Configuration.class), anyInt())).thenReturn(haadmin);
    rmAdminCLI =
        new RMAdminCLI(new Configuration()) {

          @Override
          protected ResourceManagerAdministrationProtocol createAdminProtocol() throws IOException {
            return admin;
          }

          @Override
          protected HAServiceTarget resolveTarget(String rmId) {
            return haServiceTarget;
          }
        };

    YarnConfiguration conf = new YarnConfiguration();
    conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
    rmAdminCLIWithHAEnabled =
        new RMAdminCLI(conf) {

          @Override
          protected ResourceManagerAdministrationProtocol createAdminProtocol() throws IOException {
            return admin;
          }

          @Override
          protected HAServiceTarget resolveTarget(String rmId) {
            return haServiceTarget;
          }
        };
  }