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

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

Introduction

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

Prototype

@Public
@Stable
public abstract List<String> getCommands();

Source Link

Document

Get the list of commands for launching the container.

Usage

From source file:alluxio.yarn.ApplicationMasterTest.java

License:Apache License

/**
 * @param expectedContext the context to test for matching
 * @return an argument matcher which tests for matching the given container launch context
 *//*from  w  w  w .jav  a  2  s . co  m*/
private ArgumentMatcher<ContainerLaunchContext> getContextMatcher(
        final ContainerLaunchContext expectedContext) {
    return new ArgumentMatcher<ContainerLaunchContext>() {
        public boolean matches(Object arg) {
            if (!(arg instanceof ContainerLaunchContext)) {
                return false;
            }
            ContainerLaunchContext ctx = (ContainerLaunchContext) arg;
            // Compare only keys for local resources because values include timestamps.
            return ctx.getLocalResources().keySet().equals(expectedContext.getLocalResources().keySet())
                    && ctx.getCommands().equals(expectedContext.getCommands())
                    && ctx.getEnvironment().equals(expectedContext.getEnvironment());
        }
    };
}

From source file:husky.client.HuskyYarnClient.java

License:Apache License

private boolean run() throws YarnException, IOException {
    mYarnClient.start();//ww  w. ja  va  2s .c om

    YarnClientApplication app = mYarnClient.createApplication();

    ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
    appContext.setApplicationName(mAppName);

    Resource resource = Records.newRecord(Resource.class);
    resource.setMemory(mAppMasterMemory);
    resource.setVirtualCores(mNumVirtualCores);
    appContext.setResource(resource);

    mAppId = appContext.getApplicationId();

    ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);
    amContainer.setLocalResources(getLocalResources());
    amContainer.setEnvironment(getEnvironment());

    StringBuilder cmdBuilder = new StringBuilder();
    if (!mKeyTabFile.isEmpty()) {
        if (mUserName.isEmpty()) {
            throw new RuntimeException("Username is not given but is required by kinit");
        }
        cmdBuilder.append("kinit -kt ").append(mKeyTabFile).append(" -V ").append(mUserName).append(" && ");
    }
    cmdBuilder.append(JAVA_HOME.$()).append("/bin/java").append(" -Xmx").append(mAppMasterMemory).append("m ")
            .append(HuskyApplicationMaster.class.getName()).append(" --container_memory ")
            .append(mContainerMemory).append(" --container_vcores ").append(mNumVirtualCores)
            .append(" --app_priority ").append(mAppPriority).append(" --app_master_log_dir <LOG_DIR>")
            .append(" --master ").append(mMasterExec).append(" --application ").append(mAppExec)
            .append(" --config ").append(mConfigFile);
    if (!mLdLibraryPath.isEmpty()) {
        cmdBuilder.append(" --ld_library_path \"").append(mLdLibraryPath).append("\" ");
    }
    cmdBuilder.append(" --worker_infos ").append(mWorkerInfos.get(0).getFirst()).append(":")
            .append(mWorkerInfos.get(0).getSecond());
    for (int i = 1; i < mWorkerInfos.size(); i++) {
        cmdBuilder.append(',').append(mWorkerInfos.get(i).getFirst()).append(":")
                .append(mWorkerInfos.get(i).getSecond());
    }
    if (!mLocalFiles.isEmpty()) {
        cmdBuilder.append(" --local_files \"").append(mLocalFiles).append("\"");
    }
    if (!mLocalArchives.isEmpty()) {
        cmdBuilder.append(" --local_archives \"").append(mLocalArchives).append("\"");
    }
    if (!mLogPathToHDFS.isEmpty()) {
        cmdBuilder.append(" --log_to_hdfs \"").append(mLogPathToHDFS).append("\"");
    }
    cmdBuilder.append(" 1>").append("<LOG_DIR>/HuskyAppMaster.stdout").append(" 2>")
            .append("<LOG_DIR>/HuskyAppMaster.stderr");
    if (!mLogPathToHDFS.isEmpty()) {
        cmdBuilder.append("; am_exit_code=$?").append("; hadoop fs -put -f <LOG_DIR>/HuskyAppMaster.stdout ")
                .append(mLogPathToHDFS).append("; hadoop fs -put -f <LOG_DIR>/HuskyAppMaster.stderr ")
                .append(mLogPathToHDFS).append("; exit \"$am_exit_code\"");
    }

    amContainer.setCommands(Collections.singletonList(cmdBuilder.toString()));

    LOG.info("Command: " + amContainer.getCommands().get(0));

    appContext.setAMContainerSpec(amContainer);

    mYarnClient.submitApplication(appContext);

    return monitorApp();
}

