Search in sources :

Example 51 with LocalResource

use of org.apache.hadoop.yarn.api.records.LocalResource in project kitten by cloudera.

the class LuaContainerLaunchParameters method constructExtraResource.

private LocalResource constructExtraResource(String key) {
    LocalResource rsrc = Records.newRecord(LocalResource.class);
    rsrc.setType(LocalResourceType.FILE);
    rsrc.setVisibility(LocalResourceVisibility.APPLICATION);
    try {
        Path path = new Path(localFileUris.get(key));
        configureLocalResourceForPath(rsrc, path);
    } catch (IOException e) {
        LOG.error("Error constructing extra local resource: " + key, e);
        return null;
    }
    return rsrc;
}
Also used : Path(org.apache.hadoop.fs.Path) IOException(java.io.IOException) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource)

Example 52 with LocalResource

use of org.apache.hadoop.yarn.api.records.LocalResource in project alluxio by Alluxio.

the class Client method setupContainerLaunchContext.

private void setupContainerLaunchContext() throws IOException, YarnException {
    Map<String, String> applicationMasterArgs = ImmutableMap.<String, String>of("-num_workers", Integer.toString(mNumWorkers), "-master_address", mMasterAddress, "-resource_path", mResourcePath);
    final String amCommand = YarnUtils.buildCommand(YarnContainerType.APPLICATION_MASTER, applicationMasterArgs);
    System.out.println("ApplicationMaster command: " + amCommand);
    mAmContainer.setCommands(Collections.singletonList(amCommand));
    // Setup local resources
    Map<String, LocalResource> localResources = new HashMap<String, LocalResource>();
    localResources.put("alluxio.tar.gz", YarnUtils.createLocalResourceOfFile(mYarnConf, mResourcePath + "/alluxio.tar.gz"));
    localResources.put("alluxio-yarn-setup.sh", YarnUtils.createLocalResourceOfFile(mYarnConf, mResourcePath + "/alluxio-yarn-setup.sh"));
    localResources.put("alluxio.jar", YarnUtils.createLocalResourceOfFile(mYarnConf, mResourcePath + "/alluxio.jar"));
    mAmContainer.setLocalResources(localResources);
    // Setup CLASSPATH for ApplicationMaster
    Map<String, String> appMasterEnv = new HashMap<String, String>();
    setupAppMasterEnv(appMasterEnv);
    mAmContainer.setEnvironment(appMasterEnv);
    // Set up security tokens for launching our ApplicationMaster container.
    if (UserGroupInformation.isSecurityEnabled()) {
        Credentials credentials = new Credentials();
        String tokenRenewer = mYarnConf.get(YarnConfiguration.RM_PRINCIPAL);
        if (tokenRenewer == null || tokenRenewer.length() == 0) {
            throw new IOException("Can't get Master Kerberos principal for the RM to use as renewer");
        }
        org.apache.hadoop.fs.FileSystem fs = org.apache.hadoop.fs.FileSystem.get(mYarnConf);
        // getting tokens for the default file-system.
        final Token<?>[] tokens = fs.addDelegationTokens(tokenRenewer, credentials);
        if (tokens != null) {
            for (Token<?> token : tokens) {
                LOG.info("Got dt for " + fs.getUri() + "; " + token);
            }
        }
        // getting yarn resource manager token
        org.apache.hadoop.conf.Configuration config = mYarnClient.getConfig();
        Token<TokenIdentifier> token = ConverterUtils.convertFromYarn(mYarnClient.getRMDelegationToken(new org.apache.hadoop.io.Text(tokenRenewer)), ClientRMProxy.getRMDelegationTokenService(config));
        LOG.info("Added RM delegation token: " + token);
        credentials.addToken(token.getService(), token);
        DataOutputBuffer dob = new DataOutputBuffer();
        credentials.writeTokenStorageToStream(dob);
        ByteBuffer buffer = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
        mAmContainer.setTokens(buffer);
    }
}
Also used : TokenIdentifier(org.apache.hadoop.security.token.TokenIdentifier) HashMap(java.util.HashMap) Token(org.apache.hadoop.security.token.Token) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) Credentials(org.apache.hadoop.security.Credentials)

Example 53 with LocalResource

use of org.apache.hadoop.yarn.api.records.LocalResource in project apex-core by apache.

the class LaunchContainerRunnable method run.

/**
   * Connects to CM, sets up container launch context and eventually dispatches the container start request to the CM.
   */
