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