Skip to content

Commit

Permalink
Alarm server command line options: Allow -export -config in any order
Browse files Browse the repository at this point in the history
  • Loading branch information
kasemir committed May 20, 2022
1 parent 8bbc121 commit 4f3f5bc
Showing 1 changed file with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<String> args = new ArrayList<>(List.of(original_args));
Expand Down Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down

0 comments on commit 4f3f5bc

Please sign in to comment.