From 0d56a51e9cff1a63a9cc3f6b911dbc38b23649db Mon Sep 17 00:00:00 2001 From: Khyati Mahendru Date: Fri, 22 Nov 2024 06:27:32 +0000 Subject: [PATCH 1/3] Update Registrar Command Line Options to use arg_name instead of arg_type --- .../google/udmi/util/CommandLineOption.java | 5 +++++ .../udmi/util/CommandLineProcessor.java | 6 +++--- .../google/daq/mqtt/registrar/Registrar.java | 19 ++++++++++--------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/com/google/udmi/util/CommandLineOption.java b/common/src/main/java/com/google/udmi/util/CommandLineOption.java index 4753f3ef5..1ee4a967d 100644 --- a/common/src/main/java/com/google/udmi/util/CommandLineOption.java +++ b/common/src/main/java/com/google/udmi/util/CommandLineOption.java @@ -33,4 +33,9 @@ * Set the argument type description. */ String arg_type() default NO_VALUE; + + /** + * Set the argument name. + */ + String arg_name() default NO_VALUE; } diff --git a/common/src/main/java/com/google/udmi/util/CommandLineProcessor.java b/common/src/main/java/com/google/udmi/util/CommandLineProcessor.java index c9734cb2b..cf128e68d 100644 --- a/common/src/main/java/com/google/udmi/util/CommandLineProcessor.java +++ b/common/src/main/java/com/google/udmi/util/CommandLineProcessor.java @@ -91,8 +91,8 @@ private void showUsage() { public void showUsage(String message) { ifNotNullThen(message, m -> System.err.println(m)); System.err.println("Options supported:"); - optionMap.forEach((option, method) -> System.err.printf(" %s %1s %s%n", - option.short_form(), option.arg_type(), option.description())); + optionMap.forEach((option, method) -> System.err.printf(" %s %10s %s%n", + option.short_form(), option.arg_name(), option.description())); System.exit(message == null ? LINUX_SUCCESS_CODE : LINUX_ERROR_CODE); } @@ -131,7 +131,7 @@ private boolean processArgEntry(String arg, CommandLineOption option, Method met if (method.equals(showHelpMethod)) { showUsage(); } else if (requiresArg(method)) { - checkState(!option.arg_type().isBlank(), "Option with argument missing type parameter"); + checkState(!option.arg_name().isBlank(), "Option with argument missing name parameter"); String parameter = argList.remove(0); method.invoke(target, parameter); } else { diff --git a/validator/src/main/java/com/google/daq/mqtt/registrar/Registrar.java b/validator/src/main/java/com/google/daq/mqtt/registrar/Registrar.java index 9341d3b98..a7c8d3041 100644 --- a/validator/src/main/java/com/google/daq/mqtt/registrar/Registrar.java +++ b/validator/src/main/java/com/google/daq/mqtt/registrar/Registrar.java @@ -230,7 +230,7 @@ private void setBlockUnknown() { blockUnknown = true; } - @CommandLineOption(short_form = "-c", arg_type = "n", description = "Create registries") + @CommandLineOption(short_form = "-c", arg_name = "count", description = "Create registries") private void setCreateRegistries(String registrySpec) { try { createRegistries = Integer.parseInt(registrySpec); @@ -242,7 +242,7 @@ private void setCreateRegistries(String registrySpec) { } } - @CommandLineOption(short_form = "-n", arg_type = "n", + @CommandLineOption(short_form = "-n", arg_name = "threads", description = "Set number of runner threads") private void setRunnerThreads(String argValue) { runnerThreads = Integer.parseInt(argValue); @@ -262,7 +262,7 @@ private void setExpungeDevices() { this.updateCloudIoT = true; } - @CommandLineOption(short_form = "-e", arg_type = "s", description = "Set registry suffix") + @CommandLineOption(short_form = "-e", arg_name = "suffix", description = "Set registry suffix") private void setRegistrySuffix(String suffix) { siteModel.getExecutionConfiguration().registry_suffix = suffix; } @@ -348,7 +348,7 @@ private void setMetadataModelOut() { metadataModelOut = true; } - @CommandLineOption(short_form = "-l", arg_type = "t", description = "Set idle limit") + @CommandLineOption(short_form = "-l", arg_name = "timeout", description = "Set idle limit") private void setIdleLimit(String option) { idleLimit = Duration.parse("PT" + option); System.err.println("Limiting devices to duration " + idleLimit.toSeconds() + "s"); @@ -364,7 +364,7 @@ private void setDeviceList(List deviceList) { blockUnknown = false; } - @CommandLineOption(short_form = "-f", arg_type = "s", description = "Set PubSub feed topic") + @CommandLineOption(short_form = "-f", arg_name = "topic", description = "Set PubSub feed topic") private void setFeedTopic(String feedTopic) { System.err.println("Sending device feed to topic " + feedTopic); feedPusher = new PubSubPusher(projectId, feedTopic); @@ -433,7 +433,7 @@ private SetupUdmiConfig getCloudVersionInfo() { return ifNotNullGet(cloudIotManager, CloudIotManager::getVersionInformation); } - @CommandLineOption(short_form = "-s", arg_type = "s", description = "Set site path") + @CommandLineOption(short_form = "-s", arg_name = "site_path", description = "Set site path") private void setSitePath(String sitePath) { checkNotNull(SCHEMA_NAME, "schemaName not set yet"); siteDir = new File(sitePath); @@ -1178,7 +1178,7 @@ private void initializeDevices(Map localDevices) { }); } - @CommandLineOption(short_form = "-p", arg_type = "s", description = "Set project id") + @CommandLineOption(short_form = "-p", arg_name = "project_id", description = "Set project id") private void setProjectId(String projectId) { if (NO_SITE.equals(projectId) || projectId == null) { this.projectId = null; @@ -1190,7 +1190,7 @@ private void setProjectId(String projectId) { this.projectId = projectId; } - @CommandLineOption(short_form = "-r", arg_type = "s", description = "Set tool root") + @CommandLineOption(short_form = "-r", arg_name = "root_path", description = "Set tool root") private void setToolRoot(String toolRoot) { try { schemaBase = new File(toolRoot, SCHEMA_BASE_PATH); @@ -1271,7 +1271,8 @@ public List getMockActions() { return cloudIotManager.getMockActions(); } - @CommandLineOption(short_form = "-a", arg_type = "s", description = "Set alternate registry") + @CommandLineOption(short_form = "-a", arg_name = "alternate", + description = "Set alternate registry") private void setTargetRegistry(String altRegistry) { siteModel.getExecutionConfiguration().registry_id = altRegistry; siteModel.getExecutionConfiguration().alt_registry = null; From 72cfc5f2fddc45cf73a55a8ed6ddca647238da09 Mon Sep 17 00:00:00 2001 From: Khyati Mahendru Date: Fri, 22 Nov 2024 07:03:28 +0000 Subject: [PATCH 2/3] Update command line options for Validator to use arg_name, not arg_type --- .../udmi/util/CommandLineProcessor.java | 2 +- .../google/daq/mqtt/validator/Validator.java | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/google/udmi/util/CommandLineProcessor.java b/common/src/main/java/com/google/udmi/util/CommandLineProcessor.java index cf128e68d..8608ef4b2 100644 --- a/common/src/main/java/com/google/udmi/util/CommandLineProcessor.java +++ b/common/src/main/java/com/google/udmi/util/CommandLineProcessor.java @@ -91,7 +91,7 @@ private void showUsage() { public void showUsage(String message) { ifNotNullThen(message, m -> System.err.println(m)); System.err.println("Options supported:"); - optionMap.forEach((option, method) -> System.err.printf(" %s %10s %s%n", + optionMap.forEach((option, method) -> System.err.printf(" %s %12s %s%n", option.short_form(), option.arg_name(), option.description())); System.exit(message == null ? LINUX_SUCCESS_CODE : LINUX_ERROR_CODE); } diff --git a/validator/src/main/java/com/google/daq/mqtt/validator/Validator.java b/validator/src/main/java/com/google/daq/mqtt/validator/Validator.java index 69edeff7c..8e0f8f71e 100644 --- a/validator/src/main/java/com/google/daq/mqtt/validator/Validator.java +++ b/validator/src/main/java/com/google/daq/mqtt/validator/Validator.java @@ -378,7 +378,7 @@ private void setProfileMode() { MqttPublisher.reportStatistics = true; } - @CommandLineOption(short_form = "-d", arg_type = "n", description = "Report delay (sec)") + @CommandLineOption(short_form = "-d", arg_name = "delay", description = "Report delay (sec)") private void setReportDelay(String arg) { reportingDelaySec = Integer.parseInt(arg); } @@ -388,7 +388,7 @@ private void setValidateCurrent() { validateCurrent = true; } - @CommandLineOption(short_form = "-p", arg_type = "s", description = "Set project id") + @CommandLineOption(short_form = "-p", arg_name = "project_id", description = "Set project id") private void setProjectId(String projectId) { if (!projectId.startsWith(PROJECT_PROVIDER_PREFIX)) { config.project_id = projectId; @@ -399,7 +399,8 @@ private void setProjectId(String projectId) { config.project_id = parts[1]; } - @CommandLineOption(short_form = "-t", arg_type = "s", description = "Validate pub sub target") + @CommandLineOption(short_form = "-t", arg_name = "target", + description = "Validate pub sub target") private void validatePubSub(String pubSubCombo) { validatePubSub(pubSubCombo, true); } @@ -439,7 +440,8 @@ MessageReadingClient getMessageReadingClient() { return (MessageReadingClient) client; } - @CommandLineOption(short_form = "-r", arg_type = "s", description = "Validate message trace") + @CommandLineOption(short_form = "-r", arg_name = "message_dir", + description = "Validate message trace") private void validateMessageTrace(String messageDir) { client = new MessageReadingClient(getRegistryId(), messageDir); dataSinks.add(client); @@ -456,7 +458,7 @@ Validator prepForMock() { * * @param siteDir site model directory */ - @CommandLineOption(short_form = "-s", arg_type = "s", description = "Set site directory") + @CommandLineOption(short_form = "-s", arg_name = "site_dir", description = "Set site directory") private void setSiteDir(String siteDir) { config.site_model = siteDir; final File baseDir; @@ -482,7 +484,7 @@ private ExecutionConfiguration resolveSiteConfig(ExecutionConfiguration config, return GeneralUtils.mergeObject(siteConfig, config); } - @CommandLineOption(short_form = "-w", arg_type = "s", description = "Write trace output") + @CommandLineOption(short_form = "-w", arg_name = "trace_dir", description = "Write trace output") private void setMessageTraceDir(String writeDirArg) { traceDir = new File(writeDirArg); outputLogger.info("Tracing message capture to " + traceDir.getAbsolutePath()); @@ -525,7 +527,7 @@ private ReportingDevice newReportingDevice(String device) { * * @param schemaPath schema specification directory */ - @CommandLineOption(short_form = "-a", arg_type = "s", description = "Set schema path") + @CommandLineOption(short_form = "-a", arg_name = "schema_path", description = "Set schema path") private void setSchemaSpec(String schemaPath) { File schemaPart = new File(schemaPath); boolean rawPath = schemaPart.isAbsolute() || Strings.isNullOrEmpty(config.udmi_root); @@ -1179,7 +1181,8 @@ private void validateFiles(String schemaSpec, String prefix, String targetSpec) schemaExceptions.throwIfNotEmpty(); } - @CommandLineOption(short_form = "-f", arg_type = "s", description = "Validate from files") + @CommandLineOption(short_form = "-f", arg_name = "target_spec", + description = "Validate from files") private void validateFilesOutput(String targetSpec) { try { String[] parts = targetSpec.split(":"); From 53e1589fe1f065e1e61a7b666e6768eeb7cdffd7 Mon Sep 17 00:00:00 2001 From: Khyati Mahendru Date: Fri, 22 Nov 2024 13:59:02 +0000 Subject: [PATCH 3/3] Remove arg_type as there is no current use for it --- .../main/java/com/google/udmi/util/CommandLineOption.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/common/src/main/java/com/google/udmi/util/CommandLineOption.java b/common/src/main/java/com/google/udmi/util/CommandLineOption.java index 1ee4a967d..a54dd2b49 100644 --- a/common/src/main/java/com/google/udmi/util/CommandLineOption.java +++ b/common/src/main/java/com/google/udmi/util/CommandLineOption.java @@ -29,11 +29,6 @@ */ String long_form() default NO_VALUE; - /** - * Set the argument type description. - */ - String arg_type() default NO_VALUE; - /** * Set the argument name. */