Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,40 @@ private void parseCommandLine(String[] args) {
CommandLineParser parser = new DefaultParser();
try {
CommandLine commands = parser.parse(this.OPTIONS, args, true);
this.uri = this.parseUri(commands.getOptionValue(FUNCTIONS_URI_OPTION));
this.workerId = this.parseWorkerId(commands.getOptionValue(FUNCTIONS_WORKER_ID_OPTION));
this.requestId = this.parseRequestId(commands.getOptionValue(FUNCTIONS_REQUEST_ID_OPTION));
this.logToConsole = commands.hasOption(FUNCTIONS_CONSOLE_LOG_OPTION);

if (commands.hasOption("fu")) {
this.uri = this.parseUri(commands.getOptionValue(FUNCTIONS_URI_OPTION));
}else if (commands.hasOption("h") && commands.hasOption("p")) {
this.host = this.parseHost(commands.getOptionValue("h"));
this.port = this.parsePort(commands.getOptionValue("p"));
}else {
throw new ParseException("Error parsing command line options. Please include functions host and port or uri.");
}

if (commands.hasOption("fw")) {
this.workerId = this.parseWorkerId(commands.getOptionValue(FUNCTIONS_WORKER_ID_OPTION));
}else if (commands.hasOption("w")) {
this.workerId = this.parseWorkerId(commands.getOptionValue("w"));
}else {
throw new ParseException("Error parsing command line options. Please include worker id.");
}

if (commands.hasOption("fq")) {
this.requestId = this.parseRequestId(commands.getOptionValue(FUNCTIONS_REQUEST_ID_OPTION));
}else if (commands.hasOption("q")) {
this.requestId = this.parseRequestId(commands.getOptionValue("q"));
}else {
throw new ParseException("Error parsing command line options. Please include request id.");
}

this.logToConsole = commands.hasOption(FUNCTIONS_CONSOLE_LOG_OPTION) || commands.hasOption("l");

if (commands.hasOption(FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION)) {
this.maxMessageSize = this.parseMaxMessageSize(commands.getOptionValue(FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION));
} else if (commands.hasOption("m")) {
this.maxMessageSize = this.parseMaxMessageSize(commands.getOptionValue("m"));
}else {
throw new ParseException("Error parsing command line options. Please include message size in bytes.");
}
this.commandParseSucceeded = true;
} catch (ParseException ex) {
Expand Down Expand Up @@ -61,26 +89,46 @@ public static void main(String[] args) {
private boolean logToConsole;
private Integer maxMessageSize = null;
private final Options OPTIONS = new Options()
.addOption(Option.builder("u").longOpt(FUNCTIONS_URI_OPTION)
.addOption(Option.builder("h").longOpt("host")
.hasArg().argName("HostName")
.desc("The address of the machine that the Azure Functions host is running on")
.build())
.addOption(Option.builder("p").longOpt("port")
.hasArg().argName("PortNumber")
.desc("The port number which the Azure Functions host is listening to")
.build())
.addOption(Option.builder("w").longOpt("workerId")
.hasArg().argName("WorkerId")
.desc("The ID of this running worker throughout communication session")
.build())
.addOption(Option.builder("q").longOpt("requestId")
.hasArg().argName("RequestId")
.desc("The startup request ID of this communication session")
.build())
.addOption(Option.builder("l").longOpt("consoleLog")
.desc("Whether to duplicate all host logs to console as well")
.build())
.addOption(Option.builder("m").longOpt("grpcMaxMessageLength")
.hasArg().argName("MessageSizeInBytes")
.desc("The maximum message size could be used by GRPC protocol")
.build())
.addOption(Option.builder("fu").longOpt(FUNCTIONS_URI_OPTION)
.hasArg().argName("Uri")
.desc("The uri of the machine that the Azure Functions host is running on")
.required()
.build())
.addOption(Option.builder("w").longOpt(FUNCTIONS_WORKER_ID_OPTION)
.addOption(Option.builder("fw").longOpt(FUNCTIONS_WORKER_ID_OPTION)
.hasArg().argName("WorkerId")
.desc("The ID of this running worker throughout communication session")
.required()
.build())
.addOption(Option.builder("q").longOpt(FUNCTIONS_REQUEST_ID_OPTION)
.addOption(Option.builder("fq").longOpt(FUNCTIONS_REQUEST_ID_OPTION)
.hasArg().argName("RequestId")
.desc("The startup request ID of this communication session")
.required()
.build())
.addOption(Option.builder("l").longOpt(FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION)
.addOption(Option.builder("fm").longOpt(FUNCTIONS_GRPC_MAX_MESSAGE_LENGTH_OPTION)
.hasArg().argName("MessageSizeInBytes")
.desc("The maximum message size could be used by GRPC protocol")
.build())
.addOption(Option.builder("m").longOpt(FUNCTIONS_CONSOLE_LOG_OPTION)
.addOption(Option.builder("fl").longOpt(FUNCTIONS_CONSOLE_LOG_OPTION)
.desc("Whether to duplicate all host logs to console as well")
.build());

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

private String parseHost(String input) { return input; }

private int parsePort(String input) throws ParseException {
try {
int result = Integer.parseInt(input);
if (result < 1 || result > 65535) {
throw new IndexOutOfBoundsException("port number out of range");
}
return result;
} catch (NumberFormatException | IndexOutOfBoundsException ex) {
throw new ParseException(String.format(
"port number \"%s\" is not qualified. It must be an integer within range [1, 65535]", input));
}
}

@Override
public int getPort() {
return this.port;
Expand Down