Java Code Examples for org.apache.hadoop.service.Service.STATE

The following examples show how to use org.apache.hadoop.service.Service.STATE. These examples are extracted from open source projects. 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 Project: hadoop   Source File: TestNodeStatusUpdater.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 2
Source Project: hadoop   Source File: TestNodeStatusUpdater.java    License: Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 3
Source Project: hadoop   Source File: TestLocalDirsHandlerService.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 4
Source Project: hadoop   Source File: TestRMRestart.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 5
Source Project: hadoop   Source File: TestRMAdminCLI.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 6
Source Project: hadoop   Source File: TestJobHistoryServer.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 7
Source Project: hadoop   Source File: TestCompositeService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 8
Source Project: hadoop   Source File: TestCompositeService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 9
Source Project: hadoop   Source File: TestCompositeService.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 10
Source Project: hadoop   Source File: TestCompositeService.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 11
Source Project: big-c   Source File: TestNodeStatusUpdater.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 12
Source Project: big-c   Source File: TestNodeStatusUpdater.java    License: Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 13
Source Project: big-c   Source File: TestLocalDirsHandlerService.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 14
Source Project: big-c   Source File: TestRMRestart.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 15
Source Project: big-c   Source File: TestRMAdminCLI.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 16
Source Project: big-c   Source File: TestJobHistoryServer.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 17
Source Project: big-c   Source File: TestCompositeService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 18
Source Project: big-c   Source File: TestCompositeService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 19
Source Project: big-c   Source File: TestCompositeService.java    License: Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 20
Source Project: big-c   Source File: TestCompositeService.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 21
Source Project: hadoop   Source File: TestWebAppProxyServer.java    License: Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 22
Source Project: hadoop   Source File: TestNodeStatusUpdater.java    License: Apache License 2.0 5 votes vote down vote up
@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();
  }
}
 
Example 23
Source Project: hadoop   Source File: QueueACLsTestBase.java    License: Apache License 2.0 5 votes vote down vote up
@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());
  }
}
 
Example 24
Source Project: hadoop   Source File: TestRMWebServices.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 25
Source Project: hadoop   Source File: TestApplicationHistoryServer.java    License: Apache License 2.0 5 votes vote down vote up
@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();
  }
}
 
Example 26
Source Project: hadoop   Source File: TestRMFailover.java    License: Apache License 2.0 5 votes vote down vote up
@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();
  }
}
 
Example 27
Source Project: hadoop   Source File: TestAMRMClient.java    License: Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void tearDown() {
  if (yarnClient != null && yarnClient.getServiceState() == STATE.STARTED) {
    yarnClient.stop();
  }
  if (yarnCluster != null && yarnCluster.getServiceState() == STATE.STARTED) {
    yarnCluster.stop();
  }
}
 
Example 28
Source Project: hadoop   Source File: TestAMRMClient.java    License: Apache License 2.0 5 votes vote down vote up
@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();
    }
  }
}
 
Example 29
Source Project: hadoop   Source File: TestGetGroups.java    License: Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 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);

}