Java源码示例:org.apache.hadoop.service.Service.STATE

示例1
@Test
public void testNodeDecommision() throws Exception {
  nm = getNodeManager(NodeAction.SHUTDOWN);
  YarnConfiguration conf = createNMConfig();
  nm.init(conf);
  Assert.assertEquals(STATE.INITED, nm.getServiceState());
  nm.start();

  int waitCount = 0;
  while (heartBeatID < 1 && waitCount++ != 200) {
    Thread.sleep(500);
  }
  Assert.assertFalse(heartBeatID < 1);
  Assert.assertTrue(nm.getNMContext().getDecommissioned());

  // NM takes a while to reach the STOPPED state.
  waitCount = 0;
  while (nm.getServiceState() != STATE.STOPPED && waitCount++ != 20) {
    LOG.info("Waiting for NM to stop..");
    Thread.sleep(1000);
  }

  Assert.assertEquals(STATE.STOPPED, nm.getServiceState());
}
 
示例2
private void verifyNodeStartFailure(String errMessage) throws Exception {
  Assert.assertNotNull("nm is null", nm);
  YarnConfiguration conf = createNMConfig();
  nm.init(conf);
  try {
    nm.start();
    Assert.fail("NM should have failed to start. Didn't get exception!!");
  } catch (Exception e) {
    //the version in trunk looked in the cause for equality
    // and assumed failures were nested.
    //this version assumes that error strings propagate to the base and
    //use a contains() test only. It should be less brittle
    if(!e.getMessage().contains(errMessage)) {
      throw e;
    }
  }

  // the service should be stopped
  Assert.assertEquals("NM state is wrong!", STATE.STOPPED, nm
      .getServiceState());

  Assert.assertEquals("Number of registered nodes is wrong!", 0,
      this.registeredNodes.size());
}
 
示例3
@Test
public void testValidPathsDirHandlerService() throws Exception {
  Configuration conf = new YarnConfiguration();
  String localDir1 = new File("file:///" + testDir, "localDir1").getPath();
  String localDir2 = new File("hdfs:///" + testDir, "localDir2").getPath();
  conf.set(YarnConfiguration.NM_LOCAL_DIRS, localDir1 + "," + localDir2);
  String logDir1 = new File("file:///" + testDir, "logDir1").getPath();
  conf.set(YarnConfiguration.NM_LOG_DIRS, logDir1);
  LocalDirsHandlerService dirSvc = new LocalDirsHandlerService();
  try {
    dirSvc.init(conf);
    Assert.fail("Service should have thrown an exception due to wrong URI");
  } catch (YarnRuntimeException e) {
  }
  Assert.assertEquals("Service should not be inited",
                      STATE.STOPPED,
                      dirSvc.getServiceState());
  dirSvc.close();
}
 
示例4
@Test (timeout = 10000)
public void testRMShutdown() throws Exception {
  MemoryRMStateStore memStore = new MemoryRMStateStore() {
    @Override
    public synchronized void checkVersion()
        throws Exception {
      throw new Exception("Invalid version.");
    }
  };
  // start RM
  memStore.init(conf);
  MockRM rm1 = null;
  try {
    rm1 = createMockRM(conf, memStore);
    rm1.start();
    Assert.fail();
  } catch (Exception e) {
    Assert.assertTrue(e.getMessage().contains("Invalid version."));
  }
  Assert.assertTrue(rm1.getServiceState() == STATE.STOPPED);
}
 
