use of org.apache.oozie.cli.CLIParser in project oozie by apache.
the class TestOozieCLI method testNoRetryForError.
public void testNoRetryForError() throws Exception {
runTest(END_POINTS, SERVLET_CLASSES, false, new Callable<Void>() {
@Override
public Void call() throws Exception {
HeaderTestingVersionServlet.OOZIE_HEADERS.clear();
String oozieUrl = getContextURL();
String[] args = new String[] { "job", "-info", "aaa", "-oozie", oozieUrl, "-debug" };
OozieCLI cli = new OozieCLI();
CLIParser parser = cli.getCLIParser();
try {
final CLIParser.Command command = parser.parse(args);
cli.processCommand(parser, command);
} catch (Exception e) {
// Create connection will be successful, no retry
assertFalse(e.getMessage().contains("Error while connecting Oozie server"));
assertTrue(e.getMessage().contains("invalid job id [aaa]"));
}
return null;
}
});
}
use of org.apache.oozie.cli.CLIParser in project oozie by apache.
the class OozieSharelibCLI method run.
public synchronized int run(String[] args) throws Exception {
if (used) {
throw new IllegalStateException("CLI instance already used");
}
used = true;
CLIParser parser = new CLIParser("oozie-setup.sh", HELP_INFO);
String oozieHome = System.getProperty(OOZIE_HOME);
parser.addCommand(HELP_CMD, "", "display usage for all commands or specified command", new Options(), false);
parser.addCommand(CREATE_CMD, "", "create a new timestamped version of oozie sharelib", createUpgradeOptions(CREATE_CMD), false);
parser.addCommand(UPGRADE_CMD, "", "[deprecated][use command \"create\" to create new version] upgrade oozie sharelib \n", createUpgradeOptions(UPGRADE_CMD), false);
try {
final CLIParser.Command command = parser.parse(args);
String sharelibAction = command.getName();
if (sharelibAction.equals(HELP_CMD)) {
parser.showHelp(command.getCommandLine());
return 0;
}
if (!command.getCommandLine().hasOption(FS_OPT)) {
throw new Exception("-fs option must be specified");
}
int threadPoolSize = Integer.valueOf(command.getCommandLine().getOptionValue(CONCURRENCY_OPT, "1"));
File srcFile = null;
// Check whether user provided locallib
if (command.getCommandLine().hasOption(LIB_OPT)) {
srcFile = new File(command.getCommandLine().getOptionValue(LIB_OPT));
} else {
// Since user did not provide locallib, find the default one under oozie home dir
Collection<File> files = FileUtils.listFiles(new File(oozieHome), new WildcardFileFilter("oozie-sharelib*.tar.gz"), null);
if (files.size() > 1) {
throw new IOException("more than one sharelib tar found at " + oozieHome);
}
if (files.isEmpty()) {
throw new IOException("default sharelib tar not found in oozie home dir: " + oozieHome);
}
srcFile = files.iterator().next();
}
File temp = File.createTempFile("oozie", ".dir");
temp.delete();
temp.mkdir();
temp.deleteOnExit();
// Check whether the lib is a tar file or folder
if (!srcFile.isDirectory()) {
FileUtil.unTar(srcFile, temp);
srcFile = new File(temp.toString() + "/share/lib");
} else {
// Get the lib directory since it's a folder
srcFile = new File(srcFile, "lib");
}
String hdfsUri = command.getCommandLine().getOptionValue(FS_OPT);
Path srcPath = new Path(srcFile.toString());
Services services = new Services();
services.getConf().set(Services.CONF_SERVICE_CLASSES, "org.apache.oozie.service.LiteWorkflowAppService, org.apache.oozie.service.HadoopAccessorService");
services.getConf().set(Services.CONF_SERVICE_EXT_CLASSES, "");
services.init();
WorkflowAppService lwas = services.get(WorkflowAppService.class);
HadoopAccessorService has = services.get(HadoopAccessorService.class);
Path dstPath = lwas.getSystemLibPath();
URI uri = new Path(hdfsUri).toUri();
Configuration fsConf = has.createConfiguration(uri.getAuthority());
FileSystem fs = FileSystem.get(uri, fsConf);
if (!fs.exists(dstPath)) {
fs.mkdirs(dstPath);
}
ECPolicyDisabler.tryDisableECPolicyForPath(fs, dstPath);
if (sharelibAction.equals(CREATE_CMD) || sharelibAction.equals(UPGRADE_CMD)) {
dstPath = new Path(dstPath.toString() + Path.SEPARATOR + SHARE_LIB_PREFIX + getTimestampDirectory());
}
System.out.println("the destination path for sharelib is: " + dstPath);
if (!srcFile.exists()) {
throw new IOException(srcPath + " cannot be found");
}
if (threadPoolSize > 1) {
concurrentCopyFromLocal(fs, threadPoolSize, srcFile, dstPath);
} else {
fs.copyFromLocalFile(false, srcPath, dstPath);
}
services.destroy();
FileUtils.deleteDirectory(temp);
return 0;
} catch (ParseException ex) {
System.err.println("Invalid sub-command: " + ex.getMessage());
System.err.println();
System.err.println(parser.shortHelp());
return 1;
} catch (Exception ex) {
logError(ex.getMessage(), ex);
return 1;
}
}
use of org.apache.oozie.cli.CLIParser in project oozie by apache.
the class OozieDBCLI method run.
public synchronized int run(String[] args) {
if (used) {
throw new IllegalStateException("CLI instance already used");
}
used = true;
CLIParser parser = new CLIParser("ooziedb.sh", HELP_INFO);
parser.addCommand(HELP_CMD, "", "display usage for all commands or specified command", new Options(), false);
parser.addCommand(VERSION_CMD, "", "show Oozie DB version information", new Options(), false);
parser.addCommand(CREATE_CMD, "", "create Oozie DB schema", createUpgradeOptions(), false);
parser.addCommand(UPGRADE_CMD, "", "upgrade Oozie DB", createUpgradeOptions(), false);
parser.addCommand(POST_UPGRADE_CMD, "", "post upgrade Oozie DB", createUpgradeOptions(), false);
try {
System.out.println();
CLIParser.Command command = parser.parse(args);
if (command.getName().equals(HELP_CMD)) {
parser.showHelp(command.getCommandLine());
} else if (command.getName().equals(VERSION_CMD)) {
showVersion();
} else {
if (!command.getCommandLine().hasOption(SQL_FILE_OPT) && !command.getCommandLine().hasOption(RUN_OPT)) {
throw new Exception("'-sqlfile <FILE>' or '-run' options must be specified");
}
CommandLine commandLine = command.getCommandLine();
String sqlFile = commandLine.getOptionValue(SQL_FILE_OPT);
if (sqlFile == null || sqlFile.isEmpty()) {
File tempFile = File.createTempFile("ooziedb-", ".sql");
tempFile.deleteOnExit();
sqlFile = tempFile.getAbsolutePath();
}
boolean run = commandLine.hasOption(RUN_OPT);
if (command.getName().equals(CREATE_CMD)) {
createDB(sqlFile, run);
}
if (command.getName().equals(UPGRADE_CMD)) {
upgradeDB(sqlFile, run);
}
if (command.getName().equals(POST_UPGRADE_CMD)) {
postUpgradeDB(sqlFile, run);
}
System.out.println();
System.out.println("The SQL commands have been written to: " + sqlFile);
if (!run) {
System.out.println();
System.out.println("WARN: The SQL commands have NOT been executed, you must use the '-run' option");
System.out.println();
}
}
return 0;
} catch (ParseException ex) {
System.err.println("Invalid sub-command: " + ex.getMessage());
System.err.println();
System.err.println(parser.shortHelp());
return 1;
} catch (Exception ex) {
System.err.println();
System.err.println("Error: " + ex.getMessage());
System.err.println();
System.err.println("Stack trace for the error was (for debug purposes):");
System.err.println("--------------------------------------");
ex.printStackTrace(System.err);
System.err.println("--------------------------------------");
System.err.println();
return 1;
}
}
use of org.apache.oozie.cli.CLIParser in project oozie by apache.
the class OozieDBExportCLI method main.
public static void main(String[] args) {
CLIParser parser = new CLIParser("oozie-setup.sh", HELP_INFO);
parser.addCommand(HELP_CMD, "", "display usage for all commands or specified command", new Options(), false);
parser.addCommand(EXPORT_CMD, "", "exports the contents of the Oozie database to the specified file", new Options(), true);
try {
CLIParser.Command command = parser.parse(args);
if (command.getName().equals(EXPORT_CMD)) {
Services services = new Services();
services.getConf().set(Services.CONF_SERVICE_CLASSES, JPAService.class.getName());
services.getConf().set(Services.CONF_SERVICE_EXT_CLASSES, "");
services.init();
queryAllDBTables(command.getCommandLine().getArgs()[0]);
} else if (command.getName().equals(HELP_CMD)) {
parser.showHelp(command.getCommandLine());
}
} catch (ParseException pex) {
System.err.println("Invalid sub-command: " + pex.getMessage());
System.err.println();
System.err.println(parser.shortHelp());
System.exit(1);
} catch (Exception e) {
System.err.println();
System.err.println("Error: " + e.getMessage());
System.err.println();
System.err.println("Stack trace for the error was (for debug purposes):");
System.err.println("--------------------------------------");
e.printStackTrace(System.err);
System.err.println("--------------------------------------");
System.err.println();
System.exit(1);
} finally {
if (Services.get() != null) {
Services.get().destroy();
}
}
}
use of org.apache.oozie.cli.CLIParser in project oozie by apache.
the class OozieDBImportCLI method main.
public static void main(final String[] args) throws ParseException {
final CLIParser parser = new CLIParser("oozie-setup.sh", HELP_INFO);
parser.addCommand(HELP_CMD, "", "display usage for all commands or specified command", new Options(), false);
parser.addCommand(IMPORT_CMD, "", "imports the contents of the Oozie database from the specified file", new Options().addOption(OPTION_VERBOSE_SHORT, OPTION_VERBOSE_LONG, false, "Enables verbose logging."), true);
boolean verbose = false;
try {
final CLIParser.Command command = parser.parse(args);
if (command.getName().equals(IMPORT_CMD)) {
final Services services = new Services();
services.getConf().set(Services.CONF_SERVICE_CLASSES, JPAService.class.getName());
services.getConf().set(Services.CONF_SERVICE_EXT_CLASSES, "");
services.init();
setImportBatchSize();
System.out.println("==========================================================");
System.out.println(Arrays.toString(command.getCommandLine().getArgs()));
System.out.println(String.format("Import batch length is %d", IMPORT_BATCH_SIZE));
verbose = command.getCommandLine().hasOption(OPTION_VERBOSE_SHORT) || command.getCommandLine().hasOption(OPTION_VERBOSE_LONG);
importAllDBTables(command.getCommandLine().getArgs()[0], verbose);
} else if (command.getName().equals(HELP_CMD)) {
parser.showHelp(command.getCommandLine());
}
} catch (final ParseException pex) {
System.err.println("Invalid sub-command: " + pex.getMessage());
System.err.println();
System.err.println(parser.shortHelp());
System.exit(1);
} catch (final Throwable e) {
System.err.println();
System.err.println("Error: " + e.getMessage());
System.err.println();
if (verbose) {
System.err.println("Stack trace for the error was (for debug purposes):");
System.err.println("--------------------------------------");
e.printStackTrace(System.err);
System.err.println("--------------------------------------");
System.err.println();
}
System.exit(1);
} finally {
if (Services.get() != null) {
Services.get().destroy();
}
}
}
Aggregations