You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tr...@apache.org on 2018/01/11 23:19:54 UTC
[5/8] flink git commit: [FLINK-8338] [flip6] Make CustomCommandLines
non static in CliFrontend
[FLINK-8338] [flip6] Make CustomCommandLines non static in CliFrontend
This commit changes how CustomCommandLines are registered at the CliFrontend.
Henceforth, the CliFrontend is initialized with the set of CustomCommandLines
instead of registering them statically. This improves maintainability and
testability.
This closes #5224.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/aff43768
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/aff43768
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/aff43768
Branch: refs/heads/master
Commit: aff43768f3285a5f2bc5593369a7fec3ed77a2af
Parents: 12396f1
Author: Till Rohrmann <tr...@apache.org>
Authored: Thu Jan 11 13:55:16 2018 +0100
Committer: Till Rohrmann <tr...@apache.org>
Committed: Thu Jan 11 20:39:57 2018 +0100
----------------------------------------------------------------------
.../apache/flink/client/cli/CliFrontend.java | 207 ++++++++++---------
.../flink/client/cli/CliFrontendParser.java | 180 ++++++----------
.../CliFrontendAddressConfigurationTest.java | 62 +++---
.../flink/client/cli/CliFrontendCancelTest.java | 72 +++----
.../flink/client/cli/CliFrontendInfoTest.java | 22 +-
.../flink/client/cli/CliFrontendListTest.java | 24 ++-
.../cli/CliFrontendPackageProgramTest.java | 30 ++-
.../flink/client/cli/CliFrontendRunTest.java | 32 +--
.../client/cli/CliFrontendSavepointTest.java | 4 +-
.../flink/client/cli/CliFrontendStopTest.java | 43 ++--
.../flink/client/cli/Flip6DefaultCLITest.java | 51 +++++
.../client/cli/util/DummyCustomCommandLine.java | 73 +++++++
.../client/cli/util/MockedCliFrontend.java | 28 +--
.../org/apache/flink/api/scala/FlinkShell.scala | 39 +++-
...CliFrontendYarnAddressConfigurationTest.java | 119 ++++++++---
.../flink/yarn/FlinkYarnSessionCliTest.java | 48 +++--
.../org/apache/flink/yarn/YarnTestBase.java | 8 +-
17 files changed, 613 insertions(+), 429 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java b/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java
index 4b21e10..e539240 100644
--- a/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java
+++ b/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java
@@ -71,7 +71,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
@@ -98,67 +97,47 @@ public class CliFrontend {
private static final String ACTION_STOP = "stop";
private static final String ACTION_SAVEPOINT = "savepoint";
- // config dir parameters
+ // configuration dir parameters
private static final String CONFIG_DIRECTORY_FALLBACK_1 = "../conf";
private static final String CONFIG_DIRECTORY_FALLBACK_2 = "conf";
// --------------------------------------------------------------------------------------------
- private static final List<CustomCommandLine<?>> customCommandLines = new ArrayList<>(3);
+ private final Configuration configuration;
- static {
- // Command line interface of the YARN session, with a special initialization here
- // to prefix all options with y/yarn.
- // Tips: DefaultCLI must be added at last, because getActiveCustomCommandLine(..) will get the
- // active CustomCommandLine in order and DefaultCLI isActive always return true.
- final String flinkYarnSessionCLI = "org.apache.flink.yarn.cli.FlinkYarnSessionCli";
- try {
- customCommandLines.add(loadCustomCommandLine(flinkYarnSessionCLI, "y", "yarn"));
- } catch (Exception e) {
- LOG.warn("Could not load CLI class {}.", flinkYarnSessionCLI, e);
- }
-
- customCommandLines.add(new Flip6DefaultCLI());
- customCommandLines.add(new DefaultCLI());
- }
-
- // --------------------------------------------------------------------------------------------
-
- private final Configuration config;
+ private final List<CustomCommandLine<?>> customCommandLines;
private final String configurationDirectory;
+ private final Options customCommandLineOptions;
+
private final FiniteDuration clientTimeout;
private final int defaultParallelism;
- /**
- *
- * @throws Exception Thrown if the configuration directory was not found, the configuration could not be loaded
- */
- public CliFrontend() throws Exception {
- this(getConfigurationDirectoryFromEnv());
- }
-
- public CliFrontend(String configDir) throws Exception {
- configurationDirectory = Preconditions.checkNotNull(configDir);
-
- // configure the config directory
- File configDirectory = new File(configDir);
- LOG.info("Using configuration directory " + configDirectory.getAbsolutePath());
-
- // load the configuration
- LOG.info("Trying to load configuration file");
- this.config = GlobalConfiguration.loadConfiguration(configDirectory.getAbsolutePath());
+ public CliFrontend(
+ Configuration configuration,
+ List<CustomCommandLine<?>> customCommandLines,
+ String configurationDirectory) throws Exception {
+ this.configuration = Preconditions.checkNotNull(configuration);
+ this.customCommandLines = Preconditions.checkNotNull(customCommandLines);
+ this.configurationDirectory = Preconditions.checkNotNull(configurationDirectory);
try {
- FileSystem.initialize(config);
+ FileSystem.initialize(this.configuration);
} catch (IOException e) {
throw new Exception("Error while setting the default " +
"filesystem scheme from configuration.", e);
}
- this.clientTimeout = AkkaUtils.getClientTimeout(config);
+ this.customCommandLineOptions = new Options();
+
+ for (CustomCommandLine<?> customCommandLine : customCommandLines) {
+ customCommandLine.addGeneralOptions(customCommandLineOptions);
+ customCommandLine.addRunOptions(customCommandLineOptions);
+ }
+
+ this.clientTimeout = AkkaUtils.getClientTimeout(this.configuration);
this.defaultParallelism = GlobalConfiguration.loadConfiguration().getInteger(
ConfigConstants.DEFAULT_PARALLELISM_KEY,
ConfigConstants.DEFAULT_PARALLELISM);
@@ -176,7 +155,7 @@ public class CliFrontend {
public Configuration getConfiguration() {
Configuration copiedConfiguration = new Configuration();
- copiedConfiguration.addAll(config);
+ copiedConfiguration.addAll(configuration);
return copiedConfiguration;
}
@@ -204,13 +183,15 @@ public class CliFrontend {
final Options commandOptions = CliFrontendParser.getRunCommandOptions();
- final CommandLine commandLine = CliFrontendParser.parse(commandOptions, args, true);
+ final Options commandLineOptions = CliFrontendParser.mergeOptions(commandOptions, customCommandLineOptions);
+
+ final CommandLine commandLine = CliFrontendParser.parse(commandLineOptions, args, true);
final RunOptions runOptions = new RunOptions(commandLine);
// evaluate help flag
if (runOptions.isPrintHelp()) {
- CliFrontendParser.printHelpForRun();
+ CliFrontendParser.printHelpForRun(customCommandLines);
return 0;
}
@@ -277,32 +258,32 @@ public class CliFrontend {
final CommandLine commandLine = CliFrontendParser.parse(commandOptions, args, true);
- InfoOptions options = new InfoOptions(commandLine);
+ InfoOptions infoOptions = new InfoOptions(commandLine);
// evaluate help flag
- if (options.isPrintHelp()) {
+ if (infoOptions.isPrintHelp()) {
CliFrontendParser.printHelpForInfo();
return 0;
}
- if (options.getJarFilePath() == null) {
+ if (infoOptions.getJarFilePath() == null) {
return handleArgException(new CliArgsException("The program JAR file was not specified."));
}
// -------- build the packaged program -------------
LOG.info("Building program from JAR file");
- final PackagedProgram program = buildProgram(options);
+ final PackagedProgram program = buildProgram(infoOptions);
try {
- int parallelism = options.getParallelism();
+ int parallelism = infoOptions.getParallelism();
if (ExecutionConfig.PARALLELISM_DEFAULT == parallelism) {
parallelism = defaultParallelism;
}
LOG.info("Creating program plan dump");
- Optimizer compiler = new Optimizer(new DataStatistics(), new DefaultCostEstimator(), config);
+ Optimizer compiler = new Optimizer(new DataStatistics(), new DefaultCostEstimator(), configuration);
FlinkPlan flinkPlan = ClusterClient.getOptimizedPlan(compiler, program, parallelism);
String jsonPlan = null;
@@ -347,18 +328,20 @@ public class CliFrontend {
final Options commandOptions = CliFrontendParser.getListCommandOptions();
- final CommandLine commandLine = CliFrontendParser.parse(commandOptions, args, false);
+ final Options commandLineOptions = CliFrontendParser.mergeOptions(commandOptions, customCommandLineOptions);
+
+ final CommandLine commandLine = CliFrontendParser.parse(commandLineOptions, args, false);
- ListOptions options = new ListOptions(commandLine);
+ ListOptions listOptions = new ListOptions(commandLine);
// evaluate help flag
- if (options.isPrintHelp()) {
- CliFrontendParser.printHelpForList();
+ if (listOptions.isPrintHelp()) {
+ CliFrontendParser.printHelpForList(customCommandLines);
return 0;
}
- boolean running = options.getRunning();
- boolean scheduled = options.getScheduled();
+ boolean running = listOptions.getRunning();
+ boolean scheduled = listOptions.getScheduled();
// print running and scheduled jobs if not option supplied
if (!running && !scheduled) {
@@ -367,7 +350,7 @@ public class CliFrontend {
}
final CustomCommandLine<?> activeCommandLine = getActiveCustomCommandLine(commandLine);
- final ClusterClient client = activeCommandLine.retrieveCluster(commandLine, config, configurationDirectory);
+ final ClusterClient client = activeCommandLine.retrieveCluster(commandLine, configuration, configurationDirectory);
try {
Collection<JobStatusMessage> jobDetails;
@@ -452,17 +435,19 @@ public class CliFrontend {
final Options commandOptions = CliFrontendParser.getStopCommandOptions();
- final CommandLine commandLine = CliFrontendParser.parse(commandOptions, args, false);
+ final Options commandLineOptions = CliFrontendParser.mergeOptions(commandOptions, customCommandLineOptions);
- StopOptions options = new StopOptions(commandLine);
+ final CommandLine commandLine = CliFrontendParser.parse(commandLineOptions, args, false);
+
+ StopOptions stopOptions = new StopOptions(commandLine);
// evaluate help flag
- if (options.isPrintHelp()) {
- CliFrontendParser.printHelpForStop();
+ if (stopOptions.isPrintHelp()) {
+ CliFrontendParser.printHelpForStop(customCommandLines);
return 0;
}
- String[] stopArgs = options.getArgs();
+ String[] stopArgs = stopOptions.getArgs();
JobID jobId;
if (stopArgs.length > 0) {
@@ -475,7 +460,7 @@ public class CliFrontend {
final CustomCommandLine<?> activeCommandLine = getActiveCustomCommandLine(commandLine);
- final ClusterClient client = activeCommandLine.retrieveCluster(commandLine, config, configurationDirectory);
+ final ClusterClient client = activeCommandLine.retrieveCluster(commandLine, configuration, configurationDirectory);
try {
logAndSysout("Stopping job " + jobId + '.');
@@ -502,13 +487,15 @@ public class CliFrontend {
final Options commandOptions = CliFrontendParser.getCancelCommandOptions();
- final CommandLine commandLine = CliFrontendParser.parse(commandOptions, args, false);
+ final Options commandLineOptions = CliFrontendParser.mergeOptions(commandOptions, customCommandLineOptions);
+
+ final CommandLine commandLine = CliFrontendParser.parse(commandLineOptions, args, false);
CancelOptions cancelOptions = new CancelOptions(commandLine);
// evaluate help flag
if (cancelOptions.isPrintHelp()) {
- CliFrontendParser.printHelpForCancel();
+ CliFrontendParser.printHelpForCancel(customCommandLines);
return 0;
}
@@ -539,7 +526,7 @@ public class CliFrontend {
}
final CustomCommandLine<?> activeCommandLine = getActiveCustomCommandLine(commandLine);
- final ClusterClient client = activeCommandLine.retrieveCluster(commandLine, config, configurationDirectory);
+ final ClusterClient client = activeCommandLine.retrieveCluster(commandLine, configuration, configurationDirectory);
try {
if (withSavepoint) {
@@ -574,25 +561,34 @@ public class CliFrontend {
protected int savepoint(String[] args) throws Exception {
LOG.info("Running 'savepoint' command.");
- SavepointOptions options = CliFrontendParser.parseSavepointCommand(args);
+ final Options commandOptions = CliFrontendParser.getSavepointCommandOptions();
+
+ final Options commandLineOptions = CliFrontendParser.mergeOptions(commandOptions, customCommandLineOptions);
+
+ final CommandLine commandLine = CliFrontendParser.parse(commandLineOptions, args, false);
+
+ final SavepointOptions savepointOptions = new SavepointOptions(commandLine);
// evaluate help flag
- if (options.isPrintHelp()) {
- CliFrontendParser.printHelpForSavepoint();
+ if (savepointOptions.isPrintHelp()) {
+ CliFrontendParser.printHelpForSavepoint(customCommandLines);
return 0;
}
- CustomCommandLine<?> customCommandLine = getActiveCustomCommandLine(options.getCommandLine());
+ CustomCommandLine<?> customCommandLine = getActiveCustomCommandLine(commandLine);
- ClusterClient clusterClient = customCommandLine.retrieveCluster(options.getCommandLine(), config, configurationDirectory);
+ ClusterClient clusterClient = customCommandLine.retrieveCluster(
+ commandLine,
+ configuration,
+ configurationDirectory);
try {
- if (options.isDispose()) {
+ if (savepointOptions.isDispose()) {
// Discard
- return disposeSavepoint(clusterClient, options.getSavepointPath());
+ return disposeSavepoint(clusterClient, savepointOptions.getSavepointPath());
} else {
// Trigger
- String[] cleanedArgs = options.getArgs();
+ String[] cleanedArgs = savepointOptions.getArgs();
JobID jobId;
if (cleanedArgs.length >= 1) {
@@ -767,7 +763,7 @@ public class CliFrontend {
protected ClusterClient retrieveClient(CommandLineOptions options) {
CustomCommandLine customCLI = getActiveCustomCommandLine(options.getCommandLine());
try {
- ClusterClient client = customCLI.retrieveCluster(options.getCommandLine(), config, configurationDirectory);
+ ClusterClient client = customCLI.retrieveCluster(options.getCommandLine(), configuration, configurationDirectory);
logAndSysout("Using address " + client.getJobManagerAddress() + " to connect to JobManager.");
return client;
} catch (Exception e) {
@@ -790,7 +786,7 @@ public class CliFrontend {
ClusterClient client;
try {
- client = customCommandLine.retrieveCluster(commandLine, config, configurationDirectory);
+ client = customCommandLine.retrieveCluster(commandLine, configuration, configurationDirectory);
logAndSysout("Cluster configuration: " + client.getClusterIdentifier());
} catch (UnsupportedOperationException e) {
try {
@@ -798,7 +794,7 @@ public class CliFrontend {
client = customCommandLine.createCluster(
applicationName,
commandLine,
- config,
+ configuration,
configurationDirectory,
program.getAllLibraries());
logAndSysout("Cluster started: " + client.getClusterIdentifier());
@@ -924,7 +920,7 @@ public class CliFrontend {
// check for action
if (args.length < 1) {
- CliFrontendParser.printHelp();
+ CliFrontendParser.printHelp(customCommandLines);
System.out.println("Please specify an action.");
return 1;
}
@@ -952,7 +948,7 @@ public class CliFrontend {
return savepoint(params);
case "-h":
case "--help":
- CliFrontendParser.printHelp();
+ CliFrontendParser.printHelp(customCommandLines);
return 0;
case "-v":
case "--version":
@@ -988,9 +984,22 @@ public class CliFrontend {
public static void main(final String[] args) {
EnvironmentInformation.logEnvironmentInfo(LOG, "Command Line Client", args);
+ // 1. find the configuration directory
+ final String configurationDirectory = getConfigurationDirectoryFromEnv();
+
+ // 2. load the global configuration
+ final Configuration configuration = GlobalConfiguration.loadConfiguration(configurationDirectory);
+
+ // 3. load the custom command lines
+ final List<CustomCommandLine<?>> customCommandLines = loadCustomCommandLines();
+
try {
- final CliFrontend cli = new CliFrontend();
- SecurityUtils.install(new SecurityConfiguration(cli.config));
+ final CliFrontend cli = new CliFrontend(
+ configuration,
+ customCommandLines,
+ configurationDirectory);
+
+ SecurityUtils.install(new SecurityConfiguration(cli.configuration));
int retCode = SecurityUtils.getInstalledContext()
.runSecured(new Callable<Integer>() {
@Override
@@ -1019,7 +1028,7 @@ public class CliFrontend {
return location;
}
else {
- throw new RuntimeException("The config directory '" + location + "', specified in the '" +
+ throw new RuntimeException("The configuration directory '" + location + "', specified in the '" +
ConfigConstants.ENV_FLINK_CONF_DIR + "' environment variable, does not exist.");
}
}
@@ -1041,13 +1050,33 @@ public class CliFrontend {
* Writes the given job manager address to the associated configuration object.
*
* @param address Address to write to the configuration
- * @param config The config to write to
+ * @param config The configuration to write to
*/
public static void setJobManagerAddressInConfig(Configuration config, InetSocketAddress address) {
config.setString(JobManagerOptions.ADDRESS, address.getHostString());
config.setInteger(JobManagerOptions.PORT, address.getPort());
}
+ public static List<CustomCommandLine<?>> loadCustomCommandLines() {
+ List<CustomCommandLine<?>> customCommandLines = new ArrayList<>(2);
+
+ // Command line interface of the YARN session, with a special initialization here
+ // to prefix all options with y/yarn.
+ // Tips: DefaultCLI must be added at last, because getActiveCustomCommandLine(..) will get the
+ // active CustomCommandLine in order and DefaultCLI isActive always return true.
+ final String flinkYarnSessionCLI = "org.apache.flink.yarn.cli.FlinkYarnSessionCli";
+ try {
+ customCommandLines.add(loadCustomCommandLine(flinkYarnSessionCLI, "y", "yarn"));
+ } catch (Exception e) {
+ LOG.warn("Could not load CLI class {}.", flinkYarnSessionCLI, e);
+ }
+
+ customCommandLines.add(new Flip6DefaultCLI());
+ customCommandLines.add(new DefaultCLI());
+
+ return customCommandLines;
+ }
+
// --------------------------------------------------------------------------------------------
// Custom command-line
// --------------------------------------------------------------------------------------------
@@ -1059,7 +1088,7 @@ public class CliFrontend {
*/
public CustomCommandLine getActiveCustomCommandLine(CommandLine commandLine) {
for (CustomCommandLine cli : customCommandLines) {
- if (cli.isActive(commandLine, config)) {
+ if (cli.isActive(commandLine, configuration)) {
return cli;
}
}
@@ -1067,14 +1096,6 @@ public class CliFrontend {
}
/**
- * Retrieves the loaded custom command-lines.
- * @return An unmodifiable list of loaded custom command-lines.
- */
- public static List<CustomCommandLine<?>> getCustomCommandLineList() {
- return Collections.unmodifiableList(customCommandLines);
- }
-
- /**
* Loads a class from the classpath that implements the CustomCommandLine interface.
* @param className The fully-qualified class name to load.
* @param params The constructor parameters
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java b/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java
index 64cfdce..c6e705d 100644
--- a/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java
+++ b/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java
@@ -26,8 +26,10 @@ import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+
+import java.util.Collection;
/**
* A simple command line parser (based on Apache Commons CLI) that extracts command
@@ -35,8 +37,6 @@ import org.slf4j.LoggerFactory;
*/
public class CliFrontendParser {
- private static final Logger LOG = LoggerFactory.getLogger(CliFrontendParser.class);
-
static final Option HELP_OPTION = new Option("h", "help", false,
"Show the help message for the CLI Frontend or the action.");
@@ -137,24 +137,15 @@ public class CliFrontendParser {
}
private static final Options RUN_OPTIONS = getRunCommandOptions();
- private static final Options INFO_OPTIONS = getInfoCommandOptions();
- private static final Options LIST_OPTIONS = getListCommandOptions();
- private static final Options CANCEL_OPTIONS = getCancelCommandOptions();
- private static final Options STOP_OPTIONS = getStopCommandOptions();
- private static final Options SAVEPOINT_OPTIONS = getSavepointCommandOptions();
private static Options buildGeneralOptions(Options options) {
options.addOption(HELP_OPTION);
// backwards compatibility: ignore verbose flag (-v)
options.addOption(new Option("v", "verbose", false, "This option is deprecated."));
- // add general options of all CLIs
- for (CustomCommandLine customCLI : CliFrontend.getCustomCommandLineList()) {
- customCLI.addGeneralOptions(options);
- }
return options;
}
- public static Options getProgramSpecificOptions(Options options) {
+ private static Options getProgramSpecificOptions(Options options) {
options.addOption(JAR_OPTION);
options.addOption(CLASS_OPTION);
options.addOption(CLASSPATH_OPTION);
@@ -176,17 +167,13 @@ public class CliFrontendParser {
return options;
}
- static Options getRunCommandOptions() {
- return getRunOptions(buildGeneralOptions(new Options()));
- }
-
- private static Options getRunOptions(Options options) {
+ public static Options getRunCommandOptions() {
+ Options options = buildGeneralOptions(new Options());
options = getProgramSpecificOptions(options);
options.addOption(SAVEPOINT_PATH_OPTION);
options.addOption(SAVEPOINT_ALLOW_NON_RESTORED_OPTION);
- options = getJobManagerAddressOption(options);
- return addCustomCliOptions(options, true);
+ return getJobManagerAddressOption(options);
}
private static Options getJobManagerAddressOption(Options options) {
@@ -195,54 +182,33 @@ public class CliFrontendParser {
}
static Options getInfoCommandOptions() {
- return getInfoOptions(buildGeneralOptions(new Options()));
- }
-
- private static Options getInfoOptions(Options options) {
+ Options options = buildGeneralOptions(new Options());
options = getProgramSpecificOptions(options);
- options = getJobManagerAddressOption(options);
- return addCustomCliOptions(options, false);
+ return getJobManagerAddressOption(options);
}
static Options getListCommandOptions() {
- return getListOptions(buildGeneralOptions(new Options()));
- }
-
- private static Options getListOptions(Options options) {
+ Options options = buildGeneralOptions(new Options());
options.addOption(RUNNING_OPTION);
options.addOption(SCHEDULED_OPTION);
- options = getJobManagerAddressOption(options);
- return addCustomCliOptions(options, false);
+ return getJobManagerAddressOption(options);
}
static Options getCancelCommandOptions() {
- return getCancelOptions(buildGeneralOptions(new Options()));
- }
-
- private static Options getCancelOptions(Options options) {
+ Options options = buildGeneralOptions(new Options());
options.addOption(CANCEL_WITH_SAVEPOINT_OPTION);
- options = getJobManagerAddressOption(options);
- return addCustomCliOptions(options, false);
+ return getJobManagerAddressOption(options);
}
static Options getStopCommandOptions() {
- return getStopOptions(buildGeneralOptions(new Options()));
- }
-
- private static Options getStopOptions(Options options) {
- options = getJobManagerAddressOption(options);
- return addCustomCliOptions(options, false);
+ Options options = buildGeneralOptions(new Options());
+ return getJobManagerAddressOption(options);
}
static Options getSavepointCommandOptions() {
- return getSavepointOptions(buildGeneralOptions(new Options()));
- }
-
- private static Options getSavepointOptions(Options options) {
- options = getJobManagerAddressOption(options);
+ Options options = buildGeneralOptions(new Options());
options.addOption(SAVEPOINT_DISPOSE_OPTION);
- options.addOption(JAR_OPTION);
- return addCustomCliOptions(options, false);
+ return options.addOption(JAR_OPTION);
}
// --------------------------------------------------------------------------------------------
@@ -291,22 +257,22 @@ public class CliFrontendParser {
/**
* Prints the help for the client.
*/
- public static void printHelp() {
+ public static void printHelp(Collection<CustomCommandLine<?>> customCommandLines) {
System.out.println("./flink <ACTION> [OPTIONS] [ARGUMENTS]");
System.out.println();
System.out.println("The following actions are available:");
- printHelpForRun();
+ printHelpForRun(customCommandLines);
printHelpForInfo();
- printHelpForList();
- printHelpForStop();
- printHelpForCancel();
- printHelpForSavepoint();
+ printHelpForList(customCommandLines);
+ printHelpForStop(customCommandLines);
+ printHelpForCancel(customCommandLines);
+ printHelpForSavepoint(customCommandLines);
System.out.println();
}
- public static void printHelpForRun() {
+ public static void printHelpForRun(Collection<CustomCommandLine<?>> customCommandLines) {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(5);
formatter.setWidth(80);
@@ -316,7 +282,7 @@ public class CliFrontendParser {
formatter.setSyntaxPrefix(" \"run\" action options:");
formatter.printHelp(" ", getRunOptionsWithoutDeprecatedOptions(new Options()));
- printCustomCliOptions(formatter, true);
+ printCustomCliOptions(customCommandLines, formatter, true);
System.out.println();
}
@@ -331,12 +297,10 @@ public class CliFrontendParser {
formatter.setSyntaxPrefix(" \"info\" action options:");
formatter.printHelp(" ", getInfoOptionsWithoutDeprecatedOptions(new Options()));
- printCustomCliOptions(formatter, false);
-
System.out.println();
}
- public static void printHelpForList() {
+ public static void printHelpForList(Collection<CustomCommandLine<?>> customCommandLines) {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(5);
formatter.setWidth(80);
@@ -346,12 +310,12 @@ public class CliFrontendParser {
formatter.setSyntaxPrefix(" \"list\" action options:");
formatter.printHelp(" ", getListOptionsWithoutDeprecatedOptions(new Options()));
- printCustomCliOptions(formatter, false);
+ printCustomCliOptions(customCommandLines, formatter, false);
System.out.println();
}
- public static void printHelpForStop() {
+ public static void printHelpForStop(Collection<CustomCommandLine<?>> customCommandLines) {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(5);
formatter.setWidth(80);
@@ -361,12 +325,12 @@ public class CliFrontendParser {
formatter.setSyntaxPrefix(" \"stop\" action options:");
formatter.printHelp(" ", getStopOptionsWithoutDeprecatedOptions(new Options()));
- printCustomCliOptions(formatter, false);
+ printCustomCliOptions(customCommandLines, formatter, false);
System.out.println();
}
- public static void printHelpForCancel() {
+ public static void printHelpForCancel(Collection<CustomCommandLine<?>> customCommandLines) {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(5);
formatter.setWidth(80);
@@ -376,12 +340,12 @@ public class CliFrontendParser {
formatter.setSyntaxPrefix(" \"cancel\" action options:");
formatter.printHelp(" ", getCancelOptionsWithoutDeprecatedOptions(new Options()));
- printCustomCliOptions(formatter, false);
+ printCustomCliOptions(customCommandLines, formatter, false);
System.out.println();
}
- public static void printHelpForSavepoint() {
+ public static void printHelpForSavepoint(Collection<CustomCommandLine<?>> customCommandLines) {
HelpFormatter formatter = new HelpFormatter();
formatter.setLeftPadding(5);
formatter.setWidth(80);
@@ -391,35 +355,22 @@ public class CliFrontendParser {
formatter.setSyntaxPrefix(" \"savepoint\" action options:");
formatter.printHelp(" ", getSavepointOptionsWithoutDeprecatedOptions(new Options()));
- printCustomCliOptions(formatter, false);
+ printCustomCliOptions(customCommandLines, formatter, false);
System.out.println();
}
/**
- * Adds custom cli options.
- * @param options The options to add options to
- * @param runOptions Whether to include run options
- * @return Options with additions
- */
- private static Options addCustomCliOptions(Options options, boolean runOptions) {
- for (CustomCommandLine cli: CliFrontend.getCustomCommandLineList()) {
- cli.addGeneralOptions(options);
- if (runOptions) {
- cli.addRunOptions(options);
- }
- }
- return options;
- }
-
- /**
* Prints custom cli options.
* @param formatter The formatter to use for printing
* @param runOptions True if the run options should be printed, False to print only general options
*/
- private static void printCustomCliOptions(HelpFormatter formatter, boolean runOptions) {
+ private static void printCustomCliOptions(
+ Collection<CustomCommandLine<?>> customCommandLines,
+ HelpFormatter formatter,
+ boolean runOptions) {
// prints options from all available command-line classes
- for (CustomCommandLine cli: CliFrontend.getCustomCommandLineList()) {
+ for (CustomCommandLine cli: customCommandLines) {
if (cli.getId() != null) {
formatter.setSyntaxPrefix(" Options for " + cli.getId() + " mode:");
Options customOpts = new Options();
@@ -448,46 +399,37 @@ public class CliFrontendParser {
}
}
- public static CancelOptions parseCancelCommand(String[] args) throws CliArgsException {
- try {
- DefaultParser parser = new DefaultParser();
- CommandLine line = parser.parse(CANCEL_OPTIONS, args, false);
- return new CancelOptions(line);
- }
- catch (ParseException e) {
- throw new CliArgsException(e.getMessage());
- }
- }
+ public static CommandLine parse(Options options, String[] args, boolean stopAtNonOptions) throws CliArgsException {
+ final DefaultParser parser = new DefaultParser();
- public static StopOptions parseStopCommand(String[] args) throws CliArgsException {
try {
- DefaultParser parser = new DefaultParser();
- CommandLine line = parser.parse(STOP_OPTIONS, args, false);
- return new StopOptions(line);
+ return parser.parse(options, args, stopAtNonOptions);
} catch (ParseException e) {
throw new CliArgsException(e.getMessage());
}
}
- public static SavepointOptions parseSavepointCommand(String[] args) throws CliArgsException {
- try {
- DefaultParser parser = new DefaultParser();
- CommandLine line = parser.parse(SAVEPOINT_OPTIONS, args, false);
- return new SavepointOptions(line);
- }
- catch (ParseException e) {
- throw new CliArgsException(e.getMessage());
+ /**
+ * Merges the given {@link Options} into a new Options object.
+ *
+ * @param optionsA options to merge, can be null if none
+ * @param optionsB options to merge, can be null if none
+ * @return
+ */
+ static Options mergeOptions(@Nullable Options optionsA, @Nullable Options optionsB) {
+ final Options resultOptions = new Options();
+ if (optionsA != null) {
+ for (Option option : optionsA.getOptions()) {
+ resultOptions.addOption(option);
+ }
}
- }
-
- public static CommandLine parse(Options options, String[] args, boolean stopAtNonOptions) throws CliArgsException {
- final DefaultParser parser = new DefaultParser();
- try {
- return parser.parse(options, args, stopAtNonOptions);
- } catch (ParseException e) {
- throw new CliArgsException(e.getMessage());
+ if (optionsB != null) {
+ for (Option option : optionsB.getOptions()) {
+ resultOptions.addOption(option);
+ }
}
- }
+ return resultOptions;
+ }
}
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendAddressConfigurationTest.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendAddressConfigurationTest.java b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendAddressConfigurationTest.java
index a030442..97fb28d 100644
--- a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendAddressConfigurationTest.java
+++ b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendAddressConfigurationTest.java
@@ -20,7 +20,8 @@ package org.apache.flink.client.cli;
import org.apache.flink.client.program.ClusterClient;
import org.apache.flink.configuration.Configuration;
-import org.apache.flink.configuration.IllegalConfigurationException;
+import org.apache.flink.configuration.GlobalConfiguration;
+import org.apache.flink.util.TestLogger;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -28,15 +29,15 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.net.InetSocketAddress;
+import java.util.Collections;
import static org.apache.flink.client.cli.CliFrontendTestUtils.checkJobManagerAddress;
-import static org.junit.Assert.fail;
/**
* Tests that verify that the CLI client picks up the correct address for the JobManager
* from configuration and configs.
*/
-public class CliFrontendAddressConfigurationTest {
+public class CliFrontendAddressConfigurationTest extends TestLogger {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@@ -47,50 +48,37 @@ public class CliFrontendAddressConfigurationTest {
}
@Test
- public void testValidConfig() {
- try {
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
- RunOptions options = CliFrontendParser.parseRunCommand(new String[] {});
-
- ClusterClient clusterClient = frontend.retrieveClient(options);
-
- checkJobManagerAddress(
- clusterClient.getFlinkConfiguration(),
- CliFrontendTestUtils.TEST_JOB_MANAGER_ADDRESS,
- CliFrontendTestUtils.TEST_JOB_MANAGER_PORT);
- }
- catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
- }
+ public void testValidConfig() throws Exception {
+ CliFrontend frontend = new CliFrontend(
+ GlobalConfiguration.loadConfiguration(CliFrontendTestUtils.getConfigDir()),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
- @Test(expected = IllegalConfigurationException.class)
- public void testInvalidConfigAndNoOption() throws Exception {
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getInvalidConfigDir());
RunOptions options = CliFrontendParser.parseRunCommand(new String[] {});
- frontend.retrieveClient(options);
+ ClusterClient clusterClient = frontend.retrieveClient(options);
+
+ checkJobManagerAddress(
+ clusterClient.getFlinkConfiguration(),
+ CliFrontendTestUtils.TEST_JOB_MANAGER_ADDRESS,
+ CliFrontendTestUtils.TEST_JOB_MANAGER_PORT);
}
@Test
- public void testManualOptionsOverridesConfig() {
- try {
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ public void testManualOptionsOverridesConfig() throws Exception {
+ CliFrontend frontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
- RunOptions options = CliFrontendParser.parseRunCommand(new String[] {"-m", "203.0.113.22:7788"});
+ RunOptions options = CliFrontendParser.parseRunCommand(new String[] {"-m", "203.0.113.22:7788"});
- ClusterClient client = frontend.retrieveClient(options);
- Configuration config = client.getFlinkConfiguration();
+ ClusterClient client = frontend.retrieveClient(options);
+ Configuration config = client.getFlinkConfiguration();
- InetSocketAddress expectedAddress = new InetSocketAddress("203.0.113.22", 7788);
+ InetSocketAddress expectedAddress = new InetSocketAddress("203.0.113.22", 7788);
- checkJobManagerAddress(config, expectedAddress.getHostName(), expectedAddress.getPort());
- }
- catch (Exception e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
+ checkJobManagerAddress(config, expectedAddress.getHostName(), expectedAddress.getPort());
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendCancelTest.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendCancelTest.java b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendCancelTest.java
index 06ac709..1c1f4f4 100644
--- a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendCancelTest.java
+++ b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendCancelTest.java
@@ -20,21 +20,23 @@ package org.apache.flink.client.cli;
import org.apache.flink.api.common.JobID;
import org.apache.flink.client.cli.util.MockedCliFrontend;
+import org.apache.flink.client.program.ClusterClient;
+import org.apache.flink.configuration.Configuration;
import org.apache.flink.util.TestLogger;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
+import java.util.Collections;
+
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.isNull;
import static org.mockito.Matchers.notNull;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
-import static org.powermock.api.mockito.PowerMockito.doThrow;
/**
* Tests for the CANCEL command.
@@ -48,33 +50,26 @@ public class CliFrontendCancelTest extends TestLogger {
@Test
public void testCancel() throws Exception {
-
// test cancel properly
- {
- JobID jid = new JobID();
+ JobID jid = new JobID();
- String[] parameters = { jid.toString() };
- CancelTestCliFrontend testFrontend = new CancelTestCliFrontend(false);
+ String[] parameters = { jid.toString() };
+ final ClusterClient clusterClient = createClusterClient();
+ MockedCliFrontend testFrontend = new MockedCliFrontend(clusterClient);
- int retCode = testFrontend.cancel(parameters);
- assertEquals(0, retCode);
+ int retCode = testFrontend.cancel(parameters);
+ assertEquals(0, retCode);
- Mockito.verify(testFrontend.client, times(1)).cancel(any(JobID.class));
- }
-
- // test flip6 switch
- {
- String[] parameters =
- {"-flip6", String.valueOf(new JobID())};
- CancelOptions options = CliFrontendParser.parseCancelCommand(parameters);
- assertTrue(options.getCommandLine().hasOption(Flip6DefaultCLI.FLIP_6.getOpt()));
- }
+ Mockito.verify(clusterClient, times(1)).cancel(any(JobID.class));
}
@Test(expected = CliArgsException.class)
public void testMissingJobId() throws Exception {
String[] parameters = {};
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.cancel(parameters);
fail("Should have failed.");
@@ -83,7 +78,10 @@ public class CliFrontendCancelTest extends TestLogger {
@Test(expected = CliArgsException.class)
public void testUnrecognizedOption() throws Exception {
String[] parameters = {"-v", "-l"};
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.cancel(parameters);
fail("Should have failed with CliArgsException.");
@@ -99,10 +97,11 @@ public class CliFrontendCancelTest extends TestLogger {
JobID jid = new JobID();
String[] parameters = { "-s", jid.toString() };
- CancelTestCliFrontend testFrontend = new CancelTestCliFrontend(false);
+ final ClusterClient clusterClient = createClusterClient();
+ MockedCliFrontend testFrontend = new MockedCliFrontend(clusterClient);
assertEquals(0, testFrontend.cancel(parameters));
- Mockito.verify(testFrontend.client, times(1))
+ Mockito.verify(clusterClient, times(1))
.cancelWithSavepoint(any(JobID.class), isNull(String.class));
}
@@ -111,10 +110,11 @@ public class CliFrontendCancelTest extends TestLogger {
JobID jid = new JobID();
String[] parameters = { "-s", "targetDirectory", jid.toString() };
- CancelTestCliFrontend testFrontend = new CancelTestCliFrontend(false);
+ final ClusterClient clusterClient = createClusterClient();
+ MockedCliFrontend testFrontend = new MockedCliFrontend(clusterClient);
assertEquals(0, testFrontend.cancel(parameters));
- Mockito.verify(testFrontend.client, times(1))
+ Mockito.verify(clusterClient, times(1))
.cancelWithSavepoint(any(JobID.class), notNull(String.class));
}
}
@@ -123,7 +123,10 @@ public class CliFrontendCancelTest extends TestLogger {
public void testCancelWithSavepointWithoutJobId() throws Exception {
// Cancel with savepoint (with target directory), but no job ID
String[] parameters = { "-s", "targetDirectory" };
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.cancel(parameters);
fail("Should have failed.");
@@ -133,19 +136,18 @@ public class CliFrontendCancelTest extends TestLogger {
public void testCancelWithSavepointWithoutParameters() throws Exception {
// Cancel with savepoint (no target directory) and no job ID
String[] parameters = { "-s" };
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.cancel(parameters);
fail("Should have failed.");
}
- private static final class CancelTestCliFrontend extends MockedCliFrontend {
+ private static ClusterClient createClusterClient() throws Exception {
+ final ClusterClient clusterClient = mock(ClusterClient.class);
- CancelTestCliFrontend(boolean reject) throws Exception {
- if (reject) {
- doThrow(new IllegalArgumentException("Test exception")).when(client).cancel(any(JobID.class));
- doThrow(new IllegalArgumentException("Test exception")).when(client).cancelWithSavepoint(any(JobID.class), anyString());
- }
- }
+ return clusterClient;
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendInfoTest.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendInfoTest.java b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendInfoTest.java
index cfca33e..3f1de55 100644
--- a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendInfoTest.java
+++ b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendInfoTest.java
@@ -18,12 +18,14 @@
package org.apache.flink.client.cli;
+import org.apache.flink.configuration.Configuration;
import org.apache.flink.util.TestLogger;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.util.Collections;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -40,7 +42,10 @@ public class CliFrontendInfoTest extends TestLogger {
@Test(expected = CliArgsException.class)
public void testMissingOption() throws Exception {
String[] parameters = {};
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.cancel(parameters);
fail("Should have failed with CliArgsException");
@@ -49,7 +54,10 @@ public class CliFrontendInfoTest extends TestLogger {
@Test(expected = CliArgsException.class)
public void testUnrecognizedOption() throws Exception {
String[] parameters = {"-v", "-l"};
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.cancel(parameters);
fail("Should have failed with CliArgsException");
@@ -61,7 +69,10 @@ public class CliFrontendInfoTest extends TestLogger {
try {
String[] parameters = new String[]{CliFrontendTestUtils.getTestJarPath(), "-f", "true"};
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
int retCode = testFrontend.info(parameters);
assertTrue(retCode == 0);
assertTrue(buffer.toString().contains("\"parallelism\": \"1\""));
@@ -76,7 +87,10 @@ public class CliFrontendInfoTest extends TestLogger {
replaceStdOut();
try {
String[] parameters = {"-p", "17", CliFrontendTestUtils.getTestJarPath()};
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
int retCode = testFrontend.info(parameters);
assertTrue(retCode == 0);
assertTrue(buffer.toString().contains("\"parallelism\": \"17\""));
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendListTest.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendListTest.java b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendListTest.java
index 3185d23..8e10233 100644
--- a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendListTest.java
+++ b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendListTest.java
@@ -19,6 +19,8 @@
package org.apache.flink.client.cli;
import org.apache.flink.client.cli.util.MockedCliFrontend;
+import org.apache.flink.client.program.ClusterClient;
+import org.apache.flink.configuration.Configuration;
import org.apache.flink.util.TestLogger;
import org.junit.BeforeClass;
@@ -30,8 +32,9 @@ import java.util.concurrent.CompletableFuture;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
-import static org.powermock.api.mockito.PowerMockito.when;
+import static org.mockito.Mockito.when;
/**
* Tests for the LIST command.
@@ -48,10 +51,11 @@ public class CliFrontendListTest extends TestLogger {
// test list properly
{
String[] parameters = {"-r", "-s"};
- ListTestCliFrontend testFrontend = new ListTestCliFrontend();
+ ClusterClient clusterClient = createClusterClient();
+ MockedCliFrontend testFrontend = new MockedCliFrontend(clusterClient);
int retCode = testFrontend.list(parameters);
assertTrue(retCode == 0);
- Mockito.verify(testFrontend.client, times(1))
+ Mockito.verify(clusterClient, times(1))
.listJobs();
}
}
@@ -59,16 +63,20 @@ public class CliFrontendListTest extends TestLogger {
@Test(expected = CliArgsException.class)
public void testUnrecognizedOption() throws Exception {
String[] parameters = {"-v", "-k"};
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.list(parameters);
fail("Should have failed with an CliArgsException.");
}
- private static final class ListTestCliFrontend extends MockedCliFrontend {
+ private static ClusterClient createClusterClient() throws Exception {
+ final ClusterClient clusterClient = mock(ClusterClient.class);
- ListTestCliFrontend() throws Exception {
- when(client.listJobs()).thenReturn(CompletableFuture.completedFuture(Collections.emptyList()));
- }
+ when(clusterClient.listJobs()).thenReturn(CompletableFuture.completedFuture(Collections.emptyList()));
+
+ return clusterClient;
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendPackageProgramTest.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendPackageProgramTest.java b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendPackageProgramTest.java
index b27eab2..26f26ff 100644
--- a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendPackageProgramTest.java
+++ b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendPackageProgramTest.java
@@ -26,13 +26,16 @@ import org.apache.flink.optimizer.CompilerException;
import org.apache.flink.optimizer.DataStatistics;
import org.apache.flink.optimizer.Optimizer;
import org.apache.flink.optimizer.costs.DefaultCostEstimator;
+import org.apache.flink.util.TestLogger;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.net.URL;
+import java.util.Collections;
import static org.apache.flink.client.cli.CliFrontendTestUtils.TEST_JAR_CLASSLOADERTEST_CLASS;
import static org.apache.flink.client.cli.CliFrontendTestUtils.TEST_JAR_MAIN_CLASS;
@@ -50,18 +53,26 @@ import static org.mockito.Mockito.when;
/**
* Tests for the RUN command with {@link PackagedProgram PackagedPrograms}.
*/
-public class CliFrontendPackageProgramTest {
+public class CliFrontendPackageProgramTest extends TestLogger {
+
+ private CliFrontend frontend;
@BeforeClass
public static void init() {
pipeSystemOutToNull();
}
+ @Before
+ public void setup() throws Exception {
+ frontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
+ }
+
@Test
public void testNonExistingJarFile() {
try {
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
-
ProgramOptions options = mock(ProgramOptions.class);
when(options.getJarFilePath()).thenReturn("/some/none/existing/path");
@@ -82,8 +93,6 @@ public class CliFrontendPackageProgramTest {
@Test
public void testFileNotJarFile() {
try {
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
-
ProgramOptions options = mock(ProgramOptions.class);
when(options.getJarFilePath()).thenReturn(getNonJarFilePath());
@@ -117,7 +126,6 @@ public class CliFrontendPackageProgramTest {
assertArrayEquals(classpath, options.getClasspaths().toArray());
assertArrayEquals(reducedArguments, options.getProgramArgs());
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
PackagedProgram prog = frontend.buildProgram(options);
Assert.assertArrayEquals(reducedArguments, prog.getArguments());
@@ -145,8 +153,6 @@ public class CliFrontendPackageProgramTest {
assertArrayEquals(classpath, options.getClasspaths().toArray());
assertArrayEquals(reducedArguments, options.getProgramArgs());
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
-
PackagedProgram prog = frontend.buildProgram(options);
Assert.assertArrayEquals(reducedArguments, prog.getArguments());
@@ -174,8 +180,6 @@ public class CliFrontendPackageProgramTest {
assertArrayEquals(classpath, options.getClasspaths().toArray());
assertArrayEquals(reducedArguments, options.getProgramArgs());
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
-
PackagedProgram prog = frontend.buildProgram(options);
Assert.assertArrayEquals(reducedArguments, prog.getArguments());
@@ -189,7 +193,6 @@ public class CliFrontendPackageProgramTest {
@Test(expected = CliArgsException.class)
public void testNoJarNoArgumentsAtAll() throws Exception {
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
assertTrue(frontend.run(new String[0]) != 0);
fail("Should have failed.");
@@ -211,8 +214,6 @@ public class CliFrontendPackageProgramTest {
assertArrayEquals(classpath, options.getClasspaths().toArray());
assertArrayEquals(reducedArguments, options.getProgramArgs());
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
-
try {
frontend.buildProgram(options);
fail("Should fail with an exception");
@@ -236,8 +237,6 @@ public class CliFrontendPackageProgramTest {
assertEquals(arguments[0], options.getJarFilePath());
assertArrayEquals(new String[0], options.getProgramArgs());
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
-
try {
frontend.buildProgram(options);
}
@@ -303,7 +302,6 @@ public class CliFrontendPackageProgramTest {
assertEquals(TEST_JAR_CLASSLOADERTEST_CLASS, options.getEntryPointClassName());
assertArrayEquals(reducedArguments, options.getProgramArgs());
- CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
PackagedProgram prog = spy(frontend.buildProgram(options));
ClassLoader testClassLoader = new ClassLoader(prog.getUserCodeClassLoader()) {
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendRunTest.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendRunTest.java b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendRunTest.java
index d17d999..bc55e2d 100644
--- a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendRunTest.java
+++ b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendRunTest.java
@@ -20,11 +20,15 @@ package org.apache.flink.client.cli;
import org.apache.flink.client.program.ClusterClient;
import org.apache.flink.client.program.PackagedProgram;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.GlobalConfiguration;
import org.apache.flink.runtime.jobgraph.SavepointRestoreSettings;
import org.junit.BeforeClass;
import org.junit.Test;
+import java.util.Collections;
+
import static org.apache.flink.client.cli.CliFrontendTestUtils.getTestJarPath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -102,21 +106,16 @@ public class CliFrontendRunTest {
assertEquals("--arg2", options.getProgramArgs()[3]);
assertEquals("value2", options.getProgramArgs()[4]);
}
-
- // test flip6 switch
- {
- String[] parameters =
- {"-flip6", getTestJarPath()};
- RunOptions options = CliFrontendParser.parseRunCommand(parameters);
- assertTrue(options.getCommandLine().hasOption(Flip6DefaultCLI.FLIP_6.getOpt()));
- }
}
@Test(expected = CliArgsException.class)
public void testUnrecognizedOption() throws Exception {
// test unrecognized option
String[] parameters = {"-v", "-l", "-a", "some", "program", "arguments"};
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.run(parameters);
fail("Should have failed.");
@@ -126,7 +125,10 @@ public class CliFrontendRunTest {
public void testInvalidParallelismOption() throws Exception {
// test configure parallelism with non integer value
String[] parameters = {"-v", "-p", "text", getTestJarPath()};
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.run(parameters);
fail("Should have failed.");
@@ -136,7 +138,10 @@ public class CliFrontendRunTest {
public void testParallelismWithOverflow() throws Exception {
// test configure parallelism with overflow integer value
String[] parameters = {"-v", "-p", "475871387138", getTestJarPath()};
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.run(parameters);
fail("Should have failed.");
@@ -151,7 +156,10 @@ public class CliFrontendRunTest {
private final boolean isDetached;
public RunTestingCliFrontend(int expectedParallelism, boolean logging, boolean isDetached) throws Exception {
- super(CliFrontendTestUtils.getConfigDir());
+ super(
+ GlobalConfiguration.loadConfiguration(CliFrontendTestUtils.getConfigDir()),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
this.expectedParallelism = expectedParallelism;
this.sysoutLogging = logging;
this.isDetached = isDetached;
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendSavepointTest.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendSavepointTest.java b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendSavepointTest.java
index ff36b7b..f8b62cd 100644
--- a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendSavepointTest.java
+++ b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendSavepointTest.java
@@ -285,9 +285,9 @@ public class CliFrontendSavepointTest extends TestLogger {
private static final class DisposeSavepointClusterClient extends StandaloneClusterClient {
- final BiFunction<String, Time, CompletableFuture<Acknowledge>> disposeSavepointFunction;
+ private final BiFunction<String, Time, CompletableFuture<Acknowledge>> disposeSavepointFunction;
- public DisposeSavepointClusterClient(BiFunction<String, Time, CompletableFuture<Acknowledge>> disposeSavepointFunction) throws Exception {
+ DisposeSavepointClusterClient(BiFunction<String, Time, CompletableFuture<Acknowledge>> disposeSavepointFunction) throws Exception {
super(new Configuration(), new TestingHighAvailabilityServices());
this.disposeSavepointFunction = Preconditions.checkNotNull(disposeSavepointFunction);
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendStopTest.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendStopTest.java b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendStopTest.java
index 08de063..fc873cc 100644
--- a/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendStopTest.java
+++ b/flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendStopTest.java
@@ -20,6 +20,8 @@ package org.apache.flink.client.cli;
import org.apache.flink.api.common.JobID;
import org.apache.flink.client.cli.util.MockedCliFrontend;
+import org.apache.flink.client.program.ClusterClient;
+import org.apache.flink.configuration.Configuration;
import org.apache.flink.util.FlinkException;
import org.apache.flink.util.TestLogger;
@@ -27,11 +29,13 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
+import java.util.Collections;
+
import static org.apache.flink.client.cli.CliFrontendTestUtils.pipeSystemOutToNull;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.powermock.api.mockito.PowerMockito.doThrow;
@@ -53,20 +57,13 @@ public class CliFrontendStopTest extends TestLogger {
String jidString = jid.toString();
String[] parameters = { jidString };
- StopTestCliFrontend testFrontend = new StopTestCliFrontend(false);
+ final ClusterClient clusterClient = createClusterClient(false);
+ MockedCliFrontend testFrontend = new MockedCliFrontend(clusterClient);
int retCode = testFrontend.stop(parameters);
assertEquals(0, retCode);
- Mockito.verify(testFrontend.client, times(1)).stop(any(JobID.class));
- }
-
- // test flip6 switch
- {
- String[] parameters =
- {"-flip6", String.valueOf(new JobID())};
- StopOptions options = CliFrontendParser.parseStopCommand(parameters);
- assertTrue(options.getCommandLine().hasOption(Flip6DefaultCLI.FLIP_6.getOpt()));
+ Mockito.verify(clusterClient, times(1)).stop(any(JobID.class));
}
}
@@ -74,7 +71,10 @@ public class CliFrontendStopTest extends TestLogger {
public void testUnrecognizedOption() throws Exception {
// test unrecognized option
String[] parameters = { "-v", "-l" };
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.stop(parameters);
fail("Should have failed.");
@@ -84,7 +84,10 @@ public class CliFrontendStopTest extends TestLogger {
public void testMissingJobId() throws Exception {
// test missing job id
String[] parameters = {};
- CliFrontend testFrontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());
+ CliFrontend testFrontend = new CliFrontend(
+ new Configuration(),
+ Collections.singletonList(new DefaultCLI()),
+ CliFrontendTestUtils.getConfigDir());
testFrontend.stop(parameters);
fail("Should have failed.");
@@ -96,7 +99,8 @@ public class CliFrontendStopTest extends TestLogger {
JobID jid = new JobID();
String[] parameters = { jid.toString() };
- StopTestCliFrontend testFrontend = new StopTestCliFrontend(true);
+ final ClusterClient clusterClient = createClusterClient(true);
+ MockedCliFrontend testFrontend = new MockedCliFrontend(clusterClient);
testFrontend.stop(parameters);
fail("Should have failed.");
@@ -110,12 +114,13 @@ public class CliFrontendStopTest extends TestLogger {
}
}
- private static final class StopTestCliFrontend extends MockedCliFrontend {
+ private static ClusterClient createClusterClient(boolean reject) throws Exception {
+ final ClusterClient clusterClient = mock(ClusterClient.class);
- StopTestCliFrontend(boolean reject) throws Exception {
- if (reject) {
- doThrow(new TestException("Test Exception")).when(client).stop(any(JobID.class));
- }
+ if (reject) {
+ doThrow(new TestException("Test Exception")).when(clusterClient).stop(any(JobID.class));
}
+
+ return clusterClient;
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/test/java/org/apache/flink/client/cli/Flip6DefaultCLITest.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/Flip6DefaultCLITest.java b/flink-clients/src/test/java/org/apache/flink/client/cli/Flip6DefaultCLITest.java
new file mode 100644
index 0000000..6a538d4
--- /dev/null
+++ b/flink-clients/src/test/java/org/apache/flink/client/cli/Flip6DefaultCLITest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.client.cli;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.util.TestLogger;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test cases for the {@link Flip6DefaultCLI}.
+ */
+public class Flip6DefaultCLITest extends TestLogger {
+
+ /**
+ * Tests that the flip6 command line switch is recognized.
+ */
+ @Test
+ public void testFlip6Switch() throws CliArgsException {
+ final String[] args = {"-flip6"};
+ final Flip6DefaultCLI flip6DefaultCLI = new Flip6DefaultCLI();
+
+ final Options options = new Options();
+ flip6DefaultCLI.addGeneralOptions(options);
+ flip6DefaultCLI.addRunOptions(options);
+
+ final CommandLine commandLine = CliFrontendParser.parse(options, args, false);
+
+ Assert.assertTrue(commandLine.hasOption(Flip6DefaultCLI.FLIP_6.getOpt()));
+ Assert.assertTrue(flip6DefaultCLI.isActive(commandLine, new Configuration()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/test/java/org/apache/flink/client/cli/util/DummyCustomCommandLine.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/util/DummyCustomCommandLine.java b/flink-clients/src/test/java/org/apache/flink/client/cli/util/DummyCustomCommandLine.java
new file mode 100644
index 0000000..1bbafae
--- /dev/null
+++ b/flink-clients/src/test/java/org/apache/flink/client/cli/util/DummyCustomCommandLine.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.client.cli.util;
+
+import org.apache.flink.client.cli.CustomCommandLine;
+import org.apache.flink.client.program.ClusterClient;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+
+import java.net.URL;
+import java.util.List;
+
+/**
+ * Dummy implementation of the {@link CustomCommandLine} for testing purposes.
+ *
+ * @param <T> type of the returned cluster client
+ */
+public class DummyCustomCommandLine<T extends ClusterClient> implements CustomCommandLine<T> {
+ private final T clusterClient;
+
+ public DummyCustomCommandLine(T clusterClient) {
+ this.clusterClient = Preconditions.checkNotNull(clusterClient);
+ }
+
+ @Override
+ public boolean isActive(CommandLine commandLine, Configuration configuration) {
+ return true;
+ }
+
+ @Override
+ public String getId() {
+ return DummyCustomCommandLine.class.getSimpleName();
+ }
+
+ @Override
+ public void addRunOptions(Options baseOptions) {
+ // nothing to add
+ }
+
+ @Override
+ public void addGeneralOptions(Options baseOptions) {
+ // nothing to add
+ }
+
+ @Override
+ public T retrieveCluster(CommandLine commandLine, Configuration config, String configurationDirectory) throws UnsupportedOperationException {
+ return clusterClient;
+ }
+
+ @Override
+ public T createCluster(String applicationName, CommandLine commandLine, Configuration config, String configurationDirectory, List<URL> userJarFiles) throws Exception {
+ return clusterClient;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-clients/src/test/java/org/apache/flink/client/cli/util/MockedCliFrontend.java
----------------------------------------------------------------------
diff --git a/flink-clients/src/test/java/org/apache/flink/client/cli/util/MockedCliFrontend.java b/flink-clients/src/test/java/org/apache/flink/client/cli/util/MockedCliFrontend.java
index 6d2bcca..135e831 100644
--- a/flink-clients/src/test/java/org/apache/flink/client/cli/util/MockedCliFrontend.java
+++ b/flink-clients/src/test/java/org/apache/flink/client/cli/util/MockedCliFrontend.java
@@ -20,16 +20,10 @@ package org.apache.flink.client.cli.util;
import org.apache.flink.client.cli.CliFrontend;
import org.apache.flink.client.cli.CliFrontendTestUtils;
-import org.apache.flink.client.cli.CustomCommandLine;
import org.apache.flink.client.program.ClusterClient;
import org.apache.flink.configuration.Configuration;
-import org.apache.commons.cli.CommandLine;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.powermock.api.mockito.PowerMockito.mock;
-import static org.powermock.api.mockito.PowerMockito.when;
+import java.util.Collections;
/**
* Utility class for mocking the {@link ClusterClient} within a {@link CliFrontend}.
@@ -37,23 +31,11 @@ import static org.powermock.api.mockito.PowerMockito.when;
* <p>The mocking behavior can be defined in the constructor of the sub-class.
*/
public class MockedCliFrontend extends CliFrontend {
- public final ClusterClient client;
public MockedCliFrontend(ClusterClient clusterClient) throws Exception {
- super(CliFrontendTestUtils.getConfigDir());
- this.client = clusterClient;
- }
-
- protected MockedCliFrontend() throws Exception {
- super(CliFrontendTestUtils.getConfigDir());
- this.client = mock(ClusterClient.class);
- }
-
- @Override
- public CustomCommandLine getActiveCustomCommandLine(CommandLine commandLine) {
- CustomCommandLine ccl = mock(CustomCommandLine.class);
- when(ccl.retrieveCluster(any(CommandLine.class), any(Configuration.class), anyString()))
- .thenReturn(client);
- return ccl;
+ super(
+ new Configuration(),
+ Collections.singletonList(new DummyCustomCommandLine<>(clusterClient)),
+ CliFrontendTestUtils.getConfigDir());
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/aff43768/flink-scala-shell/src/main/scala/org/apache/flink/api/scala/FlinkShell.scala
----------------------------------------------------------------------
diff --git a/flink-scala-shell/src/main/scala/org/apache/flink/api/scala/FlinkShell.scala b/flink-scala-shell/src/main/scala/org/apache/flink/api/scala/FlinkShell.scala
index 43149d9..b412620 100644
--- a/flink-scala-shell/src/main/scala/org/apache/flink/api/scala/FlinkShell.scala
+++ b/flink-scala-shell/src/main/scala/org/apache/flink/api/scala/FlinkShell.scala
@@ -23,9 +23,11 @@ import java.util.Collections
import org.apache.commons.cli.CommandLine
import org.apache.flink.client.cli.{CliFrontend, CliFrontendParser}
+import org.apache.flink.client.deployment.ClusterDescriptor
+import org.apache.flink.client.deployment.ClusterSpecification.ClusterSpecificationBuilder
import org.apache.flink.client.program.ClusterClient
import org.apache.flink.runtime.minicluster.StandaloneMiniCluster
-import org.apache.flink.configuration.{ConfigConstants, GlobalConfiguration, JobManagerOptions}
+import org.apache.flink.configuration.{ConfigConstants, Configuration, GlobalConfiguration, JobManagerOptions}
import org.apache.flink.runtime.minicluster.{FlinkMiniCluster, LocalFlinkMiniCluster}
import scala.collection.mutable.ArrayBuffer
@@ -139,6 +141,7 @@ object FlinkShell {
}
def fetchConnectionInfo(
+ configuration: Configuration,
config: Config
): (String, Int, Option[Either[StandaloneMiniCluster, ClusterClient]]) = {
config.executionMode match {
@@ -161,9 +164,15 @@ object FlinkShell {
case ExecutionMode.YARN => // YARN mode
config.yarnConfig match {
case Some(yarnConfig) => // if there is information for new cluster
- deployNewYarnCluster(yarnConfig)
+ deployNewYarnCluster(
+ configuration,
+ config.configDir.getOrElse(CliFrontend.getConfigurationDirectoryFromEnv),
+ yarnConfig)
case None => // there is no information for new cluster. Then we use yarn properties.
- fetchDeployedYarnClusterInfo()
+ fetchDeployedYarnClusterInfo(
+ configuration,
+ config.configDir.getOrElse(CliFrontend.getConfigurationDirectoryFromEnv)
+ )
}
case ExecutionMode.UNDEFINED => // Wrong input
@@ -182,10 +191,10 @@ object FlinkShell {
}
val configDirectory = new File(confDirPath)
- GlobalConfiguration.loadConfiguration(configDirectory.getAbsolutePath)
+ val configuration = GlobalConfiguration.loadConfiguration(configDirectory.getAbsolutePath)
val (repl, cluster) = try {
- val (host, port, cluster) = fetchConnectionInfo(config)
+ val (host, port, cluster) = fetchConnectionInfo(configuration, config)
val conf = cluster match {
case Some(Left(miniCluster)) => miniCluster.getConfiguration
case Some(Right(yarnCluster)) => yarnCluster.getFlinkConfiguration
@@ -226,7 +235,10 @@ object FlinkShell {
println(" good bye ..")
}
- def deployNewYarnCluster(yarnConfig: YarnConfig) = {
+ def deployNewYarnCluster(
+ configuration: Configuration,
+ configurationDirectory: String,
+ yarnConfig: YarnConfig) = {
val args = ArrayBuffer[String](
"-m", "yarn-cluster"
@@ -246,9 +258,11 @@ object FlinkShell {
yarnConfig.queue.foreach((queue) => args ++= Seq("-yqu", queue.toString))
yarnConfig.slots.foreach((slots) => args ++= Seq("-ys", slots.toString))
-
val options = CliFrontendParser.parseRunCommand(args.toArray)
- val frontend = new CliFrontend()
+ val frontend = new CliFrontend(
+ configuration,
+ CliFrontend.loadCustomCommandLines(),
+ configurationDirectory)
val config = frontend.getConfiguration
val customCLI = frontend.getActiveCustomCommandLine(options.getCommandLine)
@@ -265,7 +279,9 @@ object FlinkShell {
(address, port, Some(Right(cluster)))
}
- def fetchDeployedYarnClusterInfo() = {
+ def fetchDeployedYarnClusterInfo(
+ configuration: Configuration,
+ configurationDirectory: String) = {
val args = ArrayBuffer[String](
@@ -273,7 +289,10 @@ object FlinkShell {
)
val options = CliFrontendParser.parseRunCommand(args.toArray)
- val frontend = new CliFrontend()
+ val frontend = new CliFrontend(
+ configuration,
+ CliFrontend.loadCustomCommandLines(),
+ configurationDirectory)
val config = frontend.getConfiguration
val customCLI = frontend.getActiveCustomCommandLine(options.getCommandLine)