示例5
@Test
public void testAccessLocalNodeLabelManager() throws Exception {
  assertFalse(dummyNodeLabelsManager.getServiceState() == STATE.STOPPED);
  
  String[] args =
      { "-addToClusterNodeLabels", "x,y", "-directlyAccessNodeLabelStore" };
  assertEquals(0, rmAdminCLI.run(args));
  assertTrue(dummyNodeLabelsManager.getClusterNodeLabels().containsAll(
      ImmutableSet.of("x", "y")));
  
  // reset localNodeLabelsManager
  dummyNodeLabelsManager.removeFromClusterNodeLabels(ImmutableSet.of("x", "y"));
  
  // change the sequence of "-directlyAccessNodeLabelStore" and labels,
  // should not matter
  args =
      new String[] { "-addToClusterNodeLabels",
          "-directlyAccessNodeLabelStore", "x,y" };
  assertEquals(0, rmAdminCLI.run(args));
  assertTrue(dummyNodeLabelsManager.getClusterNodeLabels().containsAll(
      ImmutableSet.of("x", "y")));
  
  // local node labels manager will be close after running
  assertTrue(dummyNodeLabelsManager.getServiceState() == STATE.STOPPED);
}
 
示例6
@Test (timeout= 50000 )
public void testStartStopServer() throws Exception {
  historyServer = new JobHistoryServer();
  Configuration config = new Configuration();
  historyServer.init(config);
  assertEquals(STATE.INITED, historyServer.getServiceState());
  assertEquals(6, historyServer.getServices().size());
  HistoryClientService historyService = historyServer.getClientService();
  assertNotNull(historyServer.getClientService());
  assertEquals(STATE.INITED, historyService.getServiceState());

  historyServer.start();
  assertEquals(STATE.STARTED, historyServer.getServiceState());
  assertEquals(STATE.STARTED, historyService.getServiceState());
  historyServer.stop();
  assertEquals(STATE.STOPPED, historyServer.getServiceState());
  assertNotNull(historyService.getClientHandler().getConnectAddress());
}
 
示例7
/**
 * Shut down from not-inited: expect nothing to have happened
 */
@Test
public void testServiceStopFromNotInited() {
  ServiceManager serviceManager = new ServiceManager("ServiceManager");

  // Add services
  for (int i = 0; i < NUM_OF_SERVICES; i++) {
    CompositeServiceImpl service = new CompositeServiceImpl(i);
    serviceManager.addTestService(service);
  }

  CompositeServiceImpl[] services = serviceManager.getServices().toArray(
    new CompositeServiceImpl[0]);
  serviceManager.stop();
  assertInState(STATE.NOTINITED, services);
}
 
示例8
/**
 * Shut down from inited
 */
@Test
public void testServiceStopFromInited() {
  ServiceManager serviceManager = new ServiceManager("ServiceManager");

  // Add services
  for (int i = 0; i < NUM_OF_SERVICES; i++) {
    CompositeServiceImpl service = new CompositeServiceImpl(i);
    serviceManager.addTestService(service);
  }

  CompositeServiceImpl[] services = serviceManager.getServices().toArray(
    new CompositeServiceImpl[0]);
  serviceManager.init(new Configuration());
  serviceManager.stop();
  if (STOP_ONLY_STARTED_SERVICES) {
    //this policy => no services were stopped
    assertInState(STATE.INITED, services);
  } else {
    assertInState(STATE.STOPPED, services);
  }
}
 
示例9
@Test(timeout = 1000)
public void testAddUninitedSiblingInInit() throws Throwable {
  CompositeService parent = new CompositeService("parent");
  BreakableService sibling = new BreakableService();
  parent.addService(new AddSiblingService(parent,
                                          sibling,
                                          STATE.INITED));
  parent.init(new Configuration());
  try {
    parent.start();
    fail("Expected an exception, got " + parent);
  } catch (ServiceStateException e) {
    //expected
  }
  parent.stop();
  assertEquals("Incorrect number of services",
               2, parent.getServices().size());
}
 
示例10
@Test(timeout = 1000)
public void testAddStartedSiblingInInit() throws Throwable {
  CompositeService parent = new CompositeService("parent");
  BreakableService sibling = new BreakableService();
  sibling.init(new Configuration());
  sibling.start();
  parent.addService(new AddSiblingService(parent,
                                          sibling,
                                          STATE.INITED));
  parent.init(new Configuration());
  assertInState(STATE.STARTED, sibling);
  parent.start();
  assertInState(STATE.STARTED, sibling);
  parent.stop();
  assertEquals("Incorrect number of services",
               2, parent.getServices().size());
  assertInState(STATE.STOPPED, sibling);
}
 
