19
19
package com .dtstack .flink .sql .launcher ;
20
20
21
21
import avro .shaded .com .google .common .collect .Lists ;
22
+ import com .dtstack .flink .sql .util .PluginUtil ;
22
23
import org .apache .commons .cli .BasicParser ;
23
24
import org .apache .commons .cli .CommandLine ;
24
25
import org .apache .commons .cli .Options ;
25
26
import org .apache .commons .lang .StringUtils ;
26
27
import org .apache .flink .hadoop .shaded .com .google .common .base .Charsets ;
27
28
import org .apache .flink .hadoop .shaded .com .google .common .base .Preconditions ;
28
-
29
29
import java .io .File ;
30
30
import java .io .FileInputStream ;
31
31
import java .net .URLEncoder ;
32
32
import java .util .List ;
33
33
import java .util .Map ;
34
- import java .util .Properties ;
35
-
36
- import static com .dtstack .flink .sql .launcher .LauncherOptions .*;
37
- import static com .dtstack .flink .sql .launcher .ClusterMode .*;
38
-
34
+ import com .dtstack .flink .sql .ClusterMode ;
39
35
40
36
/**
41
37
* The Parser of Launcher commandline options
45
41
*/
46
42
public class LauncherOptionParser {
47
43
44
+ public static final String OPTION_MODE = "mode" ;
45
+
46
+ public static final String OPTION_NAME = "name" ;
47
+
48
+ public static final String OPTION_SQL = "sql" ;
49
+
50
+ public static final String OPTION_FLINK_CONF_DIR = "flinkconf" ;
51
+
52
+ public static final String OPTION_YARN_CONF_DIR = "yarnconf" ;
53
+
54
+ public static final String OPTION_LOCAL_SQL_PLUGIN_PATH = "localSqlPluginPath" ;
55
+
56
+ public static final String OPTION_REMOTE_SQL_PLUGIN_PATH = "remoteSqlPluginPath" ;
57
+
58
+ public static final String OPTION_ADDJAR = "addjar" ;
59
+
60
+ public static final String OPTION_CONF_PROP = "confProp" ;
61
+
62
+ public static final String OPTION_SAVE_POINT_PATH = "savePointPath" ;
63
+
64
+ public static final String OPTION_ALLOW_NON_RESTORED_STATE = "allowNonRestoredState" ;
65
+
48
66
private Options options = new Options ();
49
67
50
68
private BasicParser parser = new BasicParser ();
51
69
52
- private Properties properties = new Properties ();
70
+ private LauncherOptions properties = new LauncherOptions ();
53
71
54
72
public LauncherOptionParser (String [] args ) {
55
- options .addOption (LauncherOptions . OPTION_MODE , true , "Running mode" );
73
+ options .addOption (OPTION_MODE , true , "Running mode" );
56
74
options .addOption (OPTION_SQL , true , "Job sql file" );
57
75
options .addOption (OPTION_NAME , true , "Job name" );
58
76
options .addOption (OPTION_FLINK_CONF_DIR , true , "Flink configuration directory" );
@@ -62,11 +80,14 @@ public LauncherOptionParser(String[] args) {
62
80
options .addOption (OPTION_CONF_PROP , true , "sql ref prop,eg specify event time" );
63
81
options .addOption (OPTION_YARN_CONF_DIR , true , "Yarn and hadoop configuration directory" );
64
82
83
+ options .addOption (OPTION_SAVE_POINT_PATH , true , "Savepoint restore path" );
84
+ options .addOption (OPTION_ALLOW_NON_RESTORED_STATE , true , "Flag indicating whether non restored state is allowed if the savepoint" );
85
+
65
86
try {
66
87
CommandLine cl = parser .parse (options , args );
67
- String mode = cl .getOptionValue (OPTION_MODE , MODE_LOCAL );
88
+ String mode = cl .getOptionValue (OPTION_MODE , ClusterMode . local . name () );
68
89
//check mode
69
- properties .put ( OPTION_MODE , mode );
90
+ properties .setMode ( mode );
70
91
71
92
String job = Preconditions .checkNotNull (cl .getOptionValue (OPTION_SQL ),
72
93
"Must specify job file using option '" + OPTION_SQL + "'" );
@@ -76,78 +97,65 @@ public LauncherOptionParser(String[] args) {
76
97
in .read (filecontent );
77
98
String content = new String (filecontent , "UTF-8" );
78
99
String sql = URLEncoder .encode (content , Charsets .UTF_8 .name ());
79
- properties .put (OPTION_SQL , sql );
80
-
100
+ properties .setSql (sql );
81
101
String localPlugin = Preconditions .checkNotNull (cl .getOptionValue (OPTION_LOCAL_SQL_PLUGIN_PATH ));
82
- properties .put (OPTION_LOCAL_SQL_PLUGIN_PATH , localPlugin );
83
-
102
+ properties .setLocalSqlPluginPath (localPlugin );
84
103
String remotePlugin = cl .getOptionValue (OPTION_REMOTE_SQL_PLUGIN_PATH );
85
- if (!mode . equalsIgnoreCase ( ClusterMode . MODE_LOCAL )){
104
+ if (!ClusterMode . local . name (). equals ( mode )){
86
105
Preconditions .checkNotNull (remotePlugin );
87
- properties .put ( OPTION_REMOTE_SQL_PLUGIN_PATH , remotePlugin );
106
+ properties .setRemoteSqlPluginPath ( remotePlugin );
88
107
}
89
-
90
108
String name = Preconditions .checkNotNull (cl .getOptionValue (OPTION_NAME ));
91
- properties .put (OPTION_NAME , name );
92
-
109
+ properties .setName (name );
93
110
String addJar = cl .getOptionValue (OPTION_ADDJAR );
94
111
if (StringUtils .isNotBlank (addJar )){
95
- properties .put ( OPTION_ADDJAR , addJar );
112
+ properties .setAddjar ( addJar );
96
113
}
97
-
98
114
String confProp = cl .getOptionValue (OPTION_CONF_PROP );
99
115
if (StringUtils .isNotBlank (confProp )){
100
- properties .put ( OPTION_CONF_PROP , confProp );
116
+ properties .setConfProp ( confProp );
101
117
}
102
-
103
118
String flinkConfDir = cl .getOptionValue (OPTION_FLINK_CONF_DIR );
104
119
if (StringUtils .isNotBlank (flinkConfDir )) {
105
- properties .put ( OPTION_FLINK_CONF_DIR , flinkConfDir );
120
+ properties .setFlinkconf ( flinkConfDir );
106
121
}
107
122
108
123
String yarnConfDir = cl .getOptionValue (OPTION_YARN_CONF_DIR );
109
124
if (StringUtils .isNotBlank (yarnConfDir )) {
110
- properties .put (OPTION_YARN_CONF_DIR , yarnConfDir );
125
+ properties .setYarnconf (yarnConfDir );
126
+ }
127
+
128
+ String savePointPath = cl .getOptionValue (OPTION_SAVE_POINT_PATH );
129
+ if (StringUtils .isNotBlank (savePointPath )) {
130
+ properties .setSavePointPath (savePointPath );
131
+ }
132
+
133
+ String allow_non = cl .getOptionValue (OPTION_ALLOW_NON_RESTORED_STATE );
134
+ if (StringUtils .isNotBlank (allow_non )) {
135
+ properties .setAllowNonRestoredState (allow_non );
111
136
}
112
137
113
138
} catch (Exception e ) {
114
139
throw new RuntimeException (e );
115
140
}
116
-
117
141
}
118
142
119
- public Properties getProperties (){
143
+ public LauncherOptions getLauncherOptions (){
120
144
return properties ;
121
145
}
122
146
123
- public Object getVal (String key ){
124
- return properties .get (key );
125
- }
126
-
127
- public List <String > getAllArgList (){
147
+ public List <String > getProgramExeArgList () throws Exception {
148
+ Map <String ,Object > mapConf = PluginUtil .ObjectToMap (properties );
128
149
List <String > args = Lists .newArrayList ();
129
- for (Map .Entry <Object , Object > one : properties .entrySet ()){
130
- args .add ("-" + one .getKey ().toString ());
131
- args .add (one .getValue ().toString ());
132
- }
133
-
134
- return args ;
135
- }
136
-
137
- public List <String > getProgramExeArgList (){
138
- List <String > args = Lists .newArrayList ();
139
- for (Map .Entry <Object , Object > one : properties .entrySet ()){
140
- String key = one .getKey ().toString ();
150
+ for (Map .Entry <String , Object > one : mapConf .entrySet ()){
151
+ String key = one .getKey ();
141
152
if (OPTION_FLINK_CONF_DIR .equalsIgnoreCase (key )
142
153
|| OPTION_YARN_CONF_DIR .equalsIgnoreCase (key )){
143
154
continue ;
144
155
}
145
-
146
156
args .add ("-" + key );
147
157
args .add (one .getValue ().toString ());
148
158
}
149
-
150
159
return args ;
151
160
}
152
-
153
161
}
0 commit comments