Пример #1
0
        /// <exception cref="System.IO.IOException"/>
        private void ConfigureSuperUserIPAddresses(Configuration conf, string superUserShortName
                                                   )
        {
            AList <string> ipList = new AList <string>();
            Enumeration <NetworkInterface> netInterfaceList = NetworkInterface.GetNetworkInterfaces
                                                                  ();

            while (netInterfaceList.MoveNext())
            {
                NetworkInterface        inf      = netInterfaceList.Current;
                Enumeration <IPAddress> addrList = inf.GetInetAddresses();
                while (addrList.MoveNext())
                {
                    IPAddress addr = addrList.Current;
                    ipList.AddItem(addr.GetHostAddress());
                }
            }
            StringBuilder builder = new StringBuilder();

            foreach (string ip in ipList)
            {
                builder.Append(ip);
                builder.Append(',');
            }
            builder.Append("127.0.1.1,");
            builder.Append(Runtime.GetLocalHost().ToString());
            Log.Info("Local Ip addresses: " + builder.ToString());
            conf.SetStrings(DefaultImpersonationProvider.GetTestProvider().GetProxySuperuserIpConfKey
                                (superUserShortName), builder.ToString());
        }
Пример #2
0
        /// <summary>Log the current thread stacks at INFO level.</summary>
        /// <param name="log">the logger that logs the stack trace</param>
        /// <param name="title">a descriptive title for the call stacks</param>
        /// <param name="minInterval">the minimum time from the last</param>
        public static void LogThreadInfo(Org.Apache.Hadoop.Log log, string title, long minInterval)
        {
            bool dumpStack = false;

            if (log.IsInfoEnabled())
            {
                lock (typeof(ReflectionUtils))
                {
                    long now = Time.Now();
                    if (now - previousLogTime >= minInterval * 1000)
                    {
                        previousLogTime = now;
                        dumpStack       = true;
                    }
                }
                if (dumpStack)
                {
                    try
                    {
                        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                        PrintThreadInfo(new TextWriter(buffer, false, "UTF-8"), title);
                        log.Info(buffer.ToString(Encoding.Default.Name()));
                    }
                    catch (UnsupportedEncodingException)
                    {
                    }
                }
            }
        }
Пример #3
0
        /// <exception cref="System.Exception"/>
        public virtual void TestInvalidDefaultFS()
        {
            // if default fs doesn't exist or is invalid, but the path provided in
            // arguments is valid - fsshell should work
            FsShell       shell = new FsShell();
            Configuration conf  = new Configuration();

            conf.Set(CommonConfigurationKeysPublic.FsDefaultNameKey, "hhhh://doesnotexist/");
            shell.SetConf(conf);
            string[] args = new string[2];
            args[0] = "-ls";
            args[1] = "file:///";
            // this is valid, so command should run
            int res = shell.Run(args);

            System.Console.Out.WriteLine("res =" + res);
            shell.SetConf(conf);
            ByteArrayOutputStream bytes  = new ByteArrayOutputStream();
            TextWriter            @out   = new TextWriter(bytes);
            TextWriter            oldErr = System.Console.Error;

            Runtime.SetErr(@out);
            string results;

            try
            {
                int run = shell.Run(args);
                results = bytes.ToString();
                Log.Info("result=" + results);
                Assert.True("Return code should be 0", run == 0);
            }
            finally
            {
                IOUtils.CloseStream(@out);
                Runtime.SetErr(oldErr);
            }
        }