Exemplo n.º 1
0
        /// <summary>Add some endpoints</summary>
        /// <param name="entry">entry</param>
        /// <exception cref="Sharpen.URISyntaxException"/>
        public static void AddSampleEndpoints(ServiceRecord entry, string hostname)
        {
            NUnit.Framework.Assert.IsNotNull(hostname);
            entry.AddExternalEndpoint(RegistryTypeUtils.WebEndpoint(HttpApi, new URI("http",
                                                                                     hostname + ":80", "/")));
            entry.AddExternalEndpoint(RegistryTypeUtils.RestEndpoint(ApiWebhdfs, new URI("http"
                                                                                         , hostname + ":8020", "/")));
            Endpoint endpoint = RegistryTypeUtils.IpcEndpoint(ApiHdfs, null);

            endpoint.addresses.AddItem(RegistryTypeUtils.HostnamePortPair(hostname, 8030));
            entry.AddInternalEndpoint(endpoint);
            IPEndPoint localhost = new IPEndPoint("localhost", 8050);

            entry.AddInternalEndpoint(RegistryTypeUtils.InetAddrEndpoint(Nnipc, ProtocolTypes
                                                                         .ProtocolThrift, "localhost", 8050));
            entry.AddInternalEndpoint(RegistryTypeUtils.IpcEndpoint(Ipc2, localhost));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public virtual int Bind(string[] args)
        {
            Option  rest       = OptionBuilder.Create("rest");
            Option  webui      = OptionBuilder.Create("webui");
            Option  inet       = OptionBuilder.Create("inet");
            Option  port       = OptionBuilder.Create("p");
            Option  host       = OptionBuilder.Create("h");
            Option  apiOpt     = OptionBuilder.Create("api");
            Options inetOption = new Options();

            inetOption.AddOption(inet);
            inetOption.AddOption(port);
            inetOption.AddOption(host);
            inetOption.AddOption(apiOpt);
            Options webuiOpt = new Options();

            webuiOpt.AddOption(webui);
            webuiOpt.AddOption(apiOpt);
            Options restOpt = new Options();

            restOpt.AddOption(rest);
            restOpt.AddOption(apiOpt);
            CommandLineParser parser = new GnuParser();
            ServiceRecord     sr     = new ServiceRecord();
            CommandLine       line;

            if (args.Length <= 1)
            {
                return(UsageError("Invalid syntax ", BindUsage));
            }
            if (args[1].Equals("-inet"))
            {
                int    portNum;
                string hostName;
                string api;
                try
                {
                    line = parser.Parse(inetOption, args);
                }
                catch (ParseException exp)
                {
                    return(UsageError("Invalid syntax " + exp.Message, BindUsage));
                }
                if (line.HasOption("inet") && line.HasOption("p") && line.HasOption("h") && line.
                    HasOption("api"))
                {
                    try
                    {
                        portNum = System.Convert.ToInt32(line.GetOptionValue("p"));
                    }
                    catch (FormatException exp)
                    {
                        return(UsageError("Invalid Port - int required" + exp.Message, BindUsage));
                    }
                    hostName = line.GetOptionValue("h");
                    api      = line.GetOptionValue("api");
                    sr.AddExternalEndpoint(RegistryTypeUtils.InetAddrEndpoint(api, ProtocolTypes.ProtocolHadoopIpc
                                                                              , hostName, portNum));
                }
                else
                {
                    return(UsageError("Missing options: must have host, port and api", BindUsage));
                }
            }
            else
            {
                if (args[1].Equals("-webui"))
                {
                    try
                    {
                        line = parser.Parse(webuiOpt, args);
                    }
                    catch (ParseException exp)
                    {
                        return(UsageError("Invalid syntax " + exp.Message, BindUsage));
                    }
                    if (line.HasOption("webui") && line.HasOption("api"))
                    {
                        URI theUri;
                        try
                        {
                            theUri = new URI(line.GetOptionValue("webui"));
                        }
                        catch (URISyntaxException e)
                        {
                            return(UsageError("Invalid URI: " + e.Message, BindUsage));
                        }
                        sr.AddExternalEndpoint(RegistryTypeUtils.WebEndpoint(line.GetOptionValue("api"),
                                                                             theUri));
                    }
                    else
                    {
                        return(UsageError("Missing options: must have value for uri and api", BindUsage));
                    }
                }
                else
                {
                    if (args[1].Equals("-rest"))
                    {
                        try
                        {
                            line = parser.Parse(restOpt, args);
                        }
                        catch (ParseException exp)
                        {
                            return(UsageError("Invalid syntax " + exp.Message, BindUsage));
                        }
                        if (line.HasOption("rest") && line.HasOption("api"))
                        {
                            URI theUri = null;
                            try
                            {
                                theUri = new URI(line.GetOptionValue("rest"));
                            }
                            catch (URISyntaxException e)
                            {
                                return(UsageError("Invalid URI: " + e.Message, BindUsage));
                            }
                            sr.AddExternalEndpoint(RegistryTypeUtils.RestEndpoint(line.GetOptionValue("api"),
                                                                                  theUri));
                        }
                        else
                        {
                            return(UsageError("Missing options: must have value for uri and api", BindUsage));
                        }
                    }
                    else
                    {
                        return(UsageError("Invalid syntax", BindUsage));
                    }
                }
            }
            IList <string> argsList = line.GetArgList();

            if (argsList.Count != 2)
            {
                return(UsageError("bind requires exactly one path argument", BindUsage));
            }
            if (!ValidatePath(argsList[1]))
            {
                return(-1);
            }
            try
            {
                registry.Bind(argsList[1], sr, BindFlags.Overwrite);
                return(0);
            }
            catch (Exception e)
            {
                syserr.WriteLine(AnalyzeException("bind", e, argsList));
            }
            return(-1);
        }