示例11
@Test
public void testNodeDecommision() throws Exception {
  nm = getNodeManager(NodeAction.SHUTDOWN);
  YarnConfiguration conf = createNMConfig();
  nm.init(conf);
  Assert.assertEquals(STATE.INITED, nm.getServiceState());
  nm.start();

  int waitCount = 0;
  while (heartBeatID < 1 && waitCount++ != 200) {
    Thread.sleep(500);
  }
  Assert.assertFalse(heartBeatID < 1);
  Assert.assertTrue(nm.getNMContext().getDecommissioned());

  // NM takes a while to reach the STOPPED state.
  waitCount = 0;
  while (nm.getServiceState() != STATE.STOPPED && waitCount++ != 20) {
    LOG.info("Waiting for NM to stop..");
    Thread.sleep(1000);
  }

  Assert.assertEquals(STATE.STOPPED, nm.getServiceState());
}
 
示例12
private void verifyNodeStartFailure(String errMessage) throws Exception {
  Assert.assertNotNull("nm is null", nm);
  YarnConfiguration conf = createNMConfig();
  nm.init(conf);
  try {
    nm.start();
    Assert.fail("NM should have failed to start. Didn't get exception!!");
  } catch (Exception e) {
    //the version in trunk looked in the cause for equality
    // and assumed failures were nested.
    //this version assumes that error strings propagate to the base and
    //use a contains() test only. It should be less brittle
    if(!e.getMessage().contains(errMessage)) {
      throw e;
    }
  }

  // the service should be stopped
  Assert.assertEquals("NM state is wrong!", STATE.STOPPED, nm
      .getServiceState());

  Assert.assertEquals("Number of registered nodes is wrong!", 0,
      this.registeredNodes.size());
}
 
示例13
@Test
public void testValidPathsDirHandlerService() throws Exception {
  Configuration conf = new YarnConfiguration();
  String localDir1 = new File("file:///" + testDir, "localDir1").getPath();
  String localDir2 = new File("hdfs:///" + testDir, "localDir2").getPath();
  conf.set(YarnConfiguration.NM_LOCAL_DIRS, localDir1 + "," + localDir2);
  String logDir1 = new File("file:///" + testDir, "logDir1").getPath();
  conf.set(YarnConfiguration.NM_LOG_DIRS, logDir1);
  LocalDirsHandlerService dirSvc = new LocalDirsHandlerService();
  try {
    dirSvc.init(conf);
    Assert.fail("Service should have thrown an exception due to wrong URI");
  } catch (YarnRuntimeException e) {
  }
  Assert.assertEquals("Service should not be inited",
                      STATE.STOPPED,
                      dirSvc.getServiceState());
  dirSvc.close();
}
 
示例14
@Test (timeout = 10000)
public void testRMShutdown() throws Exception {
  MemoryRMStateStore memStore = new MemoryRMStateStore() {
    @Override
    public synchronized void checkVersion()
        throws Exception {
      throw new Exception("Invalid version.");
    }
  };
  // start RM
  memStore.init(conf);
  MockRM rm1 = null;
  try {
    rm1 = createMockRM(conf, memStore);
    rm1.start();
    Assert.fail();
  } catch (Exception e) {
    Assert.assertTrue(e.getMessage().contains("Invalid version."));
  }
  Assert.assertTrue(rm1.getServiceState() == STATE.STOPPED);
}
 
