|
@@ -58,6 +58,7 @@ import org.apache.hadoop.yarn.api.records.ResourceRequest;
|
|
|
import org.apache.hadoop.yarn.api.records.Token;
|
|
|
import org.apache.hadoop.yarn.api.records.UpdateContainerError;
|
|
|
import org.apache.hadoop.yarn.api.records.UpdatedContainer;
|
|
|
+import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.exceptions.ApplicationMasterNotRegisteredException;
|
|
|
import org.apache.hadoop.yarn.exceptions.InvalidApplicationMasterRequestException;
|
|
@@ -71,6 +72,7 @@ import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
|
|
|
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo;
|
|
|
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterRegisterRequest;
|
|
|
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterState;
|
|
|
+import org.apache.hadoop.yarn.server.federation.utils.FederationRegistryClient;
|
|
|
import org.apache.hadoop.yarn.server.federation.utils.FederationStateStoreFacade;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.Context;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext;
|
|
@@ -1119,4 +1121,125 @@ public class TestFederationInterceptor extends BaseAMRMProxyTest {
|
|
|
return null;
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testRemoveAppFromRegistryApplicationSuccess()
|
|
|
+ throws IOException, InterruptedException {
|
|
|
+
|
|
|
+ final RegisterApplicationMasterRequest registerReq =
|
|
|
+ Records.newRecord(RegisterApplicationMasterRequest.class);
|
|
|
+ registerReq.setHost(Integer.toString(testAppId));
|
|
|
+ registerReq.setRpcPort(testAppId);
|
|
|
+ registerReq.setTrackingUrl("");
|
|
|
+
|
|
|
+ UserGroupInformation ugi = interceptor.getUGIWithToken(interceptor.getAttemptId());
|
|
|
+
|
|
|
+ ugi.doAs((PrivilegedExceptionAction<Object>) () -> {
|
|
|
+
|
|
|
+ // Register the application
|
|
|
+ RegisterApplicationMasterRequest registerReq1 =
|
|
|
+ Records.newRecord(RegisterApplicationMasterRequest.class);
|
|
|
+ registerReq1.setHost(Integer.toString(testAppId));
|
|
|
+ registerReq1.setRpcPort(0);
|
|
|
+ registerReq1.setTrackingUrl("");
|
|
|
+
|
|
|
+ // Register ApplicationMaster
|
|
|
+ RegisterApplicationMasterResponse registerResponse =
|
|
|
+ interceptor.registerApplicationMaster(registerReq1);
|
|
|
+ Assert.assertNotNull(registerResponse);
|
|
|
+ lastResponseId = 0;
|
|
|
+
|
|
|
+ Assert.assertEquals(0, interceptor.getUnmanagedAMPoolSize());
|
|
|
+
|
|
|
+ // Allocate the first batch of containers, with sc1 active
|
|
|
+ registerSubCluster(SubClusterId.newInstance("SC-1"));
|
|
|
+
|
|
|
+ int numberOfContainers = 3;
|
|
|
+ List<Container> containers =
|
|
|
+ getContainersAndAssert(numberOfContainers, numberOfContainers);
|
|
|
+ Assert.assertEquals(1, interceptor.getUnmanagedAMPoolSize());
|
|
|
+ Assert.assertEquals(numberOfContainers, containers.size());
|
|
|
+
|
|
|
+ // Finish the application
|
|
|
+ FinishApplicationMasterRequest finishReq =
|
|
|
+ Records.newRecord(FinishApplicationMasterRequest.class);
|
|
|
+ finishReq.setDiagnostics("");
|
|
|
+ finishReq.setTrackingUrl("");
|
|
|
+ finishReq.setFinalApplicationStatus(FinalApplicationStatus.SUCCEEDED);
|
|
|
+
|
|
|
+ FinishApplicationMasterResponse finishResp = interceptor.finishApplicationMaster(finishReq);
|
|
|
+ Assert.assertNotNull(finishResp);
|
|
|
+ Assert.assertTrue(finishResp.getIsUnregistered());
|
|
|
+
|
|
|
+ FederationRegistryClient client = interceptor.getRegistryClient();
|
|
|
+ List<String> applications = client.getAllApplications();
|
|
|
+ Assert.assertNotNull(finishResp);
|
|
|
+ Assert.assertEquals(0, applications.size());
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testRemoveAppFromRegistryApplicationFailed()
|
|
|
+ throws IOException, InterruptedException {
|
|
|
+
|
|
|
+ final RegisterApplicationMasterRequest registerReq =
|
|
|
+ Records.newRecord(RegisterApplicationMasterRequest.class);
|
|
|
+
|
|
|
+ registerReq.setHost(Integer.toString(testAppId));
|
|
|
+ registerReq.setRpcPort(testAppId);
|
|
|
+ registerReq.setTrackingUrl("");
|
|
|
+
|
|
|
+ UserGroupInformation ugi = interceptor.getUGIWithToken(interceptor.getAttemptId());
|
|
|
+
|
|
|
+ ugi.doAs((PrivilegedExceptionAction<Object>) () -> {
|
|
|
+
|
|
|
+ // Register the application
|
|
|
+ RegisterApplicationMasterRequest registerReq1 =
|
|
|
+ Records.newRecord(RegisterApplicationMasterRequest.class);
|
|
|
+ registerReq1.setHost(Integer.toString(testAppId));
|
|
|
+ registerReq1.setRpcPort(0);
|
|
|
+ registerReq1.setTrackingUrl("");
|
|
|
+
|
|
|
+ // Register ApplicationMaster
|
|
|
+ RegisterApplicationMasterResponse registerResponse =
|
|
|
+ interceptor.registerApplicationMaster(registerReq1);
|
|
|
+ Assert.assertNotNull(registerResponse);
|
|
|
+ lastResponseId = 0;
|
|
|
+
|
|
|
+ Assert.assertEquals(0, interceptor.getUnmanagedAMPoolSize());
|
|
|
+
|
|
|
+ // Allocate the first batch of containers, with sc1 active
|
|
|
+ registerSubCluster(SubClusterId.newInstance("SC-1"));
|
|
|
+
|
|
|
+ int numberOfContainers = 3;
|
|
|
+ List<Container> containers =
|
|
|
+ getContainersAndAssert(numberOfContainers, numberOfContainers);
|
|
|
+ Assert.assertEquals(1, interceptor.getUnmanagedAMPoolSize());
|
|
|
+ Assert.assertEquals(numberOfContainers, containers.size());
|
|
|
+
|
|
|
+ // Finish the application
|
|
|
+ FinishApplicationMasterRequest finishReq =
|
|
|
+ Records.newRecord(FinishApplicationMasterRequest.class);
|
|
|
+ finishReq.setDiagnostics("");
|
|
|
+ finishReq.setTrackingUrl("");
|
|
|
+ finishReq.setFinalApplicationStatus(FinalApplicationStatus.FAILED);
|
|
|
+
|
|
|
+ // Check Registry Applications
|
|
|
+ // At this time, the Application should not be cleaned up because the state is not SUCCESS.
|
|
|
+ FederationRegistryClient client = interceptor.getRegistryClient();
|
|
|
+ List<String> applications = client.getAllApplications();
|
|
|
+ Assert.assertNotNull(applications);
|
|
|
+ Assert.assertEquals(1, applications.size());
|
|
|
+
|
|
|
+ // interceptor cleanupRegistry
|
|
|
+ ApplicationId applicationId = interceptor.getAttemptId().getApplicationId();
|
|
|
+ client.removeAppFromRegistry(applicationId);
|
|
|
+ applications = client.getAllApplications();
|
|
|
+ Assert.assertNotNull(applications);
|
|
|
+ Assert.assertEquals(0, applications.size());
|
|
|
+
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|