/// <summary> /// List children of a directory and retrieve their /// <see cref="Org.Apache.Hadoop.Registry.Client.Types.RegistryPathStatus"/> /// values. /// <p> /// This is not an atomic operation; A child may be deleted /// during the iteration through the child entries. If this happens, /// the <code>PathNotFoundException</code> is caught and that child /// entry ommitted. /// </summary> /// <param name="path">path</param> /// <returns> /// a possibly empty map of child entries listed by /// their short name. /// </returns> /// <exception cref="Org.Apache.Hadoop.FS.PathNotFoundException">path is not in the registry. /// </exception> /// <exception cref="Org.Apache.Hadoop.Registry.Client.Exceptions.InvalidPathnameException /// ">the path is invalid.</exception> /// <exception cref="System.IO.IOException">Any other IO Exception</exception> public static IDictionary <string, RegistryPathStatus> StatChildren(RegistryOperations registryOperations, string path) { IList <string> childNames = registryOperations.List(path); IDictionary <string, RegistryPathStatus> results = new Dictionary <string, RegistryPathStatus >(); foreach (string childName in childNames) { string child = RegistryPathUtils.Join(path, childName); try { RegistryPathStatus stat = registryOperations.Stat(child); results[childName] = stat; } catch (PathNotFoundException pnfe) { if (Log.IsDebugEnabled()) { Log.Debug("stat failed on {}: moved? {}", child, pnfe, pnfe); } } } // and continue return(results); }
/// <summary>Create a service classpath</summary> /// <param name="user">username or ""</param> /// <param name="serviceClass">service name</param> /// <returns>a full path</returns> public static string ServiceclassPath(string user, string serviceClass) { string services = RegistryPathUtils.Join(HomePathForUser(user), RegistryConstants .PathUserServices); return(RegistryPathUtils.Join(services, serviceClass)); }
/// <summary>Buld the user path -switches to the system path if the user is "".</summary> /// <remarks> /// Buld the user path -switches to the system path if the user is "". /// It also cross-converts the username to ascii via punycode /// </remarks> /// <param name="username">username or ""</param> /// <returns>the path to the user</returns> public static string HomePathForUser(string username) { Preconditions.CheckArgument(username != null, "null user"); // catch recursion if (username.StartsWith(RegistryConstants.PathUsers)) { return(username); } if (username.IsEmpty()) { return(RegistryConstants.PathSystemServices); } // convert username to registry name string convertedName = ConvertUsername(username); return(RegistryPathUtils.Join(RegistryConstants.PathUsers, RegistryPathUtils.EncodeForRegistry (convertedName))); }
/// <summary> /// Extract all service records under a list of stat operations...this /// skips entries that are too short or simply not matching /// </summary> /// <param name="operations">operation support for fetches</param> /// <param name="parentpath">path of the parent of all the entries</param> /// <param name="stats">Collection of stat results</param> /// <returns>a possibly empty map of fullpath:record.</returns> /// <exception cref="System.IO.IOException">for any IO Operation that wasn't ignored. /// </exception> public static IDictionary <string, ServiceRecord> ExtractServiceRecords(RegistryOperations operations, string parentpath, ICollection <RegistryPathStatus> stats) { IDictionary <string, ServiceRecord> results = new Dictionary <string, ServiceRecord >(stats.Count); foreach (RegistryPathStatus stat in stats) { if (stat.size > ServiceRecord.RecordType.Length) { // maybe has data string path = RegistryPathUtils.Join(parentpath, stat.path); try { ServiceRecord serviceRecord = operations.Resolve(path); results[path] = serviceRecord; } catch (EOFException) { if (Log.IsDebugEnabled()) { Log.Debug("data too short for {}", path); } } catch (InvalidRecordException) { if (Log.IsDebugEnabled()) { Log.Debug("Invalid record at {}", path); } } catch (NoRecordException) { if (Log.IsDebugEnabled()) { Log.Debug("No record at {}", path); } } } } return(results); }
/// <summary>Create the path to a service record for a component</summary> /// <param name="user">username or ""</param> /// <param name="serviceClass">service name</param> /// <param name="serviceName">service name unique for that user and service class</param> /// <param name="componentName">unique name/ID of the component</param> /// <returns>a full path</returns> public static string ComponentPath(string user, string serviceClass, string serviceName , string componentName) { return(RegistryPathUtils.Join(ComponentListPath(user, serviceClass, serviceName), componentName)); }
/// <summary>Create a path for listing components under a service</summary> /// <param name="user">username or ""</param> /// <param name="serviceClass">service name</param> /// <param name="serviceName">service name unique for that user and service class</param> /// <returns>a full path</returns> public static string ComponentListPath(string user, string serviceClass, string serviceName ) { return(RegistryPathUtils.Join(ServicePath(user, serviceClass, serviceName), RegistryConstants .SubpathComponents)); }
/// <summary>Create a path to a service under a user and service class</summary> /// <param name="user">username or ""</param> /// <param name="serviceClass">service name</param> /// <param name="serviceName">service name unique for that user and service class</param> /// <returns>a full path</returns> public static string ServicePath(string user, string serviceClass, string serviceName ) { return(RegistryPathUtils.Join(ServiceclassPath(user, serviceClass), serviceName)); }