Example usage for org.apache.hadoop.security UserGroupInformation getCurrentUser

List of usage examples for org.apache.hadoop.security UserGroupInformation getCurrentUser

Introduction

In this page you can find the example usage for org.apache.hadoop.security UserGroupInformation getCurrentUser.

Prototype

@InterfaceAudience.Public
@InterfaceStability.Evolving
public static UserGroupInformation getCurrentUser() throws IOException 

Source Link

Document

Return the current user, including any doAs in the current stack.

Usage

From source file:org.apache.tez.auxservices.TestIndexCache.java

License:Apache License

@Test
public void testBadIndex() throws Exception {
    final int parts = 30;
    fs.delete(p, true);/*from w  w w .  ja  v  a  2  s  . c  o m*/
    conf.setInt(INDEX_CACHE_MB, 1);
    IndexCache cache = new IndexCache(conf);

    Path f = new Path(p, "badindex");
    FSDataOutputStream out = fs.create(f, false);
    CheckedOutputStream iout = new CheckedOutputStream(out, new CRC32());
    DataOutputStream dout = new DataOutputStream(iout);
    for (int i = 0; i < parts; ++i) {
        for (int j = 0; j < Constants.MAP_OUTPUT_INDEX_RECORD_LENGTH / 8; ++j) {
            if (0 == (i % 3)) {
                dout.writeLong(i);
            } else {
                out.writeLong(i);
            }
        }
    }
    out.writeLong(iout.getChecksum().getValue());
    dout.close();
    try {
        cache.getIndexInformation("badindex", 7, f, UserGroupInformation.getCurrentUser().getShortUserName());
        fail("Did not detect bad checksum");
    } catch (IOException e) {
        if (!(e.getCause() instanceof ChecksumException)) {
            throw e;
        }
    }
}

From source file:org.apache.tez.auxservices.TestIndexCache.java

License:Apache License

@Test
public void testInvalidReduceNumberOrLength() throws Exception {
    fs.delete(p, true);/* ww w . j  av  a2 s  . c  om*/
    conf.setInt(INDEX_CACHE_MB, 1);
    final int partsPerMap = 1000;
    final int bytesPerFile = partsPerMap * 24;
    IndexCache cache = new IndexCache(conf);

    // fill cache
    Path feq = new Path(p, "invalidReduceOrPartsPerMap");
    writeFile(fs, feq, bytesPerFile, partsPerMap);

    // Number of reducers should always be less than partsPerMap as reducer
    // numbers start from 0 and there cannot be more reducer than parts

    try {
        // Number of reducers equal to partsPerMap
        cache.getIndexInformation("reduceEqualPartsPerMap", partsPerMap, // reduce number == partsPerMap
                feq, UserGroupInformation.getCurrentUser().getShortUserName());
        fail("Number of reducers equal to partsPerMap did not fail");
    } catch (Exception e) {
        if (!(e instanceof IOException)) {
            throw e;
        }
    }

    try {
        // Number of reducers more than partsPerMap
        cache.getIndexInformation("reduceMorePartsPerMap", partsPerMap + 1, // reduce number > partsPerMap
                feq, UserGroupInformation.getCurrentUser().getShortUserName());
        fail("Number of reducers more than partsPerMap did not fail");
    } catch (Exception e) {
        if (!(e instanceof IOException)) {
            throw e;
        }
    }
}

From source file:org.apache.tez.auxservices.TestIndexCache.java

License:Apache License

