hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vino...@apache.org
Subject svn commit: r1143250 [4/4] - in /hadoop/common/branches/MR-279/mapreduce: ./ mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/launcher/ mr-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapre...
Date Wed, 06 Jul 2011 04:51:48 GMT
Modified: hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRMRPCResponseId.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRMRPCResponseId.java?rev=1143250&r1=1143249&r2=1143250&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRMRPCResponseId.java (original)
+++ hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRMRPCResponseId.java Wed Jul  6 04:51:46 2011
@@ -27,6 +27,7 @@ import junit.framework.Assert;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest;
 import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest;
+import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest;
 import org.apache.hadoop.yarn.api.records.AMResponse;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.api.records.ApplicationMaster;
@@ -42,8 +43,10 @@ import org.apache.hadoop.yarn.factories.
 import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
 import org.apache.hadoop.yarn.security.ApplicationTokenSecretManager;
 import org.apache.hadoop.yarn.server.resourcemanager.ApplicationMasterService;
+import org.apache.hadoop.yarn.server.resourcemanager.ClientRMService;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.RMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationEventType;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.ApplicationsStore.ApplicationStore;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemStore;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation;
@@ -57,6 +60,7 @@ public class TestAMRMRPCResponseId {
   ApplicationMasterService amService = null;
   ApplicationTokenSecretManager appTokenManager = new ApplicationTokenSecretManager();
   DummyApplicationsManager applicationsManager;
+  private ClientRMService clientService;
   DummyScheduler scheduler;
   private final static Container[] EMPTY_CONTAINER_ARRAY = new Container[] {};
   private final static List<Container> EMPTY_CONTAINER_LIST = Arrays.asList(EMPTY_CONTAINER_ARRAY);
@@ -68,18 +72,6 @@ public class TestAMRMRPCResponseId {
         YarnScheduler scheduler, RMContext asmContext) {
       super(applicationTokenSecretManager, scheduler, asmContext);      
     }
-    @Override
-    public void registerApplicationMaster(ApplicationMaster applicationMaster)
-    throws IOException {
-    }
-    @Override
-    public void applicationHeartbeat(ApplicationStatus status)
-    throws IOException {      
-    }
-    @Override
-    public void finishApplicationMaster(ApplicationMaster applicationMaster)
-    throws IOException {  
-    }
   }
   
   
