Example usage for org.apache.hadoop.yarn.api.records ContainerId getApplicationAttemptId

List of usage examples for org.apache.hadoop.yarn.api.records ContainerId getApplicationAttemptId

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.records ContainerId getApplicationAttemptId.

Prototype

@Public
@Stable
public abstract ApplicationAttemptId getApplicationAttemptId();

Source Link

Document

Get the ApplicationAttemptId of the application to which the Container was assigned.

Usage

From source file:org.apache.tajo.worker.TaskRunnerId.java

License:Apache License

public static YarnProtos.ContainerIdProto getContainerIdProto(ContainerId containerId) {
    if (containerId instanceof TaskRunnerId) {
        return ((TaskRunnerId) containerId).getProto();
    } else {// w w w.  ja va  2 s  .c  o m
        YarnProtos.ApplicationIdProto appIdProto = YarnProtos.ApplicationIdProto.newBuilder()
                .setClusterTimestamp(
                        containerId.getApplicationAttemptId().getApplicationId().getClusterTimestamp())
                .setId(containerId.getApplicationAttemptId().getApplicationId().getId()).build();

        YarnProtos.ApplicationAttemptIdProto attemptIdProto = YarnProtos.ApplicationAttemptIdProto.newBuilder()
                .setAttemptId(containerId.getApplicationAttemptId().getAttemptId()).setApplicationId(appIdProto)
                .build();

        return YarnProtos.ContainerIdProto.newBuilder().setAppAttemptId(attemptIdProto).setAppId(appIdProto)
                .setId(containerId.getId()).build();
    }
}

From source file:org.apache.tajo.yarn.ApplicationMaster.java

License:Apache License

/**
 * Parse command line options/* w  w  w .  ja  v  a  2 s  .c om*/
 *
 * @param args Command line args
 * @return Whether init successful and getLaunchContext should be invoked
 * @throws org.apache.commons.cli.ParseException
 * @throws java.io.IOException
 */
public boolean init(String[] args) throws ParseException, IOException {

    Options opts = new Options();
    opts.addOption("app_attempt_id", true, "App Attempt ID. Not to be used unless for testing purposes");
    opts.addOption("qm_memory", true,
            "Amount of memory in MB to be requested to launch a QueryMaster. Default 512");
    opts.addOption("qm_vcores", true,
            "Amount of virtual cores to be requested to launch a QueryMaster. Default 2");
    opts.addOption("tr_memory", true,
            "Amount of memory in MB to be requested to launch a TaskRunner. Default 1024");
    opts.addOption("tr_vcores", true,
            "Amount of virtual cores to be requested to launch a TaskRunner. Default 4");
    opts.addOption("worker_memory", true,
            "Amount of memory in MB to be requested to launch a worker. Default 2048");
    opts.addOption("worker_vcores", true,
            "Amount of virtual cores to be requested to launch a worker. Default 4");
    opts.addOption("help", false, "Print usage");

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

    // Check whether customer log4j.properties file exists
    if (fileExist(log4jPath)) {
        try {
            Log4jPropertyHelper.updateLog4jConfiguration(ApplicationMaster.class, log4jPath);
        } catch (Exception e) {
            LOG.warn("Can not set up custom log4j properties. " + e);
        }
    }

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

    ApplicationAttemptId appAttemptID = null;
    Map<String, String> envs = System.getenv();

    if (!envs.containsKey(Environment.CONTAINER_ID.name())) {
        if (cliParser.hasOption("app_attempt_id")) {
            String appIdStr = cliParser.getOptionValue("app_attempt_id", "");
            appAttemptID = ConverterUtils.toApplicationAttemptId(appIdStr);
        } else {
            throw new IllegalArgumentException("Application Attempt Id not set in the environment");
        }
    } else {
        ContainerId containerId = ConverterUtils.toContainerId(envs.get(Environment.CONTAINER_ID.name()));
        appAttemptID = containerId.getApplicationAttemptId();
    }

    if (!envs.containsKey(ApplicationConstants.APP_SUBMIT_TIME_ENV)) {
        throw new RuntimeException(ApplicationConstants.APP_SUBMIT_TIME_ENV + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_HOST.name())) {
        throw new RuntimeException(Environment.NM_HOST.name() + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_HTTP_PORT.name())) {
        throw new RuntimeException(Environment.NM_HTTP_PORT + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_PORT.name())) {
        throw new RuntimeException(Environment.NM_PORT.name() + " not set in the environment");
    }

    LOG.info("Application master for app" + ", appId=" + appAttemptID.getApplicationId().getId()
            + ", clustertimestamp=" + appAttemptID.getApplicationId().getClusterTimestamp() + ", attemptId="
            + appAttemptID.getAttemptId());

    int qmMemory = Integer.parseInt(cliParser.getOptionValue("qm_memory", "512"));
    int qmVCores = Integer.parseInt(cliParser.getOptionValue("qm_vcores", "2"));
    int trMemory = Integer.parseInt(cliParser.getOptionValue("tr_memory", "1024"));
    int trVCores = Integer.parseInt(cliParser.getOptionValue("tr_vcores", "4"));
    int workerMemory = Integer.parseInt(cliParser.getOptionValue("worker_memory", "2048"));
    int workerVCores = Integer.parseInt(cliParser.getOptionValue("worker_vcores", "4"));

    int requestPriority = Integer.parseInt(cliParser.getOptionValue("priority", "0"));

    String appMasterHostName = InetAddress.getLocalHost().getHostName();

    this.appContext = new AppContext(conf, appAttemptID, workerMemory, workerVCores, requestPriority,
            appMasterHostName);

    return true;
}