@Test
public void testRemoveMap() throws Exception {
    // This test case use two thread to call getIndexInformation and
    // removeMap concurrently, in order to construct race condition.
    // This test case may not repeatable. But on my macbook this test
    // fails with probability of 100% on code before MAPREDUCE-2541,
    // so it is repeatable in practice.
    fs.delete(p, true);//from www  . j a  v a2  s.co m
    conf.setInt(INDEX_CACHE_MB, 10);
    // Make a big file so removeMapThread almost surely runs faster than
    // getInfoThread
    final int partsPerMap = 100000;
    final int bytesPerFile = partsPerMap * 24;
    final IndexCache cache = new IndexCache(conf);

    final Path big = new Path(p, "bigIndex");
    final String user = UserGroupInformation.getCurrentUser().getShortUserName();
    writeFile(fs, big, bytesPerFile, partsPerMap);

    // run multiple times
    for (int i = 0; i < 20; ++i) {
        Thread getInfoThread = new Thread() {
            @Override
            public void run() {
                try {
                    cache.getIndexInformation("bigIndex", partsPerMap, big, user);
                } catch (Exception e) {
                    // should not be here
                }
            }
        };
        Thread removeMapThread = new Thread() {
            @Override
            public void run() {
                cache.removeMap("bigIndex");
            }
        };
        if (i % 2 == 0) {
            getInfoThread.start();
            removeMapThread.start();
        } else {
            removeMapThread.start();
            getInfoThread.start();
        }
        getInfoThread.join();
        removeMapThread.join();
        assertEquals(true, cache.checkTotalMemoryUsed());
    }
}

From source file:org.apache.tez.auxservices.TestIndexCache.java

License:Apache License

@Test
public void testCreateRace() throws Exception {
    fs.delete(p, true);/*from w ww.j  a va  2s.  com*/
    conf.setInt(INDEX_CACHE_MB, 1);
    final int partsPerMap = 1000;
    final int bytesPerFile = partsPerMap * 24;
    final IndexCache cache = new IndexCache(conf);

    final Path racy = new Path(p, "racyIndex");
    final String user = UserGroupInformation.getCurrentUser().getShortUserName();
    writeFile(fs, racy, bytesPerFile, partsPerMap);

    // run multiple instances
    Thread[] getInfoThreads = new Thread[50];
    for (int i = 0; i < 50; i++) {
        getInfoThreads[i] = new Thread() {
            @Override
            public void run() {
                try {
                    cache.getIndexInformation("racyIndex", partsPerMap, racy, user);
                    cache.removeMap("racyIndex");
                } catch (Exception e) {
                    // should not be here
                }
            }
        };
    }

    for (int i = 0; i < 50; i++) {
        getInfoThreads[i].start();
    }

    final Thread mainTestThread = Thread.currentThread();

    Thread timeoutThread = new Thread() {
        @Override
        public void run() {
            try {
                Thread.sleep(15000);
                mainTestThread.interrupt();
            } catch (InterruptedException ie) {
                // we are done;
            }
        }
    };

    for (int i = 0; i < 50; i++) {
        try {
            getInfoThreads[i].join();
        } catch (InterruptedException ie) {
            // we haven't finished in time. Potential deadlock/race.
            fail("Unexpectedly long delay during concurrent cache entry creations");
        }
    }
    // stop the timeoutThread. If we get interrupted before stopping, there
    // must be something wrong, although it wasn't a deadlock. No need to
    // catch and swallow.
    timeoutThread.interrupt();
}

From source file:org.apache.tez.auxservices.TestShuffleHandlerJobs.java

License:Apache License

