2020
2121import static org .apache .commons .lang3 .StringUtils .isNotEmpty ;
2222import static org .apache .pulsar .common .functions .Utils .inferMissingArguments ;
23- import com .beust .jcommander .IStringConverter ;
24- import com .beust .jcommander .JCommander ;
25- import com .beust .jcommander .Parameter ;
2623import com .google .gson .Gson ;
2724import com .google .gson .GsonBuilder ;
2825import com .google .gson .JsonParser ;
8784import org .apache .pulsar .functions .utils .functions .FunctionUtils ;
8885import org .apache .pulsar .functions .utils .io .Connector ;
8986import org .apache .pulsar .functions .utils .io .ConnectorUtils ;
87+ import picocli .CommandLine ;
88+ import picocli .CommandLine .ITypeConverter ;
89+ import picocli .CommandLine .Option ;
90+ import picocli .CommandLine .TypeConversionException ;
9091
9192@ Slf4j
9293public class LocalRunner implements AutoCloseable {
@@ -115,95 +116,95 @@ private static class UserCodeClassLoader {
115116 boolean classLoaderCreated ;
116117 }
117118
118- public static class FunctionConfigConverter implements IStringConverter <FunctionConfig > {
119+ public static class FunctionConfigConverter implements ITypeConverter <FunctionConfig > {
119120 @ Override
120121 public FunctionConfig convert (String value ) {
121122 try {
122123 return ObjectMapperFactory .getMapper ().reader ().readValue (value , FunctionConfig .class );
123124 } catch (IOException e ) {
124- throw new RuntimeException ( "Failed to parse function config:" , e );
125+ throw new TypeConversionException ( e . getMessage () );
125126 }
126127 }
127128 }
128129
129- public static class SourceConfigConverter implements IStringConverter <SourceConfig > {
130+ public static class SourceConfigConverter implements ITypeConverter <SourceConfig > {
130131 @ Override
131132 public SourceConfig convert (String value ) {
132133 try {
133134 return ObjectMapperFactory .getMapper ().reader ().readValue (value , SourceConfig .class );
134135 } catch (IOException e ) {
135- throw new RuntimeException ( "Failed to parse source config:" , e );
136+ throw new TypeConversionException ( e . getMessage () );
136137 }
137138 }
138139 }
139140
140- public static class SinkConfigConverter implements IStringConverter <SinkConfig > {
141+ public static class SinkConfigConverter implements ITypeConverter <SinkConfig > {
141142 @ Override
142143 public SinkConfig convert (String value ) {
143144 try {
144145 return ObjectMapperFactory .getMapper ().reader ().readValue (value , SinkConfig .class );
145146 } catch (IOException e ) {
146- throw new RuntimeException ( "Failed to parse sink config:" , e );
147+ throw new TypeConversionException ( e . getMessage () );
147148 }
148149 }
149150 }
150151
151- public static class RuntimeConverter implements IStringConverter <RuntimeEnv > {
152+ public static class RuntimeConverter implements ITypeConverter <RuntimeEnv > {
152153 @ Override
153154 public RuntimeEnv convert (String value ) {
154155 return RuntimeEnv .valueOf (value );
155156 }
156157 }
157158
158- @ Parameter (names = "--functionConfig" , description = "The json representation of FunctionConfig" ,
159+ @ Option (names = "--functionConfig" , description = "The json representation of FunctionConfig" ,
159160 hidden = true , converter = FunctionConfigConverter .class )
160161 protected FunctionConfig functionConfig ;
161- @ Parameter (names = "--sourceConfig" , description = "The json representation of SourceConfig" ,
162+ @ Option (names = "--sourceConfig" , description = "The json representation of SourceConfig" ,
162163 hidden = true , converter = SourceConfigConverter .class )
163164 protected SourceConfig sourceConfig ;
164- @ Parameter (names = "--sinkConfig" , description = "The json representation of SinkConfig" ,
165+ @ Option (names = "--sinkConfig" , description = "The json representation of SinkConfig" ,
165166 hidden = true , converter = SinkConfigConverter .class )
166167 protected SinkConfig sinkConfig ;
167- @ Parameter (names = "--stateStorageImplClass" , description = "The implemenatation class "
168+ @ Option (names = "--stateStorageImplClass" , description = "The implemenatation class "
168169 + "state storage service (by default Apache BookKeeper)" , hidden = true , required = false )
169170 protected String stateStorageImplClass ;
170- @ Parameter (names = "--stateStorageServiceUrl" , description = "The URL for the state storage service "
171+ @ Option (names = "--stateStorageServiceUrl" , description = "The URL for the state storage service "
171172 + "(by default Apache BookKeeper)" , hidden = true )
172173 protected String stateStorageServiceUrl ;
173- @ Parameter (names = "--brokerServiceUrl" , description = "The URL for the Pulsar broker" , hidden = true )
174+ @ Option (names = "--brokerServiceUrl" , description = "The URL for the Pulsar broker" , hidden = true )
174175 protected String brokerServiceUrl ;
175- @ Parameter (names = "--webServiceUrl" , description = "The URL for the Pulsar web service" , hidden = true )
176+ @ Option (names = "--webServiceUrl" , description = "The URL for the Pulsar web service" , hidden = true )
176177 protected String webServiceUrl = null ;
177- @ Parameter (names = "--clientAuthPlugin" , description = "Client authentication plugin using which "
178+ @ Option (names = "--clientAuthPlugin" , description = "Client authentication plugin using which "
178179 + "function-process can connect to broker" , hidden = true )
179180 protected String clientAuthPlugin ;
180- @ Parameter (names = "--clientAuthParams" , description = "Client authentication param" , hidden = true )
181+ @ Option (names = "--clientAuthParams" , description = "Client authentication param" , hidden = true )
181182 protected String clientAuthParams ;
182- @ Parameter (names = "--useTls" , description = "Use tls connection\n " , hidden = true , arity = 1 )
183+ @ Option (names = "--useTls" , description = "Use tls connection\n " , hidden = true , arity = "1" )
183184 protected boolean useTls ;
184- @ Parameter (names = "--tlsAllowInsecureConnection" , description = "Allow insecure tls connection\n " ,
185- hidden = true , arity = 1 )
185+ @ Option (names = "--tlsAllowInsecureConnection" , description = "Allow insecure tls connection\n " ,
186+ hidden = true , arity = "1" )
186187 protected boolean tlsAllowInsecureConnection ;
187- @ Parameter (names = "--tlsHostNameVerificationEnabled" , description = "Enable hostname verification" , hidden = true
188- , arity = 1 )
188+ @ Option (names = "--tlsHostNameVerificationEnabled" , description = "Enable hostname verification" , hidden = true
189+ , arity = "1" )
189190 protected boolean tlsHostNameVerificationEnabled ;
190- @ Parameter (names = "--tlsTrustCertFilePath" , description = "tls trust cert file path" , hidden = true )
191+ @ Option (names = "--tlsTrustCertFilePath" , description = "tls trust cert file path" , hidden = true )
191192 protected String tlsTrustCertFilePath ;
192- @ Parameter (names = "--instanceIdOffset" , description = "Start the instanceIds from this offset" , hidden = true )
193+ @ Option (names = "--instanceIdOffset" , description = "Start the instanceIds from this offset" , hidden = true )
193194 protected int instanceIdOffset = 0 ;
194- @ Parameter (names = "--runtime" , description = "Function runtime to use (Thread/Process)" , hidden = true ,
195+ @ Option (names = "--runtime" , description = "Function runtime to use (Thread/Process)" , hidden = true ,
195196 converter = RuntimeConverter .class )
196197 protected RuntimeEnv runtimeEnv ;
197- @ Parameter (names = "--secretsProviderClassName" ,
198+ @ Option (names = "--secretsProviderClassName" ,
198199 description = "Whats the classname of secrets provider" , hidden = true )
199200 protected String secretsProviderClassName ;
200- @ Parameter (names = "--secretsProviderConfig" ,
201+ @ Option (names = "--secretsProviderConfig" ,
201202 description = "Whats the config for the secrets provider" , hidden = true )
202203 protected String secretsProviderConfig ;
203- @ Parameter (names = "--metricsPortStart" , description = "The starting port range for metrics server. When running "
204+ @ Option (names = "--metricsPortStart" , description = "The starting port range for metrics server. When running "
204205 + "instances as threads, one metrics server is used to host the stats for all instances." , hidden = true )
205206 protected Integer metricsPortStart ;
206- @ Parameter (names = "--exitOnError" , description = "The starting port range for metrics server. When running "
207+ @ Option (names = "--exitOnError" , description = "The starting port range for metrics server. When running "
207208 + "instances as threads, one metrics server is used to host the stats for all instances." , hidden = true )
208209 protected boolean exitOnError ;
209210
@@ -212,11 +213,10 @@ public RuntimeEnv convert(String value) {
212213
213214 public static void main (String [] args ) throws Exception {
214215 LocalRunner localRunner = LocalRunner .builder ().build ();
215- JCommander jcommander = new JCommander (localRunner );
216- jcommander .setProgramName ("LocalRunner" );
216+ CommandLine jcommander = new CommandLine (localRunner );
217+ jcommander .setCommandName ("LocalRunner" );
217218
218- // parse args by JCommander
219- jcommander .parse (args );
219+ jcommander .parseArgs (args );
220220 try {
221221 localRunner .start (true );
222222 } catch (Exception e ) {
0 commit comments