Source:
private YarnClient getYarnClientForSubmit() throws Exception { YarnClientFactoryBean yarnClientFactory = new YarnClientFactoryBean(); Configuration configuration = getHadoopConfiguration(); yarnClientFactory.setConfiguration(configuration); LocalResourcesFactoryBean localResourcesFactory = new LocalResourcesFactoryBean(); localResourcesFactory.setConfiguration(configuration); Collection<TransferEntry> transferEntries = new ArrayList<TransferEntry>(); transferEntries.add(new TransferEntry(LocalResourceType.ARCHIVE, null, "/xd/xdapp.zip", null, null, false)); localResourcesFactory.setHdfsEntries(transferEntries); localResourcesFactory.setCopyEntries(new ArrayList<CopyEntry>()); localResourcesFactory.afterPropertiesSet(); yarnClientFactory.setResourceLocalizer(localResourcesFactory.getObject()); EnvironmentFactoryBean environmentFactory = new EnvironmentFactoryBean(); environmentFactory.setClasspath("./xdapp.zip/lib/*"); environmentFactory.setDefaultYarnAppClasspath(true); environmentFactory.setDelimiter(":"); environmentFactory.setIncludeBaseDirectory(true); environmentFactory.afterPropertiesSet(); yarnClientFactory.setEnvironment(environmentFactory.getObject()); LaunchCommandsFactoryBean launchCommandsFactory = new LaunchCommandsFactoryBean(); launchCommandsFactory.setRunner(XdYarnAppmasterRunner.class); launchCommandsFactory.setContextFile("appmaster-context.xml"); launchCommandsFactory.setBeanName(YarnSystemConstants.DEFAULT_ID_APPMASTER); Properties arguments = new Properties(); arguments.put("container-count", "2"); arguments.put("-Dxd.store", "redis"); arguments.put("-Dxd.transport", "redis"); arguments.put("-Dxd.home", "./xdapp.zip"); launchCommandsFactory.setArguments(arguments); launchCommandsFactory.setStdout("<LOG_DIR>/Appmaster.stdout"); launchCommandsFactory.setStderr("<LOG_DIR>/Appmaster.stderr"); launchCommandsFactory.afterPropertiesSet(); yarnClientFactory.setCommands(launchCommandsFactory.getObject()); yarnClientFactory.setAppName("xdapp"); yarnClientFactory.afterPropertiesSet(); return yarnClientFactory.getObject(); }

Target:
private YarnClient getYarnClientForSubmit() throws Exception { YarnClientFactoryBean yarnClientFactory = new YarnClientFactoryBean(); Configuration configuration = getHadoopConfiguration(); yarnClientFactory.setConfiguration(configuration); LocalResourcesFactoryBean localResourcesFactory = new LocalResourcesFactoryBean(); localResourcesFactory.setConfiguration(configuration); Collection<TransferEntry> transferEntries = new ArrayList<TransferEntry>(); transferEntries.add(new TransferEntry(LocalResourceType.ARCHIVE, null, "/xd/xdapp.zip", null, null, false)); localResourcesFactory.setHdfsEntries(transferEntries); localResourcesFactory.setCopyEntries(new ArrayList<CopyEntry>()); localResourcesFactory.afterPropertiesSet(); yarnClientFactory.setResourceLocalizer(localResourcesFactory.getObject()); EnvironmentFactoryBean environmentFactory = new EnvironmentFactoryBean(); environmentFactory.setClasspath("./xdapp.zip/lib/*"); environmentFactory.setDefaultYarnAppClasspath(true); environmentFactory.setDelimiter(":"); environmentFactory.setIncludeBaseDirectory(true); environmentFactory.afterPropertiesSet(); yarnClientFactory.setEnvironment(environmentFactory.getObject()); LaunchCommandsFactoryBean launchCommandsFactory = new LaunchCommandsFactoryBean(); launchCommandsFactory.setRunner(XdYarnAppmasterRunner.class); launchCommandsFactory.setContextFile("appmaster-context.xml"); launchCommandsFactory.setBeanName(YarnSystemConstants.DEFAULT_ID_APPMASTER); Properties arguments = new Properties(); arguments.put("container-count", "2"); arguments.put("-DXD_STORE", "redis"); arguments.put("-DXD_TRANSPORT", "redis"); arguments.put("-DXD_HOME", "./xdapp.zip"); launchCommandsFactory.setArguments(arguments); launchCommandsFactory.setStdout("<LOG_DIR>/Appmaster.stdout"); launchCommandsFactory.setStderr("<LOG_DIR>/Appmaster.stderr"); launchCommandsFactory.afterPropertiesSet(); yarnClientFactory.setCommands(launchCommandsFactory.getObject()); yarnClientFactory.setAppName("xdapp"); yarnClientFactory.afterPropertiesSet(); return yarnClientFactory.getObject(); }