@Test(timeout = 300000)
public void testOrderedWordCount() throws Exception {
    String inputDirStr = "/tmp/owc-input/";
    Path inputDir = new Path(inputDirStr);
    Path stagingDirPath = new Path("/tmp/owc-staging-dir");
    remoteFs.mkdirs(inputDir);// w  w w. j av  a  2 s .  com
    remoteFs.mkdirs(stagingDirPath);
    generateOrderedWordCountInput(inputDir, remoteFs);

    String outputDirStr = "/tmp/owc-output/";
    Path outputDir = new Path(outputDirStr);

    TezConfiguration tezConf = new TezConfiguration(tezCluster.getConfig());
    tezConf.set(TezConfiguration.TEZ_AM_STAGING_DIR, stagingDirPath.toString());
    tezConf.set(TezConfiguration.TEZ_AM_SHUFFLE_AUXILIARY_SERVICE_ID, ShuffleHandler.TEZ_SHUFFLE_SERVICEID);
    tezConf.setBoolean(TezConfiguration.TEZ_AM_DAG_CLEANUP_ON_COMPLETION, true);
    tezConf.setBoolean(TezConfiguration.TEZ_AM_SESSION_MODE, true);
    tezConf.setBoolean(TezRuntimeConfiguration.TEZ_RUNTIME_OPTIMIZE_LOCAL_FETCH, false);
    tezConf.setBoolean(TezConfiguration.TEZ_AM_CONTAINER_REUSE_ENABLED, false);
    TezClient tezSession = TezClient.create("WordCountTest", tezConf);
    tezSession.start();
    try {
        final OrderedWordCount job = new OrderedWordCount();
        Assert.assertTrue("OrderedWordCount failed", job.run(tezConf,
                new String[] { "-counter", inputDirStr, outputDirStr, "10" }, tezSession) == 0);
        verifyOutput(outputDir, remoteFs);
        tezSession.stop();
        ClientRMService rmService = tezCluster.getResourceManager().getClientRMService();
        boolean isAppComplete = false;
        while (!isAppComplete) {
            GetApplicationReportResponse resp = rmService
                    .getApplicationReport(new GetApplicationReportRequest() {
                        @Override
                        public ApplicationId getApplicationId() {
                            return job.getAppId();
                        }

                        @Override
                        public void setApplicationId(ApplicationId applicationId) {
                        }
                    });
            if (resp.getApplicationReport().getYarnApplicationState() == YarnApplicationState.FINISHED) {
                isAppComplete = true;
            }
            Thread.sleep(100);
        }
        for (int i = 0; i < NUM_NMS; i++) {
            String appPath = tezCluster.getTestWorkDir() + "/" + this.getClass().getName() + "-localDir-nm-" + i
                    + "_0/usercache/" + UserGroupInformation.getCurrentUser().getUserName() + "/appcache/"
                    + job.getAppId();
            String dagPathStr = appPath + "/dag_1";

            File fs = new File(dagPathStr);
            Assert.assertFalse(fs.exists());
            fs = new File(appPath);
            Assert.assertTrue(fs.exists());
        }
    } finally {
        remoteFs.delete(stagingDirPath, true);
    }
}

From source file:org.apache.tez.client.LocalClient.java

License:Apache License

protected Thread createDAGAppMaster(final ApplicationSubmissionContext appContext) {
    Thread thread = new Thread(new Runnable() {
        @Override//from   ww  w  . j a v  a  2 s . c  om
        public void run() {
            try {
                ApplicationId appId = appContext.getApplicationId();

                // Set up working directory for DAGAppMaster
                Path staging = TezCommonUtils.getTezSystemStagingPath(conf, appId.toString());
                Path userDir = TezCommonUtils.getTezSystemStagingPath(conf, appId.toString() + "_wd");
                LOG.info("Using working directory: " + userDir.toUri().getPath());

                FileSystem fs = FileSystem.get(conf);
                // copy data from staging directory to working directory to simulate the resource localizing
                FileUtil.copy(fs, staging, fs, userDir, false, conf);
                // Prepare Environment
                Path logDir = new Path(userDir, "localmode-log-dir");
                Path localDir = new Path(userDir, "localmode-local-dir");
                fs.mkdirs(logDir);
                fs.mkdirs(localDir);

                UserGroupInformation.setConfiguration(conf);
                // Add session specific credentials to the AM credentials.
                ByteBuffer tokens = appContext.getAMContainerSpec().getTokens();

                Credentials amCredentials;
                if (tokens != null) {
                    amCredentials = TezCommonUtils.parseCredentialsBytes(tokens.array());
                } else {
                    amCredentials = new Credentials();
                }

                // Construct, initialize, and start the DAGAppMaster
                ApplicationAttemptId applicationAttemptId = ApplicationAttemptId.newInstance(appId, 0);
                ContainerId cId = ContainerId.newInstance(applicationAttemptId, 1);
                String currentHost = InetAddress.getLocalHost().getHostName();
                int nmPort = YarnConfiguration.DEFAULT_NM_PORT;
                int nmHttpPort = YarnConfiguration.DEFAULT_NM_WEBAPP_PORT;
                long appSubmitTime = System.currentTimeMillis();

                dagAppMaster = createDAGAppMaster(applicationAttemptId, cId, currentHost, nmPort, nmHttpPort,
                        new SystemClock(), appSubmitTime, isSession, userDir.toUri().getPath(),
                        new String[] { localDir.toUri().getPath() }, new String[] { logDir.toUri().getPath() },
                        amCredentials, UserGroupInformation.getCurrentUser().getShortUserName());
                clientHandler = new DAGClientHandler(dagAppMaster);
                DAGAppMaster.initAndStartAppMaster(dagAppMaster, conf);

            } catch (Throwable t) {
                LOG.fatal("Error starting DAGAppMaster", t);
                if (dagAppMaster != null) {
                    dagAppMaster.stop();
                }
                amFailException = t;
            }
        }
    });

    thread.setName("DAGAppMaster Thread");
    LOG.info("DAGAppMaster thread has been created");

    return thread;
}

