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

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

Introduction

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

Prototype

@InterfaceAudience.Public
@InterfaceStability.Evolving
public static UserGroupInformation createRemoteUser(String user) 

Source Link

Document

Create a user from a login name.

Usage

From source file:com.splicemachine.yarn.test.BareYarnTest.java

License:Apache License

/**
 * All we really need to do here is to create a yarn client, configure it using the same
 * yarn-site.xml as was used by the server to start up.
 * @throws YarnException/*from   w w w. ja  v  a 2  s  . c o  m*/
 * @throws IOException
 */
@Test(timeout = 60000)
@Ignore("Broken by dependency change")
public void testAMRMClientMatchingFitInferredRack() throws YarnException, IOException {
    // create, submit new app
    ApplicationSubmissionContext appContext = yarnClient.createApplication().getApplicationSubmissionContext();
    ApplicationId appId = appContext.getApplicationId();
    // set the application name
    appContext.setApplicationName("Test");
    // Set the priority for the application master
    Priority pri = Records.newRecord(Priority.class);
    pri.setPriority(0);
    appContext.setPriority(pri);
    // Set the queue to which this application is to be submitted in the RM
    appContext.setQueue("default");
    // Set up the container launch context for the application master
    ContainerLaunchContext amContainer = BuilderUtils.newContainerLaunchContext(
            Collections.<String, LocalResource>emptyMap(), new HashMap<String, String>(),
            Arrays.asList("sleep", "100"), new HashMap<String, ByteBuffer>(), null,
            new HashMap<ApplicationAccessType, String>());
    appContext.setAMContainerSpec(amContainer);
    appContext.setResource(Resource.newInstance(1024, 1));
    // Create the request to send to the applications manager
    SubmitApplicationRequest appRequest = Records.newRecord(SubmitApplicationRequest.class);
    appRequest.setApplicationSubmissionContext(appContext);
    // Submit the application to the applications manager
    yarnClient.submitApplication(appContext);

    // wait for app to start
    RMAppAttempt appAttempt;
    while (true) {
        ApplicationReport appReport = yarnClient.getApplicationReport(appId);
        if (appReport.getYarnApplicationState() == YarnApplicationState.ACCEPTED) {
            ApplicationAttemptId attemptId = appReport.getCurrentApplicationAttemptId();
            appAttempt = yarnPlatform.getResourceManager().getRMContext().getRMApps()
                    .get(attemptId.getApplicationId()).getCurrentAppAttempt();
            while (true) {
                if (appAttempt.getAppAttemptState() == RMAppAttemptState.LAUNCHED) {
                    break;
                }
            }
            break;
        }
    }
    // Just dig into the ResourceManager and get the AMRMToken just for the sake
    // of testing.
    UserGroupInformation.setLoginUser(
            UserGroupInformation.createRemoteUser(UserGroupInformation.getCurrentUser().getUserName()));
    UserGroupInformation.getCurrentUser().addToken(appAttempt.getAMRMToken());
}

From source file:com.telefonica.iot.cygnus.backends.hdfs.HDFSBackendImplBinary.java

License:Open Source License

@Override
public void createDir(String dirPath) throws Exception {
    CreateDirPEA pea = new CreateDirPEA(dirPath);
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(hdfsUser);
    ugi.doAs(pea);/*from  w  w w .j ava 2  s  .  co  m*/
}

From source file:com.telefonica.iot.cygnus.backends.hdfs.HDFSBackendImplBinary.java

License:Open Source License

@Override
public void createFile(String filePath, String data) throws Exception {
    CreateFilePEA pea = new CreateFilePEA(filePath, data);
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(hdfsUser);
    ugi.doAs(pea);//from   www  .ja  va2 s  .  c  o m
}

From source file:com.telefonica.iot.cygnus.backends.hdfs.HDFSBackendImplBinary.java

License:Open Source License

@Override
public void append(String filePath, String data) throws Exception {
    AppendPEA pea = new AppendPEA(filePath, data);
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(hdfsUser);
    ugi.doAs(pea);// w w  w . j  a v a  2s  .  c  om
}

From source file:com.telefonica.iot.cygnus.backends.hdfs.HDFSBackendImplBinary.java

License:Open Source License

@Override
public boolean exists(String filePath) throws Exception {
    ExistsPEA pea = new ExistsPEA(filePath);
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(hdfsUser);
    ugi.doAs(pea);/*from   ww w. j ava2  s  .c  o m*/
    return pea.exists();
}

From source file:edu.umn.cs.spatialHadoop.visualization.HadoopvizServer.java

License:Open Source License

/**
 * Visualizes a dataset.//from w  w w.  j  a v  a  2 s  . c  o  m
 * @param request
 * @param response
 */
