Example usage for org.apache.hadoop.security.token Token getKind

List of usage examples for org.apache.hadoop.security.token Token getKind

Introduction

In this page you can find the example usage for org.apache.hadoop.security.token Token getKind.

Prototype

public synchronized Text getKind() 

Source Link

Document

Get the token kind.

Usage

From source file:x10.x10rt.yarn.ApplicationMaster.java

License:Open Source License

private void setup() throws IOException, YarnException {
    LOG.info("Starting ApplicationMaster");

    // Remove the AM->RM token so that containers cannot access it.
    Credentials credentials = UserGroupInformation.getCurrentUser().getCredentials();
    DataOutputBuffer dob = new DataOutputBuffer();
    credentials.writeTokenStorageToStream(dob);
    Iterator<Token<?>> iter = credentials.getAllTokens().iterator();
    LOG.info("Executing with tokens:");
    while (iter.hasNext()) {
        Token<?> token = iter.next();
        LOG.info(token);// w  ww .ja  v a2 s .  c  om
        if (token.getKind().equals(AMRMTokenIdentifier.KIND_NAME)) {
            iter.remove();
        }
    }
    allTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
    // Create appSubmitterUgi and add original tokens to it
    String appSubmitterUserName = System.getenv(ApplicationConstants.Environment.USER.name());
    UserGroupInformation appSubmitterUgi = UserGroupInformation.createRemoteUser(appSubmitterUserName);
    appSubmitterUgi.addCredentials(credentials);

    resourceManager = AMRMClientAsync.createAMRMClientAsync(1000, new RMCallbackHandler());
    resourceManager.init(conf);
    resourceManager.start();

    nodeManager = new NMClientAsyncImpl(new NMCallbackHandler(this));
    nodeManager.init(conf);
    nodeManager.start();

    // Register self with ResourceManager
    // This will start heartbeating to the RM
    appMasterHostname = NetUtils.getHostname();
    RegisterApplicationMasterResponse response = resourceManager.registerApplicationMaster(appMasterHostname,
            appMasterRpcPort, appMasterTrackingUrl);
    {
        int slash = appMasterHostname.indexOf('/');
        if (slash != -1)
            appMasterHostname = appMasterHostname.substring(0, slash);
    }
    // Dump out information about cluster capability as seen by the
    // resource manager
    int maxMem = response.getMaximumResourceCapability().getMemory();
    LOG.info("Max mem capabililty of resources in this cluster " + maxMem);
    int maxVCores = response.getMaximumResourceCapability().getVirtualCores();
    LOG.info("Max vcores capabililty of resources in this cluster " + maxVCores);
    // A resource ask cannot exceed the max.

    // TODO: should we reject instead of modifying to fit?
    if (memoryPerPlaceInMb > maxMem) {
        LOG.info("Container memory specified above max threshold of cluster." + " Using max value."
                + ", specified=" + memoryPerPlaceInMb + ", max=" + maxMem);
        memoryPerPlaceInMb = maxMem;
    }
    if (coresPerPlace > maxVCores) {
        LOG.info("Container virtual cores specified above max threshold of cluster." + " Using max value."
                + ", specified=" + coresPerPlace + ", max=" + maxVCores);
        coresPerPlace = maxVCores;
    } else if (coresPerPlace == 0) {
        LOG.info("Container virtual cores specified as auto (X10_NTHREADS=0)." + " Using max value."
                + ", specified=" + coresPerPlace + ", max=" + maxVCores);
        coresPerPlace = maxVCores;
    }
    List<Container> previousAMRunningContainers = response.getContainersFromPreviousAttempts();
    LOG.info(appAttemptID + " received " + previousAMRunningContainers.size()
            + " previous attempts' running containers on AM registration.");
    numAllocatedContainers.addAndGet(previousAMRunningContainers.size());
    int numTotalContainersToRequest = initialNumPlaces - previousAMRunningContainers.size();

    // open a local port for X10rt management, and register it with the selector
    launcherChannel = ServerSocketChannel.open();
    //launcherChannel.bind(new InetSocketAddress(appMasterHostname, 0)); // bind to the visible network hostname and random port
    launcherChannel.bind(null);
    launcherChannel.configureBlocking(false);
    appMasterPort = launcherChannel.socket().getLocalPort();
    launcherChannel.register(selector, SelectionKey.OP_ACCEPT);

    numRequestedContainers.set(initialNumPlaces);
    // Send request for containers to RM
    for (int i = 0; i < numTotalContainersToRequest; ++i) {
        Resource capability = Resource.newInstance(memoryPerPlaceInMb, coresPerPlace);
        ContainerRequest request = new ContainerRequest(capability, null, null, Priority.newInstance(0));
        LOG.info("Requested container ask: " + request.toString());
        resourceManager.addContainerRequest(request);
        pendingRequests.add(request);
    }
}

From source file:yarnkit.utils.YarnUtils.java

License:Apache License

public static void removeToken(@Nonnull final Credentials credentials, @Nonnull final Text tokenKindToRemove) {
    Iterator<Token<?>> iter = credentials.getAllTokens().iterator();
    while (iter.hasNext()) {
        Token<?> token = iter.next();
        if (token.getKind().equals(tokenKindToRemove)) {
            iter.remove();/*  w w  w.j  a v  a2 s.co  m*/
        }
    }
}