From source file:org.apache.tez.client.TezClientUtils.java

License:Apache License

/**
 * Verify or create the Staging area directory on the configured Filesystem
 * @param stagingArea Staging area directory path
 * @return the FileSytem for the staging area directory
 * @throws IOException/*from  w  ww .j a v  a2  s.co  m*/
 */
public static FileSystem ensureStagingDirExists(Configuration conf, Path stagingArea) throws IOException {
    FileSystem fs = stagingArea.getFileSystem(conf);
    String realUser;
    String currentUser;
    UserGroupInformation ugi = UserGroupInformation.getLoginUser();
    realUser = ugi.getShortUserName();
    currentUser = UserGroupInformation.getCurrentUser().getShortUserName();
    if (fs.exists(stagingArea)) {
        FileStatus fsStatus = fs.getFileStatus(stagingArea);
        String owner = fsStatus.getOwner();
        if (!(owner.equals(currentUser) || owner.equals(realUser))) {
            throw new IOException("The ownership on the staging directory " + stagingArea
                    + " is not as expected. " + "It is owned by " + owner + ". The directory must "
                    + "be owned by the submitter " + currentUser + " or " + "by " + realUser);
        }
        if (!fsStatus.getPermission().equals(TezCommonUtils.TEZ_AM_DIR_PERMISSION)) {
            LOG.info("Permissions on staging directory " + stagingArea + " are " + "incorrect: "
                    + fsStatus.getPermission() + ". Fixing permissions " + "to correct value "
                    + TezCommonUtils.TEZ_AM_DIR_PERMISSION);
            fs.setPermission(stagingArea, TezCommonUtils.TEZ_AM_DIR_PERMISSION);
        }
    } else {
        TezCommonUtils.mkDirForAM(fs, stagingArea);
    }
    return fs;
}

From source file:org.apache.tez.client.TezClientUtils.java

License:Apache License

/**
 * Create an ApplicationSubmissionContext to launch a Tez AM
 * @param appId Application Id/*  ww w.j  a  v  a 2s .  c  o m*/
 * @param dag DAG to be submitted
 * @param amName Name for the application
 * @param amConfig AM Configuration
 * @param tezJarResources Resources to be used by the AM
 * @param sessionCreds the credential object which will be populated with session specific
 * @param historyACLPolicyManager
 * @return an ApplicationSubmissionContext to launch a Tez AM
 * @throws IOException
 * @throws YarnException
 */
