You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2022/11/25 08:47:13 UTC
[GitHub] [bookkeeper] equanz commented on a diff in pull request #3663: Exit bookkeeper shell correctly even if fails to run for some reason
equanz commented on code in PR #3663:
URL: https://github.com/apache/bookkeeper/pull/3663#discussion_r1032131218
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieShell.java:
##########
@@ -2397,50 +2397,56 @@ public int compare(File file1, File file2) {
}
}
- public static void main(String[] argv) throws Exception {
- BookieShell shell = new BookieShell();
-
- // handle some common options for multiple cmds
- Options opts = new Options();
- opts.addOption(CONF_OPT, true, "configuration file");
- opts.addOption(LEDGERID_FORMATTER_OPT, true, "format of ledgerId");
- opts.addOption(ENTRY_FORMATTER_OPT, true, "format of entries");
- BasicParser parser = new BasicParser();
- CommandLine cmdLine = parser.parse(opts, argv, true);
-
- // load configuration
- CompositeConfiguration conf = new CompositeConfiguration();
- if (cmdLine.hasOption(CONF_OPT)) {
- String val = cmdLine.getOptionValue(CONF_OPT);
- conf.addConfiguration(new PropertiesConfiguration(
- new File(val).toURI().toURL()));
- }
- shell.setConf(conf);
-
- // ledgerid format
- if (cmdLine.hasOption(LEDGERID_FORMATTER_OPT)) {
- String val = cmdLine.getOptionValue(LEDGERID_FORMATTER_OPT);
- shell.ledgerIdFormatter = LedgerIdFormatter.newLedgerIdFormatter(val, shell.bkConf);
- } else {
- shell.ledgerIdFormatter = LedgerIdFormatter.newLedgerIdFormatter(shell.bkConf);
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("Using ledgerIdFormatter {}", shell.ledgerIdFormatter.getClass());
- }
+ public static void main(String[] argv) {
+ int res = -1;
+ try {
+ BookieShell shell = new BookieShell();
- // entry format
- if (cmdLine.hasOption(ENTRY_FORMATTER_OPT)) {
- String val = cmdLine.getOptionValue(ENTRY_FORMATTER_OPT);
- shell.entryFormatter = EntryFormatter.newEntryFormatter(val, shell.bkConf);
- } else {
- shell.entryFormatter = EntryFormatter.newEntryFormatter(shell.bkConf);
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("Using entry formatter {}", shell.entryFormatter.getClass());
- }
+ // handle some common options for multiple cmds
+ Options opts = new Options();
+ opts.addOption(CONF_OPT, true, "configuration file");
+ opts.addOption(LEDGERID_FORMATTER_OPT, true, "format of ledgerId");
+ opts.addOption(ENTRY_FORMATTER_OPT, true, "format of entries");
+ BasicParser parser = new BasicParser();
+ CommandLine cmdLine = parser.parse(opts, argv, true);
+
+ // load configuration
+ CompositeConfiguration conf = new CompositeConfiguration();
+ if (cmdLine.hasOption(CONF_OPT)) {
+ String val = cmdLine.getOptionValue(CONF_OPT);
+ conf.addConfiguration(new PropertiesConfiguration(
+ new File(val).toURI().toURL()));
+ }
+ shell.setConf(conf);
- int res = shell.run(cmdLine.getArgs());
- System.exit(res);
+ // ledgerid format
+ if (cmdLine.hasOption(LEDGERID_FORMATTER_OPT)) {
+ String val = cmdLine.getOptionValue(LEDGERID_FORMATTER_OPT);
+ shell.ledgerIdFormatter = LedgerIdFormatter.newLedgerIdFormatter(val, shell.bkConf);
+ } else {
+ shell.ledgerIdFormatter = LedgerIdFormatter.newLedgerIdFormatter(shell.bkConf);
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using ledgerIdFormatter {}", shell.ledgerIdFormatter.getClass());
+ }
+
+ // entry format
+ if (cmdLine.hasOption(ENTRY_FORMATTER_OPT)) {
+ String val = cmdLine.getOptionValue(ENTRY_FORMATTER_OPT);
+ shell.entryFormatter = EntryFormatter.newEntryFormatter(val, shell.bkConf);
+ } else {
+ shell.entryFormatter = EntryFormatter.newEntryFormatter(shell.bkConf);
+ }
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using entry formatter {}", shell.entryFormatter.getClass());
+ }
+
+ res = shell.run(cmdLine.getArgs());
+ } catch (Exception e) {
Review Comment:
Addressed. PTAL
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org