|
@@ -19,6 +19,7 @@ import org.apache.hadoop.fs.FileStatus;
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
+import org.apache.hadoop.yarn.client.api.AppAdminClient;
|
|
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
|
|
import org.apache.hadoop.yarn.service.api.ServiceApiConstants;
|
|
|
import org.apache.hadoop.yarn.service.api.records.Artifact;
|
|
@@ -27,7 +28,7 @@ import org.apache.hadoop.yarn.service.api.records.ConfigFile;
|
|
|
import org.apache.hadoop.yarn.service.api.records.Resource;
|
|
|
import org.apache.hadoop.yarn.service.api.records.ResourceInformation;
|
|
|
import org.apache.hadoop.yarn.service.api.records.Service;
|
|
|
-import org.apache.hadoop.yarn.service.client.ServiceClient;
|
|
|
+import org.apache.hadoop.yarn.service.utils.ServiceApiUtil;
|
|
|
import org.apache.hadoop.yarn.submarine.client.cli.param.Quicklink;
|
|
|
import org.apache.hadoop.yarn.submarine.client.cli.param.RunJobParameters;
|
|
|
import org.apache.hadoop.yarn.submarine.common.ClientContext;
|
|
@@ -53,6 +54,8 @@ import java.util.Set;
|
|
|
import java.util.StringTokenizer;
|
|
|
|
|
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
|
|
|
+import static org.apache.hadoop.yarn.service.exceptions.LauncherExitCodes.EXIT_SUCCESS;
|
|
|
+import static org.apache.hadoop.yarn.service.utils.ServiceApiUtil.jsonSerDeser;
|
|
|
|
|
|
/**
|
|
|
* Submit a job to cluster
|
|
@@ -530,6 +533,20 @@ public class YarnServiceJobSubmitter implements JobSubmitter {
|
|
|
return serviceSpec;
|
|
|
}
|
|
|
|
|
|
+ private String generateServiceSpecFile(Service service) throws IOException {
|
|
|
+ File serviceSpecFile = File.createTempFile(service.getName(), ".json");
|
|
|
+ String buffer = jsonSerDeser.toJson(service);
|
|
|
+ Writer w = new OutputStreamWriter(new FileOutputStream(serviceSpecFile),
|
|
|
+ "UTF-8");
|
|
|
+ PrintWriter pw = new PrintWriter(w);
|
|
|
+ try {
|
|
|
+ pw.append(buffer);
|
|
|
+ } finally {
|
|
|
+ pw.close();
|
|
|
+ }
|
|
|
+ return serviceSpecFile.getAbsolutePath();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* {@inheritDoc}
|
|
|
*/
|
|
@@ -537,13 +554,30 @@ public class YarnServiceJobSubmitter implements JobSubmitter {
|
|
|
public ApplicationId submitJob(RunJobParameters parameters)
|
|
|
throws IOException, YarnException {
|
|
|
createServiceByParameters(parameters);
|
|
|
- ServiceClient serviceClient = YarnServiceUtils.createServiceClient(
|
|
|
+ String serviceSpecFile = generateServiceSpecFile(serviceSpec);
|
|
|
+
|
|
|
+ AppAdminClient appAdminClient = YarnServiceUtils.createServiceClient(
|
|
|
clientContext.getYarnConfig());
|
|
|
- ApplicationId appid = serviceClient.actionCreate(serviceSpec);
|
|
|
- serviceClient.stop();
|
|
|
+ int code = appAdminClient.actionLaunch(serviceSpecFile,
|
|
|
+ serviceSpec.getName(), null, null);
|
|
|
+ if(code != EXIT_SUCCESS) {
|
|
|
+ throw new YarnException("Fail to launch application with exit code:" +
|
|
|
+ code);
|
|
|
+ }
|
|
|
+
|
|
|
+ String appStatus=appAdminClient.getStatusString(serviceSpec.getName());
|
|
|
+ Service app=ServiceApiUtil.jsonSerDeser.fromJson(appStatus);
|
|
|
+ if(app.getId() == null) {
|
|
|
+ throw new YarnException("Can't get application id for Service " +
|
|
|
+ serviceSpec.getName());
|
|
|
+ }
|
|
|
+ ApplicationId appid = ApplicationId.fromString(app.getId());
|
|
|
+ appAdminClient.stop();
|
|
|
return appid;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@VisibleForTesting
|
|
|
public Service getServiceSpec() {
|
|
|
return serviceSpec;
|