public int doMain(String[] args) {
String jarFilename;
File outputFile;
String locationFactory;
String id;
LocationFactory lf;
CommandLineParser parser = new GnuParser();
Options options = new Options();
options.addOption("i", "id", true, "Account ID");
options.addOption("j", "jar", true, "Application JAR");
options.addOption("f", "locfactory", true, "Location Factory (LOCAL or DISTRIBUTED)");
options.addOption("o", "output", true, "Output");
// Check all the options of command line
try {
CommandLine line = parser.parse(options, args);
if (!line.hasOption("jar")) {
LOG.error("Application JAR not specified.");
return -1;
}
if (!line.hasOption("output")) {
LOG.error("Output file not specified.");
return -1;
}
if (!line.hasOption("id")) {
LOG.error("Account id not specified.");
return -1;
}
if (!line.hasOption("locfactory")) {
LOG.error("Location factory not specified.");
return -1;
}
jarFilename = line.getOptionValue("jar");
outputFile = new File(line.getOptionValue("output"));
id = line.getOptionValue("id");
locationFactory = line.getOptionValue("locfactory");
} catch (ParseException e) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("SandboxJVM", options);
return -1;
}
// Load the JAR using the JAR class load and load the manifest file.
File unpackedJarDir = Files.createTempDir();
try {
Application app;
try {
if ("LOCAL".equals(locationFactory)) {
lf = new LocalLocationFactory();
} else if ("DISTRIBUTED".equals(locationFactory)) {
lf = new HDFSLocationFactory(new Configuration());
} else {
LOG.error("Unknown location factory specified");
return -1;
}
Program archive = Programs.createWithUnpack(lf.create(jarFilename), unpackedJarDir);
Object appMain = archive.getMainClass().newInstance();
if (!(appMain instanceof Application)) {
LOG.error(String.format("Application main class is of invalid type: %s",
appMain.getClass().getName()));
return -1;