From 289aba4ebbb47a920f07dff00a9c35f04ab71063 Mon Sep 17 00:00:00 2001 From: Sourabh Badhya Date: Sat, 3 May 2025 13:51:19 +0530 Subject: [PATCH] TEZ-4626: Remove usage of deprecated classes of commons-cli --- .../org/apache/tez/dag/app/DAGAppMaster.java | 16 ++++--- .../org/apache/tez/history/ATSImportTool.java | 35 +++++++------- .../helpers/SplitsInClientOptionParser.java | 17 ++++--- .../tez/analyzer/plugins/TezAnalyzerBase.java | 46 +++++++++---------- 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java b/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java index 2ccc6d7dee..05d3f5da94 100644 --- a/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java +++ b/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java @@ -64,7 +64,8 @@ import com.google.common.collect.Lists; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.DefaultParser; +import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.hadoop.yarn.api.records.NodeId; @@ -2400,11 +2401,14 @@ public static void main(String[] args) { .getenv(ApplicationConstants.Environment.USER.name()); // Command line options - Options opts = new Options(); - opts.addOption(TezConstants.TEZ_SESSION_MODE_CLI_OPTION, - false, "Run Tez Application Master in Session mode"); - - CommandLine cliParser = new GnuParser().parse(opts, args); + Option option = Option.builder() + .longOpt(TezConstants.TEZ_SESSION_MODE_CLI_OPTION) + .hasArg(false) + .desc("Run Tez Application Master in Session mode") + .build(); + Options opts = new Options().addOption(option); + + CommandLine cliParser = new DefaultParser().parse(opts, args); boolean sessionModeCliOption = cliParser.hasOption(TezConstants.TEZ_SESSION_MODE_CLI_OPTION); LOG.info("Creating DAGAppMaster for " diff --git a/tez-plugins/tez-history-parser/src/main/java/org/apache/tez/history/ATSImportTool.java b/tez-plugins/tez-history-parser/src/main/java/org/apache/tez/history/ATSImportTool.java index c909f7aa0d..74663d8585 100644 --- a/tez-plugins/tez-history-parser/src/main/java/org/apache/tez/history/ATSImportTool.java +++ b/tez-plugins/tez-history-parser/src/main/java/org/apache/tez/history/ATSImportTool.java @@ -33,10 +33,9 @@ import com.sun.jersey.client.urlconnection.URLConnectionClientHandler; import com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.io.IOUtils; @@ -358,27 +357,27 @@ public int run(String[] args) throws Exception { } private static Options buildOptions() { - Option dagIdOption = OptionBuilder.withArgName(DAG_ID).withLongOpt(DAG_ID) - .withDescription("DagId that needs to be downloaded").hasArg().isRequired(true).create(); + Option dagIdOption = Option.builder().argName(DAG_ID).longOpt(DAG_ID) + .desc("DagId that needs to be downloaded").hasArg().required(true).build(); - Option downloadDirOption = OptionBuilder.withArgName(BASE_DOWNLOAD_DIR).withLongOpt + Option downloadDirOption = Option.builder().argName(BASE_DOWNLOAD_DIR).longOpt (BASE_DOWNLOAD_DIR) - .withDescription("Download directory where data needs to be downloaded").hasArg() - .isRequired(true).create(); + .desc("Download directory where data needs to be downloaded").hasArg() + .required(true).build(); - Option atsAddressOption = OptionBuilder.withArgName(YARN_TIMELINE_SERVICE_ADDRESS).withLongOpt( + Option atsAddressOption = Option.builder().argName(YARN_TIMELINE_SERVICE_ADDRESS).longOpt( YARN_TIMELINE_SERVICE_ADDRESS) - .withDescription("Optional. ATS address (e.g http://clusterATSNode:8188)").hasArg() - .isRequired(false) - .create(); + .desc("Optional. ATS address (e.g http://clusterATSNode:8188)").hasArg() + .required(false) + .build(); - Option batchSizeOption = OptionBuilder.withArgName(BATCH_SIZE).withLongOpt(BATCH_SIZE) - .withDescription("Optional. batch size for downloading data").hasArg() - .isRequired(false) - .create(); + Option batchSizeOption = Option.builder().argName(BATCH_SIZE).longOpt(BATCH_SIZE) + .desc("Optional. batch size for downloading data").hasArg() + .required(false) + .build(); - Option help = OptionBuilder.withArgName("help").withLongOpt("help") - .withDescription("print help").isRequired(false).create(); + Option help = Option.builder().argName("help").longOpt("help") + .desc("print help").required(false).build(); Options opts = new Options(); opts.addOption(dagIdOption); @@ -451,7 +450,7 @@ public static int process(String[] args) throws Exception { Options options = buildOptions(); try { Configuration conf = new Configuration(); - CommandLine cmdLine = new GnuParser().parse(options, args); + CommandLine cmdLine = new DefaultParser().parse(options, args); String dagId = cmdLine.getOptionValue(DAG_ID); File downloadDir = new File(cmdLine.getOptionValue(BASE_DOWNLOAD_DIR)); diff --git a/tez-tests/src/main/java/org/apache/tez/mapreduce/examples/helpers/SplitsInClientOptionParser.java b/tez-tests/src/main/java/org/apache/tez/mapreduce/examples/helpers/SplitsInClientOptionParser.java index 21419e7179..5d8c3c925d 100644 --- a/tez-tests/src/main/java/org/apache/tez/mapreduce/examples/helpers/SplitsInClientOptionParser.java +++ b/tez-tests/src/main/java/org/apache/tez/mapreduce/examples/helpers/SplitsInClientOptionParser.java @@ -20,9 +20,8 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; @@ -50,15 +49,15 @@ public boolean parse(String[] args, boolean defaultVal) throws ParseException { Preconditions.checkState(parsed == false, "Create a new instance for different option sets"); parsed = true; - Options opts = new Options(); - Option opt = OptionBuilder - .withArgName("splits_in_client") + Option opt = Option.builder() + .option("generateSplitsInClient") + .argName("splits_in_client") .hasArg() - .withDescription( + .desc( "specify whether splits should be generated in the client") - .create("generateSplitsInClient"); - opts.addOption(opt); - CommandLineParser parser = new GnuParser(); + .build(); + Options opts = new Options().addOption(opt); + CommandLineParser parser = new DefaultParser(); cmdLine = parser.parse(opts, args, false); if (cmdLine.hasOption("generateSplitsInClient")) { diff --git a/tez-tools/analyzers/job-analyzer/src/main/java/org/apache/tez/analyzer/plugins/TezAnalyzerBase.java b/tez-tools/analyzers/job-analyzer/src/main/java/org/apache/tez/analyzer/plugins/TezAnalyzerBase.java index 705c6e9cfb..666817911a 100644 --- a/tez-tools/analyzers/job-analyzer/src/main/java/org/apache/tez/analyzer/plugins/TezAnalyzerBase.java +++ b/tez-tools/analyzers/job-analyzer/src/main/java/org/apache/tez/analyzer/plugins/TezAnalyzerBase.java @@ -27,9 +27,8 @@ import java.util.stream.Collectors; import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.GnuParser; +import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.io.FileUtils; @@ -75,35 +74,35 @@ public TezAnalyzerBase(Configuration config) { @SuppressWarnings("static-access") private static Options buildOptions() { - Option dagIdOption = OptionBuilder.withArgName(DAG_ID).withLongOpt(DAG_ID) - .withDescription("DagId that needs to be analyzed").hasArg().isRequired(true).create(); + Option dagIdOption = Option.builder().argName(DAG_ID).longOpt(DAG_ID) + .desc("DagId that needs to be analyzed").hasArg().required(true).build(); - Option outputDirOption = OptionBuilder.withArgName(OUTPUT_DIR).withLongOpt(OUTPUT_DIR) - .withDescription("Directory to write outputs to.").hasArg().isRequired(false).create(); + Option outputDirOption = Option.builder().argName(OUTPUT_DIR).longOpt(OUTPUT_DIR) + .desc("Directory to write outputs to.").hasArg().required(false).build(); - Option saveResults = OptionBuilder.withArgName(SAVE_RESULTS).withLongOpt(SAVE_RESULTS) - .withDescription("Saves results to output directory (optional)") - .hasArg(false).isRequired(false).create(); + Option saveResults = Option.builder().argName(SAVE_RESULTS).longOpt(SAVE_RESULTS) + .desc("Saves results to output directory (optional)") + .hasArg(false).required(false).build(); - Option eventFileNameOption = OptionBuilder.withArgName(EVENT_FILE_NAME).withLongOpt + Option eventFileNameOption = Option.builder().argName(EVENT_FILE_NAME).longOpt (EVENT_FILE_NAME) - .withDescription("File with event data for the DAG").hasArg() - .isRequired(false).create(); + .desc("File with event data for the DAG").hasArg() + .required(false).build(); - Option fromSimpleHistoryOption = OptionBuilder.withArgName(FROM_SIMPLE_HISTORY).withLongOpt + Option fromSimpleHistoryOption = Option.builder().argName(FROM_SIMPLE_HISTORY).longOpt (FROM_SIMPLE_HISTORY) - .withDescription("Event data from Simple History logging. Must also specify event file") - .isRequired(false).create(); + .desc("Event data from Simple History logging. Must also specify event file") + .required(false).build(); Option fromProtoHistoryOption = - OptionBuilder.withArgName(FROM_PROTO_HISTORY).withLongOpt(FROM_PROTO_HISTORY) - .withDescription("Event data from Proto History logging. Must also specify event file") - .isRequired(false).create(); + Option.builder().argName(FROM_PROTO_HISTORY).longOpt(FROM_PROTO_HISTORY) + .desc("Event data from Proto History logging. Must also specify event file") + .required(false).build(); - Option help = OptionBuilder.withArgName(HELP).withLongOpt + Option help = Option.builder().argName(HELP).longOpt (HELP) - .withDescription("print help") - .isRequired(false).create(); + .desc("print help") + .required(false).build(); Options opts = new Options(); opts.addOption(dagIdOption); @@ -123,8 +122,7 @@ protected String getOutputDir() { private void printUsage() { System.err.println("Analyzer base options are"); Options options = buildOptions(); - for (Object obj : options.getOptions()) { - Option option = (Option) obj; + for (Option option : options.getOptions()) { System.err.println(option.getArgName() + " : " + option.getDescription()); } } @@ -134,7 +132,7 @@ public int run(String[] args) throws Exception { //Parse downloaded contents CommandLine cmdLine = null; try { - cmdLine = new GnuParser().parse(buildOptions(), args); + cmdLine = new DefaultParser().parse(buildOptions(), args); } catch (ParseException e) { System.err.println("Invalid options on command line"); printUsage();