Search in sources :

Example 1 with CLIParser

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;
        }
    });
}
Also used : CLIParser(org.apache.oozie.cli.CLIParser) OozieCLI(org.apache.oozie.cli.OozieCLI)

Example 2 with CLIParser

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;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Options(org.apache.commons.cli.Options) Configuration(org.apache.hadoop.conf.Configuration) WorkflowAppService(org.apache.oozie.service.WorkflowAppService) CLIParser(org.apache.oozie.cli.CLIParser) IOException(java.io.IOException) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) HadoopAccessorService(org.apache.oozie.service.HadoopAccessorService) URI(java.net.URI) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ParseException(org.apache.commons.cli.ParseException) Services(org.apache.oozie.service.Services) FileSystem(org.apache.hadoop.fs.FileSystem) ParseException(org.apache.commons.cli.ParseException) File(java.io.File)

Example 3 with CLIParser

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;
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) CLIParser(org.apache.oozie.cli.CLIParser) ParseException(org.apache.commons.cli.ParseException) File(java.io.File) ParseException(org.apache.commons.cli.ParseException)

Example 4 with CLIParser

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();
        }
    }
}
Also used : Options(org.apache.commons.cli.Options) Services(org.apache.oozie.service.Services) CLIParser(org.apache.oozie.cli.CLIParser) ParseException(org.apache.commons.cli.ParseException) JPAService(org.apache.oozie.service.JPAService) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException) StoreException(org.apache.oozie.store.StoreException)

Example 5 with CLIParser

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();
        }
    }
}
Also used : Options(org.apache.commons.cli.Options) Services(org.apache.oozie.service.Services) CLIParser(org.apache.oozie.cli.CLIParser) ParseException(org.apache.commons.cli.ParseException) JPAService(org.apache.oozie.service.JPAService)

Aggregations

CLIParser (org.apache.oozie.cli.CLIParser)5 Options (org.apache.commons.cli.Options)4 ParseException (org.apache.commons.cli.ParseException)4 Services (org.apache.oozie.service.Services)3 File (java.io.File)2 IOException (java.io.IOException)2 JPAService (org.apache.oozie.service.JPAService)2 URI (java.net.URI)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 CommandLine (org.apache.commons.cli.CommandLine)1 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 OozieCLI (org.apache.oozie.cli.OozieCLI)1 HadoopAccessorService (org.apache.oozie.service.HadoopAccessorService)1 WorkflowAppService (org.apache.oozie.service.WorkflowAppService)1 StoreException (org.apache.oozie.store.StoreException)1