@Private
@VisibleForTesting
public static ApplicationSubmissionContext createApplicationSubmissionContext(ApplicationId appId, DAG dag,
        String amName, AMConfiguration amConfig, Map<String, LocalResource> tezJarResources,
        Credentials sessionCreds, boolean tezLrsAsArchive, TezApiVersionInfo apiVersionInfo,
        HistoryACLPolicyManager historyACLPolicyManager) throws IOException, YarnException {

    Preconditions.checkNotNull(sessionCreds);
    TezConfiguration conf = amConfig.getTezConfiguration();

    FileSystem fs = TezClientUtils.ensureStagingDirExists(conf, TezCommonUtils.getTezBaseStagingPath(conf));
    String strAppId = appId.toString();
    Path tezSysStagingPath = TezCommonUtils.createTezSystemStagingPath(conf, strAppId);
    Path binaryConfPath = TezCommonUtils.getTezConfStagingPath(tezSysStagingPath);
    binaryConfPath = fs.makeQualified(binaryConfPath);

    // Setup resource requirements
    Resource capability = Records.newRecord(Resource.class);
    capability.setMemory(amConfig.getTezConfiguration().getInt(TezConfiguration.TEZ_AM_RESOURCE_MEMORY_MB,
            TezConfiguration.TEZ_AM_RESOURCE_MEMORY_MB_DEFAULT));
    capability.setVirtualCores(amConfig.getTezConfiguration().getInt(
            TezConfiguration.TEZ_AM_RESOURCE_CPU_VCORES, TezConfiguration.TEZ_AM_RESOURCE_CPU_VCORES_DEFAULT));
    if (LOG.isDebugEnabled()) {
        LOG.debug("AppMaster capability = " + capability);
    }

    // Setup required Credentials for the AM launch. DAG specific credentials
    // are handled separately.
    ByteBuffer securityTokens = null;
    // Setup security tokens
    Credentials amLaunchCredentials = new Credentials();
    if (amConfig.getCredentials() != null) {
        amLaunchCredentials.addAll(amConfig.getCredentials());
    }

    // Add Staging dir creds to the list of session credentials.
    TokenCache.obtainTokensForFileSystems(sessionCreds, new Path[] { binaryConfPath }, conf);

    // Add session specific credentials to the AM credentials.
    amLaunchCredentials.mergeAll(sessionCreds);

    DataOutputBuffer dob = new DataOutputBuffer();
    amLaunchCredentials.writeTokenStorageToStream(dob);
    securityTokens = ByteBuffer.wrap(dob.getData(), 0, dob.getLength());

    // Setup the command to run the AM
    List<String> vargs = new ArrayList<String>(8);
    vargs.add(Environment.JAVA_HOME.$() + "/bin/java");

    String amOpts = constructAMLaunchOpts(amConfig.getTezConfiguration(), capability);
    vargs.add(amOpts);

    String amLogLevelString = amConfig.getTezConfiguration().get(TezConfiguration.TEZ_AM_LOG_LEVEL,
            TezConfiguration.TEZ_AM_LOG_LEVEL_DEFAULT);
    String[] amLogParams = parseLogParams(amLogLevelString);

    String amLogLevel = amLogParams[0];
    maybeAddDefaultLoggingJavaOpts(amLogLevel, vargs);

    // FIX sun bug mentioned in TEZ-327
    vargs.add("-Dsun.nio.ch.bugLevel=''");

    vargs.add(TezConstants.TEZ_APPLICATION_MASTER_CLASS);
    if (dag == null) {
        vargs.add("--" + TezConstants.TEZ_SESSION_MODE_CLI_OPTION);
    }

    vargs.add("1>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + File.separator + ApplicationConstants.STDOUT);
    vargs.add("2>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + File.separator + ApplicationConstants.STDERR);

    Vector<String> vargsFinal = new Vector<String>(8);
    // Final command
    StringBuilder mergedCommand = new StringBuilder();
    for (CharSequence str : vargs) {
        mergedCommand.append(str).append(" ");
    }
    vargsFinal.add(mergedCommand.toString());

    if (LOG.isDebugEnabled()) {
        LOG.debug("Command to launch container for ApplicationMaster is : " + mergedCommand);
    }

    Map<String, String> environment = new TreeMap<String, String>();
    TezYARNUtils.setupDefaultEnv(environment, conf, TezConfiguration.TEZ_AM_LAUNCH_ENV,
            TezConfiguration.TEZ_AM_LAUNCH_ENV_DEFAULT, tezLrsAsArchive);

    addVersionInfoToEnv(environment, apiVersionInfo);
    addLogParamsToEnv(environment, amLogParams);

    Map<String, LocalResource> amLocalResources = new TreeMap<String, LocalResource>();

    // Not fetching credentials for AMLocalResources. Expect this to be provided via AMCredentials.
    if (amConfig.getAMLocalResources() != null) {
        amLocalResources.putAll(amConfig.getAMLocalResources());
    }
    amLocalResources.putAll(tezJarResources);

    // Setup Session ACLs and update conf as needed
    Map<String, String> aclConfigs = null;
    if (historyACLPolicyManager != null) {
        if (dag == null) {
            aclConfigs = historyACLPolicyManager.setupSessionACLs(amConfig.getTezConfiguration(), appId);
        } else {
            // Non-session mode
            // As only a single DAG is support, we should combine AM and DAG ACLs under the same
            // acl management layer
            aclConfigs = historyACLPolicyManager.setupNonSessionACLs(amConfig.getTezConfiguration(), appId,
                    dag.getDagAccessControls());
        }
    }

    // emit conf as PB file
    ConfigurationProto finalConfProto = createFinalConfProtoForApp(amConfig.getTezConfiguration(), aclConfigs);

    FSDataOutputStream amConfPBOutBinaryStream = null;
    try {
        amConfPBOutBinaryStream = TezCommonUtils.createFileForAM(fs, binaryConfPath);
        finalConfProto.writeTo(amConfPBOutBinaryStream);
    } finally {
        if (amConfPBOutBinaryStream != null) {
            amConfPBOutBinaryStream.close();
        }
    }

    LocalResource binaryConfLRsrc = TezClientUtils.createLocalResource(fs, binaryConfPath,
            LocalResourceType.FILE, LocalResourceVisibility.APPLICATION);
    amConfig.setBinaryConfLR(binaryConfLRsrc);
    amLocalResources.put(TezConstants.TEZ_PB_BINARY_CONF_NAME, binaryConfLRsrc);

    // Create Session Jars definition to be sent to AM as a local resource
    Path sessionJarsPath = TezCommonUtils.getTezAMJarStagingPath(tezSysStagingPath);
    FSDataOutputStream sessionJarsPBOutStream = null;
    try {
        sessionJarsPBOutStream = TezCommonUtils.createFileForAM(fs, sessionJarsPath);
        // Write out the initial list of resources which will be available in the AM
        DAGProtos.PlanLocalResourcesProto amResourceProto;
        if (amLocalResources != null && !amLocalResources.isEmpty()) {
            amResourceProto = DagTypeConverters.convertFromLocalResources(amLocalResources);
        } else {
            amResourceProto = DAGProtos.PlanLocalResourcesProto.getDefaultInstance();
        }
        amResourceProto.writeDelimitedTo(sessionJarsPBOutStream);
    } finally {
        if (sessionJarsPBOutStream != null) {
            sessionJarsPBOutStream.close();
        }
    }

    LocalResource sessionJarsPBLRsrc = TezClientUtils.createLocalResource(fs, sessionJarsPath,
            LocalResourceType.FILE, LocalResourceVisibility.APPLICATION);
    amLocalResources.put(TezConstants.TEZ_AM_LOCAL_RESOURCES_PB_FILE_NAME, sessionJarsPBLRsrc);

    String user = UserGroupInformation.getCurrentUser().getShortUserName();
    ACLManager aclManager = new ACLManager(user, amConfig.getTezConfiguration());
    Map<ApplicationAccessType, String> acls = aclManager.toYARNACls();

    if (dag != null) {

        DAGPlan dagPB = prepareAndCreateDAGPlan(dag, amConfig, tezJarResources, tezLrsAsArchive, sessionCreds);

        // emit protobuf DAG file style
        Path binaryPath = TezCommonUtils.getTezBinPlanStagingPath(tezSysStagingPath);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Stage directory information for AppId :" + appId + " tezSysStagingPath :"
                    + tezSysStagingPath + " binaryConfPath :" + binaryConfPath + " sessionJarsPath :"
                    + sessionJarsPath + " binaryPlanPath :" + binaryPath);
        }

        FSDataOutputStream dagPBOutBinaryStream = null;

        try {
            //binary output
            dagPBOutBinaryStream = TezCommonUtils.createFileForAM(fs, binaryPath);
            dagPB.writeTo(dagPBOutBinaryStream);
        } finally {
            if (dagPBOutBinaryStream != null) {
                dagPBOutBinaryStream.close();
            }
        }

        amLocalResources.put(TezConstants.TEZ_PB_PLAN_BINARY_NAME, TezClientUtils.createLocalResource(fs,
                binaryPath, LocalResourceType.FILE, LocalResourceVisibility.APPLICATION));

        if (Level.DEBUG.isGreaterOrEqual(Level.toLevel(amLogLevel))) {
            Path textPath = localizeDagPlanAsText(dagPB, fs, amConfig, strAppId, tezSysStagingPath);
            amLocalResources.put(TezConstants.TEZ_PB_PLAN_TEXT_NAME, TezClientUtils.createLocalResource(fs,
                    textPath, LocalResourceType.FILE, LocalResourceVisibility.APPLICATION));
        }
    }

    // Setup ContainerLaunchContext for AM container
    ContainerLaunchContext amContainer = ContainerLaunchContext.newInstance(amLocalResources, environment,
            vargsFinal, null, securityTokens, acls);

    // Set up the ApplicationSubmissionContext
    ApplicationSubmissionContext appContext = Records.newRecord(ApplicationSubmissionContext.class);

    appContext.setApplicationType(TezConstants.TEZ_APPLICATION_TYPE);
    appContext.setApplicationId(appId);
    appContext.setResource(capability);
    if (amConfig.getQueueName() != null) {
        appContext.setQueue(amConfig.getQueueName());
    }
    appContext.setApplicationName(amName);
    appContext.setCancelTokensWhenComplete(amConfig.getTezConfiguration().getBoolean(
            TezConfiguration.TEZ_CANCEL_DELEGATION_TOKENS_ON_COMPLETION,
            TezConfiguration.TEZ_CANCEL_DELEGATION_TOKENS_ON_COMPLETION_DEFAULT));
    appContext.setAMContainerSpec(amContainer);

    appContext.setMaxAppAttempts(amConfig.getTezConfiguration().getInt(TezConfiguration.TEZ_AM_MAX_APP_ATTEMPTS,
            TezConfiguration.TEZ_AM_MAX_APP_ATTEMPTS_DEFAULT));

    return appContext;

}

