Skip to content

Commit edd3c4c

Browse files
Updated to fall back to old command line args if new args are missing (#728)
1 parent b037e95 commit edd3c4c

File tree

1 file changed

+75
-12
lines changed

1 file changed

+75
-12
lines changed

src/main/java/com/microsoft/azure/functions/worker/Application.java

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,40 @@ private void parseCommandLine(String[] args) {
2525
CommandLineParser parser = new DefaultParser();
2626
try {
2727
CommandLine commands = parser.parse(this.OPTIONS, args, true);
28-
this.uri = this.parseUri(commands.getOptionValue(FUNCTIONS_URI_OPTION));
29-
this.workerId = this.parseWorkerId(commands.getOptionValue(FUNCTIONS_WORKER_ID_OPTION));
30-
this.requestId = this.parseRequestId(commands.getOptionValue(FUNCTIONS_REQUEST_ID_OPTION));
31-
this.logToConsole = commands.hasOption(FUNCTIONS_CONSOLE_LOG_OPTION);
28+
29+
if (commands.hasOption("fu")) {
30+
this.uri = this.parseUri(commands.getOptionValue(FUNCTIONS_URI_OPTION));
31+
}else if (commands.hasOption("h") && commands.hasOption("p")) {
32+
this.host = this.parseHost(commands.getOptionValue("h"));
33+
this.port = this.parsePort(commands.getOptionValue("p"));
34+
}else {
35+
throw new ParseException("Error parsing command line options. Please include functions host and port or uri.");
36+
}
37+
38+
if (commands.hasOption("fw")) {
39+
this.workerId = this.parseWorkerId(commands.getOptionValue(FUNCTIONS_WORKER_ID_OPTION));
40+
}else if (commands.hasOption("w")) {
41+
this.workerId = this.parseWorkerId(commands.getOptionValue("w"));
42+
}else {
43+
throw new ParseException("Error parsing command line options. Please include worker id.");
44+
}
45+
46+
if (commands.hasOption("fq")) {
47+
this.requestId = this.parseRequestId(commands.getOptionValue(FUNCTIONS_REQUEST_ID_OPTION));
48+
}else if (commands.hasOption("q")) {
49+
this.requestId = this.parseRequestId(commands.getOptionValue("q"));
50+
}else {
51+
throw new ParseException("Error parsing command line options. Please include request id.");
52+
}
53+
54+
this.logToConsole = commands.hasOption(FUNCTIONS_CONSOLE_LOG_OPTION) || commands.hasOption("l");
55+
3256
if (commands.hasOption(FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION)) {
3357
this.maxMessageSize = this.parseMaxMessageSize(commands.getOptionValue(FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION));
58+
} else if (commands.hasOption("m")) {
59+
this.maxMessageSize = this.parseMaxMessageSize(commands.getOptionValue("m"));
60+
}else {
61+
throw new ParseException("Error parsing command line options. Please include message size in bytes.");
3462
}
3563
this.commandParseSucceeded = true;
3664
} catch (ParseException ex) {
@@ -61,26 +89,46 @@ public static void main(String[] args) {
6189
private boolean logToConsole;
6290
private Integer maxMessageSize = null;
6391
private final Options OPTIONS = new Options()
64-
.addOption(Option.builder("u").longOpt(FUNCTIONS_URI_OPTION)
92+
.addOption(Option.builder("h").longOpt("host")
93+
.hasArg().argName("HostName")
94+
.desc("The address of the machine that the Azure Functions host is running on")
95+
.build())
96+
.addOption(Option.builder("p").longOpt("port")
97+
.hasArg().argName("PortNumber")
98+
.desc("The port number which the Azure Functions host is listening to")
99+
.build())
100+
.addOption(Option.builder("w").longOpt("workerId")
101+
.hasArg().argName("WorkerId")
102+
.desc("The ID of this running worker throughout communication session")
103+
.build())
104+
.addOption(Option.builder("q").longOpt("requestId")
105+
.hasArg().argName("RequestId")
106+
.desc("The startup request ID of this communication session")
107+
.build())
108+
.addOption(Option.builder("l").longOpt("consoleLog")
109+
.desc("Whether to duplicate all host logs to console as well")
110+
.build())
111+
.addOption(Option.builder("m").longOpt("grpcMaxMessageLength")
112+
.hasArg().argName("MessageSizeInBytes")
113+
.desc("The maximum message size could be used by GRPC protocol")
114+
.build())
115+
.addOption(Option.builder("fu").longOpt(FUNCTIONS_URI_OPTION)
65116
.hasArg().argName("Uri")
66117
.desc("The uri of the machine that the Azure Functions host is running on")
67-
.required()
68118
.build())
69-
.addOption(Option.builder("w").longOpt(FUNCTIONS_WORKER_ID_OPTION)
119+
.addOption(Option.builder("fw").longOpt(FUNCTIONS_WORKER_ID_OPTION)
70120
.hasArg().argName("WorkerId")
71121
.desc("The ID of this running worker throughout communication session")
72-
.required()
73122
.build())
74-
.addOption(Option.builder("q").longOpt(FUNCTIONS_REQUEST_ID_OPTION)
123+
.addOption(Option.builder("fq").longOpt(FUNCTIONS_REQUEST_ID_OPTION)
75124
.hasArg().argName("RequestId")
76125
.desc("The startup request ID of this communication session")
77-
.required()
78126
.build())
79-
.addOption(Option.builder("l").longOpt(FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION)
127+
.addOption(Option.builder("fm").longOpt(FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION)
80128
.hasArg().argName("MessageSizeInBytes")
81129
.desc("The maximum message size could be used by GRPC protocol")
82130
.build())
83-
.addOption(Option.builder("m").longOpt(FUNCTIONS_CONSOLE_LOG_OPTION)
131+
.addOption(Option.builder("fl").longOpt(FUNCTIONS_CONSOLE_LOG_OPTION)
84132
.desc("Whether to duplicate all host logs to console as well")
85133
.build());
86134

@@ -89,6 +137,21 @@ public String getHost() {
89137
return this.host;
90138
}
91139

140+
private String parseHost(String input) { return input; }
141+
142+
private int parsePort(String input) throws ParseException {
143+
try {
144+
int result = Integer.parseInt(input);
145+
if (result < 1 || result > 65535) {
146+
throw new IndexOutOfBoundsException("port number out of range");
147+
}
148+
return result;
149+
} catch (NumberFormatException | IndexOutOfBoundsException ex) {
150+
throw new ParseException(String.format(
151+
"port number \"%s\" is not qualified. It must be an integer within range [1, 65535]", input));
152+
}
153+
}
154+
92155
@Override
93156
public int getPort() {
94157
return this.port;

0 commit comments

Comments
 (0)