/** Wait for service to finish. (Normally, it runs forever.) */
 public void join() {
   try {
     if (server != null) server.join();
     if (aggregateDaemon != null) aggregateDaemon.join();
   } catch (InterruptedException ie) {
     // do nothing
   }
 }
示例#2
0
  protected void startServer() throws Exception {
    Configuration conf = getConfig();
    YarnRPC rpc = YarnRPC.create(conf);
    this.server =
        (Server)
            rpc.getServer(
                ResourceManagerAdministrationProtocol.class,
                this,
                masterServiceAddress,
                conf,
                null,
                conf.getInt(
                    YarnConfiguration.RM_ADMIN_CLIENT_THREAD_COUNT,
                    YarnConfiguration.DEFAULT_RM_ADMIN_CLIENT_THREAD_COUNT));

    // Enable service authorization?
    if (conf.getBoolean(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, false)) {
      refreshServiceAcls(
          getConfiguration(conf, YarnConfiguration.HADOOP_POLICY_CONFIGURATION_FILE),
          RMPolicyProvider.getInstance());
    }

    if (rmContext.isHAEnabled()) {
      RPC.setProtocolEngine(conf, HAServiceProtocolPB.class, ProtobufRpcEngine.class);

      HAServiceProtocolServerSideTranslatorPB haServiceProtocolXlator =
          new HAServiceProtocolServerSideTranslatorPB(this);
      BlockingService haPbService =
          HAServiceProtocolProtos.HAServiceProtocolService.newReflectiveBlockingService(
              haServiceProtocolXlator);
      server.addProtocol(RPC.RpcKind.RPC_PROTOCOL_BUFFER, HAServiceProtocol.class, haPbService);
    }

    this.server.start();
    conf.updateConnectAddr(YarnConfiguration.RM_ADMIN_ADDRESS, server.getListenerAddress());
  }
示例#3
0
  @Test
  public void testRpcFailover() throws Exception {
    String appPath = testMeta.dir;
    Configuration conf = new Configuration(false);
    final AtomicBoolean timedout = new AtomicBoolean();

    StreamingContainerUmbilicalProtocol impl =
        MockitoUtil.mockProtocol(StreamingContainerUmbilicalProtocol.class);

    Mockito.doAnswer(
            new org.mockito.stubbing.Answer<Void>() {
              @Override
              public Void answer(InvocationOnMock invocation) {
                LOG.debug("got call: " + invocation.getMethod());
                if (!timedout.get()) {
                  try {
                    timedout.set(true);
                    Thread.sleep(1000);
                  } catch (Exception e) {
                  }
                  // throw new RuntimeException("fail");
                }
                return null;
              }
            })
        .when(impl)
        .log("containerId", "timeout");

    Server server =
        new RPC.Builder(conf)
            .setProtocol(StreamingContainerUmbilicalProtocol.class)
            .setInstance(impl)
            .setBindAddress("0.0.0.0")
            .setPort(0)
            .setNumHandlers(1)
            .setVerbose(false)
            .build();
    server.start();
    InetSocketAddress address = NetUtils.getConnectAddress(server);
    LOG.info("Mock server listening at " + address);

    int rpcTimeoutMillis = 500;
    int retryDelayMillis = 100;
    int retryTimeoutMillis = 500;

    FSRecoveryHandler recoveryHandler = new FSRecoveryHandler(appPath, conf);
    URI uri =
        RecoverableRpcProxy.toConnectURI(
            address, rpcTimeoutMillis, retryDelayMillis, retryTimeoutMillis);
    recoveryHandler.writeConnectUri(uri.toString());

    RecoverableRpcProxy rp = new RecoverableRpcProxy(appPath, conf);
    StreamingContainerUmbilicalProtocol protocolProxy = rp.getProxy();
    protocolProxy.log("containerId", "msg");
    // simulate socket read timeout
    try {
      protocolProxy.log("containerId", "timeout");
      Assert.fail("expected socket timeout");
    } catch (java.net.SocketTimeoutException e) {
      // expected
    }
    Assert.assertTrue("timedout", timedout.get());
    rp.close();

    // test success on retry
    timedout.set(false);
    retryTimeoutMillis = 1500;
    uri =
        RecoverableRpcProxy.toConnectURI(
            address, rpcTimeoutMillis, retryDelayMillis, retryTimeoutMillis);
    recoveryHandler.writeConnectUri(uri.toString());

    protocolProxy.log("containerId", "timeout");
    Assert.assertTrue("timedout", timedout.get());

    rp.close();
    server.stop();
  }
 /** Stop all Collector threads and wait for all to finish. */
 public void stop() {
   running = false;
   if (server != null) server.stop();
   if (aggregateDaemon != null) aggregateDaemon.interrupt();
 }