示例15
@Test
public void testAccessLocalNodeLabelManager() throws Exception {
  assertFalse(dummyNodeLabelsManager.getServiceState() == STATE.STOPPED);
  
  String[] args =
      { "-addToClusterNodeLabels", "x,y", "-directlyAccessNodeLabelStore" };
  assertEquals(0, rmAdminCLI.run(args));
  assertTrue(dummyNodeLabelsManager.getClusterNodeLabels().containsAll(
      ImmutableSet.of("x", "y")));
  
  // reset localNodeLabelsManager
  dummyNodeLabelsManager.removeFromClusterNodeLabels(ImmutableSet.of("x", "y"));
  
  // change the sequence of "-directlyAccessNodeLabelStore" and labels,
  // should not matter
  args =
      new String[] { "-addToClusterNodeLabels",
          "-directlyAccessNodeLabelStore", "x,y" };
  assertEquals(0, rmAdminCLI.run(args));
  assertTrue(dummyNodeLabelsManager.getClusterNodeLabels().containsAll(
      ImmutableSet.of("x", "y")));
  
  // local node labels manager will be close after running
  assertTrue(dummyNodeLabelsManager.getServiceState() == STATE.STOPPED);
}
 
示例16
@Test (timeout= 50000 )
public void testStartStopServer() throws Exception {
  historyServer = new JobHistoryServer();
  Configuration config = new Configuration();
  historyServer.init(config);
  assertEquals(STATE.INITED, historyServer.getServiceState());
  assertEquals(6, historyServer.getServices().size());
  HistoryClientService historyService = historyServer.getClientService();
  assertNotNull(historyServer.getClientService());
  assertEquals(STATE.INITED, historyService.getServiceState());

  historyServer.start();
  assertEquals(STATE.STARTED, historyServer.getServiceState());
  assertEquals(STATE.STARTED, historyService.getServiceState());
  historyServer.stop();
  assertEquals(STATE.STOPPED, historyServer.getServiceState());
  assertNotNull(historyService.getClientHandler().getConnectAddress());
}
 
示例17
/**
 * Shut down from not-inited: expect nothing to have happened
 */
@Test
public void testServiceStopFromNotInited() {
  ServiceManager serviceManager = new ServiceManager("ServiceManager");

  // Add services
  for (int i = 0; i < NUM_OF_SERVICES; i++) {
    CompositeServiceImpl service = new CompositeServiceImpl(i);
    serviceManager.addTestService(service);
  }

  CompositeServiceImpl[] services = serviceManager.getServices().toArray(
    new CompositeServiceImpl[0]);
  serviceManager.stop();
  assertInState(STATE.NOTINITED, services);
}
 
示例18
/**
 * Shut down from inited
 */
@Test
public void testServiceStopFromInited() {
  ServiceManager serviceManager = new ServiceManager("ServiceManager");

  // Add services
  for (int i = 0; i < NUM_OF_SERVICES; i++) {
    CompositeServiceImpl service = new CompositeServiceImpl(i);
    serviceManager.addTestService(service);
  }

  CompositeServiceImpl[] services = serviceManager.getServices().toArray(
    new CompositeServiceImpl[0]);
  serviceManager.init(new Configuration());
  serviceManager.stop();
  if (STOP_ONLY_STARTED_SERVICES) {
    //this policy => no services were stopped
    assertInState(STATE.INITED, services);
  } else {
    assertInState(STATE.STOPPED, services);
  }
}
 
示例19
@Test(timeout = 1000)
public void testAddUninitedSiblingInInit() throws Throwable {
  CompositeService parent = new CompositeService("parent");
  BreakableService sibling = new BreakableService();
  parent.addService(new AddSiblingService(parent,
                                          sibling,
                                          STATE.INITED));
  parent.init(new Configuration());
  try {
    parent.start();
    fail("Expected an exception, got " + parent);
  } catch (ServiceStateException e) {
    //expected
  }
  parent.stop();
  assertEquals("Incorrect number of services",
               2, parent.getServices().size());
}
 
示例20
@Test(timeout = 1000)
public void testAddStartedSiblingInInit() throws Throwable {
  CompositeService parent = new CompositeService("parent");
  BreakableService sibling = new BreakableService();
  sibling.init(new Configuration());
  sibling.start();
  parent.addService(new AddSiblingService(parent,
                                          sibling,
                                          STATE.INITED));
  parent.init(new Configuration());
  assertInState(STATE.STARTED, sibling);
  parent.start();
  assertInState(STATE.STARTED, sibling);
  parent.stop();
  assertEquals("Incorrect number of services",
               2, parent.getServices().size());
  assertInState(STATE.STOPPED, sibling);
}
 
