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/client/SystemServiceManagerImpl.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/client/SystemServiceManagerImpl.java index f9cfa92ea45..2ad53396a92 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/client/SystemServiceManagerImpl.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/client/SystemServiceManagerImpl.java @@ -228,7 +228,14 @@ private void launchServices(UserGroupInformation userUgi, userUgi.doAs(new PrivilegedExceptionAction() { @Override public ApplicationId run() throws IOException, YarnException { - ApplicationId applicationId = serviceClient.actionCreate(service); + try { + serviceClient.actionBuild(service); + } catch (Exception e) { + LOG.info("Got exception saving {}, will attempt to start " + + "service", service.getName()); + } + ApplicationId applicationId = serviceClient + .actionStartAndGetId(service.getName()); return applicationId; } }); 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 578273c6492..82fadae8bc3 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 @@ -648,8 +648,7 @@ private Response startService(String appName, ServiceClient sc = getServiceClient(); sc.init(YARN_CONFIG); sc.start(); - sc.actionStart(appName); - ApplicationId appId = sc.getAppId(appName); + ApplicationId appId = sc.actionStartAndGetId(appName); sc.close(); return appId; } 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 81be750d27e..d022614e708 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 @@ -103,13 +103,13 @@ public Service getStatus(String appName) throws FileNotFoundException { } @Override - public int actionStart(String serviceName) + public ApplicationId actionStartAndGetId(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; + return appId; } else { throw new ApplicationNotFoundException(""); } 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/client/TestSystemServiceManagerImpl.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/client/TestSystemServiceManagerImpl.java index d39083dab13..58d0ed48491 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/client/TestSystemServiceManagerImpl.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/client/TestSystemServiceManagerImpl.java @@ -51,6 +51,7 @@ private String[] users = new String[] {"user1", "user2"}; private static Map> loadedServices = new HashMap<>(); + private static Map> savedServices = new HashMap<>(); private static Map> submittedServices = new HashMap<>(); @Before @@ -72,7 +73,7 @@ public void setup() { } @After - public void teadDown() { + public void tearDown() { systemService.stop(); } @@ -102,6 +103,11 @@ public void testSystemServiceSubmission() throws Exception { // 2nd time launch service to handle if service exist scenario systemService.launchUserService(userServices); verifyForLaunchedUserServices(); + + // verify start of stopped services + submittedServices.clear(); + systemService.launchUserService(userServices); + verifyForLaunchedUserServices(); } private void verifyForScannedUserServices( @@ -149,7 +155,26 @@ protected void serviceInit(Configuration configuration) } @Override - public ApplicationId actionCreate(Service service) + public int actionBuild(Service service) + throws YarnException, IOException { + String userName = + UserGroupInformation.getCurrentUser().getShortUserName(); + Set services = savedServices.get(userName); + if (services != null) { + services = new HashSet<>(); + savedServices.put(userName, services); + } + if (services.contains(service.getName())) { + String message = "Failed to save service " + service.getName() + + ", because it already exists."; + throw new YarnException(message); + } + services.add(service.getName()); + return 0; + } + + @Override + public ApplicationId actionStartAndGetId(String serviceName) throws YarnException, IOException { String userName = UserGroupInformation.getCurrentUser().getShortUserName(); @@ -158,12 +183,12 @@ public ApplicationId actionCreate(Service service) services = new HashSet<>(); submittedServices.put(userName, services); } - if (services.contains(service.getName())) { - String message = "Failed to create service " + service.getName() + if (services.contains(serviceName)) { + String message = "Failed to create service " + serviceName + ", because it already exists."; throw new YarnException(message); } - services.add(service.getName()); + services.add(serviceName); return ApplicationId.newInstance(System.currentTimeMillis(), 1); } } 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 3f6e8966e4f..b5773a67082 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 @@ -1003,6 +1003,12 @@ private boolean addAMLog4jResource(String serviceName, Configuration conf, @Override public int actionStart(String serviceName) throws YarnException, IOException { + actionStartAndGetId(serviceName); + return EXIT_SUCCESS; + } + + public ApplicationId actionStartAndGetId(String serviceName) throws + YarnException, IOException { ServiceApiUtil.validateNameFormat(serviceName, getConfig()); Service liveService = getStatus(serviceName); if (liveService == null || @@ -1019,11 +1025,11 @@ public int actionStart(String serviceName) throws YarnException, IOException { // write app definition on to hdfs Path appJson = ServiceApiUtil.writeAppDefinition(fs, appDir, service); LOG.info("Persisted service " + service.getName() + " at " + appJson); - return 0; + return appId; } else { LOG.info("Finalize service {} upgrade"); - ApplicationReport appReport = - yarnClient.getApplicationReport(getAppId(serviceName)); + ApplicationId appId = getAppId(serviceName); + ApplicationReport appReport = yarnClient.getApplicationReport(appId); if (StringUtils.isEmpty(appReport.getHost())) { throw new YarnException(serviceName + " AM hostname is empty"); } @@ -1032,7 +1038,7 @@ public int actionStart(String serviceName) throws YarnException, IOException { RestartServiceRequestProto.Builder requestBuilder = RestartServiceRequestProto.newBuilder(); proxy.restart(requestBuilder.build()); - return 0; + return appId; } }