Esempio n. 1
0
        public virtual void TestPurgeEntryCuratorCallback()
        {
            string        path    = "/users/example/hbase/hbase1/";
            ServiceRecord written = BuildExampleServiceEntry(PersistencePolicies.ApplicationAttempt
                                                             );

            written.Set(YarnRegistryAttributes.YarnId, "testAsyncPurgeEntry_attempt_001");
            operations.Mknode(RegistryPathUtils.ParentOf(path), true);
            operations.Bind(path, written, 0);
            ZKPathDumper        dump   = registry.DumpPath(false);
            CuratorEventCatcher events = new CuratorEventCatcher();

            Log.Info("Initial state {}", dump);
            // container query
            string id      = written.Get(YarnRegistryAttributes.YarnId, string.Empty);
            int    opcount = Purge("/", id, PersistencePolicies.Container, RegistryAdminService.PurgePolicy
                                   .PurgeAll, events);

            AssertPathExists(path);
            NUnit.Framework.Assert.AreEqual(0, opcount);
            NUnit.Framework.Assert.AreEqual("Event counter", 0, events.GetCount());
            // now the application attempt
            opcount = Purge("/", id, PersistencePolicies.ApplicationAttempt, RegistryAdminService.PurgePolicy
                            .PurgeAll, events);
            Log.Info("Final state {}", dump);
            AssertPathNotFound(path);
            NUnit.Framework.Assert.AreEqual("wrong no of delete operations in " + dump, 1, opcount
                                            );
            // and validate the callback event
            NUnit.Framework.Assert.AreEqual("Event counter", 1, events.GetCount());
        }
Esempio n. 2
0
        public virtual void TestAsyncPurgeEntry()
        {
            string        path    = "/users/example/hbase/hbase1/";
            ServiceRecord written = BuildExampleServiceEntry(PersistencePolicies.ApplicationAttempt
                                                             );

            written.Set(YarnRegistryAttributes.YarnId, "testAsyncPurgeEntry_attempt_001");
            operations.Mknode(RegistryPathUtils.ParentOf(path), true);
            operations.Bind(path, written, 0);
            ZKPathDumper dump = registry.DumpPath(false);

            Log.Info("Initial state {}", dump);
            DeleteCompletionCallback deletions = new DeleteCompletionCallback();
            int opcount = Purge("/", written.Get(YarnRegistryAttributes.YarnId, string.Empty)
                                , PersistencePolicies.Container, RegistryAdminService.PurgePolicy.PurgeAll, deletions
                                );

            AssertPathExists(path);
            dump = registry.DumpPath(false);
            NUnit.Framework.Assert.AreEqual("wrong no of delete operations in " + dump, 0, deletions
                                            .GetEventCount());
            NUnit.Framework.Assert.AreEqual("wrong no of delete operations in " + dump, 0, opcount
                                            );
            // now app attempt
            deletions = new DeleteCompletionCallback();
            opcount   = Purge("/", written.Get(YarnRegistryAttributes.YarnId, string.Empty), PersistencePolicies
                              .ApplicationAttempt, RegistryAdminService.PurgePolicy.PurgeAll, deletions);
            dump = registry.DumpPath(false);
            Log.Info("Final state {}", dump);
            AssertPathNotFound(path);
            NUnit.Framework.Assert.AreEqual("wrong no of delete operations in " + dump, 1, deletions
                                            .GetEventCount());
            NUnit.Framework.Assert.AreEqual("wrong no of delete operations in " + dump, 1, opcount
                                            );
        }
        /// <summary>
        /// Create a service entry with the sample endpoints, and put it
        /// at the destination
        /// </summary>
        /// <param name="path">path</param>
        /// <param name="createFlags">flags</param>
        /// <returns>the record</returns>
        /// <exception cref="System.IO.IOException">on a failure</exception>
        /// <exception cref="Sharpen.URISyntaxException"/>
        protected internal virtual ServiceRecord PutExampleServiceEntry(string path, int
                                                                        createFlags, string persistence)
        {
            ServiceRecord record = BuildExampleServiceEntry(persistence);

            registry.Mknode(RegistryPathUtils.ParentOf(path), true);
            operations.Bind(path, record, createFlags);
            return(record);
        }
