Driver extends Configured implements Tool { final public int runner(String... arguments) { int returnValue; try { reset(); returnValue = ToolRunner.run(this, arguments); } catch (Exception exception) { if (LOG.isErrorEnabled()) { LOG.error("Fatal error encountered", exception); } returnValue = FAILURE_RUNTIME; } if (returnValue != SUCCESS) { if (LOG.isInfoEnabled()) { StringBuilder optionsAndParameters = new StringBuilder(256); for (int i = 0; i < options().length; i++) { optionsAndParameters.append(" [--").append(options()[i]).append("]"); } for (int i = 0; i < parameters().length; i++) { optionsAndParameters.append(parameters().length == 0 ? "" : " " + "<" + parameters()[i] + ">"); } if (description() != null && !description().equals("")) { LOG.info("Description: " + description()); } LOG.info("Usage: " + (engine.equals(Engine.HADOOP) ? "hadoop" : "spark-submit") + " " + this.getClass().getCanonicalName() + " [generic options]" + optionsAndParameters) ; } } return returnValue; } Driver(Engine engine);  Driver(Configuration conf, Engine engine); String description(); String[] options(); String[] parameters(); @SuppressWarnings("SameReturnValue") int prepare(String... arguments); abstract int execute(); @SuppressWarnings("SameReturnValue") int cleanup(); void reset(); @Override final int run(String[] args); final int runner(String... arguments); boolean pollMetaData(MetaDataExecution metaData); List<MetaDataExecution> pullMetaData(MetaDataExecution metaData); void addMetaDataCounter(MetaDataExecution metaData, Enum label, Long counter); void pushMetaData(MetaDataExecution metaData); void pushMetadataTags(MetaDataExecution metaData, String remove, String add); List<Object> getResults(); void addResults(List<Object> results); void addResult(Object result); Map<String, Map<Enum<?>, Long>> getCounters(); Map<Enum<?>, Long> getCounters(String group); Set<String> getCountersGroups(); Long getCounter(String group, Enum<?> counter); Long incrementCounter(Enum<?> counter, long increment); Long incrementCounter(String group, Enum<?> counter, long increment); Long incrementCounter(Enum<?> counter, int increment, String tag, Set<String> set); Long incrementCounter(String group, Enum<?> counter, int increment, String tag, Set<String> set); static String getApplicationProperty(String key); static final int SUCCESS; static final int FAILURE_ARGUMENTS; static final int FAILURE_RUNTIME; static final String CONF_CLDR_JOB_NAME; static final String CONF_CLDR_JOB_GROUP; static final String CONF_CLDR_JOB_VERSION; static final String CONF_CLDR_JOB_TRANSACTION; static final String CONF_CLDR_JOB_METADATA; static final String CONF_SETTINGS; static final String CONF_APPLICATION; static final String METADATA_NAMESPACE; }
@Test public void testRunnerFailureOptionsHadoop() throws Exception { Driver driver = new CountFilesDriver(dfsServer.getConf(), Engine.HADOOP); driver.getConf().setBoolean("i.should.fail.option", true); assertEquals(Driver.FAILURE_RUNTIME, driver.runner("false")); }
@Test public void testRunnerFailureOptionsSpark() throws Exception { Driver driver = new CountFilesDriver(dfsServer.getConf(), Engine.SPARK); assertEquals(Driver.FAILURE_RUNTIME, driver.runner("-Di.should.fail.option=true", "false")); assertEquals(Driver.FAILURE_RUNTIME, driver.runner("--i.should.fail.option=true", "false")); }
@Test public void testRunnerFailureHadoop() throws Exception { Driver driver = new CountFilesDriver(dfsServer.getConf(), Engine.HADOOP); assertEquals(Driver.FAILURE_ARGUMENTS, driver.runner()); }
@Test public void testRunnerFailureSpark() throws Exception { Driver driver = new CountFilesDriver(dfsServer.getConf(), Engine.SPARK); assertEquals(Driver.FAILURE_ARGUMENTS, driver.runner()); }
@Test public void testRunnerSuccessParametersHadoop() throws Exception { Driver driver = new CountFilesDriver(dfsServer.getConf(), Engine.HADOOP); assertEquals(Driver.SUCCESS, driver.runner("false")); }
@Test public void testRunnerSuccessOptionsHadoop() throws Exception { Driver driver = new CountFilesDriver(dfsServer.getConf(), Engine.HADOOP); driver.getConf().setBoolean("i.should.fail.option", false); assertEquals(Driver.SUCCESS, driver.runner("false")); }
@Test public void testRunnerFailureParametersHadoop() throws Exception { Driver driver = new CountFilesDriver(dfsServer.getConf(), Engine.HADOOP); assertEquals(Driver.FAILURE_RUNTIME, driver.runner("true")); }
@Test public void testRunnerFailureParametersSpark() throws Exception { Driver driver = new CountFilesDriver(dfsServer.getConf(), Engine.SPARK); assertEquals(Driver.FAILURE_RUNTIME, driver.runner("true")); }