Example usage for org.apache.hadoop.yarn.api.records ContainerLaunchContext getServiceData

List of usage examples for org.apache.hadoop.yarn.api.records ContainerLaunchContext getServiceData

Introduction

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

Prototype

@Public
@Stable
public abstract Map<String, ByteBuffer> getServiceData();

Source Link

Document

Get application-specific binary service data.

Usage

From source file:org.apache.tajo.master.YarnContainerProxy.java

License:Apache License

public ContainerLaunchContext createContainerLaunchContext(
        ContainerLaunchContext commonContainerLaunchContext) {
    // Setup environment by cloning from common env.
    Map<String, String> env = commonContainerLaunchContext.getEnvironment();
    Map<String, String> myEnv = new HashMap<String, String>(env.size());
    myEnv.putAll(env);/*w w w .j  av a  2 s. c o  m*/

    // Duplicate the ByteBuffers for access by multiple containers.
    Map<String, ByteBuffer> myServiceData = new HashMap<String, ByteBuffer>();
    for (Map.Entry<String, ByteBuffer> entry : commonContainerLaunchContext.getServiceData().entrySet()) {
        myServiceData.put(entry.getKey(), entry.getValue().duplicate());
    }

    ////////////////////////////////////////////////////////////////////////////
    // Set the local resources
    ////////////////////////////////////////////////////////////////////////////
    // Set the necessary command to execute the application master
    Vector<CharSequence> vargs = new Vector<CharSequence>(30);

    // Set java executable command
    //LOG.info("Setting up app master command");
    vargs.add("${JAVA_HOME}" + "/bin/java");
    // Set Xmx based on am memory size
    vargs.add("-Xmx2000m");
    // Set Remote Debugging
    //if (!context.getQuery().getSubQuery(event.getExecutionBlockId()).isLeafQuery()) {
    //vargs.add("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
    //}
    // Set class name
    //vargs.add(getRunnerClass());
    vargs.add(TajoWorker.class.getCanonicalName());
    vargs.add("tr"); //workerMode
    vargs.add(getId()); // subqueryId
    vargs.add(containerMgrAddress); // nodeId
    vargs.add(containerID.toString()); // containerId
    Vector<CharSequence> taskParams = getTaskParams();
    if (taskParams != null) {
        vargs.addAll(taskParams);
    }

    vargs.add("1>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stdout");
    vargs.add("2>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stderr");

    // Get final commmand
    StringBuilder command = new StringBuilder();
    for (CharSequence str : vargs) {
        command.append(str).append(" ");
    }

    LOG.info("Completed setting up TaskRunner command " + command.toString());
    List<String> commands = new ArrayList<String>();
    commands.add(command.toString());

    return BuilderUtils.newContainerLaunchContext(commonContainerLaunchContext.getLocalResources(), myEnv,
            commands, myServiceData, null, new HashMap<ApplicationAccessType, String>());
}

From source file:org.apache.tez.dag.app.rm.container.AMContainerHelpers.java

License:Apache License

@VisibleForTesting
public static ContainerLaunchContext createContainerLaunchContext(TezDAGID tezDAGID,
        Map<String, LocalResource> commonDAGLRs, Map<ApplicationAccessType, String> acls,
        ContainerId containerId, Map<String, LocalResource> localResources, Map<String, String> vertexEnv,
        String javaOpts, InetSocketAddress taskAttemptListenerAddress, Credentials credentials,
        AppContext appContext, Resource containerResource, Configuration conf) {

    ContainerLaunchContext commonContainerSpec = null;
    synchronized (commonContainerSpecLock) {
        if (!commonContainerSpecs.containsKey(tezDAGID)) {
            commonContainerSpec = createCommonContainerLaunchContext(acls, credentials, commonDAGLRs);
            commonContainerSpecs.put(tezDAGID, commonContainerSpec);
        } else {/*from   w  ww .j  av  a2  s . c om*/
            commonContainerSpec = commonContainerSpecs.get(tezDAGID);
        }

        // Ensure that we remove container specs for previous AMs to reduce
        // memory footprint
        if (lastDAGID == null) {
            lastDAGID = tezDAGID;
        } else if (!lastDAGID.equals(tezDAGID)) {
            commonContainerSpecs.remove(lastDAGID);
            lastDAGID = tezDAGID;
        }
    }

    // Fill in the fields needed per-container that are missing in the common
    // spec.
    Map<String, LocalResource> lResources = new TreeMap<String, LocalResource>();
    lResources.putAll(commonContainerSpec.getLocalResources());
    lResources.putAll(localResources);

    // Setup environment by cloning from common env.
    Map<String, String> env = commonContainerSpec.getEnvironment();
    Map<String, String> myEnv = new HashMap<String, String>(env.size());
    myEnv.putAll(env);
    myEnv.putAll(vertexEnv);

    String modifiedJavaOpts = TezClientUtils.maybeAddDefaultMemoryJavaOpts(javaOpts, containerResource,
            conf.getDouble(TezConfiguration.TEZ_CONTAINER_MAX_JAVA_HEAP_FRACTION,
                    TezConfiguration.TEZ_CONTAINER_MAX_JAVA_HEAP_FRACTION_DEFAULT));
    if (LOG.isDebugEnabled()) {
        if (!modifiedJavaOpts.equals(javaOpts)) {
            LOG.debug("Modified java opts for container" + ", containerId=" + containerId
                    + ", originalJavaOpts=" + javaOpts + ", modifiedJavaOpts=" + modifiedJavaOpts);
        }
    }

    List<String> commands = TezRuntimeChildJVM.getVMCommand(taskAttemptListenerAddress, containerId.toString(),
            appContext.getApplicationID().toString(), appContext.getApplicationAttemptId().getAttemptId(),
            modifiedJavaOpts);

    // Duplicate the ByteBuffers for access by multiple containers.
    Map<String, ByteBuffer> myServiceData = new HashMap<String, ByteBuffer>();
    for (Entry<String, ByteBuffer> entry : commonContainerSpec.getServiceData().entrySet()) {
        myServiceData.put(entry.getKey(), entry.getValue().duplicate());
    }

    // Construct the actual Container
    ContainerLaunchContext container = ContainerLaunchContext.newInstance(lResources, myEnv, commands,
            myServiceData, commonContainerSpec.getTokens().duplicate(), acls);

    return container;
}