From 4f3f5bc85820a0b28ce10247d55ab4410a7579b3 Mon Sep 17 00:00:00 2001 From: kasemir Date: Fri, 20 May 2022 15:16:06 -0400 Subject: [PATCH] Alarm server command line options: Allow -export -config in any order #1729 --- .../alarm/server/AlarmServerMain.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/services/alarm-server/src/main/java/org/phoebus/applications/alarm/server/AlarmServerMain.java b/services/alarm-server/src/main/java/org/phoebus/applications/alarm/server/AlarmServerMain.java index ea2ae3e42e..01ac18c32e 100644 --- a/services/alarm-server/src/main/java/org/phoebus/applications/alarm/server/AlarmServerMain.java +++ b/services/alarm-server/src/main/java/org/phoebus/applications/alarm/server/AlarmServerMain.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018 Oak Ridge National Laboratory. + * Copyright (c) 2018-2022 Oak Ridge National Laboratory. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -554,6 +554,8 @@ public static void main(final String[] original_args) throws Exception boolean use_args_server = false; boolean use_args_config = false; boolean use_settings = false; + String import_filename = null; + String export_filename = null; // Handle arguments final List args = new ArrayList<>(List.of(original_args)); @@ -629,22 +631,16 @@ else if (cmd.equals("-import")) if (! iter.hasNext()) throw new Exception("Missing -import file name"); iter.remove(); - final String filename = iter.next(); + import_filename = iter.next(); iter.remove(); - logger.info("Import model from " + filename); - new AlarmConfigTool().importModel(filename, server, use_args_config ? args_config : config); - return; } else if (cmd.equals("-export")) { if (! iter.hasNext()) throw new Exception("Missing -export file name"); iter.remove(); - final String filename = iter.next(); + export_filename = iter.next(); iter.remove(); - logger.info("Exporting model to " + filename); - new AlarmConfigTool().exportModel(filename, server, use_args_config ? args_config : config); - return; } else throw new Exception("Unknown option " + cmd); @@ -667,6 +663,22 @@ else if (cmd.equals("-export")) config = args_config; } + // Export or import requested? + // Actually allow _both_ export and import, first exporting + // so that existing config gets exported, then new one imported + if (export_filename != null) + { + logger.info("Exporting model to " + export_filename); + new AlarmConfigTool().exportModel(export_filename, server, use_args_config ? args_config : config); + } + if (import_filename != null) + { + logger.info("Import model from " + import_filename); + new AlarmConfigTool().importModel(import_filename, server, use_args_config ? args_config : config); + } + // Any export/import means we're done, not running alarm server + if (export_filename != null || import_filename != null) + return; } catch (final Exception ex) {