From source file:org.apache.tez.dag.app.DAGAppMaster.java

License:Apache License

public static void main(String[] args) {
    try {/*from   w ww .  j  a  va 2s.c  om*/
        Thread.setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler());
        String containerIdStr = System.getenv(Environment.CONTAINER_ID.name());
        String nodeHostString = System.getenv(Environment.NM_HOST.name());
        String nodePortString = System.getenv(Environment.NM_PORT.name());
        String nodeHttpPortString = System.getenv(Environment.NM_HTTP_PORT.name());
        String appSubmitTimeStr = System.getenv(ApplicationConstants.APP_SUBMIT_TIME_ENV);
        String clientVersion = System.getenv(TezConstants.TEZ_CLIENT_VERSION_ENV);
        if (clientVersion == null) {
            clientVersion = VersionInfo.UNKNOWN;
        }

        // TODO Should this be defaulting to 1. Was there a version of YARN where this was not setup ?
        int maxAppAttempts = 1;
        String maxAppAttemptsEnv = System.getenv(ApplicationConstants.MAX_APP_ATTEMPTS_ENV);
        if (maxAppAttemptsEnv != null) {
            maxAppAttempts = Integer.valueOf(maxAppAttemptsEnv);
        }

        validateInputParam(appSubmitTimeStr, ApplicationConstants.APP_SUBMIT_TIME_ENV);

        ContainerId containerId = ConverterUtils.toContainerId(containerIdStr);
        ApplicationAttemptId applicationAttemptId = containerId.getApplicationAttemptId();

        long appSubmitTime = Long.parseLong(appSubmitTimeStr);

        String jobUserName = System.getenv(ApplicationConstants.Environment.USER.name());

        // Command line options
        Options opts = new Options();
        opts.addOption(TezConstants.TEZ_SESSION_MODE_CLI_OPTION, false,
                "Run Tez Application Master in Session mode");

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

        // TODO Does this really need to be a YarnConfiguration ?
        Configuration conf = new Configuration(new YarnConfiguration());
        TezUtilsInternal.addUserSpecifiedTezConfiguration(System.getenv(Environment.PWD.name()), conf);
        UserGroupInformation.setConfiguration(conf);
        Credentials credentials = UserGroupInformation.getCurrentUser().getCredentials();

        DAGAppMaster appMaster = new DAGAppMaster(applicationAttemptId, containerId, nodeHostString,
                Integer.parseInt(nodePortString), Integer.parseInt(nodeHttpPortString), new SystemClock(),
                appSubmitTime, cliParser.hasOption(TezConstants.TEZ_SESSION_MODE_CLI_OPTION),
                System.getenv(Environment.PWD.name()),
                TezCommonUtils.getTrimmedStrings(System.getenv(Environment.LOCAL_DIRS.name())),
                TezCommonUtils.getTrimmedStrings(System.getenv(Environment.LOG_DIRS.name())), clientVersion,
                maxAppAttempts, credentials, jobUserName);
        ShutdownHookManager.get().addShutdownHook(new DAGAppMasterShutdownHook(appMaster),
                SHUTDOWN_HOOK_PRIORITY);

        initAndStartAppMaster(appMaster, conf);

    } catch (Throwable t) {
        LOG.fatal("Error starting DAGAppMaster", t);
        System.exit(1);
    }
}

