Example usage for org.apache.hadoop.yarn.applications.distributedshell Log4jPropertyHelper updateLog4jConfiguration

List of usage examples for org.apache.hadoop.yarn.applications.distributedshell Log4jPropertyHelper updateLog4jConfiguration

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.applications.distributedshell Log4jPropertyHelper updateLog4jConfiguration.

Prototype

public static void updateLog4jConfiguration(Class<?> targetClass, String log4jPath) throws Exception 

Source Link

Usage

From source file:timo.yarn_app_call_java_app.Client.java

License:Apache License

/**
 * Parse command line options// w  w w. ja  va2s . co m
 * 
 * @param args
 *          Parsed command line options
 * @return Whether the init was successful to run the client
 * @throws ParseException
 */
public boolean init(String[] args) throws ParseException {

    CommandLine cliParser = new GnuParser().parse(opts, args);

    if (args.length == 0) {
        throw new IllegalArgumentException("No args specified for client to initialize");
    }

    if (cliParser.hasOption("log_properties")) {
        String log4jPath = cliParser.getOptionValue("log_properties");
        try {
            Log4jPropertyHelper.updateLog4jConfiguration(Client.class, log4jPath);
        } catch (Exception e) {
            LOG.warn("Can not set up custom log4j properties. " + e);
        }
    }

    if (cliParser.hasOption("help")) {
        printUsage();
        return false;
    }

    if (cliParser.hasOption("debug")) {
        debugFlag = true;

    }

    if (cliParser.hasOption("keep_containers_across_application_attempts")) {
        LOG.info("keep_containers_across_application_attempts");
        keepContainers = true;
    }

    amPriority = Integer.parseInt(cliParser.getOptionValue("priority", "0"));
    amQueue = cliParser.getOptionValue("queue", "default");
    amMemory = Integer.parseInt(cliParser.getOptionValue("master_memory", "10"));
    amVCores = Integer.parseInt(cliParser.getOptionValue("master_vcores", "1"));

    if (amMemory < 0) {
        throw new IllegalArgumentException(
                "Invalid memory specified for application master, exiting." + " Specified memory=" + amMemory);
    }
    if (amVCores < 0) {
        throw new IllegalArgumentException("Invalid virtual cores specified for application master, exiting."
                + " Specified virtual cores=" + amVCores);
    }

    if (!cliParser.hasOption("jar")) {
        throw new IllegalArgumentException("No jar file specified for application master");
    }

    appMasterJar = cliParser.getOptionValue("jar");

    containerMemory = Integer.parseInt(cliParser.getOptionValue("container_memory", "10"));
    containerVirtualCores = Integer.parseInt(cliParser.getOptionValue("container_vcores", "1"));
    numContainers = Integer.parseInt(cliParser.getOptionValue("num_containers", "1"));

    if (containerMemory < 0 || containerVirtualCores < 0 || numContainers < 1) {
        throw new IllegalArgumentException("Invalid no. of containers or container memory/vcores specified,"
                + " exiting." + " Specified containerMemory=" + containerMemory + ", containerVirtualCores="
                + containerVirtualCores + ", numContainer=" + numContainers);
    }

    nodeLabelExpression = cliParser.getOptionValue("node_label_expression", null);

    clientTimeout = Integer.parseInt(cliParser.getOptionValue("timeout", "60000"));

    attemptFailuresValidityInterval = Long
            .parseLong(cliParser.getOptionValue("attempt_failures_validity_interval", "-1"));

    log4jPropFile = cliParser.getOptionValue("log_properties", "");

    // Get timeline domain options
    if (cliParser.hasOption("domain")) {
        domainId = cliParser.getOptionValue("domain");
        toCreateDomain = cliParser.hasOption("create");
        if (cliParser.hasOption("view_acls")) {
            viewACLs = cliParser.getOptionValue("view_acls");
        }
        if (cliParser.hasOption("modify_acls")) {
            modifyACLs = cliParser.getOptionValue("modify_acls");
        }
    }

    return true;
}