Search in sources :

Example 1 with XOozieClient

use of org.apache.oozie.client.XOozieClient in project oozie by apache.

the class OozieCLI method validateCommand.

private void validateCommand(CommandLine commandLine) throws OozieCLIException {
    String[] args = commandLine.getArgs();
    if (args.length != 1) {
        throw new OozieCLIException("One file must be specified");
    }
    try {
        XOozieClient wc = createXOozieClient(commandLine);
        String result = wc.validateXML(args[0].toString());
        if (result == null) {
            // TODO This is only for backward compatibility. Need to remove after 4.2.0 higher version.
            System.out.println("Using client-side validation. Check out Oozie server version.");
            validateCommandV41(commandLine);
            return;
        }
        System.out.println(result);
    } catch (OozieClientException e) {
        throw new OozieCLIException(e.getMessage(), e);
    }
}
Also used : OozieClientException(org.apache.oozie.client.OozieClientException) XOozieClient(org.apache.oozie.client.XOozieClient)

Example 2 with XOozieClient

use of org.apache.oozie.client.XOozieClient in project oozie by apache.

the class OozieCLI method sqoopCommand.

private void sqoopCommand(CommandLine commandLine) throws IOException, OozieCLIException {
    List<String> args = commandLine.getArgList();
    if (args.size() > 0) {
        // checking if args starts with -X (because CLIParser cannot check this)
        if (!args.get(0).equals("-X")) {
            throw new OozieCLIException("Unrecognized option: " + args.get(0) + " Expecting -X");
        }
        args.remove(0);
    }
    if (!commandLine.hasOption(SQOOP_COMMAND_OPTION)) {
        throw new OozieCLIException("Need to specify -command");
    }
    if (!commandLine.hasOption(CONFIG_OPTION)) {
        throw new OozieCLIException("Need to specify -config <configfile>");
    }
    try {
        XOozieClient wc = createXOozieClient(commandLine);
        Properties conf = getConfiguration(wc, commandLine);
        String[] command = commandLine.getOptionValues(SQOOP_COMMAND_OPTION);
        System.out.println(JOB_ID_PREFIX + wc.submitSqoop(conf, command, args.toArray(new String[args.size()])));
    } catch (OozieClientException ex) {
        throw new OozieCLIException(ex.toString(), ex);
    }
}
Also used : OozieClientException(org.apache.oozie.client.OozieClientException) XOozieClient(org.apache.oozie.client.XOozieClient) Properties(java.util.Properties)

Example 3 with XOozieClient

use of org.apache.oozie.client.XOozieClient in project oozie by apache.

the class OozieCLI method mrCommand.

private void mrCommand(CommandLine commandLine) throws IOException, OozieCLIException {
    try {
        XOozieClient wc = createXOozieClient(commandLine);
        Properties conf = getConfiguration(wc, commandLine);
        String mapper = conf.getProperty(MAPRED_MAPPER, conf.getProperty(MAPRED_MAPPER_2));
        if (mapper == null) {
            throw new OozieCLIException("mapper (" + MAPRED_MAPPER + " or " + MAPRED_MAPPER_2 + ") must be specified in conf");
        }
        String reducer = conf.getProperty(MAPRED_REDUCER, conf.getProperty(MAPRED_REDUCER_2));
        if (reducer == null) {
            throw new OozieCLIException("reducer (" + MAPRED_REDUCER + " or " + MAPRED_REDUCER_2 + ") must be specified in conf");
        }
        String inputDir = conf.getProperty(MAPRED_INPUT);
        if (inputDir == null) {
            throw new OozieCLIException("input dir (" + MAPRED_INPUT + ") must be specified in conf");
        }
        String outputDir = conf.getProperty(MAPRED_OUTPUT);
        if (outputDir == null) {
            throw new OozieCLIException("output dir (" + MAPRED_OUTPUT + ") must be specified in conf");
        }
        System.out.println(JOB_ID_PREFIX + wc.submitMapReduce(conf));
    } catch (OozieClientException ex) {
        throw new OozieCLIException(ex.toString(), ex);
    }
}
Also used : OozieClientException(org.apache.oozie.client.OozieClientException) XOozieClient(org.apache.oozie.client.XOozieClient) Properties(java.util.Properties)

Example 4 with XOozieClient

use of org.apache.oozie.client.XOozieClient in project oozie by apache.

the class OozieCLI method slaCommand.

private void slaCommand(CommandLine commandLine) throws IOException, OozieCLIException {
    XOozieClient wc = createXOozieClient(commandLine);
    String s = commandLine.getOptionValue(OFFSET_OPTION);
    int start = Integer.parseInt((s != null) ? s : "0");
    s = commandLine.getOptionValue(LEN_OPTION);
    int len = Integer.parseInt((s != null) ? s : "100");
    String filter = commandLine.getOptionValue(FILTER_OPTION);
    try {
        wc.getSlaInfo(start, len, filter);
    } catch (OozieClientException ex) {
        throw new OozieCLIException(ex.toString(), ex);
    }
}
Also used : OozieClientException(org.apache.oozie.client.OozieClientException) XOozieClient(org.apache.oozie.client.XOozieClient)

Example 5 with XOozieClient

use of org.apache.oozie.client.XOozieClient in project oozie by apache.

the class OozieCLI method adminCommand.

