@Override
public final ProgramController run(final Program program, final ProgramOptions options) {
final File hConfFile;
final File cConfFile;
final Program copiedProgram;
final File programDir; // Temp directory for unpacking the program
try {
// Copy config files and program jar to local temp, and ask Twill to localize it to container.
// What Twill does is to save those files in HDFS and keep using them during the lifetime of application.
// Twill will manage the cleanup of those files in HDFS.
hConfFile = saveHConf(hConf, File.createTempFile("hConf", ".xml"));
cConfFile = saveCConf(cConf, File.createTempFile("cConf", ".xml"));
programDir = Files.createTempDir();
copiedProgram = copyProgramJar(program, programDir);
} catch (IOException e) {
throw Throwables.propagate(e);
}
final String runtimeArgs = new Gson().toJson(options.getUserArguments());
// Obtains and add the HBase delegation token as well (if in non-secure mode, it's a no-op)
// Twill would also ignore it if it is not running in secure mode.
// The HDFS token should already obtained by Twill.
return launch(copiedProgram, options, hConfFile, cConfFile, new ApplicationLauncher() {
@Override
public TwillController launch(TwillApplication twillApplication) {
TwillPreparer twillPreparer = twillRunner
.prepare(twillApplication);
if (options.isDebug()) {
LOG.info("Starting {} with debugging enabled.", program.getId());
twillPreparer.enableDebugging();
}
List<URI> containerResources = addLogbackConfig(Lists.<URI>newArrayList());
TwillController twillController = twillPreparer
.withDependencies(new HBaseTableUtilFactory().get().getClass())
//TODO: Fix Logging in Distributed Mode.
//.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
.addSecureStore(YarnSecureStore.create(HBaseTokenUtils.obtainToken(hConf, new Credentials())))
.withResources(containerResources)
.withApplicationArguments(
String.format("--%s", RunnableOptions.JAR), copiedProgram.getJarLocation().getName(),
String.format("--%s", RunnableOptions.RUNTIME_ARGS), runtimeArgs
).start();
return addCleanupListener(twillController, hConfFile, cConfFile, copiedProgram, programDir);
}
});