List of usage examples for org.apache.hadoop.security UserGroupInformation getCurrentUser
@InterfaceAudience.Public @InterfaceStability.Evolving public static UserGroupInformation getCurrentUser() throws IOException
From source file:wherehows.SchemaFetch.java
License:Open Source License
/** * Main entrance of scan a path//from w w w .j a v a2 s . co m * Change user based on the folder owner, create the FileSystem based on the user * * @param path * @throws java.io.IOException */ private static void scanPath(Path path, FileSystem fs) throws IOException, InterruptedException, SQLException { // TODO create a new filesystem use current user //FileSystem scanFs = FileSystem.newInstance(SchemaFetch.conf); FileSystem scanFs = fs; System.out.println("Now reading data as:" + UserGroupInformation.getCurrentUser()); if (!scanFs.exists(path)) { logger.info("path : " + path.getName() + " doesn't exist!"); } scanPathHelper(path, scanFs); }
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);/*from w ww . j av a 2 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.appmaster.ApplicationMasterService.java
License:Apache License
@Override protected void startUp() throws Exception { LOG.info("Starting Application Master"); // create security tokens Credentials credentials = UserGroupInformation.getCurrentUser().getCredentials(); ByteBuffer securityTokens = YarnUtils.getSecurityToken(credentials); // Create appSubmitterUgi and add original tokens to it String userName = System.getenv(ApplicationConstants.Environment.USER.name()); UserGroupInformation appSubmitterUgi = UserGroupInformation.createRemoteUser(userName); // remove the AM->RM token so that containers cannot access it. YarnUtils.removeToken(credentials, AMRMTokenIdentifier.KIND_NAME); appSubmitterUgi.addCredentials(credentials); // start a resource manager (RM) this.resourceManager = AMRMClientAsync.createAMRMClientAsync(1000, this); resourceManager.init(yarnConf);//from w w w .j av a2s . c om resourceManager.start(); // register a application master (AM) to resource manager (RM) final RegisterApplicationMasterResponse registration; try { registration = resourceManager.registerApplicationMaster(parameters.getHostname(), parameters.getClientPort(), parameters.getTrackingUrl()); LOG.info("Registered Application Master: " + registration); } catch (Exception e) { LOG.error("Exception thrown registering Application Master", e); stop(); return; } // assign containers ContainerLaunchContextFactory factory = new ContainerLaunchContextFactory( registration.getMaximumResourceCapability(), securityTokens); ContainerLaunchParameters containerLaunchParams = parameters.getContainerLaunchParameters(); this.tracker = new ContainerTracker(this, containerLaunchParams); tracker.init(factory, yarnConf); this.hasRunningContainers = true; }
From source file:yrun.YarnRunner.java
License:Apache License
public static void main(final String[] args) throws IOException, InterruptedException { CommandLine cmd = parse(args, new PrintWriter(System.out)); final String yarnName = cmd.getOptionValue("n"); LOG.info("Yarn name [" + yarnName + "]"); String resourceManagerAddress = cmd.getOptionValue("rma"); LOG.info("Resource Manager Address [" + resourceManagerAddress + "]"); String installPathStr = cmd.getOptionValue("p"); LOG.info("Install Path [" + installPathStr + "]"); final String command = StringUtils.join(" ", cmd.getOptionValues("c")); LOG.info("Command [" + command + "]"); final String queue; if (cmd.hasOption("q")) { queue = cmd.getOptionValue("q"); } else {//w w w . ja v a2s . c o m queue = "default"; } LOG.info("Queue [" + queue + "]"); final YarnConfiguration configuration = new YarnConfiguration(); configuration.set(YARN_RESOURCEMANAGER_ADDRESS, resourceManagerAddress); LOG.info("Using resource manager [" + resourceManagerAddress + "]"); final Path installPath = new Path(installPathStr); final List<Path> archivePathList = new ArrayList<Path>(); if (cmd.hasOption("a")) { String[] archivePaths = cmd.getOptionValues("a"); for (String archivePath : archivePaths) { archivePathList.add(new Path(archivePath)); } } final boolean isDaemon = !cmd.hasOption("k"); UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); ugi.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { YarnRunner yarnRunner = new YarnRunner(configuration, installPath, archivePathList, command, yarnName, queue, isDaemon); yarnRunner.execute(); return null; } }); }