From source file:org.apache.tez.client.TezClientUtils.java

License:Apache License

@Private
public static DAGClientAMProtocolBlockingPB getAMProxy(final Configuration conf, String amHost, int amRpcPort,
        org.apache.hadoop.yarn.api.records.Token clientToAMToken) throws IOException {

    final InetSocketAddress serviceAddr = NetUtils.createSocketAddrForHost(amHost, amRpcPort);
    UserGroupInformation userUgi = UserGroupInformation
            .createRemoteUser(UserGroupInformation.getCurrentUser().getUserName());
    if (clientToAMToken != null) {
        Token<ClientToAMTokenIdentifier> token = ConverterUtils.convertFromYarn(clientToAMToken, serviceAddr);
        userUgi.addToken(token);/*  w w  w  .j a v a 2s .  c  o m*/
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Connecting to Tez AM at " + serviceAddr);
    }
    DAGClientAMProtocolBlockingPB proxy = null;
    try {
        proxy = userUgi.doAs(new PrivilegedExceptionAction<DAGClientAMProtocolBlockingPB>() {
            @Override
            public DAGClientAMProtocolBlockingPB run() throws IOException {
                RPC.setProtocolEngine(conf, DAGClientAMProtocolBlockingPB.class, ProtobufRpcEngine.class);
                return (DAGClientAMProtocolBlockingPB) RPC.getProxy(DAGClientAMProtocolBlockingPB.class, 0,
                        serviceAddr, conf);
            }
        });
    } catch (InterruptedException e) {
        throw new IOException("Failed to connect to AM", e);
    }
    return proxy;
}

From source file:org.apache.tez.dag.api.client.rpc.DAGClientAMProtocolBlockingPBServerImpl.java

License:Apache License

private UserGroupInformation getRPCUser() throws ServiceException {
    try {//from ww w . j a  v  a2  s.  com
        return UserGroupInformation.getCurrentUser();
    } catch (IOException e) {
        throw wrapException(e);
    }
}