Пример #1
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
                                            );
        }
Пример #2
0
        public virtual bool ShouldSelect(string path, RegistryPathStatus registryPathStatus
                                         , ServiceRecord serviceRecord)
        {
            string policy = serviceRecord.Get(YarnRegistryAttributes.YarnPersistence, string.Empty
                                              );

            return(id.Equals(serviceRecord.Get(YarnRegistryAttributes.YarnId, string.Empty)) &&
                   (targetPolicy.Equals(policy)));
        }
Пример #3
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());
        }
Пример #4
0
        public virtual void TestUnknownFieldsRoundTrip()
        {
            ServiceRecord record = CreateRecord(PersistencePolicies.ApplicationAttempt);

            record.Set("key", "value");
            record.Set("intval", "2");
            NUnit.Framework.Assert.AreEqual("value", record.Get("key"));
            NUnit.Framework.Assert.AreEqual("2", record.Get("intval"));
            NUnit.Framework.Assert.IsNull(record.Get("null"));
            NUnit.Framework.Assert.AreEqual("defval", record.Get("null", "defval"));
            byte[]        bytes = marshal.ToBytes(record);
            ServiceRecord r2    = marshal.FromBytes(string.Empty, bytes);

            NUnit.Framework.Assert.AreEqual("value", r2.Get("key"));
            NUnit.Framework.Assert.AreEqual("2", r2.Get("intval"));
        }
Пример #5
0
        /// <summary>Assert the records match.</summary>
        /// <param name="source">record that was written</param>
        /// <param name="resolved">the one that resolved.</param>
        public static void AssertMatches(ServiceRecord source, ServiceRecord resolved)
        {
            NUnit.Framework.Assert.IsNotNull("Null source record ", source);
            NUnit.Framework.Assert.IsNotNull("Null resolved record ", resolved);
            NUnit.Framework.Assert.AreEqual(source.description, resolved.description);
            IDictionary <string, string> srcAttrs      = source.Attributes();
            IDictionary <string, string> resolvedAttrs = resolved.Attributes();
            string sourceAsString   = source.ToString();
            string resolvedAsString = resolved.ToString();

            NUnit.Framework.Assert.AreEqual("Wrong count of attrs in \n" + sourceAsString + "\nfrom\n"
                                            + resolvedAsString, srcAttrs.Count, resolvedAttrs.Count);
            foreach (KeyValuePair <string, string> entry in srcAttrs)
            {
                string attr = entry.Key;
                NUnit.Framework.Assert.AreEqual("attribute " + attr, entry.Value, resolved.Get(attr
                                                                                               ));
            }
            NUnit.Framework.Assert.AreEqual("wrong external endpoint count", source.external.
                                            Count, resolved.external.Count);
            NUnit.Framework.Assert.AreEqual("wrong external endpoint count", source.@internal
                                            .Count, [email protected]);
        }
Пример #6
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);
        }