YARN-8368. yarn app start cli should print applicationId. Contributed by Rohith Sharma K S

This commit is contained in:
Billie Rinaldi 2018-05-30 12:37:01 -07:00
parent 47c31ff16b
commit 96eefcc84a
3 changed files with 35 additions and 13 deletions

View File

@ -641,20 +641,24 @@ public String run() throws YarnException, IOException {
private Response startService(String appName,
final UserGroupInformation ugi) throws IOException,
InterruptedException {
ugi.doAs(new PrivilegedExceptionAction<Void>() {
@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<ApplicationId>() {
@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);
}

View File

@ -34,8 +34,10 @@
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<String> expectedInstances = new HashSet<>();
private Map<String, ApplicationId> serviceAppId = new HashMap<>();
public ServiceClientTest() {
super();
@ -83,7 +87,10 @@ public Configuration getConfig() {
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 Service getStatus(String appName) throws FileNotFoundException {
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 @@ static Service buildLiveGoodService() {
comp.setContainers(containers);
return service;
}
@Override
public synchronized ApplicationId getAppId(String serviceName)
throws IOException, YarnException {
return serviceAppId.get(serviceName);
}
}

View File

@ -978,6 +978,8 @@ public int actionStart(String serviceName) throws YarnException, IOException {
// 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);