示例21
@Test
public void testStart() {
  assertEquals(STATE.INITED, webAppProxy.getServiceState());
  webAppProxy.start();
  for (Service service : webAppProxy.getServices()) {
    if (service instanceof WebAppProxy) {
      assertEquals(((WebAppProxy) service).getBindAddress(), proxyAddress);
    }
  }
  assertEquals(STATE.STARTED, webAppProxy.getServiceState());
}
 
示例22
@Test
public void testApplicationKeepAlive() throws Exception {
  MyNodeManager nm = new MyNodeManager();
  try {
    YarnConfiguration conf = createNMConfig();
    conf.setBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED, true);
    conf.setLong(YarnConfiguration.RM_NM_EXPIRY_INTERVAL_MS,
        4000l);
    nm.init(conf);
    nm.start();
    // HB 2 -> app cancelled by RM.
    while (heartBeatID < 12) {
      Thread.sleep(1000l);
    }
    MyResourceTracker3 rt =
        (MyResourceTracker3) nm.getNodeStatusUpdater().getRMClient();
    rt.context.getApplications().remove(rt.appId);
    Assert.assertEquals(1, rt.keepAliveRequests.size());
    int numKeepAliveRequests = rt.keepAliveRequests.get(rt.appId).size();
    LOG.info("Number of Keep Alive Requests: [" + numKeepAliveRequests + "]");
    Assert.assertTrue(numKeepAliveRequests == 2 || numKeepAliveRequests == 3);
    while (heartBeatID < 20) {
      Thread.sleep(1000l);
    }
    int numKeepAliveRequests2 = rt.keepAliveRequests.get(rt.appId).size();
    Assert.assertEquals(numKeepAliveRequests, numKeepAliveRequests2);
  } finally {
    if (nm.getServiceState() == STATE.STARTED)
      nm.stop();
  }
}
 
示例23
@Before
public void setup() throws InterruptedException, IOException {
  conf = createConfiguration();
  rpc = YarnRPC.create(conf);
  rmAddress = conf.getSocketAddr(
    YarnConfiguration.RM_ADDRESS, YarnConfiguration.DEFAULT_RM_ADDRESS,
    YarnConfiguration.DEFAULT_RM_PORT);
  
  AccessControlList adminACL = new AccessControlList("");
  conf.set(YarnConfiguration.YARN_ADMIN_ACL, adminACL.getAclString());

  resourceManager = new MockRM(conf) {
    protected ClientRMService createClientRMService() {
      return new ClientRMService(getRMContext(), this.scheduler,
        this.rmAppManager, this.applicationACLsManager,
        this.queueACLsManager, getRMContext().getRMDelegationTokenSecretManager());
    };

    @Override
    protected void doSecureLogin() throws IOException {
    }
  };
  new Thread() {
    public void run() {
      resourceManager.start();
    };
  }.start();
  int waitCount = 0;
  while (resourceManager.getServiceState() == STATE.INITED
      && waitCount++ < 60) {
    LOG.info("Waiting for RM to start...");
    Thread.sleep(1500);
  }
  if (resourceManager.getServiceState() != STATE.STARTED) {
    // RM could have failed.
    throw new IOException("ResourceManager failed to start. Final state is "
        + resourceManager.getServiceState());
  }
}
 
