Пример #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));
        }
Пример #2
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);
        }