From 7bd5d79177c8b1c2d1c0fcc0220b88da3c06df6a Mon Sep 17 00:00:00 2001 From: Billie Rinaldi Date: Wed, 30 May 2018 12:37:01 -0700 Subject: [PATCH] YARN-8368. yarn app start cli should print applicationId. Contributed by Rohith Sharma K S (cherry picked from commit 96eefcc84aacc4cc82ad7e3e72c5bdad56f4a7b7) --- .../hadoop/yarn/service/webapp/ApiServer.java | 28 +++++++++++-------- .../yarn/service/ServiceClientTest.java | 18 +++++++++++- .../yarn/service/client/ServiceClient.java | 2 ++ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/service/webapp/ApiServer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/service/webapp/ApiServer.java index 46c9abe6d0e..578273c6492 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/service/webapp/ApiServer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/main/java/org/apache/hadoop/yarn/service/webapp/ApiServer.java @@ -641,20 +641,24 @@ public class ApiServer { private Response startService(String appName, final UserGroupInformation ugi) throws IOException, InterruptedException { - ugi.doAs(new PrivilegedExceptionAction() { - @Override - public Void run() throws YarnException, IOException { - ServiceClient sc = getServiceClient(); - sc.init(YARN_CONFIG); - sc.start(); - sc.actionStart(appName); - sc.close(); - return null; - } - }); + ApplicationId appId = + ugi.doAs(new PrivilegedExceptionAction() { + @Override public ApplicationId run() + throws YarnException, IOException { + ServiceClient sc = getServiceClient(); + sc.init(YARN_CONFIG); + sc.start(); + sc.actionStart(appName); + ApplicationId appId = sc.getAppId(appName); + sc.close(); + return appId; + } + }); LOG.info("Successfully started service " + appName); ServiceStatus status = new ServiceStatus(); - status.setDiagnostics("Service " + appName + " is successfully started."); + status.setDiagnostics( + "Service " + appName + " is successfully started with ApplicationId: " + + appId); status.setState(ServiceState.ACCEPTED); return formatResponse(Status.OK, status); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/ServiceClientTest.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/ServiceClientTest.java index 75b9486b111..81be750d27e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/ServiceClientTest.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-api/src/test/java/org/apache/hadoop/yarn/service/ServiceClientTest.java @@ -34,8 +34,10 @@ import org.apache.hadoop.yarn.service.utils.SliderFileSystem; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -50,6 +52,8 @@ public class ServiceClientTest extends ServiceClient { private Service goodServiceStatus = buildLiveGoodService(); private boolean initialized; private Set expectedInstances = new HashSet<>(); + private Map serviceAppId = new HashMap<>(); + public ServiceClientTest() { super(); @@ -83,7 +87,10 @@ public class ServiceClientTest extends ServiceClient { public ApplicationId actionCreate(Service service) throws IOException { ServiceApiUtil.validateAndResolveService(service, new SliderFileSystem(conf), getConfig()); - return ApplicationId.newInstance(System.currentTimeMillis(), 1); + ApplicationId appId = + ApplicationId.newInstance(System.currentTimeMillis(), 1); + serviceAppId.put(service.getName(), appId); + return appId; } @Override @@ -99,6 +106,9 @@ public class ServiceClientTest extends ServiceClient { public int actionStart(String serviceName) throws YarnException, IOException { if (serviceName != null && serviceName.equals("jenkins")) { + ApplicationId appId = + ApplicationId.newInstance(System.currentTimeMillis(), 1); + serviceAppId.put(serviceName, appId); return EXIT_SUCCESS; } else { throw new ApplicationNotFoundException(""); @@ -207,4 +217,10 @@ public class ServiceClientTest extends ServiceClient { comp.setContainers(containers); return service; } + + @Override + public synchronized ApplicationId getAppId(String serviceName) + throws IOException, YarnException { + return serviceAppId.get(serviceName); + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java index 0ab332280f2..e86ecbc61aa 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/client/ServiceClient.java @@ -978,6 +978,8 @@ public class ServiceClient extends AppAdminClient implements SliderExitCodes, // see if it is actually running and bail out; verifyNoLiveAppInRM(serviceName, "start"); ApplicationId appId = submitApp(service); + cachedAppInfo.put(serviceName, new AppInfo(appId, service + .getKerberosPrincipal().getPrincipalName())); service.setId(appId.toString()); // write app definition on to hdfs Path appJson = ServiceApiUtil.writeAppDefinition(fs, appDir, service);