/** * 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 user path formatted for the registry * <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 the encoded shortname of the current user * @throws RuntimeException if the current user identity cannot be determined * from the OS/kerberos. * */ public static String currentUser() { String shortUserName = currentUsernameUnencoded(); return encodeForRegistry(shortUserName); }
/** * Buld the user path -switches to the system path if the user is "". * It also cross-converts the username to ascii via punycode * @param username username or "" * @return the path to the user */ public static String homePathForUser(String username) { Preconditions.checkArgument(username != null, "null user"); // catch recursion if (username.startsWith(RegistryConstants.PATH_USERS)) { return username; } if (username.isEmpty()) { return RegistryConstants.PATH_SYSTEM_SERVICES; } // convert username to registry name String convertedName = convertUsername(username); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); }
/** * Buld the user path -switches to the system path if the user is "". * It also cross-converts the username to ascii via punycode * @param username username or "" * @return the path to the user */ public static String homePathForUser(String username) { Preconditions.checkArgument(username != null, "null user"); // catch recursion if (username.startsWith(RegistryConstants.PATH_USERS)) { return username; } if (username.isEmpty()) { return RegistryConstants.PATH_SYSTEM_SERVICES; } // convert username to registry name String convertedName = convertUsername(username); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); }
/** * Buld the user path -switches to the system path if the user is "". * It also cross-converts the username to ascii via punycode * @param username username or "" * @return the path to the user */ public static String homePathForUser(String username) { Preconditions.checkArgument(username != null, "null user"); // catch recursion if (username.startsWith(RegistryConstants.PATH_USERS)) { return username; } if (username.isEmpty()) { return RegistryConstants.PATH_SYSTEM_SERVICES; } // convert username to registry name String convertedName = convertUsername(username); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); }
/** * Buld the user path -switches to the system path if the user is "". * It also cross-converts the username to ascii via punycode * @param username username or "" * @return the path to the user */ public static String homePathForUser(String username) { Preconditions.checkArgument(username != null, "null user"); // catch recursion if (username.startsWith(RegistryConstants.PATH_USERS)) { return username; } if (username.isEmpty()) { return RegistryConstants.PATH_SYSTEM_SERVICES; } // convert username to registry name String convertedName = convertUsername(username); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); }
public static ServiceRecord lookupServiceRecord(RegistryOperations rops, String user, String type, String name) throws IOException, SliderException { if (StringUtils.isEmpty(user)) { user = currentUser(); } else { user = RegistryPathUtils.encodeForRegistry(user); } if (StringUtils.isEmpty(type)) { type = SliderKeys.APP_TYPE; } String path = servicePath(user, type, name); return resolve(rops, path); }
public static ServiceRecord lookupServiceRecord(RegistryOperations rops, String user, String type, String name) throws IOException, SliderException { if (StringUtils.isEmpty(user)) { user = currentUser(); } else { user = RegistryPathUtils.encodeForRegistry(user); } if (StringUtils.isEmpty(type)) { type = SliderKeys.APP_TYPE; } String path = servicePath(user, type, name); return resolve(rops, path); }
/** * Qualify a user. * <ol> * <li> <code>"~"</code> maps to user home path home</li> * <li> <code>"~user"</code> maps to <code>/users/$user</code></li> * <li> <code>"/"</code> maps to <code>/services/</code></li> * </ol> * @param user the username * @return the base path */ public static String qualifyUser(String user) { // qualify the user String t = user.trim(); if (t.startsWith("/")) { // already resolved return t; } else if (t.equals("~")) { // self return currentUsernameUnencoded(); } else if (t.startsWith("~")) { // another user // convert username to registry name String convertedName = convertUsername(t.substring(1)); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); } else { return "/" + t; } }
/** * Qualify a user. * <ol> * <li> <code>"~"</code> maps to user home path home</li> * <li> <code>"~user"</code> maps to <code>/users/$user</code></li> * <li> <code>"/"</code> maps to <code>/services/</code></li> * </ol> * @param user the username * @return the base path */ public static String qualifyUser(String user) { // qualify the user String t = user.trim(); if (t.startsWith("/")) { // already resolved return t; } else if (t.equals("~")) { // self return currentUsernameUnencoded(); } else if (t.startsWith("~")) { // another user // convert username to registry name String convertedName = convertUsername(t.substring(1)); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); } else { return "/" + t; } }
protected void assertConverted(String expected, String in) { String out = RegistryPathUtils.encodeForRegistry(in); assertEquals("Conversion of " + in, expected, out); }
protected void assertConverted(String expected, String in) { String out = RegistryPathUtils.encodeForRegistry(in); assertEquals("Conversion of " + in, expected, out); }
@Test public void testFormatIdempotent() throws Throwable { assertConverted("xn--lzg", RegistryPathUtils.encodeForRegistry(EURO)); }
@Test public void testFormatIdempotent() throws Throwable { assertConverted("xn--lzg", RegistryPathUtils.encodeForRegistry(EURO)); }