Java Code Examples for org.apache.hadoop.service.CompositeService

The following examples show how to use org.apache.hadoop.service.CompositeService. 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: tajo   Source File: TestSimpleScheduler.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  conf = new TajoConf();
  nodeResource = NodeResource.createResource(2000, 3);
  service = new CompositeService(TestSimpleScheduler.class.getSimpleName()) {

    @Override
    protected void serviceInit(Configuration conf) throws Exception {
      dispatcher = new AsyncDispatcher();
      addService(dispatcher);

      rmContext = new TajoRMContext(dispatcher);
      rmContext.getDispatcher().register(NodeEventType.class,
          new TajoResourceManager.WorkerEventDispatcher(rmContext));

      barrier = new Semaphore(0);
      scheduler = new MySimpleScheduler(rmContext, barrier);
      addService(scheduler);
      rmContext.getDispatcher().register(SchedulerEventType.class, scheduler);

      for (int i = 0; i < workerNum; i++) {
        WorkerConnectionInfo conn = new WorkerConnectionInfo("host" + i, 28091 + i, 28092, 21000, 28093, 28080);
        rmContext.getNodes().putIfAbsent(conn.getId(),
            new NodeStatus(rmContext, NodeResources.clone(nodeResource), conn));
        rmContext.getDispatcher().getEventHandler().handle(new NodeEvent(conn.getId(), NodeEventType.STARTED));
      }
      super.serviceInit(conf);
    }
  };
  service.init(conf);
  service.start();

  assertEquals(workerNum, rmContext.getNodes().size());
  totalResource = NodeResources.createResource(0);
  for(NodeStatus nodeStatus : rmContext.getNodes().values()) {
    NodeResources.addTo(totalResource, nodeStatus.getTotalResourceCapability());
  }
}
 
Example 2
public CompositeService getYarnCluster() {
    return yarnCluster;
}