private void handleVisualize(HttpServletRequest request, HttpServletResponse response) {
    try {
        String pathStr = request.getParameter("path");
        final Path path = new Path(pathStr);
        FileSystem fs = path.getFileSystem(commonParams);
        // Check if the input is already visualized
        final Path imagePath = new Path(path, "_data.png");
        if (fs.exists(imagePath)) {
            // Image is already visualized
            response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
            response.setHeader("Location", "/hdfs" + imagePath);
        } else {
            // This dataset has never been visualized before
            String shapeName = request.getParameter("shape");
            final OperationsParams vizParams = new OperationsParams(commonParams);
            vizParams.set("shape", shapeName);
            vizParams.setBoolean("background", true);
            vizParams.setInt("width", 2000);
            vizParams.setInt("height", 2000);

            // Retrieve the owner of the data directory
            String owner = fs.getFileStatus(path).getOwner();
            UserGroupInformation ugi = UserGroupInformation.createRemoteUser(owner);
            Job vizJob = ugi.doAs(new PrivilegedExceptionAction<Job>() {
                public Job run() throws Exception {
                    return GeometricPlot.plot(new Path[] { path }, imagePath, vizParams);
                }
            });

            // Write the response
            response.setStatus(HttpServletResponse.SC_OK);
            response.setContentType("application/json;charset=utf-8");
            PrintWriter out = response.getWriter();
            out.printf("{\"JobID\":\"%s\", \"TrackURL\": \"%s\"}", vizJob.getJobID().toString(),
                    vizJob.getTrackingURL());
            out.close();
        }
    } catch (Exception e) {
        System.out.println("error happened");
        e.printStackTrace();
        try {
            e.printStackTrace(response.getWriter());
        } catch (IOException ioe) {
            ioe.printStackTrace();
            e.printStackTrace();
        }
        response.setContentType("text/plain;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:eu.stratosphere.yarn.ApplicationMaster.java

License:Apache License

public static void main(String[] args) throws Exception {
    final String yarnClientUsername = System.getenv(Client.ENV_CLIENT_USERNAME);
    LOG.info("YARN daemon runs as '" + UserGroupInformation.getCurrentUser().getShortUserName() + "' setting"
            + " user to execute Stratosphere ApplicationMaster/JobManager to '" + yarnClientUsername + "'");
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(yarnClientUsername);
    for (Token<? extends TokenIdentifier> toks : UserGroupInformation.getCurrentUser().getTokens()) {
        ugi.addToken(toks);/*from ww w. j  a va2  s .  c o  m*/
    }
    ugi.doAs(new PrivilegedAction<Object>() {
        @Override
        public Object run() {
            try {
                new ApplicationMaster().run();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    });
}

From source file:eu.stratosphere.yarn.YarnTaskManagerRunner.java

License:Apache License

public static void main(final String[] args) throws IOException {
    Map<String, String> envs = System.getenv();
    final String yarnClientUsername = envs.get(Client.ENV_CLIENT_USERNAME);
    final String localDirs = envs.get(Environment.LOCAL_DIRS.key());

    // configure local directory
    final String[] newArgs = Arrays.copyOf(args, args.length + 2);
    newArgs[newArgs.length - 2] = "-" + TaskManager.ARG_CONF_DIR;
    newArgs[newArgs.length - 1] = localDirs;
    LOG.info("Setting log path " + localDirs);
    LOG.info("YARN daemon runs as '" + UserGroupInformation.getCurrentUser().getShortUserName() + "' setting"
            + " user to execute Stratosphere TaskManager to '" + yarnClientUsername + "'");
    UserGroupInformation ugi = UserGroupInformation.createRemoteUser(yarnClientUsername);
    for (Token<? extends TokenIdentifier> toks : UserGroupInformation.getCurrentUser().getTokens()) {
        ugi.addToken(toks);/*from   w w  w .j a v  a  2 s  . c  om*/
    }
    ugi.doAs(new PrivilegedAction<Object>() {
        @Override
        public Object run() {
            try {
                TaskManager.main(newArgs);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    });
}

From source file:hdfs.jsr203.attribute.HadoopGroupPrincipal.java

License:Apache License

public HadoopGroupPrincipal(HadoopFileSystem hdfs, String name) {
    this.ugi = UserGroupInformation.createRemoteUser(name);
    //this.hdfs = hdfs;
}

From source file:hdfs.jsr203.HadoopGroupPrincipal.java

License:Apache License

public HadoopGroupPrincipal(HadoopFileSystem hdfs, String name) {
    this.ugi = UserGroupInformation.createRemoteUser(name);
}