Exemple #1
0
        /// <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));
        }
Exemple #2
0
        /// <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);
        }
 public virtual void TestParentOf()
 {
     NUnit.Framework.Assert.AreEqual("/", RegistryPathUtils.ParentOf("/a"));
     NUnit.Framework.Assert.AreEqual("/", RegistryPathUtils.ParentOf("/a/"));
     NUnit.Framework.Assert.AreEqual("/a", RegistryPathUtils.ParentOf("/a/b"));
     NUnit.Framework.Assert.AreEqual("/a/b", RegistryPathUtils.ParentOf("/a/b/c"));
 }
        /// <exception cref="System.IO.IOException"/>
        private static void AssertCreatedPathEquals(string expected, string @base, string
                                                    path)
        {
            string fullPath = RegistryPathUtils.CreateFullPath(@base, path);

            NUnit.Framework.Assert.AreEqual("\"" + @base + "\" + \"" + path + "\" =\"" + fullPath
                                            + "\"", expected, fullPath);
        }
 public virtual void TestLastPathEntry()
 {
     NUnit.Framework.Assert.AreEqual(string.Empty, RegistryPathUtils.LastPathEntry("/"
                                                                                   ));
     NUnit.Framework.Assert.AreEqual(string.Empty, RegistryPathUtils.LastPathEntry("//"
                                                                                   ));
     NUnit.Framework.Assert.AreEqual("c", RegistryPathUtils.LastPathEntry("/a/b/c"));
     NUnit.Framework.Assert.AreEqual("c", RegistryPathUtils.LastPathEntry("/a/b/c/"));
 }
 /// <exception cref="Org.Apache.Hadoop.Registry.Client.Exceptions.InvalidPathnameException
 ///     "/>
 private void AssertInvalidPath(string path)
 {
     try
     {
         RegistryPathUtils.ValidateElementsAsDNS(path);
         NUnit.Framework.Assert.Fail("path considered valid: " + path);
     }
     catch (InvalidPathnameException)
     {
     }
 }
        public virtual void TestSplitting()
        {
            NUnit.Framework.Assert.AreEqual(1, RegistryPathUtils.Split("/a").Count);
            NUnit.Framework.Assert.AreEqual(0, RegistryPathUtils.Split("/").Count);
            NUnit.Framework.Assert.AreEqual(3, RegistryPathUtils.Split("/a/b/c").Count);
            NUnit.Framework.Assert.AreEqual(3, RegistryPathUtils.Split("/a/b/c/").Count);
            NUnit.Framework.Assert.AreEqual(3, RegistryPathUtils.Split("a/b/c").Count);
            NUnit.Framework.Assert.AreEqual(3, RegistryPathUtils.Split("/a/b//c").Count);
            NUnit.Framework.Assert.AreEqual(3, RegistryPathUtils.Split("//a/b/c/").Count);
            IList <string> split = RegistryPathUtils.Split("//a/b/c/");

            NUnit.Framework.Assert.AreEqual("a", split[0]);
            NUnit.Framework.Assert.AreEqual("b", split[1]);
            NUnit.Framework.Assert.AreEqual("c", split[2]);
        }
Exemple #8
0
        /// <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)));
        }
Exemple #9
0
        /// <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);
        }
 public virtual void TestSplittingEmpty()
 {
     NUnit.Framework.Assert.AreEqual(0, RegistryPathUtils.Split(string.Empty).Count);
     NUnit.Framework.Assert.AreEqual(0, RegistryPathUtils.Split("/").Count);
     NUnit.Framework.Assert.AreEqual(0, RegistryPathUtils.Split("///").Count);
 }
Exemple #11
0
        /// <summary>
        /// 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>.
        /// </summary>
        /// <remarks>
        /// 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.
        /// </remarks>
        /// <returns>the encoded shortname of the current user</returns>
        /// <exception cref="Sharpen.RuntimeException">
        /// if the current user identity cannot be determined
        /// from the OS/kerberos.
        /// </exception>
        public static string CurrentUser()
        {
            string shortUserName = CurrentUsernameUnencoded();

            return(RegistryPathUtils.EncodeForRegistry(shortUserName));
        }
Exemple #12
0
 /// <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));
 }
 /// <exception cref="System.Exception"/>
 public virtual void TestParentOfRoot()
 {
     RegistryPathUtils.ParentOf("/");
 }
Exemple #14
0
 /// <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));
 }
Exemple #15
0
 /// <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));
 }
 // Is this valid?    assertInvalidPath("/50");
 /// <exception cref="Org.Apache.Hadoop.Registry.Client.Exceptions.InvalidPathnameException
 ///     "/>
 private void AssertValidPath(string path)
 {
     RegistryPathUtils.ValidateZKPath(path);
 }
 public virtual void TestFormatIdempotent()
 {
     AssertConverted("xn--lzg", RegistryPathUtils.EncodeForRegistry(Euro));
 }
        protected internal virtual void AssertConverted(string expected, string @in)
        {
            string @out = RegistryPathUtils.EncodeForRegistry(@in);

            NUnit.Framework.Assert.AreEqual("Conversion of " + @in, expected, @out);
        }