From source file:org.apache.helix.provisioning.yarn.GenericApplicationMaster.java

License:Apache License

public ListenableFuture<ContainerLaunchResponse> launchContainer(Container container,
        ContainerLaunchContext containerLaunchContext) {
    LOG.info("Requesting container LAUNCH:" + container + " :"
            + Joiner.on(" ").join(containerLaunchContext.getCommands()));
    SettableFuture<ContainerLaunchResponse> future = SettableFuture.create();
    containerLaunchResponseMap.put(container.getId(), future);
    nmClientAsync.startContainerAsync(container, containerLaunchContext);
    return future;
}

From source file:org.deeplearning4j.iterativereduce.runtime.yarn.ContainerManagerHandler.java

License:Apache License

public StartContainerResponse startContainer(List<String> commands, Map<String, LocalResource> localResources,
        Map<String, String> env) throws IOException {

    if (containerManager == null)
        throw new IllegalStateException("Cannot start a continer before connecting to the container manager!");

    ContainerLaunchContext ctx = Records.newRecord(ContainerLaunchContext.class);
    ctx.setContainerId(container.getId());
    ctx.setResource(container.getResource());
    ctx.setLocalResources(localResources);
    ctx.setCommands(commands);/*from w  ww  .j  a  va 2 s  .com*/
    ctx.setUser(UserGroupInformation.getCurrentUser().getShortUserName());
    ctx.setEnvironment(env);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Using ContainerLaunchContext with" + ", containerId=" + ctx.getContainerId() + ", memory="
                + ctx.getResource().getMemory() + ", localResources=" + ctx.getLocalResources().toString()
                + ", commands=" + ctx.getCommands().toString() + ", env=" + ctx.getEnvironment().toString());
    }

    StartContainerRequest request = Records.newRecord(StartContainerRequest.class);
    request.setContainerLaunchContext(ctx);

    LOG.info("Starting container, containerId=" + container.getId().toString() + ", host="
            + container.getNodeId().getHost() + ", http=" + container.getNodeHttpAddress());

    return containerManager.startContainer(request);
}

From source file:org.elasticsearch.hadoop.yarn.am.EsCluster.java

License:Apache License

private void launchContainer(Container container) {
    ContainerLaunchContext ctx = Records.newRecord(ContainerLaunchContext.class);

    ctx.setEnvironment(setupEnv(appConfig));
    ctx.setLocalResources(setupEsZipResource(appConfig));
    ctx.setCommands(setupEsScript(appConfig));

    log.info("About to launch container for command: " + ctx.getCommands());

    // setup container
    Map<String, ByteBuffer> startContainer = nmRpc.startContainer(container, ctx);
    log.info("Started container " + container);
}

From source file:tachyon.yarn.ApplicationMasterTest.java

License:Apache License

/**
 * @param expectedContext the context to test for matching
 * @return an argument matcher which tests for matching the given container launch context
 *///from  www.j a va  2  s . c o  m
private ArgumentMatcher<ContainerLaunchContext> getContextMatcher(
        final ContainerLaunchContext expectedContext) {
    return new ArgumentMatcher<ContainerLaunchContext>() {
        public boolean matches(Object arg) {
            if (!(arg instanceof ContainerLaunchContext)) {
                return false;
            }
            ContainerLaunchContext ctx = (ContainerLaunchContext) arg;
            return ctx.getLocalResources().equals(expectedContext.getLocalResources())
                    && ctx.getCommands().equals(expectedContext.getCommands())
                    && ctx.getEnvironment().equals(expectedContext.getEnvironment());
        }
    };
}

From source file:yarnkit.container.ContainerLaunchContextFactory.java

License:Apache License

public ContainerLaunchContext duplicate(@CheckForNull ContainerLaunchContext original) {
    Preconditions.checkNotNull(original, "ContainerLaunchContext should not be null");

    ContainerLaunchContext copy = Records.newRecord(ContainerLaunchContext.class);
    copy.setCommands(original.getCommands());
    copy.setEnvironment(original.getEnvironment());
    copy.setLocalResources(original.getLocalResources());
    ByteBuffer token = original.getTokens();
    if (token != null) {
        copy.setTokens(token.duplicate());
    }/*from  w  w  w  . ja v  a  2  s.  co  m*/
    return copy;
}