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) {