示例24
public void verifyClusterGeneric(long clusterid, long startedon,
    String state, String haState, String hadoopVersionBuiltOn,
    String hadoopBuildVersion, String hadoopVersion,
    String resourceManagerVersionBuiltOn, String resourceManagerBuildVersion,
    String resourceManagerVersion) {

  assertEquals("clusterId doesn't match: ",
      ResourceManager.getClusterTimeStamp(), clusterid);
  assertEquals("startedOn doesn't match: ",
      ResourceManager.getClusterTimeStamp(), startedon);
  assertTrue("stated doesn't match: " + state,
      state.matches(STATE.INITED.toString()));
  assertTrue("HA state doesn't match: " + haState,
      haState.matches("INITIALIZING"));

  WebServicesTestUtils.checkStringMatch("hadoopVersionBuiltOn",
      VersionInfo.getDate(), hadoopVersionBuiltOn);
  WebServicesTestUtils.checkStringEqual("hadoopBuildVersion",
      VersionInfo.getBuildVersion(), hadoopBuildVersion);
  WebServicesTestUtils.checkStringMatch("hadoopVersion",
      VersionInfo.getVersion(), hadoopVersion);

  WebServicesTestUtils.checkStringMatch("resourceManagerVersionBuiltOn",
      YarnVersionInfo.getDate(), resourceManagerVersionBuiltOn);
  WebServicesTestUtils.checkStringEqual("resourceManagerBuildVersion",
      YarnVersionInfo.getBuildVersion(), resourceManagerBuildVersion);
  WebServicesTestUtils.checkStringMatch("resourceManagerVersion",
      YarnVersionInfo.getVersion(), resourceManagerVersion);
}
 
示例25
@Test(timeout = 60000)
public void testStartStopServer() throws Exception {
  ApplicationHistoryServer historyServer = new ApplicationHistoryServer();
  Configuration config = new YarnConfiguration();
  config.setClass(YarnConfiguration.TIMELINE_SERVICE_STORE,
      MemoryTimelineStore.class, TimelineStore.class);
  config.setClass(YarnConfiguration.TIMELINE_SERVICE_STATE_STORE_CLASS,
      MemoryTimelineStateStore.class, TimelineStateStore.class);
  config.set(YarnConfiguration.TIMELINE_SERVICE_WEBAPP_ADDRESS, "localhost:0");
  try {
    try {
      historyServer.init(config);
      config.setInt(YarnConfiguration.TIMELINE_SERVICE_HANDLER_THREAD_COUNT,
          0);
      historyServer.start();
      fail();
    } catch (IllegalArgumentException e) {
      Assert.assertTrue(e.getMessage().contains(
          YarnConfiguration.TIMELINE_SERVICE_HANDLER_THREAD_COUNT));
    }
    config.setInt(YarnConfiguration.TIMELINE_SERVICE_HANDLER_THREAD_COUNT,
        YarnConfiguration.DEFAULT_TIMELINE_SERVICE_CLIENT_THREAD_COUNT);
    historyServer = new ApplicationHistoryServer();
    historyServer.init(config);
    assertEquals(STATE.INITED, historyServer.getServiceState());
    assertEquals(5, historyServer.getServices().size());
    ApplicationHistoryClientService historyService =
        historyServer.getClientService();
    assertNotNull(historyServer.getClientService());
    assertEquals(STATE.INITED, historyService.getServiceState());

    historyServer.start();
    assertEquals(STATE.STARTED, historyServer.getServiceState());
    assertEquals(STATE.STARTED, historyService.getServiceState());
    historyServer.stop();
    assertEquals(STATE.STOPPED, historyServer.getServiceState());
  } finally {
    historyServer.stop();
  }
}
 
示例26
@Test
public void testWebAppProxyInStandAloneMode() throws YarnException,
    InterruptedException, IOException {
  conf.setBoolean(YarnConfiguration.AUTO_FAILOVER_ENABLED, false);
  WebAppProxyServer webAppProxyServer = new WebAppProxyServer();
  try {
    conf.set(YarnConfiguration.PROXY_ADDRESS, "0.0.0.0:9099");
    cluster.init(conf);
    cluster.start();
    getAdminService(0).transitionToActive(req);
    assertFalse("RM never turned active", -1 == cluster.getActiveRMIndex());
    verifyConnections();
    webAppProxyServer.init(conf);

    // Start webAppProxyServer
    Assert.assertEquals(STATE.INITED, webAppProxyServer.getServiceState());
    webAppProxyServer.start();
    Assert.assertEquals(STATE.STARTED, webAppProxyServer.getServiceState());

    // send httpRequest with fakeApplicationId
    // expect to get "Not Found" response and 404 response code
    URL wrongUrl = new URL("http://0.0.0.0:9099/proxy/" + fakeAppId);
    HttpURLConnection proxyConn = (HttpURLConnection) wrongUrl
        .openConnection();

    proxyConn.connect();
    verifyResponse(proxyConn);

    explicitFailover();
    verifyConnections();
    proxyConn.connect();
    verifyResponse(proxyConn);
  } finally {
    webAppProxyServer.stop();
  }
}
 
