hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acmur...@apache.org
Subject svn commit: r1082677 [33/38] - in /hadoop/mapreduce/branches/MR-279: ./ assembly/ ivy/ mr-client/ mr-client/hadoop-mapreduce-client-app/ mr-client/hadoop-mapreduce-client-app/src/ mr-client/hadoop-mapreduce-client-app/src/main/ mr-client/hadoop-mapredu...
Date Thu, 17 Mar 2011 20:21:54 GMT
Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationMasterInfo.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationMasterInfo.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationMasterInfo.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationMasterInfo.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,351 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.classification.InterfaceAudience.Private;
+import org.apache.hadoop.classification.InterfaceStability.Unstable;
+import org.apache.hadoop.yarn.ApplicationID;
+import org.apache.hadoop.yarn.ApplicationMaster;
+import org.apache.hadoop.yarn.ApplicationState;
+import org.apache.hadoop.yarn.ApplicationStatus;
+import org.apache.hadoop.yarn.ApplicationSubmissionContext;
+import org.apache.hadoop.yarn.Container;
+import org.apache.hadoop.yarn.Resource;
+import org.apache.hadoop.yarn.event.EventHandler;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ASMEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationMasterEvents.AMLauncherEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationMasterEvents.ApplicationEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationMasterEvents.ApplicationTrackerEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationMasterEvents.SNEventType;
+import org.apache.hadoop.yarn.state.InvalidStateTransitonException;
+import org.apache.hadoop.yarn.state.SingleArcTransition;
+import org.apache.hadoop.yarn.state.StateMachine;
+import org.apache.hadoop.yarn.state.StateMachineFactory;
+
+/**
+ * This class manages the state of a application master. Also, it
+ * provide a read only interface for all the services to get information
+ * about this application.
+ *
+ */
+@Private
+@Unstable
+public class ApplicationMasterInfo implements AppContext, EventHandler<ASMEvent<ApplicationEventType>> {
+  private static final Log LOG = LogFactory.getLog(ApplicationMasterInfo.class);
+  private final ApplicationSubmissionContext submissionContext;
+  private ApplicationMaster master;
+  private final EventHandler handler;
+  private Container masterContainer;
+  final private String user;
+  /* this transition is too generalized, needs to be broken up as and when we 
+   * keeping adding states. This will keep evolving and is not final yet.
+   */
+  private final  KillTransition killTransition =  new KillTransition();
+  private final StatusUpdateTransition statusUpdatetransition = new StatusUpdateTransition();
+
+  private final StateMachine<ApplicationState, ApplicationEventType, 
+  ASMEvent<ApplicationEventType>> stateMachine;
+
+  private final StateMachineFactory<ApplicationMasterInfo,
+  ApplicationState, ApplicationEventType, ASMEvent<ApplicationEventType>> stateMachineFactory 
+
+  = new StateMachineFactory
+  <ApplicationMasterInfo, ApplicationState, ApplicationEventType, ASMEvent<ApplicationEventType>>
+  (ApplicationState.PENDING)
+
+  .addTransition(ApplicationState.PENDING, ApplicationState.ALLOCATING,
+  ApplicationEventType.ALLOCATE, new AllocateTransition())
+
+  .addTransition(ApplicationState.PENDING, ApplicationState.CLEANUP, 
+  ApplicationEventType.KILL, killTransition)
+
+  .addTransition(ApplicationState.ALLOCATING, ApplicationState.ALLOCATED,
+  ApplicationEventType.ALLOCATED, new AllocatedTransition())
+
+  .addTransition(ApplicationState.ALLOCATING, ApplicationState.CLEANUP, 
+  ApplicationEventType.KILL, killTransition)
+
+  .addTransition(ApplicationState.ALLOCATED, ApplicationState.CLEANUP, 
+  ApplicationEventType.KILL, killTransition)
+
+  .addTransition(ApplicationState.ALLOCATED, ApplicationState.LAUNCHING,
+  ApplicationEventType.LAUNCH, new LaunchTransition())
+
+  .addTransition(ApplicationState.LAUNCHING, ApplicationState.LAUNCHED,
+  ApplicationEventType.LAUNCHED, new LaunchedTransition())
+  
+  .addTransition(ApplicationState.LAUNCHING, ApplicationState.KILLED,
+   ApplicationEventType.KILL, killTransition)
+   
+  .addTransition(ApplicationState.LAUNCHED, ApplicationState.CLEANUP, 
+  ApplicationEventType.KILL, killTransition)
+  
+  .addTransition(ApplicationState.LAUNCHED, ApplicationState.FAILED,
+  ApplicationEventType.EXPIRE, new ExpireTransition())
+  
+  .addTransition(ApplicationState.LAUNCHED, ApplicationState.RUNNING, 
+  ApplicationEventType.REGISTERED, new RegisterTransition())
+
+  .addTransition(ApplicationState.RUNNING,  ApplicationState.FAILED, 
+  ApplicationEventType.EXPIRE, new ExpireTransition())
+  
+  .addTransition(ApplicationState.RUNNING, ApplicationState.COMPLETED,
+  ApplicationEventType.FINISH, new DoneTransition())
+
+  .addTransition(ApplicationState.RUNNING, ApplicationState.RUNNING,
+  ApplicationEventType.STATUSUPDATE, statusUpdatetransition)
+
+  .addTransition(ApplicationState.COMPLETED, ApplicationState.COMPLETED, 
+  ApplicationEventType.EXPIRE)
+
+  .installTopology();
+
+
+
+  public ApplicationMasterInfo(EventHandler handler, String user,
+  ApplicationSubmissionContext submissionContext, String clientToken) {
+    this.user = user;
+    this.handler = handler;
+    this.submissionContext = submissionContext;
+    master = new ApplicationMaster();
+    master.applicationId = submissionContext.applicationId;
+    master.status = new ApplicationStatus();
+    master.status.applicationId = submissionContext.applicationId;
+    master.status.progress = -1.0f;
+    stateMachine = stateMachineFactory.make(this);
+    master.state = ApplicationState.PENDING;
+    master.clientToken = clientToken;
+  }
+
+  @Override
+  public ApplicationSubmissionContext getSubmissionContext() {
+    return submissionContext;
+  }
+
+  @Override
+  public Resource getResource() {
+    return submissionContext.masterCapability;
+  }
+
+  @Override
+  public synchronized ApplicationID getApplicationID() {
+    return this.master.applicationId;
+  }
+
+  @Override
+  public synchronized ApplicationStatus getStatus() {
+    return master.status;
+  }
+
+  public synchronized void updateStatus(ApplicationStatus status) {
+    this.master.status = status;
+  }
+
+  @Override
+  public synchronized ApplicationMaster getMaster() {
+    return master;
+  }
+
+  /* make sure the master state is in sync with statemachine state */
+  public synchronized ApplicationState getState() {
+    return master.state;
+  }
+
+  @Override
+  public synchronized Container getMasterContainer() {
+    return masterContainer;
+  }
+
+
+  @Override
+  public String getUser() {
+    return this.user;
+  }
+
+  @Override
+  public synchronized long getLastSeen() {
+    return this.master.status.lastSeen;
+  }
+
+  @Override
+  public String getName() {
+    return submissionContext.applicationName.toString();
+  }
+
+  @Override
+  public String getQueue() {
+    return submissionContext.queue.toString();
+  }
+  
+  /* the applicaiton master completed successfully */
+  private static class DoneTransition implements 
+    SingleArcTransition<ApplicationMasterInfo, ASMEvent<ApplicationEventType>> {
+
+    @Override
+    public void transition(ApplicationMasterInfo masterInfo,
+    ASMEvent<ApplicationEventType> event) {
+      masterInfo.handler.handle(new ASMEvent<SNEventType>(
+        SNEventType.CLEANUP, masterInfo));
+      masterInfo.handler.handle(new ASMEvent<AMLauncherEventType>(
+        AMLauncherEventType.CLEANUP, masterInfo));
+      masterInfo.handler.handle(new ASMEvent<ApplicationTrackerEventType>(
+      ApplicationTrackerEventType.REMOVE, masterInfo));
+    }
+  }
+  
+  private static class KillTransition implements
+  SingleArcTransition<ApplicationMasterInfo, ASMEvent<ApplicationEventType>> {
+    @Override
+    public void transition(ApplicationMasterInfo masterInfo,
+    ASMEvent<ApplicationEventType> event) {
+      masterInfo.handler.handle(new ASMEvent<SNEventType>(SNEventType.CLEANUP, masterInfo));
+      masterInfo.handler.handle(new ASMEvent<AMLauncherEventType>(AMLauncherEventType.CLEANUP, masterInfo));
+    }
+  }
+
+  private static class LaunchTransition implements
+  SingleArcTransition<ApplicationMasterInfo, ASMEvent<ApplicationEventType>> {
+    @Override
+    public void transition(ApplicationMasterInfo masterInfo,
+    ASMEvent<ApplicationEventType> event) {
+      masterInfo.handler.handle(new ASMEvent<AMLauncherEventType>(
+      AMLauncherEventType.LAUNCH, masterInfo));
+    }
+  }
+
+  private static class LaunchedTransition implements
+  SingleArcTransition<ApplicationMasterInfo, ASMEvent<ApplicationEventType>> {
+    @Override
+    public void transition(ApplicationMasterInfo masterInfo,
+    ASMEvent<ApplicationEventType> event) {
+      /* make sure the time stamp is update else expiry thread will expire this */
+      masterInfo.master.status.lastSeen = System.currentTimeMillis();
+    }
+  }
+
+  private static class  ExpireTransition implements
+  SingleArcTransition<ApplicationMasterInfo, ASMEvent<ApplicationEventType>> {
+    @Override
+    public void transition(ApplicationMasterInfo masterInfo,
+    ASMEvent<ApplicationEventType> event) {
+      /* for now this is the same as killed transition but will change later */
+      masterInfo.handler.handle(new ASMEvent<SNEventType>(SNEventType.CLEANUP,
+        masterInfo));
+      masterInfo.handler.handle(new ASMEvent<AMLauncherEventType>(
+        AMLauncherEventType.CLEANUP, masterInfo));
+      masterInfo.handler.handle(new ASMEvent<ApplicationTrackerEventType>(
+      ApplicationTrackerEventType.REMOVE, masterInfo));
+    }
+  }
+
+
+  /* Transition to start the process of allocating for the AM container */
+  private static class AllocateTransition implements 
+  SingleArcTransition<ApplicationMasterInfo, ASMEvent<ApplicationEventType>> {
+    @Override
+    public void transition(ApplicationMasterInfo masterInfo,
+    ASMEvent<ApplicationEventType> event) {
+      /* notify tracking applications that an applicaiton has been added */
+      masterInfo.handler.handle(new ASMEvent<ApplicationTrackerEventType>(
+        ApplicationTrackerEventType.ADD, masterInfo));
+      
+      /* schedule for a slot */
+      masterInfo.handler.handle(new ASMEvent<SNEventType>(SNEventType.SCHEDULE,
+      masterInfo));
+    }
+  }
+  
+  /* Transition on a container allocated for a container */
+  private static class AllocatedTransition implements SingleArcTransition<ApplicationMasterInfo,
+  ASMEvent<ApplicationEventType>> {
+
+    @Override
+    public void transition(ApplicationMasterInfo masterInfo,
+    ASMEvent<ApplicationEventType> event) {
+      /* set the container that was generated by the scheduler negotiator */
+      masterInfo.masterContainer = event.getAppContext().getMasterContainer();
+    }    
+  }
+
+  private static class RegisterTransition implements  SingleArcTransition<ApplicationMasterInfo,
+  ASMEvent<ApplicationEventType>> {
+    @Override
+    public void transition(ApplicationMasterInfo masterInfo,
+    ASMEvent<ApplicationEventType> event) {
+      ApplicationMaster registeredMaster = event.getAppContext().getMaster();
+      masterInfo.master.host = registeredMaster.host;
+      masterInfo.master.httpPort = registeredMaster.httpPort;
+      masterInfo.master.rpcPort = registeredMaster.rpcPort;
+      masterInfo.master.status = registeredMaster.status;
+      masterInfo.master.status.progress = 0.0f;
+      masterInfo.master.status.lastSeen = System.currentTimeMillis();
+    }
+  }
+
+  /* transition to finishing state on a cleanup, for now its not used, but will need it 
+   * later */
+  private static class FinishTransition implements 
+  SingleArcTransition<ApplicationMasterInfo, ASMEvent<ApplicationEventType>> {
+
+    @Override
+    public void transition(ApplicationMasterInfo masterInfo,
+    ASMEvent<ApplicationEventType> event) {
+      masterInfo.handler.handle(new ASMEvent<SNEventType>(
+        SNEventType.CLEANUP, masterInfo));
+      masterInfo.handler.handle(new ASMEvent<AMLauncherEventType>(
+        AMLauncherEventType.CLEANUP, masterInfo));
+    } 
+  }
+
+
+  /* Just a status update transition */
+  private static class StatusUpdateTransition implements 
+  SingleArcTransition<ApplicationMasterInfo, ASMEvent<ApplicationEventType>> {
+
+    @Override
+    public void transition(ApplicationMasterInfo masterInfo,
+    ASMEvent<ApplicationEventType> event) {
+      masterInfo.master.status = event.getAppContext().getStatus();
+      masterInfo.master.status.lastSeen = System.currentTimeMillis();
+    }
+  }
+
+  @Override
+  public synchronized void handle(ASMEvent<ApplicationEventType> event) {
+    ApplicationID appID =  event.getAppContext().getApplicationID();
+    LOG.info("Processing event for " + appID +  " of type " + event.getType());
+    final ApplicationState oldState = getState();
+    try {
+      /* keep the master in sync with the state machine */
+      stateMachine.doTransition(event.getType(), event);
+      master.state = stateMachine.getCurrentState();
+      LOG.info("State is " +  stateMachine.getCurrentState());
+    } catch (InvalidStateTransitonException e) {
+      LOG.error("Can't handle this event at current state", e);
+      /* TODO fail the application on the failed transition */
+    }
+    if (oldState != getState()) {
+      LOG.info(appID + " State change from " 
+      + oldState + " to "
+      + getState());
+    }
+  }
+}
\ No newline at end of file

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationMasterLauncher.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationMasterLauncher.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationMasterLauncher.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationMasterLauncher.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,124 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager;
+import java.util.Queue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.yarn.event.EventHandler;
+import org.apache.hadoop.yarn.security.ApplicationTokenSecretManager;
+import org.apache.hadoop.yarn.security.client.ClientToAMSecretManager;
+import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.ASMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ASMEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationMasterEvents.AMLauncherEventType;
+import org.apache.hadoop.yarn.service.AbstractService;
+
+
+class ApplicationMasterLauncher extends AbstractService implements EventHandler<ASMEvent<AMLauncherEventType>> {
+  private static final Log LOG = LogFactory.getLog(
+      ApplicationMasterLauncher.class);
+  private final ThreadPoolExecutor launcherPool;
+  private final EventHandler handler;
+  private Thread launcherHandlingThread;
+  
+  private final Queue<Runnable> masterEvents
+    = new LinkedBlockingQueue<Runnable>();
+  
+  private ApplicationTokenSecretManager applicationTokenSecretManager;
+  private ClientToAMSecretManager clientToAMSecretManager;
+  private final ASMContext context;
+  
+  public ApplicationMasterLauncher(ApplicationTokenSecretManager 
+      applicationTokenSecretManager, ClientToAMSecretManager clientToAMSecretManager,
+      ASMContext context) {
+    super(ApplicationMasterLauncher.class.getName());
+    this.context = context;
+    this.handler = context.getDispatcher().getEventHandler();
+    /* register to dispatcher */
+    this.context.getDispatcher().register(AMLauncherEventType.class, this);
+    this.launcherPool = new ThreadPoolExecutor(1, 10, 1, 
+        TimeUnit.HOURS, new LinkedBlockingQueue<Runnable>());
+    this.launcherHandlingThread = new LauncherThread();
+    this.applicationTokenSecretManager = applicationTokenSecretManager;
+    this.clientToAMSecretManager = clientToAMSecretManager;
+  }
+  
+  public void start() {
+    launcherHandlingThread.start();
+    super.start();
+  }
+  
+  protected Runnable createRunnableLauncher(AppContext masterInfo, AMLauncherEventType event) {
+    Runnable launcher = new AMLauncher(context, masterInfo, event,
+        applicationTokenSecretManager, clientToAMSecretManager, getConfig());
+    return launcher;
+  }
+  
+  private void launch(AppContext appContext) {
+    Runnable launcher = createRunnableLauncher(appContext, AMLauncherEventType.LAUNCH);
+    masterEvents.add(launcher);
+  }
+  
+
+  public void stop() {
+    launcherHandlingThread.interrupt();
+    try {
+      launcherHandlingThread.join(1000);
+    } catch (InterruptedException ie) {
+      LOG.info(launcherHandlingThread.getName() + " interrupted during join ", 
+          ie);    }
+    launcherPool.shutdown();
+    super.stop();
+  }
+
+  private class LauncherThread extends Thread {
+    @Override
+    public void run() {
+      while (!this.isInterrupted()) {
+        Runnable toLaunch = masterEvents.poll();
+        if (toLaunch != null) {
+          launcherPool.execute(toLaunch);
+        }
+      }
+    }
+  }    
+
+  private void cleanup(AppContext appContext) {
+    Runnable launcher = createRunnableLauncher(appContext, AMLauncherEventType.CLEANUP);
+    masterEvents.add(launcher);
+  } 
+  
+  @Override
+  public synchronized void  handle(ASMEvent<AMLauncherEventType> appEvent) {
+    AMLauncherEventType event = appEvent.getType();
+    AppContext appContext = appEvent.getAppContext();
+    switch (event) {
+    case LAUNCH:
+      launch(appContext);
+      break;
+    case CLEANUP:
+      cleanup(appContext);
+    default:
+      break;
+    }
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationsManager.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationsManager.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationsManager.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationsManager.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,44 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.hadoop.classification.InterfaceAudience.Private;
+import org.apache.hadoop.classification.InterfaceStability.Evolving;
+import org.apache.hadoop.yarn.Application;
+import org.apache.hadoop.yarn.ApplicationID;
+import org.apache.hadoop.yarn.ApplicationMaster;
+import org.apache.hadoop.yarn.ApplicationSubmissionContext;
+
+/**
+ * This interface defines the interface for ApplicationsManager.
+ */
+@Private
+@Evolving
+public interface ApplicationsManager {
+   ApplicationID getNewApplicationID();
+   ApplicationMaster getApplicationMaster(ApplicationID applicationId);
+   Application getApplication(ApplicationID applicationID);
+   void submitApplication(ApplicationSubmissionContext context) throws IOException;
+   void finishApplication(ApplicationID applicationId) throws IOException;
+   List<AppContext> getAllApplications();
+   List<Application> getApplications();
+}
\ No newline at end of file

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationsManagerImpl.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationsManagerImpl.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationsManagerImpl.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/ApplicationsManagerImpl.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,274 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.token.Token;
+import org.apache.hadoop.yarn.Application;
+import org.apache.hadoop.yarn.ApplicationID;
+import org.apache.hadoop.yarn.ApplicationMaster;
+import org.apache.hadoop.yarn.ApplicationState;
+import org.apache.hadoop.yarn.ApplicationStatus;
+import org.apache.hadoop.yarn.ApplicationSubmissionContext;
+import org.apache.hadoop.yarn.event.Event;
+import org.apache.hadoop.yarn.event.EventHandler;
+import org.apache.hadoop.yarn.security.ApplicationTokenIdentifier;
+import org.apache.hadoop.yarn.security.ApplicationTokenSecretManager;
+import org.apache.hadoop.yarn.security.client.ClientToAMSecretManager;
+import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
+import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.ASMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ASMEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationMasterEvents.AMLauncherEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationMasterEvents.SNEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler;
+import org.apache.hadoop.yarn.service.CompositeService;
+import org.apache.hadoop.yarn.service.Service;
+
+
+/**
+ * This is the main class for the applications manager. This keeps track
+ * of the application masters running in the system and is responsible for 
+ * getting a container for AM and launching it.
+ * {@link ApplicationsManager} is the interface that clients use to talk to 
+ * ASM via the RPC servers. {@link ApplicationMasterHandler} is the interface that 
+ * AM's use to talk to the ASM via the RPC.
+ */
+public class ApplicationsManagerImpl extends CompositeService
+  implements ApplicationsManager, ApplicationMasterHandler  {
+  private static final Log LOG = LogFactory.getLog(ApplicationsManagerImpl.class);
+
+  final private AtomicInteger applicationCounter = new AtomicInteger(0);
+  final private YarnScheduler scheduler;
+  private AMTracker amTracker;
+  private ClientToAMSecretManager clientToAMSecretManager =
+    new ClientToAMSecretManager();
+  private final EventHandler eventHandler;
+  private final ApplicationTokenSecretManager applicationTokenSecretManager;
+  private final ASMContext asmContext; 
+  
+  public ApplicationsManagerImpl(ApplicationTokenSecretManager 
+      applicationTokenSecretManager, YarnScheduler scheduler, ASMContext asmContext) {
+    super("ApplicationsManager");
+    this.scheduler = scheduler;
+    this.asmContext = asmContext;
+    this.eventHandler = this.asmContext.getDispatcher().getEventHandler();
+    this.applicationTokenSecretManager = applicationTokenSecretManager;
+  }
+  
+
+  /**
+   * create a new am heart beat handler.
+   * @return create a new am heart beat handler.
+   */
+  protected AMTracker createNewAMTracker() {
+    return new AMTracker(this.asmContext);
+  }
+
+  /**
+   * Create a new scheduler negotiator.
+   * @param scheduler the scheduler 
+   * @return scheduler negotiator that talks to the scheduler.
+   */
+  protected EventHandler<ASMEvent<SNEventType>> createNewSchedulerNegotiator(YarnScheduler scheduler) {
+    return new SchedulerNegotiator(this.asmContext, scheduler);
+  }
+
+  /**
+   * create a new application master launcher.
+   * @param tokenSecretManager the token manager for applications.
+   * @return {@link ApplicationMasterLauncher} responsible for launching
+   * application masters.
+   */
+  protected EventHandler<ASMEvent<AMLauncherEventType>> createNewApplicationMasterLauncher(
+      ApplicationTokenSecretManager tokenSecretManager) {
+    return  new ApplicationMasterLauncher(tokenSecretManager,
+        this.clientToAMSecretManager, this.asmContext);
+  }
+
+  /**
+   * Add to service if a service object.
+   * @param object
+   */
+  protected void addIfService(Object object) {
+    if (object instanceof Service) {
+      addService((Service) object);
+    }
+  }
+
+  @Override
+  public synchronized void init(Configuration conf) {
+    addIfService(createNewApplicationMasterLauncher(applicationTokenSecretManager));
+    addIfService(createNewSchedulerNegotiator(scheduler));
+    this.amTracker = createNewAMTracker();
+    addIfService(amTracker);
+    super.init(conf);
+  }
+
+  @Override
+  public synchronized void start() {
+    super.start();
+  }
+
+  @Override
+  public synchronized ApplicationMaster getApplicationMaster(ApplicationID applicationId) {
+    ApplicationMaster appMaster =
+      amTracker.get(applicationId).getMaster();
+    return appMaster;
+  }
+  
+  @Override
+  public ApplicationID getNewApplicationID() {
+    ApplicationID applicationId =
+      org.apache.hadoop.yarn.server.resourcemanager.resource.ApplicationID.create(
+          ResourceManager.clusterTimeStamp, applicationCounter.incrementAndGet());
+    LOG.info("Allocated new applicationId: " + applicationId.id);
+    return applicationId;
+  }
+
+  @Override
+  public synchronized void submitApplication(ApplicationSubmissionContext context)
+  throws IOException {
+    String user;
+    ApplicationID applicationId = context.applicationId;
+    String clientTokenStr = null;
+    try {
+      user = UserGroupInformation.getCurrentUser().getShortUserName();
+      if (UserGroupInformation.isSecurityEnabled()) {
+        Token<ApplicationTokenIdentifier> clientToken =
+          new Token<ApplicationTokenIdentifier>(
+              new ApplicationTokenIdentifier(applicationId),
+              this.clientToAMSecretManager);
+        clientTokenStr = clientToken.encodeToUrlString();
+        LOG.debug("Sending client token as " + clientTokenStr);
+      }
+    } catch (IOException e) {
+      LOG.info("Error in submitting application", e);
+      throw e;
+    } 
+
+    context.queue =
+        (context.queue == null ? "default" : context.queue.toString());
+    context.applicationName =
+        (context.applicationName == null ? "N/A" : context.applicationName);
+
+    amTracker.addMaster(user, context, clientTokenStr);
+    // TODO this should happen via dispatcher. should move it out to scheudler
+    // negotiator.
+    scheduler.addApplication(applicationId, user, 
+        (context.queue == null? "default" : context.queue.toString()), 
+        context.priority);
+    /* schedule */    
+    LOG.info("Application with id " + applicationId.id + " submitted by user " + 
+        user + " with " + context);
+  }
+
+  @Override
+  public synchronized void finishApplicationMaster(ApplicationMaster applicationMaster)
+  throws IOException {
+    amTracker.finish(applicationMaster.applicationId);
+  }
+
+  @Override
+  public synchronized void finishApplication(ApplicationID applicationId) 
+  throws IOException {
+    /* remove the applicaiton from the scheduler  for now. Later scheduler should
+     * be a event handler of adding and cleaning up appications*/
+    scheduler.removeApplication(applicationId);
+    amTracker.kill(applicationId);
+  }
+
+  @Override
+  public synchronized void applicationHeartbeat(ApplicationStatus status) 
+  throws IOException {
+    amTracker.heartBeat(status);
+  }
+
+  @Override
+  public synchronized void registerApplicationMaster(ApplicationMaster applicationMaster)
+  throws IOException {
+    amTracker.registerMaster(applicationMaster);
+ }
+
+  @Override
+  public synchronized List<AppContext> getAllApplications() {
+    return amTracker.getAllApplications();
+  }
+
+  public synchronized ApplicationMasterInfo getApplicationMasterInfo(ApplicationID
+      applicationId) {
+    return amTracker.get(applicationId);
+  }
+  
+  static class AppImpl implements Application {
+    final ApplicationMaster am;
+    final String user;
+    final String queue;
+    final String name;
+    
+    AppImpl(ApplicationMaster am, String user, String queue, String name) { 
+      this.am = am; 
+      this.user = user;
+      this.queue = queue;
+      this.name = name;
+    }
+
+    @Override public ApplicationID id() { return am.applicationId; }
+    @Override public CharSequence user() { return user; }
+    @Override public CharSequence name() { return name; }
+    @Override public CharSequence queue() { return queue; }
+    @Override public ApplicationStatus status() { return am.status; }
+    @Override public CharSequence master() { return am.host; }
+    @Override public int httpPort() { return am.httpPort; }
+    @Override public ApplicationState state() { return am.state; }
+    @Override public boolean isFinished() {
+      switch (am.state) {
+        case COMPLETED:
+        case FAILED:
+        case KILLED: return true;
+      }
+      return false;
+    }
+  }
+
+  @Override
+  public List<Application> getApplications() {
+    List<Application> apps = new ArrayList<Application>();
+    for (AppContext am: getAllApplications()) {
+      apps.add(new AppImpl(am.getMaster(), 
+          am.getUser(), am.getQueue(), am.getName()));
+    }
+    return apps;
+  }
+
+  @Override
+  public Application getApplication(ApplicationID appID) {
+    ApplicationMasterInfo master = amTracker.get(appID);
+    return (master == null) ? null : 
+      new AppImpl(master.getMaster(), 
+          master.getUser(), master.getQueue(), master.getName());
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/SchedulerNegotiator.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/SchedulerNegotiator.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/SchedulerNegotiator.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/SchedulerNegotiator.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,286 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.yarn.ApplicationID;
+import org.apache.hadoop.yarn.ApplicationMaster;
+import org.apache.hadoop.yarn.ApplicationStatus;
+import org.apache.hadoop.yarn.ApplicationSubmissionContext;
+import org.apache.hadoop.yarn.Container;
+import org.apache.hadoop.yarn.Priority;
+import org.apache.hadoop.yarn.Resource;
+import org.apache.hadoop.yarn.ResourceRequest;
+import org.apache.hadoop.yarn.event.EventHandler;
+import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.ASMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ASMEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationMasterEvents.ApplicationEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationMasterEvents.SNEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler;
+import org.apache.hadoop.yarn.service.AbstractService;
+
+/**
+ * Negotiates with the scheduler for allocation of application master container.
+ *
+ */
+class SchedulerNegotiator extends AbstractService implements EventHandler<ASMEvent<SNEventType>> {
+
+  private static final Log LOG = LogFactory.getLog(SchedulerNegotiator.class);
+
+  final static Priority AM_CONTAINER_PRIORITY = new Priority();
+  static {
+    AM_CONTAINER_PRIORITY.priority = 0;
+  }
+  static final List<ResourceRequest> EMPTY_ASK =
+    new ArrayList<ResourceRequest>();
+  static final List<Container> EMPTY_RELEASE = 
+    new ArrayList<Container>();
+
+  private final EventHandler handler;
+
+  private final SchedulerThread schedulerThread;
+  private final YarnScheduler scheduler;
+  private final List<AppContext> pendingApplications = 
+    new ArrayList<AppContext>();
+
+  @SuppressWarnings("unchecked")
+  public SchedulerNegotiator(ASMContext context, 
+      YarnScheduler scheduler) {
+    super("SchedulerNegotiator");
+    this.handler = context.getDispatcher().getEventHandler();
+    context.getDispatcher().register(SNEventType.class, this);
+    this.scheduler = scheduler;
+    this.schedulerThread = new SchedulerThread();
+  }
+
+  @Override
+  public synchronized void start() {
+    super.start();
+    schedulerThread.start();
+  }
+
+
+  @Override
+  public synchronized void stop() {
+    schedulerThread.shutdown();
+    try {
+      schedulerThread.join(1000);
+    } catch (InterruptedException ie) {
+      LOG.info(schedulerThread.getName() + " interrupted during join ", ie);
+    }
+
+    super.stop();
+  }
+
+  private class SchedulerThread extends Thread {
+    private volatile boolean shutdown = false;
+
+    public SchedulerThread() {
+      setName("ApplicationsManager:SchedulerThread");
+      setDaemon(true);
+    }
+    
+      @Override
+    public void run() {
+      List<AppContext> toSubmit = 
+        new ArrayList<AppContext>();
+      List<AppContext> submittedApplications =
+        new ArrayList<AppContext>();
+      while (!shutdown && !isInterrupted()) {
+        try {
+          toSubmit.addAll(getPendingApplications());
+          if (toSubmit.size() > 0) {
+            LOG.info("Got " + toSubmit.size() + " applications to submit");
+
+            submittedApplications.addAll(toSubmit);
+
+            for (AppContext masterInfo: toSubmit) {
+              // Register request for the ApplicationMaster container
+              ResourceRequest request = 
+                org.apache.hadoop.yarn.server.resourcemanager.resource.ResourceRequest.create(
+                    AM_CONTAINER_PRIORITY, "*", masterInfo.getResource(), 1);
+              // it ok to ignore the containers since we wont get any containers 
+              // in the first call to allocate
+              LOG.debug("About to request resources for AM of " + 
+                  masterInfo.getMaster() + " required " + request);
+              scheduler.allocate(masterInfo.getMaster().applicationId, 
+                  Collections.singletonList(request), 
+                  EMPTY_RELEASE);
+            }
+            toSubmit.clear();
+          }
+
+          List<Container> containers = null;
+
+          for (Iterator<AppContext> it=submittedApplications.iterator(); 
+          it.hasNext();) {
+            AppContext masterInfo = it.next();
+            ApplicationID appId = masterInfo.getMaster().applicationId;
+            containers = scheduler.allocate(appId, 
+                EMPTY_ASK, EMPTY_RELEASE);
+            if (!containers.isEmpty()) {
+              // there should be only one container for an application
+              assert(containers.size() == 1);
+              it.remove();
+              Container container = containers.get(0);
+              
+              LOG.info("Found container " + container + " for AM of " + 
+                  masterInfo.getMaster());
+              SNAppContext snAppContext = new SNAppContext(masterInfo.getApplicationID(),
+                container);
+              handler.handle(new ASMEvent<ApplicationEventType>(
+                ApplicationEventType.ALLOCATED, snAppContext));
+            }
+          }
+
+          Thread.sleep(1000);
+        } catch(Exception e) {
+          LOG.info("Exception in submitting applications ", e);
+        }
+      }
+    }
+    
+    /**
+     * shutdown the thread.
+     */
+    public void shutdown() {
+      shutdown = true;
+      interrupt();
+    }
+  }
+
+  private Collection<? extends AppContext> getPendingApplications() {
+    List<AppContext> pending = new ArrayList<AppContext>();
+    synchronized (pendingApplications) {
+      pending.addAll(pendingApplications);
+      pendingApplications.clear();
+    }
+    return pending;
+  }
+
+  private void addPending(AppContext masterInfo) {
+    LOG.info("Adding to pending " + masterInfo.getMaster());
+    synchronized(pendingApplications) {
+      pendingApplications.add(masterInfo);
+    }
+  }
+
+  @Override
+  public void handle(ASMEvent<SNEventType> appEvent)  {
+    SNEventType event = appEvent.getType();
+    AppContext appContext = appEvent.getAppContext();
+    switch (event) {
+    case SCHEDULE:
+      addPending(appContext);
+      break;
+    case CLEANUP:
+      try {
+        finishApplication(appContext);
+      } catch (IOException ie) {
+        LOG.info("Error finishing application", ie);
+      }
+      break;
+    default:
+      break;
+    }
+  }
+  
+  private void finishApplication(AppContext masterInfo)  
+  throws IOException {
+    LOG.info("Finishing application: cleaning up container " +
+        masterInfo.getMasterContainer());
+    //TODO we should release the container but looks like we just 
+    // wait for update from NodeManager
+    Container[] containers = new Container[] {masterInfo.getMasterContainer()};
+    scheduler.allocate(masterInfo.getMaster().applicationId, 
+        EMPTY_ASK, Arrays.asList(containers));
+  }
+  
+  private static class SNAppContext implements AppContext {
+    private final ApplicationID appID;
+    private final Container container;
+    private final UnsupportedOperationException notImplementedException;
+    
+    public SNAppContext(ApplicationID appID, Container container) {
+      this.appID = appID;
+      this.container = container;
+      this.notImplementedException = new UnsupportedOperationException("Not Implemented");
+    }
+    
+    @Override
+    public ApplicationSubmissionContext getSubmissionContext() {
+      throw notImplementedException;
+    }
+
+    @Override
+    public Resource getResource() {
+     throw notImplementedException;
+    }
+
+    @Override
+    public ApplicationID getApplicationID() {
+      return appID;
+    }
+
+    @Override
+    public ApplicationStatus getStatus() {
+      throw notImplementedException;
+    }
+   
+    @Override
+    public ApplicationMaster getMaster() {
+      throw notImplementedException;
+    }
+
+    @Override
+    public Container getMasterContainer() {
+      return container;
+    }
+
+    @Override
+    public String getUser() {
+      throw notImplementedException;
+    }
+
+    @Override
+    public long getLastSeen() {
+      throw notImplementedException;
+    }
+
+    @Override
+    public String getName() {
+      throw notImplementedException;
+    }
+
+    @Override
+    public String getQueue() {
+      throw notImplementedException;
+    }
+  }
+}
\ No newline at end of file

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/SyncDispatcher.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/SyncDispatcher.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/SyncDispatcher.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/SyncDispatcher.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,132 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.event.Dispatcher;
+import org.apache.hadoop.yarn.event.Event;
+import org.apache.hadoop.yarn.event.EventHandler;
+import org.apache.hadoop.yarn.service.AbstractService;
+
+
+public class SyncDispatcher extends AbstractService implements Dispatcher {
+  private Configuration conf;
+  private static final Log LOG = LogFactory.getLog(SyncDispatcher.class);
+  @SuppressWarnings("rawtypes")
+  private Map<Class<? extends Enum>, EventHandler> eventDispatchers = 
+    new HashMap<Class<? extends Enum>, EventHandler>();
+
+  
+  public SyncDispatcher() {
+    super("SyncDispatcher");
+  }
+  
+  @Override
+  public void init(Configuration conf) {
+    this.conf = conf;
+  }
+
+  @SuppressWarnings("rawtypes")
+  @Override
+  public void register(Class<? extends Enum> eventType,
+      EventHandler handler) {
+    /* check to see if we have a listener registered */
+      @SuppressWarnings("unchecked")
+      EventHandler<Event> registeredHandler = (EventHandler<Event>)
+      eventDispatchers.get(eventType);
+      LOG.info("Registering " + eventType + " for " + handler.getClass());
+      if (registeredHandler == null) {
+        eventDispatchers.put(eventType, handler);
+      } else if (!(registeredHandler instanceof MultiListenerHandler)){
+        /* for multiple listeners of an event add the multiple listener handler */
+        MultiListenerHandler multiHandler = new MultiListenerHandler();
+        multiHandler.addHandler(registeredHandler);
+        multiHandler.addHandler(handler);
+        eventDispatchers.put(eventType, multiHandler);
+      } else {
+        /* already a multilistener, just add to it */
+        MultiListenerHandler multiHandler
+        = (MultiListenerHandler) registeredHandler;
+        multiHandler.addHandler(handler);
+      }
+  }
+  
+  @SuppressWarnings({ "rawtypes", "unchecked" })
+  @Override
+  public EventHandler<Event> getEventHandler() {
+    return new GenericEventHandler();
+  }
+  
+  class GenericEventHandler implements EventHandler {
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void handle(Event event) {
+      if (!LOG.isDebugEnabled()) {
+        LOG.info("Dispatching event " + event);
+      }
+      Class<? extends Enum> type = event.getType().getDeclaringClass();
+      
+      try{
+        EventHandler<Event> handler = 
+          eventDispatchers.get(type);
+        if (handler == null)  
+            throw new IllegalArgumentException("Invalid event " + event
+                + " no registered handler.");
+        handler.handle(event);
+      }
+      catch (Throwable t) {
+        LOG.fatal("Error in dispatcher", t);
+        //TODO fix the shutdown
+      }
+    }
+  }
+
+  /**
+   * Multiplexing an event. Sending it to different handlers that
+   * are interested in the event.
+   * @param <T> the type of event these multiple handlers are interested in.
+   */
+  @SuppressWarnings("rawtypes")
+  static class MultiListenerHandler implements EventHandler<Event> {
+    List<EventHandler<Event>> listofHandlers;
+    
+    public MultiListenerHandler() {
+      listofHandlers = new ArrayList<EventHandler<Event>>();
+    }
+    
+    @Override
+    public void handle(Event event) {
+      for (EventHandler<Event> handler: listofHandlers) {
+        handler.handle(event);
+      }
+    }
+    
+    void addHandler(EventHandler<Event> handler) {
+      listofHandlers.add(handler);
+    }
+  }
+}
\ No newline at end of file

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/events/ASMEvent.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/events/ASMEvent.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/events/ASMEvent.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/events/ASMEvent.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,39 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events;
+
+import org.apache.hadoop.yarn.event.AbstractEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.AppContext;
+
+public class ASMEvent<T extends Enum<T>> extends AbstractEvent<T> {
+  private final AppContext context;
+  
+  public ASMEvent(T type, AppContext context) {
+    super(type);
+    this.context = context;
+  }
+  
+  /** 
+   * return the application context.
+   * @return the application context for this event.
+   */
+  public AppContext getAppContext() {
+    return this.context;
+  }
+}
\ No newline at end of file

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/events/ApplicationMasterEvents.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/events/ApplicationMasterEvents.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/events/ApplicationMasterEvents.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/events/ApplicationMasterEvents.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,61 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events;
+
+import org.apache.hadoop.classification.InterfaceAudience.Private;
+import org.apache.hadoop.classification.InterfaceStability.Evolving;
+
+/**
+ * The events for application master that are generated within the applications
+ * manager.
+ */
+@Private
+@Evolving
+public class ApplicationMasterEvents {
+  public enum SNEventType {
+    SCHEDULE,
+    CLEANUP
+  };
+
+  public enum AMLauncherEventType {
+    LAUNCH,
+    CLEANUP
+  };
+
+  /* event generated for components tracking application adding/tracking/removal */
+  public enum ApplicationTrackerEventType {
+    ADD,
+    REMOVE
+  }
+  
+  public enum ApplicationEventType {
+    ALLOCATE,
+    REGISTERED,
+    REMOVE,
+    STATUSUPDATE,
+    LAUNCH,
+    LAUNCHED,
+    FAILED,
+    ALLOCATED,
+    CLEANUP,
+    FINISH, 
+    EXPIRE,
+    KILL
+  };
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ApplicationID.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ApplicationID.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ApplicationID.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ApplicationID.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,51 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.resource;
+
+public class ApplicationID {
+  
+  public static org.apache.hadoop.yarn.ApplicationID create(long clusterTimeStamp,
+      int id) {
+    org.apache.hadoop.yarn.ApplicationID applicationId =
+        new org.apache.hadoop.yarn.ApplicationID();
+    applicationId.id = id;
+    applicationId.clusterTimeStamp = clusterTimeStamp;
+    return applicationId;
+  }
+  
+  public static org.apache.hadoop.yarn.ApplicationID convert(long clustertimestamp,
+      CharSequence id) {
+    org.apache.hadoop.yarn.ApplicationID applicationId =
+        new org.apache.hadoop.yarn.ApplicationID();
+    applicationId.id = Integer.valueOf(id.toString());
+    applicationId.clusterTimeStamp = clustertimestamp;
+    return applicationId;
+  }
+  
+  public static class Comparator 
+  implements java.util.Comparator<org.apache.hadoop.yarn.ApplicationID> {
+
+    @Override
+    public int compare(org.apache.hadoop.yarn.ApplicationID a1,
+        org.apache.hadoop.yarn.ApplicationID a2) {
+      return a1.compareTo(a2);
+    }
+    
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Container.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Container.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Container.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Container.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,74 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.resource;
+
+import org.apache.hadoop.yarn.ApplicationID;
+import org.apache.hadoop.yarn.ContainerID;
+import org.apache.hadoop.yarn.ContainerState;
+import org.apache.hadoop.yarn.Resource;
+
+public class Container {
+  
+
+  private static ContainerID getNewContainerId(ApplicationID applicationId, 
+      int containerId) {
+    ContainerID id = new ContainerID();
+    id.appID = applicationId;
+    id.id = containerId;
+    return id;
+  }
+  
+  public static org.apache.hadoop.yarn.Container create(
+      org.apache.hadoop.yarn.Container c) {
+    org.apache.hadoop.yarn.Container container = new org.apache.hadoop.yarn.Container();
+    container.id = c.id;
+    container.hostName = c.hostName;
+    container.resource = c.resource;
+    container.state = c.state;
+    return container;
+  }
+
+  public static org.apache.hadoop.yarn.Container create(
+      ApplicationID applicationId, int containerId, 
+      String hostName, Resource resource) {
+    ContainerID containerID = getNewContainerId(applicationId, containerId);
+    return create(containerID, hostName, resource);
+  }
+
+  public static org.apache.hadoop.yarn.Container create(
+      ContainerID containerId,
+      String hostName, Resource resource) {
+    org.apache.hadoop.yarn.Container container = new org.apache.hadoop.yarn.Container();
+    container.id = containerId;
+    container.hostName = hostName;
+    container.resource = resource;
+    container.state = ContainerState.INTIALIZING;
+    return container;
+  }
+  
+  public static class Comparator 
+  implements java.util.Comparator<org.apache.hadoop.yarn.Container> {
+
+    @Override
+    public int compare(org.apache.hadoop.yarn.Container c1,
+        org.apache.hadoop.yarn.Container c2) {
+      return c1.id.compareTo(c2.id);
+    }
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Priority.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Priority.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Priority.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Priority.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,37 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.resource;
+
+public class Priority {
+  
+  public static org.apache.hadoop.yarn.Priority create(int prio) {
+    org.apache.hadoop.yarn.Priority priority = new org.apache.hadoop.yarn.Priority();
+    priority.priority = prio;
+    return priority;
+  }
+  
+  public static class Comparator 
+  implements java.util.Comparator<org.apache.hadoop.yarn.Priority> {
+    @Override
+    public int compare(org.apache.hadoop.yarn.Priority o1, org.apache.hadoop.yarn.Priority o2) {
+      return o1.priority - o2.priority;
+    }
+  }
+  
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Resource.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Resource.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Resource.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/Resource.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,70 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.resource;
+
+import org.apache.hadoop.classification.InterfaceAudience.Private;
+import org.apache.hadoop.classification.InterfaceStability.Evolving;
+
+@Private
+@Evolving
+public class Resource {
+  
+  public static final org.apache.hadoop.yarn.Resource NONE = createResource(0);
+
+  public static org.apache.hadoop.yarn.Resource createResource(int memory) {
+    org.apache.hadoop.yarn.Resource resource = new org.apache.hadoop.yarn.Resource();
+    resource.memory = memory;
+    return resource;
+  }
+  
+  public static void addResource(org.apache.hadoop.yarn.Resource lhs, 
+      org.apache.hadoop.yarn.Resource rhs) {
+    lhs.memory += rhs.memory;
+  }
+  
+  public static void subtractResource(org.apache.hadoop.yarn.Resource lhs, 
+      org.apache.hadoop.yarn.Resource rhs) {
+    lhs.memory -= rhs.memory;
+  }
+  
+  public static boolean equals(org.apache.hadoop.yarn.Resource lhs,
+      org.apache.hadoop.yarn.Resource rhs) {
+    return lhs.memory == rhs.memory;
+  }
+
+  public static boolean lessThan(org.apache.hadoop.yarn.Resource lhs,
+      org.apache.hadoop.yarn.Resource rhs) {
+    return lhs.memory < rhs.memory;
+  }
+
+  public static boolean lessThanOrEqual(org.apache.hadoop.yarn.Resource lhs,
+      org.apache.hadoop.yarn.Resource rhs) {
+    return lhs.memory <= rhs.memory;
+  }
+
+  public static boolean greaterThan(org.apache.hadoop.yarn.Resource lhs,
+      org.apache.hadoop.yarn.Resource rhs) {
+    return lhs.memory > rhs.memory;
+  }
+
+  public static boolean greaterThanOrEqual(org.apache.hadoop.yarn.Resource lhs,
+      org.apache.hadoop.yarn.Resource rhs) {
+    return lhs.memory >= rhs.memory;
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ResourceRequest.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ResourceRequest.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ResourceRequest.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resource/ResourceRequest.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,67 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.resource;
+
+import org.apache.hadoop.yarn.Priority;
+
+public class ResourceRequest {
+  
+  public static org.apache.hadoop.yarn.ResourceRequest create(
+      Priority priority, CharSequence hostName, 
+      org.apache.hadoop.yarn.Resource capability, int numContainers) {
+    org.apache.hadoop.yarn.ResourceRequest request = 
+      new org.apache.hadoop.yarn.ResourceRequest();
+    request.priority = priority;
+    request.hostName = hostName;
+    request.capability = capability;
+    request.numContainers = numContainers;
+    return request;
+  }
+  
+  public static org.apache.hadoop.yarn.ResourceRequest create(
+      org.apache.hadoop.yarn.ResourceRequest r) {
+    org.apache.hadoop.yarn.ResourceRequest request = 
+      new org.apache.hadoop.yarn.ResourceRequest();
+    request.priority = r.priority;
+    request.hostName = r.hostName;
+    request.capability = r.capability;
+    request.numContainers = r.numContainers;
+    return request;
+  }
+  
+  public static class Comparator 
+  implements java.util.Comparator<org.apache.hadoop.yarn.ResourceRequest> {
+    @Override
+    public int compare(org.apache.hadoop.yarn.ResourceRequest r1,
+        org.apache.hadoop.yarn.ResourceRequest r2) {
+      
+      // Compare priority, host and capability
+      int ret = r1.priority.compareTo(r2.priority);
+      if (ret == 0) {
+        String h1 = r1.hostName.toString();
+        String h2 = r2.hostName.toString();
+        ret = h1.compareTo(h2);
+      }
+      if (ret == 0) {
+        ret = r1.capability.compareTo(r2.capability);
+      }
+      return ret;
+    }
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeInfo.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeInfo.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeInfo.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeInfo.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,70 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.resourcetracker;
+
+import org.apache.hadoop.net.Node;
+import org.apache.hadoop.yarn.NodeID;
+
+/**
+ * Node managers information on available resources 
+ * and other static information.
+ *
+ */
+public interface NodeInfo {
+  /**
+   * the node id of of this node.
+   * @return the node id of this node.
+   */
+  public NodeID getNodeID();
+  /**
+   * the hostname for this node.
+   * @return the hostname for this node.
+   */
+  public String getHostName();
+  /**
+   * the total available resource.
+   * @return the total available resource.
+   */
+  public org.apache.hadoop.yarn.Resource getTotalCapability();
+  /**
+   * The rack name for this node manager.
+   * @return the rack name.
+   */
+  public String getRackName();
+  /**
+   * the {@link Node} information for this node.
+   * @return {@link Node} information for this node.
+   */
+  public Node getNode();
+  /**
+   * the available resource for this node.
+   * @return the available resource this node.
+   */
+  public org.apache.hadoop.yarn.Resource getAvailableResource();
+  /**
+   * used resource on this node.
+   * @return the used resource on this node.
+   */
+  public org.apache.hadoop.yarn.Resource getUsedResource();
+  /**
+   * The current number of containers for this node
+   * @return the number of containers
+   */
+  public int getNumContainers();
+ }
\ No newline at end of file

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeInfoTracker.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeInfoTracker.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeInfoTracker.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeInfoTracker.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,60 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.resourcetracker;
+
+import org.apache.hadoop.yarn.HeartbeatResponse;
+import org.apache.hadoop.yarn.NodeStatus;
+
+/**
+ * Track the node info and heart beat responses for this node.
+ * This should be package private. It does not need to be public.
+ *
+ */
+class NodeInfoTracker {
+  private final NodeInfo node;
+  HeartbeatResponse lastHeartBeatResponse;
+  private NodeStatus nodeStatus = new NodeStatus();
+
+  public NodeInfoTracker(NodeInfo node, HeartbeatResponse lastHeartBeatResponse) {
+    this.node = node;
+    this.lastHeartBeatResponse = lastHeartBeatResponse;
+    this.nodeStatus.nodeId = node.getNodeID();
+    this.nodeStatus.lastSeen = System.currentTimeMillis();
+  }
+
+  public synchronized NodeInfo getNodeInfo() {
+    return this.node;
+  }
+
+  public synchronized HeartbeatResponse getLastHeartBeatResponse() {
+    return this.lastHeartBeatResponse;
+  }
+
+  public synchronized void refreshHeartBeatResponse(HeartbeatResponse heartBeatResponse) {
+    this.lastHeartBeatResponse = heartBeatResponse;
+  }
+
+  public synchronized void updateNodeStatus(NodeStatus nodeStatus) {
+    this.nodeStatus = nodeStatus;
+  }
+
+  public synchronized NodeStatus getNodeStatus() {
+    return this.nodeStatus;
+  }
+}
\ No newline at end of file

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeStatus.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeStatus.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeStatus.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/NodeStatus.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,36 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.resourcetracker;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.yarn.Container;
+import org.apache.hadoop.yarn.NodeID;
+
+
+public class NodeStatus {
+  public static org.apache.hadoop.yarn.NodeStatus createNodeStatus(
+      NodeID nodeId, Map<CharSequence, List<Container>> containers) {
+    org.apache.hadoop.yarn.NodeStatus nodeStatus = new org.apache.hadoop.yarn.NodeStatus();
+    nodeStatus.nodeId = nodeId;
+    nodeStatus.containers = containers;
+    return nodeStatus;
+  }
+}

Added: hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/RMResourceTracker.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/RMResourceTracker.java?rev=1082677&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/RMResourceTracker.java (added)
+++ hadoop/mapreduce/branches/MR-279/yarn/yarn-server/yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/resourcetracker/RMResourceTracker.java Thu Mar 17 20:21:13 2011
@@ -0,0 +1,32 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.hadoop.yarn.server.resourcemanager.resourcetracker;
+
+import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceListener;
+import org.apache.hadoop.yarn.YarnClusterMetrics;
+
+/**
+ * The listener and read only interface to the
+ * rm resource tracker.
+ */
+public interface RMResourceTracker {
+  void register(ResourceListener listener);
+  void unregister(ResourceListener listener);
+  YarnClusterMetrics getClusterMetrics();
+}
\ No newline at end of file



Mime
View raw message