private void adminCommand(CommandLine commandLine) throws OozieCLIException {
    XOozieClient wc = createXOozieClient(commandLine);
    List<String> options = new ArrayList<String>();
    for (Option option : commandLine.getOptions()) {
        options.add(option.getOpt());
    }
    try {
        SYSTEM_MODE status = SYSTEM_MODE.NORMAL;
        if (options.contains(VERSION_OPTION)) {
            System.out.println("Oozie server build version: " + wc.getServerBuildVersion());
        } else if (options.contains(SYSTEM_MODE_OPTION)) {
            String systemModeOption = commandLine.getOptionValue(SYSTEM_MODE_OPTION).toUpperCase();
            try {
                status = SYSTEM_MODE.valueOf(systemModeOption);
            } catch (Exception e) {
                throw new OozieCLIException("Invalid input provided for option: " + SYSTEM_MODE_OPTION + " value given :" + systemModeOption + " Expected values are: NORMAL/NOWEBSERVICE/SAFEMODE ");
            }
            wc.setSystemMode(status);
            System.out.println("System mode: " + status);
        } else if (options.contains(STATUS_OPTION)) {
            status = wc.getSystemMode();
            System.out.println("System mode: " + status);
        } else if (options.contains(UPDATE_SHARELIB_OPTION)) {
            System.out.println(wc.updateShareLib());
        } else if (options.contains(LIST_SHARELIB_LIB_OPTION)) {
            String sharelibKey = null;
            if (commandLine.getArgList().size() > 0) {
                sharelibKey = (String) commandLine.getArgList().get(0);
            }
            System.out.println(wc.listShareLib(sharelibKey));
        } else if (options.contains(QUEUE_DUMP_OPTION)) {
            List<String> list = wc.getQueueDump();
            if (list != null && list.size() != 0) {
                for (String str : list) {
                    System.out.println(str);
                }
            } else {
                System.out.println("QueueDump is null!");
            }
        } else if (options.contains(AVAILABLE_SERVERS_OPTION)) {
            Map<String, String> availableOozieServers = new TreeMap<String, String>(wc.getAvailableOozieServers());
            for (Map.Entry<String, String> ent : availableOozieServers.entrySet()) {
                System.out.println(ent.getKey() + " : " + ent.getValue());
            }
        } else if (options.contains(SERVER_CONFIGURATION_OPTION)) {
            Map<String, String> serverConfig = new TreeMap<String, String>(wc.getServerConfiguration());
            for (Map.Entry<String, String> ent : serverConfig.entrySet()) {
                System.out.println(ent.getKey() + " : " + ent.getValue());
            }
        } else if (options.contains(SERVER_OS_ENV_OPTION)) {
            Map<String, String> osEnv = new TreeMap<String, String>(wc.getOSEnv());
            for (Map.Entry<String, String> ent : osEnv.entrySet()) {
                System.out.println(ent.getKey() + " : " + ent.getValue());
            }
        } else if (options.contains(SERVER_JAVA_SYSTEM_PROPERTIES_OPTION)) {
            Map<String, String> javaSysProps = new TreeMap<String, String>(wc.getJavaSystemProperties());
            for (Map.Entry<String, String> ent : javaSysProps.entrySet()) {
                System.out.println(ent.getKey() + " : " + ent.getValue());
            }
        } else if (options.contains(METRICS_OPTION)) {
            OozieClient.Metrics metrics = wc.getMetrics();
            if (metrics == null) {
                System.out.println("Metrics are unavailable.  Try Instrumentation (-" + INSTRUMENTATION_OPTION + ") instead");
            } else {
                printMetrics(metrics);
            }
        } else if (options.contains(INSTRUMENTATION_OPTION)) {
            OozieClient.Instrumentation instrumentation = wc.getInstrumentation();
            if (instrumentation == null) {
                System.out.println("Instrumentation is unavailable.  Try Metrics (-" + METRICS_OPTION + ") instead");
            } else {
                printInstrumentation(instrumentation);
            }
        } else if (options.contains(PURGE_OPTION)) {
            String purgeOptions = commandLine.getOptionValue(PURGE_OPTION);
            System.out.println(wc.purgeCommand(purgeOptions));
        }
    } catch (OozieClientException ex) {
        throw new OozieCLIException(ex.toString(), ex);
    }
}
Also used : SYSTEM_MODE(org.apache.oozie.client.OozieClient.SYSTEM_MODE) OozieClientException(org.apache.oozie.client.OozieClientException) XOozieClient(org.apache.oozie.client.XOozieClient) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) ParseException(org.apache.commons.cli.ParseException) SAXException(org.xml.sax.SAXException) DOMException(org.w3c.dom.DOMException) OozieClientException(org.apache.oozie.client.OozieClientException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) OozieClient(org.apache.oozie.client.OozieClient) AuthOozieClient(org.apache.oozie.client.AuthOozieClient) XOozieClient(org.apache.oozie.client.XOozieClient) Option(org.apache.commons.cli.Option) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

XOozieClient (org.apache.oozie.client.XOozieClient)9 OozieClientException (org.apache.oozie.client.OozieClientException)8 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)4 Option (org.apache.commons.cli.Option)3 AuthOozieClient (org.apache.oozie.client.AuthOozieClient)2 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ParseException (org.apache.commons.cli.ParseException)1 OozieClient (org.apache.oozie.client.OozieClient)1 SYSTEM_MODE (org.apache.oozie.client.OozieClient.SYSTEM_MODE)1 DOMException (org.w3c.dom.DOMException)1 NodeList (org.w3c.dom.NodeList)1 SAXException (org.xml.sax.SAXException)1