Esempio n. 4
0
        public virtual void TestPutGetContainerPersistenceServiceEntry()
        {
            string        path    = EntryPath;
            ServiceRecord written = BuildExampleServiceEntry(PersistencePolicies.Container);

            operations.Mknode(RegistryPathUtils.ParentOf(path), true);
            operations.Bind(path, written, BindFlags.Create);
            ServiceRecord resolved = operations.Resolve(path);

            ValidateEntry(resolved);
            AssertMatches(written, resolved);
        }
        /// <exception cref="System.IO.IOException"/>
        public virtual RegistryPathStatus Stat(string path)
        {
            ValidatePath(path);
            Org.Apache.Zookeeper.Data.Stat stat = ZkStat(path);
            string             name             = RegistryPathUtils.LastPathEntry(path);
            RegistryPathStatus status           = new RegistryPathStatus(name, stat.GetCtime(), stat.GetDataLength
                                                                             (), stat.GetNumChildren());

            if (Log.IsDebugEnabled())
            {
                Log.Debug("Stat {} => {}", path, status);
            }
            return(status);
        }
        public virtual int Purge(string path, RegistryAdminService.NodeSelector selector,
                                 RegistryAdminService.PurgePolicy purgePolicy, BackgroundCallback callback)
        {
            bool toDelete = false;
            // look at self to see if it has a service record
            IDictionary <string, RegistryPathStatus> childEntries;
            ICollection <RegistryPathStatus>         entries;

            try
            {
                // list this path's children
                childEntries = RegistryUtils.StatChildren(this, path);
                entries      = childEntries.Values;
            }
            catch (PathNotFoundException)
            {
                // there's no record here, it may have been deleted already.
                // exit
                return(0);
            }
            try
            {
                RegistryPathStatus registryPathStatus = Stat(path);
                ServiceRecord      serviceRecord      = Resolve(path);
                // there is now an entry here.
                toDelete = selector.ShouldSelect(path, registryPathStatus, serviceRecord);
            }
            catch (EOFException)
            {
            }
            catch (InvalidRecordException)
            {
            }
            catch (NoRecordException)
            {
            }
            catch (PathNotFoundException)
            {
                // ignore
                // ignore
                // ignore
                // there's no record here, it may have been deleted already.
                // exit
                return(0);
            }
            if (toDelete && !entries.IsEmpty())
            {
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Match on record @ {} with children ", path);
                }
                switch (purgePolicy)
                {
                case RegistryAdminService.PurgePolicy.SkipOnChildren:
                {
                    // there's children
                    // don't do the deletion... continue to next record
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("Skipping deletion");
                    }
                    toDelete = false;
                    break;
                }

                case RegistryAdminService.PurgePolicy.PurgeAll:
                {
                    // mark for deletion
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("Scheduling for deletion with children");
                    }
                    toDelete = true;
                    entries  = new AList <RegistryPathStatus>(0);
                    break;
                }

                case RegistryAdminService.PurgePolicy.FailOnChildren:
                {
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("Failing deletion operation");
                    }
                    throw new PathIsNotEmptyDirectoryException(path);
                }
                }
            }
            int deleteOps = 0;

            if (toDelete)
            {
                try
                {
                    ZkDelete(path, true, callback);
                }
                catch (PathNotFoundException)
                {
                    // sign that the path was deleted during the operation.
                    // this is a no-op, and all children can be skipped
                    return(deleteOps);
                }
                deleteOps++;
            }
            // now go through the children
            foreach (RegistryPathStatus status in entries)
            {
                string childname = status.path;
                string childpath = RegistryPathUtils.Join(path, childname);
                deleteOps += Purge(childpath, selector, purgePolicy, callback);
            }
            return(deleteOps);
        }