@@ -130,12 +122,20 @@ public class TestAMRMRPCResponseId {
   @Before
   public void setUp() {
     context = new ResourceManager.RMContextImpl(new MemStore());
+
+    context.getDispatcher().register(ApplicationEventType.class,
+        new ResourceManager.ApplicationEventDispatcher(context));
+
     scheduler = new DummyScheduler();
     applicationsManager = new DummyApplicationsManager(new 
         ApplicationTokenSecretManager(), scheduler, context);
-    amService = new ApplicationMasterService(
-        appTokenManager, applicationsManager, scheduler, context);
     Configuration conf = new Configuration();
+    this.clientService = new ClientRMService(context, applicationsManager
+        .getAmLivelinessMonitor(), applicationsManager
+        .getClientToAMSecretManager(), null, scheduler);
+    this.clientService.init(conf);
+    amService = new ApplicationMasterService(appTokenManager, scheduler,
+        context);
     applicationsManager.init(conf);
     amService.init(conf);
     context.getDispatcher().init(conf);
@@ -149,10 +149,13 @@ public class TestAMRMRPCResponseId {
 
   @Test
   public void testARRMResponseId() throws Exception {
-    ApplicationId applicationID = applicationsManager.getNewApplicationID();
+    ApplicationId applicationID = clientService.getNewApplicationId();
     ApplicationSubmissionContext context = recordFactory.newRecordInstance(ApplicationSubmissionContext.class);
     context.setApplicationId(applicationID);
-    applicationsManager.submitApplication(context);
+    SubmitApplicationRequest submitRequest = recordFactory
+        .newRecordInstance(SubmitApplicationRequest.class);
+    submitRequest.setApplicationSubmissionContext(context);
+    clientService.submitApplication(submitRequest);
     ApplicationMaster applicationMaster = recordFactory.newRecordInstance(ApplicationMaster.class);
     applicationMaster.setApplicationId(applicationID);
     applicationMaster.setStatus(recordFactory.newRecordInstance(ApplicationStatus.class));

Modified: hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRestart.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRestart.java?rev=1143250&r1=1143249&r2=1143250&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRestart.java (original)
+++ hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestAMRestart.java Wed Jul  6 04:51:46 2011
@@ -12,6 +12,7 @@ import junit.framework.Assert;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.api.records.ApplicationMaster;
 import org.apache.hadoop.yarn.api.records.ApplicationState;
@@ -29,13 +30,15 @@ import org.apache.hadoop.yarn.event.Even
 import org.apache.hadoop.yarn.factories.RecordFactory;
 import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
 import org.apache.hadoop.yarn.security.ApplicationTokenSecretManager;
+import org.apache.hadoop.yarn.server.resourcemanager.ClientRMService;
 import org.apache.hadoop.yarn.server.resourcemanager.RMConfig;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.RMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMLauncherEventType;
 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.ApplicationEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationTrackerEventType;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.ApplicationsStore.ApplicationStore;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemStore;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.Store.RMState;
@@ -61,6 +64,7 @@ public class TestAMRestart {
   ApplicationTokenSecretManager appTokenSecretManager = 
     new ApplicationTokenSecretManager();
   DummyResourceScheduler scheduler;
+  private ClientRMService clientRMService;
   int count = 0;
   ApplicationId appID;
   final int maxFailures = 3;
@@ -71,7 +75,6 @@ public class TestAMRestart {
   int schedulerRemoveApplication = 0;
   int launcherLaunchCalled = 0;
   int launcherCleanupCalled = 0;
-  ApplicationMasterInfo masterInfo;
   private final static RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null);
   
   private class ExtApplicationsManagerImpl extends ApplicationsManagerImpl {
@@ -104,7 +107,7 @@ public class TestAMRestart {
                 }
               }
               asmContext.getDispatcher().getEventHandler().handle(
-                  new ApplicationMasterInfoEvent(
+                  new ApplicationEvent(
                       ApplicationEventType.LAUNCHED, appID));
               launchNotify.addAndGet(-1);
             }
@@ -226,6 +229,10 @@ public class TestAMRestart {
 
   @Before
   public void setUp() {
+
+    asmContext.getDispatcher().register(ApplicationEventType.class,
+        new ResourceManager.ApplicationEventDispatcher(asmContext));
+
     appID = recordFactory.newRecordInstance(ApplicationId.class);
     appID.setClusterTimestamp(System.currentTimeMillis());
     appID.setId(1);
@@ -240,20 +247,25 @@ public class TestAMRestart {
     conf.setInt(RMConfig.AM_MAX_RETRIES, maxFailures);
     appImpl.init(conf);
     appImpl.start();
+
+    this.clientRMService = new ClientRMService(asmContext, appImpl
+        .getAmLivelinessMonitor(), appImpl.getClientToAMSecretManager(),
+        null, scheduler); 
+    this.clientRMService.init(conf);
   }
 
   @After
   public void tearDown() {
   }
 
-  private void waitForFailed(ApplicationMasterInfo masterInfo, ApplicationState 
+  private void waitForFailed(Application application, ApplicationState 
       finalState) throws Exception {
     int count = 0;
-    while(masterInfo.getState() != finalState && count < 10) {
+    while(application.getState() != finalState && count < 10) {
       Thread.sleep(500);
       count++;
     }
-    Assert.assertEquals(finalState, masterInfo.getState());
+    Assert.assertEquals(finalState, application.getState());
   }
 
   @Test
@@ -265,8 +277,11 @@ public class TestAMRestart {
 //    subContext.environment = new HashMap<String, String>();
 //    subContext.fsTokens = new ArrayList<String>();
     subContext.setFsTokensTodo(ByteBuffer.wrap(new byte[0]));
-    appImpl.submitApplication(subContext);
-    masterInfo = appImpl.getApplicationMasterInfo(appID);
+    SubmitApplicationRequest request = recordFactory
+        .newRecordInstance(SubmitApplicationRequest.class);
+    request.setApplicationSubmissionContext(subContext);
+    clientRMService.submitApplication(request);
+    Application application = asmContext.getApplications().get(appID); 
     synchronized (schedulerNotify) {
       while(schedulerNotify.get() == 0) {
         schedulerNotify.wait();
@@ -276,8 +291,8 @@ public class TestAMRestart {
     Assert.assertEquals(maxFailures, launcherLaunchCalled);
     Assert.assertEquals(maxFailures, schedulerAddApplication);
     Assert.assertEquals(maxFailures, schedulerRemoveApplication);
-    Assert.assertEquals(maxFailures, masterInfo.getFailedCount());
-    waitForFailed(masterInfo, ApplicationState.FAILED);
+    Assert.assertEquals(maxFailures, application.getFailedCount());
+    waitForFailed(application, ApplicationState.FAILED);
     stop = true;
   }
 }
\ No newline at end of file

Modified: hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestASMStateMachine.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestASMStateMachine.java?rev=1143250&r1=1143249&r2=1143250&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestASMStateMachine.java (original)
+++ hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestASMStateMachine.java Wed Jul  6 04:51:46 2011
@@ -34,11 +34,16 @@ import org.apache.hadoop.yarn.factories.
 import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.RMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMLauncherEventType;
 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.server.resourcemanager.applicationsmanager.events.ApplicationEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMFinishEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMAllocatedEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMRegistrationEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMStatusUpdateEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationTrackerEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.SNEventType;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemStore;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.StoreFactory;
 import org.junit.After;
@@ -75,7 +80,7 @@ public class TestASMStateMachine {
   }
 
   private class DummyAMLaunchEventHandler implements EventHandler<ASMEvent<AMLauncherEventType>> {
-    AppContext appcontext;
+    Application application;
     AtomicInteger amsync = new AtomicInteger(0);
 
     public DummyAMLaunchEventHandler() {
@@ -87,10 +92,10 @@ public class TestASMStateMachine {
       switch(event.getType()) {
       case LAUNCH:
         launchCalled = true;
-        appcontext = event.getAppContext();
+        application = event.getApplication();
         context.getDispatcher().getEventHandler().handle(
-            new ApplicationMasterInfoEvent(ApplicationEventType.LAUNCHED,
-                appcontext.getApplicationID()));
+            new ApplicationEvent(ApplicationEventType.LAUNCHED,
+                application.getApplicationID()));
         break;
       case CLEANUP:
         launchCleanupCalled = true;
@@ -100,7 +105,7 @@ public class TestASMStateMachine {
   }
 
   private class DummySNEventHandler implements EventHandler<ASMEvent<SNEventType>> {
-    AppContext appContext;
+    Application application;
     AtomicInteger snsync = new AtomicInteger(0);
 
     public DummySNEventHandler() {
@@ -110,15 +115,15 @@ public class TestASMStateMachine {
     @Override
     public void handle(ASMEvent<SNEventType> event) {
       switch(event.getType()) {
-      case CLEANUP:
+      case RELEASE:
         snreceivedCleanUp = true;
         break;
       case SCHEDULE:
         snAllocateReceived = true;
-        appContext = event.getAppContext();
+        application = event.getApplication();
         context.getDispatcher().getEventHandler().handle(
-            new ApplicationMasterAllocatedEvent(appContext.getApplicationID(),
-                appContext.getMasterContainer()));
+            new AMAllocatedEvent(application.getApplicationID(),
+                application.getMasterContainer()));
         break;
       }
     }
@@ -144,19 +149,19 @@ public class TestASMStateMachine {
   }
 
   private class MockAppplicationMasterInfo implements
-      EventHandler<ApplicationMasterInfoEvent> {
+      EventHandler<ApplicationEvent> {
 
     MockAppplicationMasterInfo() {
       context.getDispatcher().register(ApplicationEventType.class, this);
     }
     @Override
-    public void handle(ApplicationMasterInfoEvent event) {
+    public void handle(ApplicationEvent event) {
       LOG.info("The event type is " + event.getType());
     }
   }
 
   private void waitForState( ApplicationState 
-      finalState, ApplicationMasterInfo masterInfo) throws Exception {
+      finalState, ApplicationImpl masterInfo) throws Exception {
     int count = 0;
     while(masterInfo.getState() != finalState && count < 10) {
       Thread.sleep(500);
@@ -175,13 +180,13 @@ public class TestASMStateMachine {
     submissioncontext.getApplicationId().setId(1);
     submissioncontext.getApplicationId().setClusterTimestamp(System.currentTimeMillis());
 
-    ApplicationMasterInfo masterInfo = new ApplicationMasterInfo(context,
+    ApplicationImpl masterInfo = new ApplicationImpl(context,
         conf, "dummyuser", submissioncontext, "dummyToken", StoreFactory
             .createVoidAppStore(), new AMLivelinessMonitor(context
             .getDispatcher().getEventHandler()));
 
     context.getDispatcher().register(ApplicationEventType.class, masterInfo);
-    handler.handle(new ApplicationMasterInfoEvent(
+    handler.handle(new ApplicationEvent(
         ApplicationEventType.ALLOCATE, submissioncontext.getApplicationId()));
 
     waitForState(ApplicationState.LAUNCHED, masterInfo);
@@ -189,21 +194,21 @@ public class TestASMStateMachine {
     Assert.assertTrue(launchCalled);
     Assert.assertTrue(addedApplication);
     handler
-        .handle(new ApplicationMasterRegistrationEvent(masterInfo.getMaster()));
+        .handle(new AMRegistrationEvent(masterInfo.getMaster()));
     waitForState(ApplicationState.RUNNING, masterInfo);
     Assert.assertEquals(ApplicationState.RUNNING, masterInfo.getState());
 
     ApplicationStatus status = recordFactory
         .newRecordInstance(ApplicationStatus.class);
     status.setApplicationId(masterInfo.getApplicationID());
-    handler.handle(new ApplicationMasterStatusUpdateEvent(status));
+    handler.handle(new AMStatusUpdateEvent(status));
 
     /* check if the state is still RUNNING */
 
     Assert.assertEquals(ApplicationState.RUNNING, masterInfo.getState());
 
-    handler.handle(new ApplicationFinishEvent(masterInfo.getApplicationID(),
-        ApplicationState.COMPLETED));
+    handler.handle(new AMFinishEvent(masterInfo.getApplicationID(),
+        ApplicationState.COMPLETED, "", ""));
     waitForState(ApplicationState.COMPLETED, masterInfo);
     Assert.assertEquals(ApplicationState.COMPLETED, masterInfo.getState());
     /* check if clean up is called for everyone */
@@ -212,7 +217,7 @@ public class TestASMStateMachine {
     Assert.assertTrue(removedApplication);
 
     /* check if expiry doesnt make it failed */
-    handler.handle(new ApplicationMasterInfoEvent(ApplicationEventType.EXPIRE,
+    handler.handle(new ApplicationEvent(ApplicationEventType.EXPIRE,
         masterInfo.getApplicationID()));
     Assert.assertEquals(ApplicationState.COMPLETED, masterInfo.getState());   
   }

Modified: hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationCleanup.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationCleanup.java?rev=1143250&r1=1143249&r2=1143250&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationCleanup.java (original)
+++ hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationCleanup.java Wed Jul  6 04:51:46 2011
@@ -34,6 +34,7 @@ import org.apache.hadoop.net.NetworkTopo
 import org.apache.hadoop.net.Node;
 import org.apache.hadoop.net.NodeBase;
 import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.api.records.ApplicationState;
 import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
@@ -46,13 +47,16 @@ import org.apache.hadoop.yarn.event.Even
 import org.apache.hadoop.yarn.factories.RecordFactory;
 import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
 import org.apache.hadoop.yarn.security.ApplicationTokenSecretManager;
+import org.apache.hadoop.yarn.server.resourcemanager.ClientRMService;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.RMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMLauncherEventType;
 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.server.resourcemanager.applicationsmanager.events.ApplicationEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMAllocatedEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationTrackerEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.SNEventType;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemStore;
 import org.apache.hadoop.yarn.server.resourcemanager.resourcetracker.NodeInfo;
 import org.apache.hadoop.yarn.server.resourcemanager.resourcetracker.NodeInfoTracker;
@@ -83,6 +87,7 @@ public class TestApplicationCleanup {
   private static final int memoryNeeded = 100;
 
   private final RMContext context = new ResourceManager.RMContextImpl(new MemStore());
+  private ClientRMService clientService;
   private TestRMResourceTrackerImpl clusterTracker;
 
   private class TestRMResourceTrackerImpl extends RMResourceTrackerImpl {
@@ -115,6 +120,9 @@ public class TestApplicationCleanup {
     context.getDispatcher().start();
     asm = new ExtASM(new ApplicationTokenSecretManager(), scheduler);
     asm.init(conf);
+    clientService = new ClientRMService(context,
+        asm.getAmLivelinessMonitor(), asm.getClientToAMSecretManager(),
+        clusterTracker, scheduler);
   }
 
   @After
@@ -142,7 +150,7 @@ public class TestApplicationCleanup {
 
     private class DummyApplicationMasterLauncher implements EventHandler<ASMEvent<AMLauncherEventType>> {
       private AtomicInteger notify = new AtomicInteger(0);
-      private AppContext appContext;
+      private Application application;
 
       public DummyApplicationMasterLauncher(RMContext context) {
         context.getDispatcher().register(AMLauncherEventType.class, this);
@@ -158,10 +166,10 @@ public class TestApplicationCleanup {
         case LAUNCH:
           LOG.info("Launcher Launch called");
           launcherLaunchCalled = true;
-          appContext = appEvent.getAppContext();
+          application = appEvent.getApplication();
           context.getDispatcher().getEventHandler().handle(
-              new ApplicationMasterInfoEvent(ApplicationEventType.LAUNCHED,
-                  appContext.getApplicationID()));
+              new ApplicationEvent(ApplicationEventType.LAUNCHED,
+                  application.getApplicationID()));
           break;
         default:
           break;
@@ -171,7 +179,7 @@ public class TestApplicationCleanup {
 
     private class DummySchedulerNegotiator implements EventHandler<ASMEvent<SNEventType>> {
       private AtomicInteger snnotify = new AtomicInteger(0);
-      AppContext acontext;
+      Application application;
       public  DummySchedulerNegotiator(RMContext context) {
         context.getDispatcher().register(SNEventType.class, this);
       }
@@ -180,15 +188,15 @@ public class TestApplicationCleanup {
       public void handle(ASMEvent<SNEventType> appEvent) {
         SNEventType event = appEvent.getType();
         switch (event) {
-        case CLEANUP:
+        case RELEASE:
           schedulerCleanupCalled = true;
           break;
         case SCHEDULE:
           schedulerScheduleCalled = true;
-          acontext = appEvent.getAppContext();
+          application = appEvent.getApplication();
           context.getDispatcher().getEventHandler().handle(
-              new ApplicationMasterAllocatedEvent(acontext.getApplicationID(),
-                  acontext.getMasterContainer()));
+              new AMAllocatedEvent(application.getApplicationID(),
+                  application.getMasterContainer()));
         default:
           break;
         }
@@ -215,13 +223,13 @@ public class TestApplicationCleanup {
   }
 
   private void waitForState(ApplicationState 
-      finalState, ApplicationMasterInfo masterInfo) throws Exception {
+      finalState, Application application) throws Exception {
     int count = 0;
-    while(masterInfo.getState() != finalState && count < 10) {
+    while(application.getState() != finalState && count < 10) {
       Thread.sleep(500);
       count++;
     }
-    Assert.assertEquals(finalState, masterInfo.getState());
+    Assert.assertEquals(finalState, application.getState());
   }
 
 
@@ -249,13 +257,17 @@ public class TestApplicationCleanup {
 
   @Test
   public void testApplicationCleanUp() throws Exception {
-    ApplicationId appID = asm.getNewApplicationID();
-    ApplicationSubmissionContext context = recordFactory.newRecordInstance(ApplicationSubmissionContext.class);
-    context.setApplicationId(appID);
-    context.setQueue("queuename");
-    context.setUser("dummyuser");
-    asm.submitApplication(context);
-    waitForState(ApplicationState.LAUNCHED, asm.getApplicationMasterInfo(appID));
+    ApplicationId appID = clientService.getNewApplicationId();
+    ApplicationSubmissionContext submissionContext = recordFactory.newRecordInstance(ApplicationSubmissionContext.class);
+    submissionContext.setApplicationId(appID);
+    submissionContext.setQueue("queuename");
+    submissionContext.setUser("dummyuser");
+    SubmitApplicationRequest request = recordFactory
+        .newRecordInstance(SubmitApplicationRequest.class);
+    request.setApplicationSubmissionContext(submissionContext);
+    clientService.submitApplication(request);
+    waitForState(ApplicationState.LAUNCHED, context.getApplications().get(
+        appID));
     List<ResourceRequest> reqs = new ArrayList<ResourceRequest>();
     ResourceRequest req = createNewResourceRequest(100, 1);
     reqs.add(req);
@@ -279,8 +291,8 @@ public class TestApplicationCleanup {
     /* only allocate the containers to the first node */
     Assert.assertEquals((firstNodeMemory - (2 * memoryNeeded)), firstNode
         .getAvailableResource().getMemory());
-    ApplicationMasterInfo masterInfo = asm.getApplicationMasterInfo(appID);
-    asm.finishApplication(appID, UserGroupInformation.getCurrentUser());
+    context.getDispatcher().getEventHandler().handle(
+        new ApplicationEvent(ApplicationEventType.KILL, appID));
     while (asm.launcherCleanupCalled != true) {
       Thread.sleep(500);
     }

Modified: hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationMasterExpiry.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationMasterExpiry.java?rev=1143250&r1=1143249&r2=1143250&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationMasterExpiry.java (original)
+++ hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationMasterExpiry.java Wed Jul  6 04:51:46 2011
@@ -34,13 +34,15 @@ import org.apache.hadoop.yarn.factories.
 import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.RMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMAllocatedEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMLauncherEventType;
 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.server.resourcemanager.applicationsmanager.events.ApplicationEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationTrackerEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.SNEventType;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemStore;
-import org.junit.After;
+import org.apache.hadoop.yarn.server.resourcemanager.recovery.ApplicationsStore.ApplicationStore;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -51,28 +53,26 @@ import org.junit.Test;
 public class TestApplicationMasterExpiry {
   private static final Log LOG = LogFactory.getLog(TestApplicationMasterExpiry.class);
   private static RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null);
-  AMTracker tracker;
   
   private final RMContext context = new ResourceManager.RMContextImpl(new MemStore());
+  private AMLivelinessMonitor amLivelinessMonitor;
   
   @Before
   public void setUp() {
     new DummyApplicationTracker();
     new DummySN();
     new DummyLauncher();
-    new ApplicationEventTypeListener();
-    tracker = new AMTracker(context); 
+    new ApplicationEventTypeListener(); 
     Configuration conf = new Configuration();
+    context.getDispatcher().register(ApplicationEventType.class,
+        new ResourceManager.ApplicationEventDispatcher(context));
     context.getDispatcher().init(conf);
     context.getDispatcher().start();
     conf.setLong(YarnConfiguration.AM_EXPIRY_INTERVAL, 1000L);
-    tracker.init(conf);
-    tracker.start();
-  }
-  
-  @After 
-  public void tearDown() {
-    tracker.stop();
+    amLivelinessMonitor = new AMLivelinessMonitor(this.context
+        .getDispatcher().getEventHandler());
+    amLivelinessMonitor.init(conf);
+    amLivelinessMonitor.start();
   }
   
   private class DummyApplicationTracker implements EventHandler<ASMEvent<ApplicationTrackerEventType>> {
@@ -88,12 +88,12 @@ public class TestApplicationMasterExpiry
   private boolean expired = false;
   
   private class ApplicationEventTypeListener implements
-      EventHandler<ApplicationMasterInfoEvent> {
+      EventHandler<ApplicationEvent> {
     ApplicationEventTypeListener() {
       context.getDispatcher().register(ApplicationEventType.class, this);
     }
     @Override
-    public void handle(ApplicationMasterInfoEvent event) {
+    public void handle(ApplicationEvent event) {
       switch(event.getType()) {
       case EXPIRE:
         expired = true;
@@ -123,14 +123,14 @@ public class TestApplicationMasterExpiry
     }
   }
   
-  private void waitForState(ApplicationMasterInfo masterInfo, ApplicationState 
+  private void waitForState(Application application, ApplicationState 
       finalState) throws Exception {
     int count = 0;
-    while(masterInfo.getState() != finalState && count < 10) {
+    while(application.getState() != finalState && count < 10) {
       Thread.sleep(500);
       count++;
     }
-    Assert.assertEquals(finalState, masterInfo.getState());
+    Assert.assertEquals(finalState, application.getState());
   }
 
   @Test
@@ -142,19 +142,31 @@ public class TestApplicationMasterExpiry
     submissionContext.getApplicationId().setClusterTimestamp(
         System.currentTimeMillis());
     submissionContext.getApplicationId().setId(1);
-    
-    tracker.addMaster(
-        "dummy", 
-        submissionContext, "dummytoken");
-    ApplicationMasterInfo masterInfo = tracker.get(submissionContext.getApplicationId());
-    tracker.runApplication(submissionContext.getApplicationId());
+
+    ApplicationStore appStore = context.getApplicationsStore()
+    .createApplicationStore(submissionContext.getApplicationId(),
+        submissionContext);
+    Application application = new ApplicationImpl(context,
+        new Configuration(), "dummy", submissionContext, "dummytoken", appStore,
+        amLivelinessMonitor);
+    context.getApplications()
+        .put(application.getApplicationID(), application);
+
+    this.context.getDispatcher().getSyncHandler().handle(
+        new ApplicationEvent(ApplicationEventType.ALLOCATE, submissionContext
+            .getApplicationId()));
+
+    waitForState(application, ApplicationState.ALLOCATING);
+
     this.context.getDispatcher().getEventHandler().handle(
-        new ApplicationMasterAllocatedEvent(masterInfo.getApplicationID(),
-            masterInfo.getMasterContainer()));
-    waitForState(masterInfo, ApplicationState.LAUNCHING);
+        new AMAllocatedEvent(application.getApplicationID(),
+            application.getMasterContainer()));
+
+    waitForState(application, ApplicationState.LAUNCHING);
+
     this.context.getDispatcher().getEventHandler().handle(
-        new ApplicationMasterInfoEvent(ApplicationEventType.LAUNCHED,
-            masterInfo.getApplicationID()));
+        new ApplicationEvent(ApplicationEventType.LAUNCHED,
+            application.getApplicationID()));
     synchronized(expiry) {
       while (expiry.get() == 0) {
         expiry.wait(1000);

Modified: hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationMasterLauncher.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationMasterLauncher.java?rev=1143250&r1=1143249&r2=1143250&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationMasterLauncher.java (original)
+++ hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestApplicationMasterLauncher.java Wed Jul  6 04:51:46 2011
@@ -35,9 +35,11 @@ import org.apache.hadoop.yarn.security.A
 import org.apache.hadoop.yarn.security.client.ClientToAMSecretManager;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.RMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMLauncherEventType;
 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.ApplicationEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMFinishEvent;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemStore;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.StoreFactory;
 import org.junit.After;
@@ -65,9 +67,9 @@ public class TestApplicationMasterLaunch
 
   private Configuration conf = new Configuration();
   
-  private class DummyASM implements EventHandler<ApplicationMasterInfoEvent> {
+  private class DummyASM implements EventHandler<ApplicationEvent> {
     @Override
-    public void handle(ApplicationMasterInfoEvent appEvent) {
+    public void handle(ApplicationEvent appEvent) {
       ApplicationEventType event = appEvent.getType();
       switch (event) {
       case FINISH:
@@ -96,8 +98,8 @@ public class TestApplicationMasterLaunch
     }
     public void run() {
       cleanedUp.incrementAndGet();
-      asmHandle.handle(new ApplicationFinishEvent(null,
-          ApplicationState.COMPLETED));
+      asmHandle.handle(new AMFinishEvent(null,
+          ApplicationState.COMPLETED, "", ""));
     }
   }
 
@@ -112,7 +114,7 @@ public class TestApplicationMasterLaunch
     }
 
     @Override
-    protected Runnable createRunnableLauncher(AppContext masterInfo, 
+    protected Runnable createRunnableLauncher(Application masterInfo, 
         AMLauncherEventType event) {
       Runnable r = null;
       switch (event) {
@@ -152,7 +154,7 @@ public class TestApplicationMasterLaunch
     submissionContext.getApplicationId().setClusterTimestamp(System.currentTimeMillis());
     submissionContext.getApplicationId().setId(1);
     submissionContext.setUser("dummyuser");
-    ApplicationMasterInfo masterInfo = new ApplicationMasterInfo(this.context,
+    ApplicationImpl masterInfo = new ApplicationImpl(this.context,
         this.conf, "dummyuser", submissionContext, "dummyclienttoken",
         StoreFactory.createVoidAppStore(), new AMLivelinessMonitor(context
             .getDispatcher().getEventHandler()));

Modified: hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestSchedulerNegotiator.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestSchedulerNegotiator.java?rev=1143250&r1=1143249&r2=1143250&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestSchedulerNegotiator.java (original)
+++ hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/applicationsmanager/TestSchedulerNegotiator.java Wed Jul  6 04:51:46 2011
@@ -42,10 +42,11 @@ import org.apache.hadoop.yarn.factories.
 import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.RMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.AMLauncherEventType;
 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.ApplicationEvent;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationEventType;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.events.ApplicationTrackerEventType;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.ApplicationsStore.ApplicationStore;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemStore;
 import org.apache.hadoop.yarn.server.resourcemanager.recovery.Store.RMState;
@@ -67,7 +68,7 @@ public class TestSchedulerNegotiator {
   private final int testNum = 99999;
   
   private final RMContext context = new ResourceManager.RMContextImpl(new MemStore());
-  ApplicationMasterInfo masterInfo;
+  ApplicationImpl masterInfo;
   private EventHandler handler;
   private Configuration conf = new Configuration();
   private class DummyScheduler implements ResourceScheduler {
@@ -166,7 +167,7 @@ public class TestSchedulerNegotiator {
     schedulerNegotiator.stop();
   }
   
-  public void waitForState(ApplicationState state, ApplicationMasterInfo info) {
+  public void waitForState(ApplicationState state, ApplicationImpl info) {
     int count = 0;
     while (info.getState() != state && count < 100) {
       try {
@@ -192,7 +193,7 @@ public class TestSchedulerNegotiator {
     submissionContext.getApplicationId().setClusterTimestamp(System.currentTimeMillis());
     submissionContext.getApplicationId().setId(1);
     
-    masterInfo = new ApplicationMasterInfo(this.context, this.conf, "dummy",
+    masterInfo = new ApplicationImpl(this.context, this.conf, "dummy",
         submissionContext, "dummyClientToken", StoreFactory
             .createVoidAppStore(), new AMLivelinessMonitor(context
             .getDispatcher().getEventHandler()));
@@ -200,7 +201,7 @@ public class TestSchedulerNegotiator {
     context.getDispatcher().register(ApplicationTrackerEventType.class, scheduler);
     context.getDispatcher().register(AMLauncherEventType.class,
         new DummyEventHandler());
-    handler.handle(new ApplicationMasterInfoEvent(
+    handler.handle(new ApplicationEvent(
         ApplicationEventType.ALLOCATE, submissionContext.getApplicationId()));
     waitForState(ApplicationState.LAUNCHING, masterInfo); // LAUNCHING because ALLOCATED automatically movesto LAUNCHING for now.
     Container container = masterInfo.getMasterContainer();

Modified: hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java?rev=1143250&r1=1143249&r2=1143250&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java (original)
+++ hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebApp.java Wed Jul  6 04:51:46 2011
@@ -18,30 +18,40 @@
 
 package org.apache.hadoop.yarn.server.resourcemanager.webapp;
 
-import com.google.inject.Injector;
+import static org.apache.hadoop.test.MockitoMaker.make;
+import static org.apache.hadoop.test.MockitoMaker.stub;
+import static org.apache.hadoop.yarn.server.resourcemanager.MockNodes.newResource;
+import static org.apache.hadoop.yarn.webapp.Params.TITLE;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
 
-import static org.apache.hadoop.test.MockitoMaker.*;
-import static org.apache.hadoop.yarn.server.resourcemanager.MockNodes.*;
-import static org.apache.hadoop.yarn.webapp.Params.*;
-
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.server.resourcemanager.ApplicationsManager;
 import org.apache.hadoop.yarn.server.resourcemanager.MockNodes;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
-import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.ApplicationsManager;
+import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.RMContext;
+import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager.RMContextImpl;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.Application;
 import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.MockAsm;
+import org.apache.hadoop.yarn.server.resourcemanager.recovery.MemStore;
+import org.apache.hadoop.yarn.server.resourcemanager.resourcetracker.ClusterTracker;
 import org.apache.hadoop.yarn.server.resourcemanager.resourcetracker.NodeInfo;
 import org.apache.hadoop.yarn.server.resourcemanager.resourcetracker.RMResourceTrackerImpl;
-import org.apache.hadoop.yarn.server.resourcemanager.resourcetracker.ClusterTracker;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler;
 import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration;
 import org.apache.hadoop.yarn.webapp.WebApps;
 import org.apache.hadoop.yarn.webapp.test.WebAppTests;
-
 import org.junit.Test;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.inject.Injector;
 
 public class TestRMWebApp {
   static final int GiB = 1024; // MiB
@@ -54,8 +64,8 @@ public class TestRMWebApp {
   }
 
   @Test public void testView() {
-    Injector injector = WebAppTests.createMockInjector(ApplicationsManager.class,
-                                                       MockAsm.create(3));
+    Injector injector = WebAppTests.createMockInjector(RMContext.class,
+                                                       mockRMContext(3));
     injector.getInstance(RmView.class).render();
     WebAppTests.flushOutput(injector);
   }
@@ -73,16 +83,33 @@ public class TestRMWebApp {
         getAllNodeInfo());
   }
 
+  public static RMContext mockRMContext(int n) {
+    final List<Application> apps = MockAsm.newApplications(n);
+    final ConcurrentMap<ApplicationId, Application> map = Maps
+        .newConcurrentMap();
+    for (Application app : apps) {
+      map.put(app.getApplicationID(), app);
+    }
+    return new RMContextImpl(new MemStore()) {
+      @Override
+      public ConcurrentMap<ApplicationId, Application> getApplications() {
+        return map;
+      }
+    };
+  }
+
   public static ResourceManager mockRm(int apps, int racks, int nodes,
                                        int mbsPerNode)
   throws Exception {
     ResourceManager rm = mock(ResourceManager.class);
-    ApplicationsManager asm = MockAsm.create(apps);
+    ApplicationsManager asm = MockAsm.create();
+    RMContext rmContext = mockRMContext(apps);
     RMResourceTrackerImpl rt = mockResource(racks, nodes, mbsPerNode);
     ResourceScheduler rs = mockCapacityScheduler();
     when(rm.getApplicationsManager()).thenReturn(asm);
     when(rm.getResourceTracker()).thenReturn(rt);
     when(rm.getResourceScheduler()).thenReturn(rs);
+    when(rm.getRMContext()).thenReturn(rmContext);
     return rm;
   }
 

Modified: hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/TestContainerTokenSecretManager.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/TestContainerTokenSecretManager.java?rev=1143250&r1=1143249&r2=1143250&view=diff
==============================================================================
--- hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/TestContainerTokenSecretManager.java (original)
+++ hadoop/common/branches/MR-279/mapreduce/yarn/yarn-server/yarn-server-tests/src/test/java/org/apache/hadoop/yarn/server/TestContainerTokenSecretManager.java Wed Jul  6 04:51:46 2011
@@ -52,7 +52,8 @@ import org.apache.hadoop.yarn.api.Contai
 import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest;
 import org.apache.hadoop.yarn.api.protocolrecords.GetContainerStatusRequest;
 import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterRequest;
-import org.apache.hadoop.yarn.api.records.Application;
+import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
 import org.apache.hadoop.yarn.api.records.ApplicationId;
 import org.apache.hadoop.yarn.api.records.ApplicationMaster;
 import org.apache.hadoop.yarn.api.records.ApplicationState;
@@ -79,6 +80,7 @@ import org.apache.hadoop.yarn.security.C
 import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
 import org.apache.hadoop.yarn.security.SchedulerSecurityInfo;
 import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
+import org.apache.hadoop.yarn.server.resourcemanager.applicationsmanager.Application;
 import org.apache.hadoop.yarn.util.ConverterUtils;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -154,18 +156,20 @@ public class TestContainerTokenSecretMan
     rsrc.setType(LocalResourceType.FILE);
     rsrc.setVisibility(LocalResourceVisibility.PRIVATE);
     appSubmissionContext.setResourceTodo("testFile", rsrc);
-    resourceManager.getApplicationsManager().submitApplication(
-        appSubmissionContext);
+    SubmitApplicationRequest submitRequest = recordFactory
+        .newRecordInstance(SubmitApplicationRequest.class);
+    submitRequest.setApplicationSubmissionContext(appSubmissionContext);
+    resourceManager.getClientRMService().submitApplication(submitRequest);
 
     // Wait till container gets allocated for AM
     int waitCounter = 0;
     Application app =
-        resourceManager.getApplicationsManager().getApplication(appID);
+        resourceManager.getRMContext().getApplications().get(appID);
     while (app.getState() != ApplicationState.LAUNCHED && waitCounter <= 20) {
       Thread.sleep(1000);
       LOG.info("Waiting for AM to be allocated a container. Current state is "
           + app.getState());
-      app = resourceManager.getApplicationsManager().getApplication(appID);
+      app = resourceManager.getRMContext().getApplications().get(appID);
     }
 
     Assert.assertTrue(ApplicationState.PENDING != app.getState());



Mime
View raw message