5151
5252import com .dtstack .flink .sql .enums .ClusterMode ;
5353import org .apache .hadoop .yarn .exceptions .YarnException ;
54+ import org .apache .hadoop .yarn .util .StringHelper ;
55+
5456import java .io .IOException ;
5557import java .util .stream .Collectors ;
5658import java .util .stream .Stream ;
@@ -113,7 +115,15 @@ public static ClusterClient createYarnClient(Options launcherOptions, String mod
113115 ApplicationId applicationId = null ;
114116 ClusterClient clusterClient = null ;
115117 if (mode .equals (ClusterMode .yarn .name ())) {//on yarn cluster mode
116- applicationId = getYarnClusterApplicationId (yarnClient );
118+ String yarnSessionConf = launcherOptions .getYarnSessionConf ();
119+ yarnSessionConf = URLDecoder .decode (yarnSessionConf , Charsets .UTF_8 .toString ());
120+ Properties yarnSessionConfProperties = PluginUtil .jsonStrToObject (yarnSessionConf , Properties .class );
121+ String yid = yarnSessionConfProperties .get ("yid" ).toString ();
122+ if (StringUtils .isNotBlank (yid )){
123+ applicationId = toApplicationId (yid );
124+ }else {
125+ applicationId = getYarnClusterApplicationId (yarnClient );
126+ }
117127 System .out .println ("applicationId=" +applicationId .toString ());
118128
119129 AbstractYarnClusterDescriptor clusterDescriptor = new YarnClusterDescriptor (
@@ -249,4 +259,21 @@ private static org.apache.hadoop.conf.Configuration haYarnConf(org.apache.hadoop
249259 return yarnConf ;
250260 }
251261
262+ private static ApplicationId toApplicationId (String appIdStr ) {
263+ Iterator <String > it = StringHelper ._split (appIdStr ).iterator ();
264+ if (!(it .next ()).equals ("application" )) {
265+ throw new IllegalArgumentException ("Invalid ApplicationId prefix: " + appIdStr + ". The valid ApplicationId should start with prefix " + "application" );
266+ } else {
267+ try {
268+ return toApplicationId (it );
269+ } catch (NumberFormatException e ) {
270+ throw new IllegalArgumentException ("Invalid AppAttemptId: " + appIdStr , e );
271+ }
272+ }
273+ }
274+
275+ private static ApplicationId toApplicationId (Iterator <String > it ) throws NumberFormatException {
276+ return ApplicationId .newInstance (Long .parseLong (it .next ()), Integer .parseInt (it .next ()));
277+ }
278+
252279}
0 commit comments