示例27
@AfterClass
public static void tearDown() {
  if (yarnClient != null && yarnClient.getServiceState() == STATE.STARTED) {
    yarnClient.stop();
  }
  if (yarnCluster != null && yarnCluster.getServiceState() == STATE.STARTED) {
    yarnCluster.stop();
  }
}
 
示例28
@Test (timeout=60000)
public void testAMRMClient() throws YarnException, IOException {
  AMRMClient<ContainerRequest> amClient = null;
  try {
    // start am rm client
    amClient = AMRMClient.<ContainerRequest>createAMRMClient();

    //setting an instance NMTokenCache
    amClient.setNMTokenCache(new NMTokenCache());
    //asserting we are not using the singleton instance cache
    Assert.assertNotSame(NMTokenCache.getSingleton(), 
        amClient.getNMTokenCache());

    amClient.init(conf);
    amClient.start();

    amClient.registerApplicationMaster("Host", 10000, "");

    testAllocation((AMRMClientImpl<ContainerRequest>)amClient);

    amClient.unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED,
        null, null);

  } finally {
    if (amClient != null && amClient.getServiceState() == STATE.STARTED) {
      amClient.stop();
    }
  }
}
 
示例29
@BeforeClass
public static void setUpResourceManager() throws IOException, InterruptedException {
  conf = new YarnConfiguration();
  resourceManager = new ResourceManager() {
    @Override
    protected void doSecureLogin() throws IOException {
    };
  };
  resourceManager.init(conf);
  new Thread() {
    public void run() {
      resourceManager.start();
    };
  }.start();
  int waitCount = 0;
  while (resourceManager.getServiceState() == STATE.INITED
      && waitCount++ < 10) {
    LOG.info("Waiting for RM to start...");
    Thread.sleep(1000);
  }
  if (resourceManager.getServiceState() != STATE.STARTED) {
    throw new IOException(
        "ResourceManager failed to start. Final state is "
            + resourceManager.getServiceState());
  }
  LOG.info("ResourceManager RMAdmin address: " +
      conf.get(YarnConfiguration.RM_ADMIN_ADDRESS));
}
 
示例30
/**
 * Start resource manager server
 */

@BeforeClass
public static void setUpResourceManager() throws IOException,
        InterruptedException {
  Configuration.addDefaultResource("config-with-security.xml");
  Configuration configuration = new YarnConfiguration();
  resourceManager = new ResourceManager() {
    @Override
    protected void doSecureLogin() throws IOException {
    }
  };
  resourceManager.init(configuration);
  new Thread() {
    public void run() {
      resourceManager.start();
    }
  }.start();
  int waitCount = 0;
  while (resourceManager.getServiceState() == STATE.INITED
          && waitCount++ < 10) {
    LOG.info("Waiting for RM to start...");
    Thread.sleep(1000);
  }
  if (resourceManager.getServiceState() != STATE.STARTED) {
    throw new IOException("ResourceManager failed to start. Final state is "
            + resourceManager.getServiceState());
  }
  LOG.info("ResourceManager RMAdmin address: "
          + configuration.get(YarnConfiguration.RM_ADMIN_ADDRESS));

  client = new ResourceManagerAdministrationProtocolPBClientImpl(1L,
          getProtocolAddress(configuration), configuration);

}