|
20 | 20 |
|
21 | 21 | import com.dtstack.flink.sql.options.LauncherOptions; |
22 | 22 | import com.dtstack.flink.sql.util.PluginUtil; |
| 23 | +import org.apache.flink.api.common.cache.DistributedCache; |
23 | 24 | import org.apache.flink.client.deployment.ClusterSpecification; |
24 | 25 | import org.apache.flink.client.program.ClusterClient; |
25 | 26 | import org.apache.flink.runtime.jobgraph.JobGraph; |
26 | 27 | import org.apache.flink.yarn.AbstractYarnClusterDescriptor; |
27 | 28 | import org.apache.hadoop.yarn.api.records.ApplicationId; |
28 | 29 | import org.slf4j.Logger; |
29 | 30 | import org.slf4j.LoggerFactory; |
30 | | - |
| 31 | +import java.net.MalformedURLException; |
| 32 | +import java.net.URL; |
| 33 | +import java.util.Map; |
31 | 34 | import java.util.Properties; |
32 | 35 |
|
33 | 36 | /** |
|
39 | 42 |
|
40 | 43 | public class PerJobSubmitter { |
41 | 44 |
|
| 45 | + private final static String CLASS_FILE_NAME_PRESTR = "class_path"; |
| 46 | + |
42 | 47 | private static final Logger LOG = LoggerFactory.getLogger(PerJobSubmitter.class); |
43 | 48 |
|
44 | 49 | public static String submit(LauncherOptions launcherOptions, JobGraph jobGraph) throws Exception { |
45 | | - |
46 | 50 | Properties confProperties = PluginUtil.jsonStrToObject(launcherOptions.getConfProp(), Properties.class); |
47 | 51 | ClusterSpecification clusterSpecification = FLinkPerJobResourceUtil.createClusterSpecification(confProperties); |
48 | | - |
49 | 52 | PerJobClusterClientBuilder perJobClusterClientBuilder = new PerJobClusterClientBuilder(); |
50 | 53 | perJobClusterClientBuilder.init(launcherOptions.getYarnconf()); |
51 | | - |
52 | 54 | String flinkJarPath = launcherOptions.getFlinkJarPath(); |
53 | | - |
54 | 55 | AbstractYarnClusterDescriptor yarnClusterDescriptor = perJobClusterClientBuilder.createPerJobClusterDescriptor(confProperties, flinkJarPath, launcherOptions.getQueue()); |
55 | | - ClusterClient<ApplicationId> clusterClient = yarnClusterDescriptor.deployJobCluster(clusterSpecification, jobGraph,true); |
56 | | - |
| 56 | + ClusterClient<ApplicationId> clusterClient = yarnClusterDescriptor.deployJobCluster(clusterSpecification,fillJobGraphClassPath(jobGraph),true); |
57 | 57 | String applicationId = clusterClient.getClusterId().toString(); |
58 | 58 | String flinkJobId = jobGraph.getJobID().toString(); |
59 | | - |
60 | 59 | String tips = String.format("deploy per_job with appId: %s, jobId: %s", applicationId, flinkJobId); |
61 | 60 | System.out.println(tips); |
62 | 61 | LOG.info(tips); |
63 | | - |
64 | 62 | return applicationId; |
65 | 63 | } |
| 64 | + |
| 65 | + private static JobGraph fillJobGraphClassPath(JobGraph jobGraph) throws MalformedURLException { |
| 66 | + Map<String, DistributedCache.DistributedCacheEntry> jobCacheFileConfig = jobGraph.getUserArtifacts(); |
| 67 | + for(Map.Entry<String, DistributedCache.DistributedCacheEntry> tmp : jobCacheFileConfig.entrySet()){ |
| 68 | + if(tmp.getKey().startsWith(CLASS_FILE_NAME_PRESTR)){ |
| 69 | + jobGraph.getClasspaths().add(new URL("file:" + tmp.getValue().filePath)); |
| 70 | + } |
| 71 | + } |
| 72 | + return jobGraph; |
| 73 | + } |
66 | 74 | } |
0 commit comments