From source file:org.apache.tez.dag.history.logging.ats.TimelineCachePluginImpl.java

License:Apache License

private TimelineEntityGroupId convertToTimelineEntityGroupId(String entityType, String entityId) {
    if (entityType == null || entityType.isEmpty() || entityId == null || entityId.isEmpty()) {
        return null;
    }/*from w w  w  . j  a  v a2s  .c o  m*/
    if (entityType.equals(EntityTypes.TEZ_DAG_ID.name())) {
        TezDAGID dagId = TezDAGID.fromString(entityId);
        if (dagId != null) {
            return TimelineEntityGroupId.newInstance(dagId.getApplicationId(), dagId.toString());
        }
    } else if (entityType.equals(EntityTypes.TEZ_VERTEX_ID.name())) {
        TezVertexID vertexID = TezVertexID.fromString(entityId);
        if (vertexID != null) {
            return TimelineEntityGroupId.newInstance(vertexID.getDAGId().getApplicationId(),
                    vertexID.getDAGId().toString());
        }

    } else if (entityType.equals(EntityTypes.TEZ_TASK_ID.name())) {
        TezTaskID taskID = TezTaskID.fromString(entityId);
        if (taskID != null) {
            return TimelineEntityGroupId.newInstance(taskID.getVertexID().getDAGId().getApplicationId(),
                    taskID.getVertexID().getDAGId().toString());
        }
    } else if (entityType.equals(EntityTypes.TEZ_TASK_ATTEMPT_ID.name())) {
        TezTaskAttemptID taskAttemptID = TezTaskAttemptID.fromString(entityId);
        if (taskAttemptID != null) {
            return TimelineEntityGroupId.newInstance(
                    taskAttemptID.getTaskID().getVertexID().getDAGId().getApplicationId(),
                    taskAttemptID.getTaskID().getVertexID().getDAGId().toString());
        }
    } else if (entityType.equals(EntityTypes.TEZ_CONTAINER_ID.name())) {
        String cId = entityId;
        if (cId.startsWith("tez_")) {
            cId = cId.substring(4);
        }
        ContainerId containerId = ContainerId.fromString(cId);
        if (containerId != null) {
            return TimelineEntityGroupId.newInstance(containerId.getApplicationAttemptId().getApplicationId(),
                    containerId.getApplicationAttemptId().getApplicationId().toString());
        }
    }
    return null;
}

From source file:org.apache.twill.internal.appmaster.ApplicationMasterService.java

License:Apache License

private RunningContainers initRunningContainers(ContainerId appMasterContainerId, String appMasterHost)
        throws Exception {
    TwillRunResources appMasterResources = new DefaultTwillRunResources(0, appMasterContainerId.toString(),
            Integer.parseInt(System.getenv(EnvKeys.YARN_CONTAINER_VIRTUAL_CORES)),
            Integer.parseInt(System.getenv(EnvKeys.YARN_CONTAINER_MEMORY_MB)), appMasterHost, null, null);
    String appId = appMasterContainerId.getApplicationAttemptId().getApplicationId().toString();
    return new RunningContainers(appId, appMasterResources, zkClient);
}