@Override
public void run() {
    LOG.info("Setting up container launch context for containerid={}", container.getId());
    ContainerLaunchContext ctx = Records.newRecord(ContainerLaunchContext.class);
    setClasspath(containerEnv);
    // Setup ACLs for the impersonating user
    try {
        String launchPrincipal = System.getenv("HADOOP_USER_NAME");
        LOG.debug("Launch principal {}", launchPrincipal);
        if (launchPrincipal != null) {
            String launchUserName = launchPrincipal;
            if (UserGroupInformation.isSecurityEnabled()) {
                try {
                    launchUserName = new HadoopKerberosName(launchPrincipal).getShortName();
                } catch (Exception ex) {
                    LOG.warn("Error resolving kerberos principal {}", launchPrincipal, ex);
                }
            }
            LOG.debug("ACL launch user {} current user {}", launchUserName, UserGroupInformation.getCurrentUser().getShortUserName());
            if (!UserGroupInformation.getCurrentUser().getShortUserName().equals(launchUserName)) {
                ACLManager.setupUserACLs(ctx, launchUserName, nmClient.getConfig());
            }
        }
    } catch (IOException e) {
        LOG.warn("Unable to setup user acls for container {}", container.getId(), e);
    }
    try {
        // propagate to replace node managers user name (effective in non-secure mode)
        containerEnv.put("HADOOP_USER_NAME", UserGroupInformation.getLoginUser().getUserName());
    } catch (Exception e) {
        LOG.error("Failed to retrieve principal name", e);
    }
    // Set the environment
    ctx.setEnvironment(containerEnv);
    ctx.setTokens(tokens);
    // Set the local resources
    Map<String, LocalResource> localResources = new HashMap<>();
    // add resources for child VM
    try {
        // child VM dependencies
        try (FileSystem fs = StramClientUtils.newFileSystemInstance(nmClient.getConfig())) {
            addFilesToLocalResources(LocalResourceType.FILE, dag.getAttributes().get(Context.DAGContext.LIBRARY_JARS), localResources, fs);
            String archives = dag.getAttributes().get(LogicalPlan.ARCHIVES);
            if (archives != null) {
                addFilesToLocalResources(LocalResourceType.ARCHIVE, archives, localResources, fs);
            }
            ctx.setLocalResources(localResources);
        }
    } catch (IOException e) {
        LOG.error("Failed to prepare local resources.", e);
        return;
    }
    // Set the necessary command to execute on the allocated container
    List<CharSequence> vargs = getChildVMCommand(container.getId().toString());
    // Get final command
    StringBuilder command = new StringBuilder(1024);
    for (CharSequence str : vargs) {
        command.append(str).append(" ");
    }
    LOG.info("Launching on node: {} command: {}", container.getNodeId(), command);
    List<String> commands = new ArrayList<>();
    commands.add(command.toString());
    ctx.setCommands(commands);
    nmClient.startContainerAsync(container, ctx);
}
Also used : HashMap(java.util.HashMap) HadoopKerberosName(org.apache.hadoop.security.HadoopKerberosName) ArrayList(java.util.ArrayList) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) IOException(java.io.IOException) IOException(java.io.IOException) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource) FileSystem(org.apache.hadoop.fs.FileSystem)

Example 54 with LocalResource

use of org.apache.hadoop.yarn.api.records.LocalResource in project asterixdb by apache.

the class AsterixApplicationMaster method distributeAsterixConfig.

/**
     * Sets up the parameters for the Asterix config.
     *
     * @throws IOException
     */
private void distributeAsterixConfig() throws IOException {
    FileSystem fs = FileSystem.get(conf);
    String pathSuffix = instanceConfPath + File.separator + ASTERIX_CONF_NAME;
    Path dst = new Path(dfsBasePath, pathSuffix);
    URI paramLocation = dst.toUri();
    FileStatus paramFileStatus = fs.getFileStatus(dst);
    Long paramLen = paramFileStatus.getLen();
    Long paramTimestamp = paramFileStatus.getModificationTime();
    LocalResource asterixParamLoc = Records.newRecord(LocalResource.class);
    asterixParamLoc.setType(LocalResourceType.FILE);
    asterixParamLoc.setVisibility(LocalResourceVisibility.PRIVATE);
    asterixParamLoc.setResource(ConverterUtils.getYarnUrlFromURI(paramLocation));
    asterixParamLoc.setTimestamp(paramTimestamp);
    asterixParamLoc.setSize(paramLen);
    localResources.put(ASTERIX_CONF_NAME, asterixParamLoc);
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) URI(java.net.URI) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource)

Example 55 with LocalResource

use of org.apache.hadoop.yarn.api.records.LocalResource in project ignite by apache.

the class IgniteYarnUtils method setupFile.

/**
     * @param file Path.
     * @param fs File system.
     * @param type Local resource type.
     * @throws Exception If failed.
     */
public static LocalResource setupFile(Path file, FileSystem fs, LocalResourceType type) throws Exception {
    LocalResource resource = Records.newRecord(LocalResource.class);
    file = fs.makeQualified(file);
    FileStatus stat = fs.getFileStatus(file);
    resource.setResource(ConverterUtils.getYarnUrlFromPath(file));
    resource.setSize(stat.getLen());
    resource.setTimestamp(stat.getModificationTime());
    resource.setType(type);
    resource.setVisibility(LocalResourceVisibility.APPLICATION);
    return resource;
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) LocalResource(org.apache.hadoop.yarn.api.records.LocalResource)

Aggregations

LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)122 Path (org.apache.hadoop.fs.Path)79 HashMap (java.util.HashMap)67 Test (org.junit.Test)48 ArrayList (java.util.ArrayList)42 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)39 IOException (java.io.IOException)34 File (java.io.File)30 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)28 Configuration (org.apache.hadoop.conf.Configuration)27 FileSystem (org.apache.hadoop.fs.FileSystem)26 URL (org.apache.hadoop.yarn.api.records.URL)26 FileStatus (org.apache.hadoop.fs.FileStatus)24 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)24 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)22 LocalResourceVisibility (org.apache.hadoop.yarn.api.records.LocalResourceVisibility)18 ByteBuffer (java.nio.ByteBuffer)17 StartContainerRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainerRequest)17 StartContainersRequest (org.apache.hadoop.yarn.api.protocolrecords.StartContainersRequest)16 Random (java.util.Random)15