use of org.ovirt.engine.core.extensions.mgr.ExtensionsManager in project ovirt-engine by oVirt.
the class ExtensionsToolExecutor method main.
public static void main(String... args) {
int exitStatus = 1;
Path tempJAASConf = null;
List<String> cmdArgs = new ArrayList<>(Arrays.asList(args));
try {
tempJAASConf = createTemporaryJAASconfiguration();
final Map<String, String> contextSubstitutions = new HashMap<>();
contextSubstitutions.put("@ENGINE_ETC@", ENGINE_ETC);
contextSubstitutions.put("@PROGRAM_NAME@", PROGRAM_NAME);
context.put(ModuleService.ContextKeys.CLI_PARSER_SUBSTITUTIONS, contextSubstitutions);
setupLogger();
ArgumentsParser parser;
Map<String, ModuleService> moduleServices = loadModules(ModuleService.class);
context.put(ModuleService.ContextKeys.MODULES, moduleServices);
final Map<String, String> substitutions = new HashMap<>(contextSubstitutions);
substitutions.put("@MODULE_LIST@", getModules(moduleServices));
try (InputStream stream = ExtensionsToolExecutor.class.getResourceAsStream("arguments.properties")) {
parser = new ArgumentsParser(stream, "core");
parser.getSubstitutions().putAll(substitutions);
}
parser.parse(cmdArgs);
Map<String, Object> argMap = parser.getParsedArgs();
setupLogger(argMap);
log.debug("Version: {}-{} ({})", PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_DISPLAY_NAME);
if ((Boolean) argMap.get("help")) {
System.out.format("Usage: %s", parser.getUsage());
throw new ExitException("Help", 0);
} else if ((Boolean) argMap.get("version")) {
System.out.format("%s-%s (%s)%n", PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_DISPLAY_NAME);
throw new ExitException("Version", 0);
}
if (!parser.getErrors().isEmpty()) {
for (Throwable t : parser.getErrors()) {
log.error(t.getMessage());
log.debug(t.getMessage(), t);
}
throw new ExitException("Parsing error", 1);
}
if (cmdArgs.size() < 1) {
log.error("Please provide module.");
throw new ExitException("Module not provided", 1);
}
String module = cmdArgs.get(0);
ModuleService moduleService = moduleServices.get(module);
if (moduleService == null) {
log.error("No such '{}' module exists.", module);
throw new ExitException(1);
}
moduleService.parseArguments(cmdArgs);
log.info("========================================================================");
log.info("============================ Initialization ============================");
log.info("========================================================================");
ExtensionsManager extensionsManager = new ExtensionsManager();
extensionsManager.getGlobalContext().put(Base.GlobalContextKeys.APPLICATION_NAME, Base.ApplicationNames.OVIRT_ENGINE_EXTENSIONS_TOOL);
context.put(ModuleService.ContextKeys.EXTENSION_MANAGER, extensionsManager);
loadExtensions(extensionsManager, moduleService, argMap);
log.info("========================================================================");
log.info("============================== Execution ===============================");
log.info("========================================================================");
moduleService.run();
exitStatus = 0;
} catch (ExitException e) {
log.debug(e.getMessage(), e);
exitStatus = e.getExitCode();
} catch (Throwable t) {
log.error(t.getMessage() != null ? t.getMessage() : t.getClass().getName());
log.debug("Exception:", t);
} finally {
if (tempJAASConf != null) {
try {
Files.delete(tempJAASConf);
} catch (IOException ex) {
log.warn("Failed to delete temporary file '{}'", tempJAASConf.toString());
}
}
}
log.debug("Exiting with status '{}'", exitStatus);
System.exit(exitStatus);
}
Aggregations