String appPath = RegistryUtils.serviceclassPath( JOYConstants.APP_NAME, JOYConstants.APP_TYPE); String path = RegistryUtils.servicePath( JOYConstants.APP_NAME, JOYConstants.APP_TYPE, instanceName); String hostPath = RegistryUtils.componentPath( JOYConstants.APP_NAME, JOYConstants.APP_TYPE, instanceName, supervisorHost); List<String> instanceNames = registryOperations.list(appPath); for (String instance : instanceNames) { String servicePath = RegistryUtils.servicePath( JOYConstants.APP_NAME, JOYConstants.APP_TYPE, instance); Map<String, ServiceRecord> hosts = RegistryUtils.listServiceRecords(registryOperations, servicePath); for (String host : hosts.keySet()) { ServiceRecord sr = hosts.get(JOYConstants.HOST);
@Override protected String getZkPathUser(Configuration conf) { // We assume that AMs and HS2 run under the same user. return RegistryUtils.currentUser(); }
String containerPath = RegistryUtils.componentPath( JOYConstants.APP_TYPE, jstormMasterContext.instanceName, allocatedContainer.getId().getApplicationAttemptId().getApplicationId().toString(), allocatedContainer.getId().toString()); String path = RegistryUtils.serviceclassPath( JOYConstants.APP_TYPE, jstormMasterContext.instanceName);
/** * Extract all service records under a list of stat operations...this * non-atomic action skips entries that are too short or simply not matching. * <p> * @param operations operation support for fetches * @param parentpath path of the parent of all the entries * @return a possibly empty map of fullpath:record. * @throws IOException for any IO Operation that wasn't ignored. */ public static Map<String, ServiceRecord> extractServiceRecords( RegistryOperations operations, String parentpath) throws IOException { return extractServiceRecords(operations, parentpath, statChildren(operations, parentpath).values()); }
/** * List instances in the registry for the current user * @return a list of slider registry instances * @throws IOException Any IO problem ... including no path in the registry * to slider service classes for this user * @throws SliderException other failures */ public Map<String, ServiceRecord> listRegistryInstances() throws IOException, SliderException { Map<String, ServiceRecord> recordMap = listServiceRecords( getRegistryOperations(), serviceclassPath(currentUser(), SliderKeys.APP_TYPE)); return recordMap; }
/** * Get the registry path for an instance under the user's home node * @param instanceName application instance * @return a path to the registry location for this application instance. */ public static String registryPathForInstance(String instanceName) { return RegistryUtils.servicePath( RegistryUtils.currentUser(), SliderKeys.APP_TYPE, instanceName ); }
public String getHostPath() { String hostPath = RegistryUtils.servicePath( JstormKeys.APP_TYPE, this.instanceName, host); return hostPath; }
@Test public void testComplexUsernames() throws Throwable { operations.mknode("/users/user with spaces", true); operations.mknode("/users/user-with_underscores", true); operations.mknode("/users/000000", true); operations.mknode("/users/-storm", true); operations.mknode("/users/windows\\ user", true); String home = RegistryUtils.homePathForUser("\u0413PA\u0414_3"); operations.mknode(home, true); operations.mknode( RegistryUtils.servicePath(home, "service.class", "service 4_5"), true); operations.mknode( RegistryUtils.homePathForUser("hbase@HADOOP.APACHE.ORG"), true); operations.mknode( RegistryUtils.homePathForUser("hbase/localhost@HADOOP.APACHE.ORG"), true); home = RegistryUtils.homePathForUser("ADMINISTRATOR/127.0.0.1"); assertTrue("No 'administrator' in " + home, home.contains("administrator")); operations.mknode( home, true); } }
/** * Convert the given user name formatted for the registry. * * @param shortUserName * @return converted user name */ public static String registryUser(String shortUserName) { String encodedName = encodeForRegistry(shortUserName); // DNS name doesn't allow "_", replace it with "-" encodedName = RegistryUtils.convertUsername(encodedName); return encodedName.replace("_", "-"); }
/** * Get the current username, before any encoding has been applied. * @return the current user from the kerberos identity, falling back * to the user and/or env variables. */ private static String currentUsernameUnencoded() { String env_hadoop_username = System.getenv( RegistryInternalConstants.HADOOP_USER_NAME); return getCurrentUsernameUnencoded(env_hadoop_username); }
try { childEntries = RegistryUtils.statChildren(this, path); entries = childEntries.values(); } catch (PathNotFoundException e) {
/** * Extract all service records under a list of stat operations...this * non-atomic action skips entries that are too short or simply not matching. * <p> * @param operations operation support for fetches * @param parentpath path of the parent of all the entries * @return a possibly empty map of fullpath:record. * @throws IOException for any IO Operation that wasn't ignored. */ public static Map<String, ServiceRecord> extractServiceRecords( RegistryOperations operations, String parentpath, Map<String , RegistryPathStatus> stats) throws IOException { return extractServiceRecords(operations, parentpath, stats.values()); }
/** * Get the home path of the current user. * <p> * In an insecure cluster, the environment variable * <code>HADOOP_USER_NAME</code> is queried <i>first</i>. * <p> * This means that in a YARN container where the creator set this * environment variable to propagate their identity, the defined * user name is used in preference to the actual user. * <p> * In a secure cluster, the kerberos identity of the current user is used. * @return a path for the current user's home dir. * @throws RuntimeException if the current user identity cannot be determined * from the OS/kerberos. */ public static String homePathForCurrentUser() { String shortUserName = currentUsernameUnencoded(); return homePathForUser(shortUserName); }
/** * Get the path to a user's home dir * @param username username * @return a path for services underneath */ protected String homeDir(String username) { return RegistryUtils.homePathForUser(username); }
/** * Create a path to a service under a user and service class * @param user username or "" * @param serviceClass service name * @param serviceName service name unique for that user and service class * @return a full path */ public static String servicePath(String user, String serviceClass, String serviceName) { return join( serviceclassPath(user, serviceClass), serviceName); }
/** * Extract all service records under a list of stat operations...this * non-atomic action skips entries that are too short or simply not matching. * <p> * @param operations operation support for fetches * @param parentpath path of the parent of all the entries * @return a possibly empty map of fullpath:record. * @throws IOException for any IO Operation that wasn't ignored. */ public static Map<String, ServiceRecord> extractServiceRecords( RegistryOperations operations, String parentpath) throws IOException { return extractServiceRecords(operations, parentpath, statChildren(operations, parentpath).values()); }
/** * List instances in the registry for the current user * @return a list of slider registry instances * @throws IOException Any IO problem ... including no path in the registry * to slider service classes for this user * @throws SliderException other failures */ public Map<String, ServiceRecord> listRegistryInstances() throws IOException, SliderException { Map<String, ServiceRecord> recordMap = listServiceRecords( getRegistryOperations(), serviceclassPath(currentUser(), SliderKeys.APP_TYPE)); return recordMap; }
/** * Get the registry path for an instance under the user's home node * @param instanceName application instance * @return a path to the registry location for this application instance. */ public static String registryPathForInstance(String instanceName) { return RegistryUtils.servicePath( RegistryUtils.currentUser(), SliderKeys.APP_TYPE, instanceName ); }
public String getSupervisorSlotPorts(int memory, int vcores, String supervisorHost) throws Exception { String hostPath = RegistryUtils.servicePath( JOYConstants.APP_TYPE, this.instanceName, supervisorHost); tryHostLock(hostPath); try { List<String> relist; int slotCount = getSlotCount(memory, vcores); LOG.info("slotCount:" + slotCount); relist = getSetPortUsedBySupervisor(supervisorHost, slotCount); LOG.info("get ports string:" + JstormYarnUtils.join(relist, JOYConstants.COMMA, false)); return JstormYarnUtils.join(relist, JOYConstants.COMMA, false); } catch (Exception e) { LOG.error(e); throw e; } finally { releaseHostLock(hostPath); } }
@Test public void testComplexUsernames() throws Throwable { operations.mknode("/users/user with spaces", true); operations.mknode("/users/user-with_underscores", true); operations.mknode("/users/000000", true); operations.mknode("/users/-storm", true); operations.mknode("/users/windows\\ user", true); String home = RegistryUtils.homePathForUser("\u0413PA\u0414_3"); operations.mknode(home, true); operations.mknode( RegistryUtils.servicePath(home, "service.class", "service 4_5"), true); operations.mknode( RegistryUtils.homePathForUser("hbase@HADOOP.APACHE.ORG"), true); operations.mknode( RegistryUtils.homePathForUser("hbase/localhost@HADOOP.APACHE.ORG"), true); home = RegistryUtils.homePathForUser("ADMINISTRATOR/127.0.0.1"); assertTrue("No 'administrator' in " + home, home.contains("administrator")); operations.mknode( home, true); } }