From source file:org.deeplearning4j.iterativereduce.runtime.yarn.appmaster.ApplicationMaster.java

License:Apache License

public ApplicationMaster(int port, ComputableMaster<T> computableMaster, Class<T> updatable)
        throws IOException {

    //masterHost = InetAddress.getLocalHost().getHostName();
    masterHost = InetAddress.getLocalHost().getCanonicalHostName();
    masterPort = port;// w ww  .  ja v  a 2s .  c  om
    masterAddr = new InetSocketAddress(masterHost, masterPort);
    masterComputable = computableMaster;
    masterUpdateable = updatable;

    props = new Properties();
    props.load(new FileInputStream(ConfigFields.APP_CONFIG_FILE)); // Should be
    // in ./ - as
    // the Client
    // should've
    // shipped it
    ContainerId containerId = ConverterUtils
            .toContainerId(System.getenv(ApplicationConstants.AM_CONTAINER_ID_ENV));
    appAttemptId = containerId.getApplicationAttemptId();
    appName = props.getProperty(ConfigFields.APP_NAME, ConfigFields.DEFAULT_APP_NAME).replace(' ', '_');

    batchSize = Integer.parseInt(props.getProperty(ConfigFields.APP_BATCH_SIZE, "200"));
    iterationCount = Integer.parseInt(props.getProperty(ConfigFields.APP_ITERATION_COUNT, "1"));

    String inputFormatClassString = props.getProperty(ConfigFields.INPUT_FORMAT_CLASS,
            ConfigFields.INPUT_FORMAT_CLASS_DEFAULT);

    LOG.debug("Using Input Format: " + inputFormatClassString);
    LOG.info("IR:AppMaster > Using Input Format: " + inputFormatClassString);

    Class<?> if_class = null;
    try {
        if_class = Class.forName(inputFormatClassString);
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // need to check its a legit input format subclass

    if (null == if_class) {

        this.inputFormatClass = TextInputFormat.class;

    } else if (InputFormat.class.isAssignableFrom(if_class)) {

        LOG.debug("good input format: " + inputFormatClassString);
        this.inputFormatClass = if_class;

    } else {
        LOG.debug("bad input format: " + inputFormatClassString + ", defaulting to TextInputFormat");
        this.inputFormatClass = TextInputFormat.class;
        // TODO: do we die here? what do we do?
    }

    // Copy all properties into appConfig to be passed down to workers, TODO:
    // fix collection merging
    appConfig = new HashMap<>();
    for (Map.Entry<Object, Object> prop : props.entrySet()) {
        appConfig.put((String) prop.getKey(), (String) prop.getValue());
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Configuration entries: ");
        for (Map.Entry<CharSequence, CharSequence> entry : appConfig.entrySet()) {
            LOG.debug(entry.getKey() + "=" + entry.getValue());
        }

        LOG.debug("Initialized application master" + ", masterHost=" + masterHost + ", masterPort=" + masterPort
                + ", masterAddress=" + masterAddr + ", masterComputable="
                + masterComputable.getClass().getName() + ", masterUpdateable="
                + masterUpdateable.getClass().getName() + ", appAttemptId=" + appAttemptId);
    }
}

From source file:org.dknight.app.ApplicationMaster.java

License:Apache License

/**
 * Parse command line options/*from   ww w  . java2s. co  m*/
 *
 * @param args Command line args
 * @return Whether init successful and run should be invoked
 * @throws ParseException
 * @throws IOException
 */
public boolean init(String[] args) throws ParseException, IOException {

    Options opts = new Options();
    opts.addOption("app_attempt_id", true, "App Attempt ID. Not to be used unless for testing purposes");
    opts.addOption("shell_command", true, "Shell command to be executed by the Application Master");
    opts.addOption("shell_script", true, "Location of the shell script to be executed");
    opts.addOption("shell_args", true, "Command line args for the shell script");
    opts.addOption("shell_env", true, "Environment for shell script. Specified as env_key=env_val pairs");
    opts.addOption("container_memory", true, "Amount of memory in MB to be requested to run the shell command");
    opts.addOption("num_containers", true, "No. of containers on which the shell command needs to be executed");
    opts.addOption("priority", true, "Application Priority. Default 0");
    opts.addOption("debug", false, "Dump out debug information");

    opts.addOption("help", false, "Print usage");
    CommandLine cliParser = new GnuParser().parse(opts, args);

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

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

    if (cliParser.hasOption("debug")) {
        dumpOutDebugInfo();
    }

    Map<String, String> envs = System.getenv();

    if (!envs.containsKey(Environment.CONTAINER_ID.name())) {
        if (cliParser.hasOption("app_attempt_id")) {
            String appIdStr = cliParser.getOptionValue("app_attempt_id", "");
            appAttemptID = ConverterUtils.toApplicationAttemptId(appIdStr);
        } else {
            throw new IllegalArgumentException("Application Attempt Id not set in the environment");
        }
    } else {
        ContainerId containerId = ConverterUtils.toContainerId(envs.get(Environment.CONTAINER_ID.name()));
        appAttemptID = containerId.getApplicationAttemptId();
    }

    if (!envs.containsKey(ApplicationConstants.APP_SUBMIT_TIME_ENV)) {
        throw new RuntimeException(ApplicationConstants.APP_SUBMIT_TIME_ENV + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_HOST.name())) {
        throw new RuntimeException(Environment.NM_HOST.name() + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_HTTP_PORT.name())) {
        throw new RuntimeException(Environment.NM_HTTP_PORT + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_PORT.name())) {
        throw new RuntimeException(Environment.NM_PORT.name() + " not set in the environment");
    }

    LOG.info("Application master for app" + ", appId=" + appAttemptID.getApplicationId().getId()
            + ", clustertimestamp=" + appAttemptID.getApplicationId().getClusterTimestamp() + ", attemptId="
            + appAttemptID.getAttemptId());

    if (!cliParser.hasOption("shell_command")) {
        throw new IllegalArgumentException("No shell command specified to be executed by application master");
    }
    shellCommand = cliParser.getOptionValue("shell_command");

    if (cliParser.hasOption("shell_args")) {
        shellArgs = cliParser.getOptionValue("shell_args");
    }
    if (cliParser.hasOption("shell_env")) {
        String shellEnvs[] = cliParser.getOptionValues("shell_env");
        for (String env : shellEnvs) {
            env = env.trim();
            int index = env.indexOf('=');
            if (index == -1) {
                shellEnv.put(env, "");
                continue;
            }
            String key = env.substring(0, index);
            String val = "";
            if (index < (env.length() - 1)) {
                val = env.substring(index + 1);
            }
            shellEnv.put(key, val);
        }
    }

    getLocalResourceFromEnv(envs);

    containerMemory = Integer.parseInt(cliParser.getOptionValue("container_memory", "10"));
    numTotalContainers = Integer.parseInt(cliParser.getOptionValue("num_containers", "1"));
    if (numTotalContainers == 0) {
        throw new IllegalArgumentException("Cannot run distributed shell with no containers");
    }
    requestPriority = Integer.parseInt(cliParser.getOptionValue("priority", "0"));

    return true;
}

From source file:org.elasticsearch.hadoop.yarn.util.YarnUtils.java

License:Apache License

public static ApplicationAttemptId getApplicationAttemptId(Map<String, String> env) {
    if (env == null) {
        return null;
    }/*from  ww  w  . j  a va  2s .  c o m*/
    String amContainerId = env.get(ApplicationConstants.Environment.CONTAINER_ID.name());
    if (amContainerId == null) {
        return null;
    }
    ContainerId containerId = ConverterUtils.toContainerId(amContainerId);
    return containerId.getApplicationAttemptId();
}

From source file:org.hdl.caffe.yarn.app.ApplicationMaster.java

License:Apache License

/**
 * Parse command line options/*from   w w w . j av  a 2s  .  com*/
 *
 * @param args Command line args
 * @return Whether init successful and run should be invoked
 * @throws ParseException
 * @throws IOException
 */
public boolean init(String[] args) throws ParseException, IOException {
    Options opts = new Options();
    opts.addOption(CaffeApplication.OPT_CAFFE_APP_ATTEMPT_ID, true,
            "App Attempt ID. Not to be used unless for testing purposes");
    opts.addOption(CaffeApplication.OPT_CAFFE_CONTAINER_MEMORY, true,
            "Amount of memory in MB to be requested to run the shell command");
    opts.addOption(CaffeApplication.OPT_CAFFE_CONTAINER_VCORES, true,
            "Amount of virtual cores to be requested to run the shell command");
    opts.addOption(CaffeApplication.OPT_CAFFE_PRIORITY, true, "Application Priority. Default 0");
    opts.addOption(CaffeApplication.OPT_CAFFE_CONTAINER_RETRY_POLICY, true,
            "Retry policy when container fails to run, " + "0: NEVER_RETRY, 1: RETRY_ON_ALL_ERRORS, "
                    + "2: RETRY_ON_SPECIFIC_ERROR_CODES");
    opts.addOption(CaffeApplication.OPT_CAFFE_CONTAINER_RETRY_ERROR_CODES, true,
            "When retry policy is set to RETRY_ON_SPECIFIC_ERROR_CODES, error "
                    + "codes is specified with this option, " + "e.g. --container_retry_error_codes 1,2,3");
    opts.addOption(CaffeApplication.OPT_CAFFE_CONTAINER_MAX_RETRIES, true,
            "If container could retry, it specifies max retires");
    opts.addOption(CaffeApplication.OPT_CAFFE_CONTAINER_RETRY_INTERVAL, true,
            "Interval between each retry, unit is milliseconds");

    opts.addOption(CaffeApplication.OPT_CAFFE_PROCESSOR_JAR, true, "Provide container jar of caffe");
    opts.addOption(CaffeApplication.OPT_CAFFE_PROCESSOR_NUM, true, "Provide processor number of caffe");
    opts.addOption(CaffeApplication.OPT_CAFFE_PROCESSOR_SOLVER, true, "solver_configuration");
    opts.addOption(CaffeApplication.OPT_CAFFE_PROCESSOR_TRAIN, true, "training_mode");
    opts.addOption(CaffeApplication.OPT_CAFFE_PROCESSOR_FEATURES, true, "name_of_output_blobs");
    opts.addOption(CaffeApplication.OPT_CAFFE_PROCESSOR_LABEL, true,
            "name of label blobs to be included in features");
    opts.addOption(CaffeApplication.OPT_CAFFE_PROCESSOR_MODEL, true, "model path");
    opts.addOption(CaffeApplication.OPT_CAFFE_PROCESSOR_OUTPUT, true, "output path");
    opts.addOption(CaffeApplication.OPT_CAFFE_PROCESSOR_CONNECTION, true, "network mode");

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

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

    if (fileExist(log4jPath)) {
        try {
            Log4jPropertyHelper.updateLog4jConfiguration(ApplicationMaster.class, log4jPath);
        } catch (Exception e) {
            LOG.warn("Can not set up custom log4j properties. " + e);
        }
    }

    Map<String, String> envs = System.getenv();

    if (!envs.containsKey(Environment.CONTAINER_ID.name())) {
        if (cliParser.hasOption(CaffeApplication.OPT_CAFFE_APP_ATTEMPT_ID)) {
            String appIdStr = cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_APP_ATTEMPT_ID, "");
            appAttemptID = ApplicationAttemptId.fromString(appIdStr);
        } else {
            throw new IllegalArgumentException("Application AttemptId not set in the environment");
        }
    } else {
        ContainerId containerId = ContainerId.fromString(envs.get(Environment.CONTAINER_ID.name()));
        appAttemptID = containerId.getApplicationAttemptId();
    }

    if (!envs.containsKey(ApplicationConstants.APP_SUBMIT_TIME_ENV)) {
        throw new RuntimeException(ApplicationConstants.APP_SUBMIT_TIME_ENV + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_HOST.name())) {
        throw new RuntimeException(Environment.NM_HOST.name() + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_HTTP_PORT.name())) {
        throw new RuntimeException(Environment.NM_HTTP_PORT + " not set in the environment");
    }
    if (!envs.containsKey(Environment.NM_PORT.name())) {
        throw new RuntimeException(Environment.NM_PORT.name() + " not set in the environment");
    }

    LOG.info("Application master for app" + ", appId=" + appAttemptID.getApplicationId().getId()
            + ", clustertimestamp=" + appAttemptID.getApplicationId().getClusterTimestamp() + ", attemptId="
            + appAttemptID.getAttemptId());

    containerMemory = Integer
            .parseInt(cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_CONTAINER_MEMORY, "256"));
    containerVirtualCores = Integer
            .parseInt(cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_CONTAINER_VCORES, "1"));

    numTotalProcessorContainers = Integer
            .parseInt(cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_PROCESSOR_NUM, "1"));
    if (numTotalProcessorContainers == 0) {
        throw new IllegalArgumentException("Cannot run caffe application with no containers");
    }
    numTotalContainers = numTotalProcessorContainers;
    if (numTotalContainers == 0) {
        throw new IllegalArgumentException("Cannot run distributed shell with no containers");
    }

    requestPriority = Integer.parseInt(cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_PRIORITY, "0"));

    containerRetryPolicy = ContainerRetryPolicy.values()[Integer
            .parseInt(cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_CONTAINER_RETRY_POLICY, "0"))];
    if (cliParser.hasOption(CaffeApplication.OPT_CAFFE_CONTAINER_RETRY_ERROR_CODES)) {
        containerRetryErrorCodes = new HashSet<>();
        for (String errorCode : cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_CONTAINER_RETRY_ERROR_CODES)
                .split(",")) {
            containerRetryErrorCodes.add(Integer.parseInt(errorCode));
        }
    }
    containerMaxRetries = Integer
            .parseInt(cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_CONTAINER_MAX_RETRIES, "0"));
    containrRetryInterval = Integer
            .parseInt(cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_CONTAINER_RETRY_INTERVAL, "0"));

    caffeProcessorJar = cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_PROCESSOR_JAR,
            CaffeAmContainer.APPMASTER_JAR_PATH);

    solver = cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_PROCESSOR_SOLVER, "");
    train = cliParser.hasOption(CaffeApplication.OPT_CAFFE_PROCESSOR_TRAIN);
    feature = cliParser.hasOption(CaffeApplication.OPT_CAFFE_PROCESSOR_FEATURES);
    label = cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_PROCESSOR_LABEL, "");
    model = cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_PROCESSOR_MODEL, "");
    output = cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_PROCESSOR_OUTPUT, "");
    connection = Integer
            .parseInt(cliParser.getOptionValue(CaffeApplication.OPT_CAFFE_PROCESSOR_CONNECTION, "2"));

    clusterSpec = ClusterSpec.makeClusterSpec(numTotalProcessorContainers);

    return true;
}

From source file:org.hdl.tensorflow.yarn.appmaster.ApplicationMaster.java

License:Apache License

private void setupPreviousRunningContainers(RegisterApplicationMasterResponse response) {
    String containerIdStr = System.getenv(Environment.CONTAINER_ID.name());
    ContainerId containerId = ContainerId.fromString(containerIdStr);
    appAttemptId = containerId.getApplicationAttemptId();
    List<Container> previousAMRunningContainers = response.getContainersFromPreviousAttempts();
    LOG.info(appAttemptId + " received " + previousAMRunningContainers.size()
            + " previous attempts' running containers on AM registration.");
    for (Container container : previousAMRunningContainers) {
        launchedContainers.add(container.getId());
    }/* w  ww .  ja v  a2  s  . com*/
    allocatedContainerNum.addAndGet(previousAMRunningContainers.size());
}