Esempio n. 7
0
        public virtual void TestCreateComplexApplication()
        {
            string        appId   = "application_1408631738011_0001";
            string        cid     = "container_1408631738011_0001_01_";
            string        cid1    = cid + "000001";
            string        cid2    = cid + "000002";
            string        appPath = Userpath + "tomcat";
            ServiceRecord webapp  = CreateRecord(appId, PersistencePolicies.Application, "tomcat-based web application"
                                                 , null);

            webapp.AddExternalEndpoint(RegistryTypeUtils.RestEndpoint("www", new URI("http",
                                                                                     "//loadbalancer/", null)));
            ServiceRecord comp1 = CreateRecord(cid1, PersistencePolicies.Container, null, null
                                               );

            comp1.AddExternalEndpoint(RegistryTypeUtils.RestEndpoint("www", new URI("http", "//rack4server3:43572"
                                                                                    , null)));
            comp1.AddInternalEndpoint(RegistryTypeUtils.InetAddrEndpoint("jmx", "JMX", "rack4server3"
                                                                         , 43573));
            // Component 2 has a container lifespan
            ServiceRecord comp2 = CreateRecord(cid2, PersistencePolicies.Container, null, null
                                               );

            comp2.AddExternalEndpoint(RegistryTypeUtils.RestEndpoint("www", new URI("http", "//rack1server28:35881"
                                                                                    , null)));
            comp2.AddInternalEndpoint(RegistryTypeUtils.InetAddrEndpoint("jmx", "JMX", "rack1server28"
                                                                         , 35882));
            operations.Mknode(Userpath, false);
            operations.Bind(appPath, webapp, BindFlags.Overwrite);
            string componentsPath = appPath + RegistryConstants.SubpathComponents;

            operations.Mknode(componentsPath, false);
            string dns1     = RegistryPathUtils.EncodeYarnID(cid1);
            string dns1path = componentsPath + dns1;

            operations.Bind(dns1path, comp1, BindFlags.Create);
            string dns2     = RegistryPathUtils.EncodeYarnID(cid2);
            string dns2path = componentsPath + dns2;

            operations.Bind(dns2path, comp2, BindFlags.Create);
            ZKPathDumper pathDumper = registry.DumpPath(false);

            Log.Info(pathDumper.ToString());
            LogRecord("tomcat", webapp);
            LogRecord(dns1, comp1);
            LogRecord(dns2, comp2);
            ServiceRecord dns1resolved = operations.Resolve(dns1path);

            NUnit.Framework.Assert.AreEqual("Persistence policies on resolved entry", PersistencePolicies
                                            .Container, dns1resolved.Get(YarnRegistryAttributes.YarnPersistence, string.Empty
                                                                         ));
            IDictionary <string, RegistryPathStatus> children = RegistryUtils.StatChildren(operations
                                                                                           , componentsPath);

            NUnit.Framework.Assert.AreEqual(2, children.Count);
            ICollection <RegistryPathStatus>    componentStats = children.Values;
            IDictionary <string, ServiceRecord> records        = RegistryUtils.ExtractServiceRecords(
                operations, componentsPath, componentStats);

            NUnit.Framework.Assert.AreEqual(2, records.Count);
            ServiceRecord retrieved1 = records[dns1path];

            LogRecord(retrieved1.Get(YarnRegistryAttributes.YarnId, string.Empty), retrieved1
                      );
            AssertMatches(dns1resolved, retrieved1);
            NUnit.Framework.Assert.AreEqual(PersistencePolicies.Container, retrieved1.Get(YarnRegistryAttributes
                                                                                          .YarnPersistence, string.Empty));
            // create a listing under components/
            operations.Mknode(componentsPath + "subdir", false);
            // this shows up in the listing of child entries
            IDictionary <string, RegistryPathStatus> childrenUpdated = RegistryUtils.StatChildren
                                                                           (operations, componentsPath);

            NUnit.Framework.Assert.AreEqual(3, childrenUpdated.Count);
            // the non-record child this is not picked up in the record listing
            IDictionary <string, ServiceRecord> recordsUpdated = RegistryUtils.ExtractServiceRecords
                                                                     (operations, componentsPath, childrenUpdated);

            NUnit.Framework.Assert.AreEqual(2, recordsUpdated.Count);
            // now do some deletions.
            // synchronous delete container ID 2
            // fail if the app policy is chosen
            NUnit.Framework.Assert.AreEqual(0, Purge("/", cid2, PersistencePolicies.Application
                                                     , RegistryAdminService.PurgePolicy.FailOnChildren));
            // succeed for container
            NUnit.Framework.Assert.AreEqual(1, Purge("/", cid2, PersistencePolicies.Container
                                                     , RegistryAdminService.PurgePolicy.FailOnChildren));
            AssertPathNotFound(dns2path);
            AssertPathExists(dns1path);
            // expect a skip on children to skip
            NUnit.Framework.Assert.AreEqual(0, Purge("/", appId, PersistencePolicies.Application
                                                     , RegistryAdminService.PurgePolicy.SkipOnChildren));
            AssertPathExists(appPath);
            AssertPathExists(dns1path);
            // attempt to delete app with policy of fail on children
            try
            {
                int p = Purge("/", appId, PersistencePolicies.Application, RegistryAdminService.PurgePolicy
                              .FailOnChildren);
                NUnit.Framework.Assert.Fail("expected a failure, got a purge count of " + p);
            }
            catch (PathIsNotEmptyDirectoryException)
            {
            }
            // expected
            AssertPathExists(appPath);
            AssertPathExists(dns1path);
            // now trigger recursive delete
            NUnit.Framework.Assert.AreEqual(1, Purge("/", appId, PersistencePolicies.Application
                                                     , RegistryAdminService.PurgePolicy.PurgeAll));
            AssertPathNotFound(appPath);
            AssertPathNotFound(dns1path);
        }
Esempio n. 8
0
 /// <summary>Recursively make a path</summary>
 /// <param name="path">path to create</param>
 /// <param name="acl">ACL for path</param>
 /// <exception cref="System.IO.IOException">any problem</exception>
 public virtual void ZkMkParentPath(string path, IList <ACL> acl)
 {
     // split path into elements
     ZkMkPath(RegistryPathUtils.ParentOf(path), CreateMode.Persistent, true, acl);
 }
Esempio n. 9
0
 /// <summary>Create a full path from the registry root and the supplied subdir</summary>
 /// <param name="path">path of operation</param>
 /// <returns>an absolute path</returns>
 /// <exception cref="System.ArgumentException">if the path is invalide</exception>
 /// <exception cref="System.IO.IOException"/>
 protected internal virtual string CreateFullPath(string path)
 {
     return(RegistryPathUtils.CreateFullPath(registryRoot, path));
 }