示例#1
0
        /// <summary>
        /// Dumps the configuration of hierarchy of queues with
        /// the xml file path given.
        /// </summary>
        /// <remarks>
        /// Dumps the configuration of hierarchy of queues with
        /// the xml file path given. It is to be used directly ONLY FOR TESTING.
        /// </remarks>
        /// <param name="out">the writer object to which dump is written to.</param>
        /// <param name="configFile">the filename of xml file</param>
        /// <exception cref="System.IO.IOException"/>
        internal static void DumpConfiguration(TextWriter @out, string configFile, Configuration
                                               conf)
        {
            if (conf != null && conf.Get(DeprecatedQueueConfigurationParser.MapredQueueNamesKey
                                         ) != null)
            {
                return;
            }
            JsonFactory              dumpFactory   = new JsonFactory();
            JsonGenerator            dumpGenerator = dumpFactory.CreateJsonGenerator(@out);
            QueueConfigurationParser parser;
            bool aclsEnabled = false;

            if (conf != null)
            {
                aclsEnabled = conf.GetBoolean(MRConfig.MrAclsEnabled, false);
            }
            if (configFile != null && !string.Empty.Equals(configFile))
            {
                parser = new QueueConfigurationParser(configFile, aclsEnabled);
            }
            else
            {
                parser = GetQueueConfigurationParser(null, false, aclsEnabled);
            }
            dumpGenerator.WriteStartObject();
            dumpGenerator.WriteFieldName("queues");
            dumpGenerator.WriteStartArray();
            DumpConfiguration(dumpGenerator, parser.GetRoot().GetChildren());
            dumpGenerator.WriteEndArray();
            dumpGenerator.WriteEndObject();
            dumpGenerator.Flush();
        }
示例#2
0
        /// <summary>Build a JSON entry from the parameters.</summary>
        /// <remarks>Build a JSON entry from the parameters. This is public for testing.</remarks>
        /// <param name="writer">destination</param>
        /// <param name="loggerName">logger name</param>
        /// <param name="timeStamp">time_t value</param>
        /// <param name="level">level string</param>
        /// <param name="threadName">name of the thread</param>
        /// <param name="message">rendered message</param>
        /// <param name="ti">nullable thrown information</param>
        /// <returns>the writer</returns>
        /// <exception cref="System.IO.IOException">on any problem</exception>
        public virtual TextWriter ToJson(TextWriter writer, string loggerName, long timeStamp
                                         , string level, string threadName, string message, ThrowableInformation ti)
        {
            JsonGenerator json = factory.CreateJsonGenerator(writer);

            json.WriteStartObject();
            json.WriteStringField(Name, loggerName);
            json.WriteNumberField(Time, timeStamp);
            DateTime date = Extensions.CreateDate(timeStamp);

            json.WriteStringField(Date, dateFormat.Format(date));
            json.WriteStringField(Level, level);
            json.WriteStringField(Thread, threadName);
            json.WriteStringField(Message, message);
            if (ti != null)
            {
                //there is some throwable info, but if the log event has been sent over the wire,
                //there may not be a throwable inside it, just a summary.
                Exception thrown = ti.GetThrowable();
                string    eclass = (thrown != null) ? thrown.GetType().FullName : string.Empty;
                json.WriteStringField(ExceptionClass, eclass);
                string[] stackTrace = ti.GetThrowableStrRep();
                json.WriteArrayFieldStart(Stack);
                foreach (string row in stackTrace)
                {
                    json.WriteString(row);
                }
                json.WriteEndArray();
            }
            json.WriteEndObject();
            json.Flush();
            json.Close();
            return(writer);
        }
示例#3
0
        /// <summary>Process a GET request for the specified resource.</summary>
        /// <param name="request">The servlet request we are processing</param>
        /// <param name="response">The servlet response we are creating</param>
        protected override void DoGet(HttpServletRequest request, HttpServletResponse response
                                      )
        {
            string      jsonpcb = null;
            PrintWriter writer  = null;

            try
            {
                if (!IsInstrumentationAccessAllowed(request, response))
                {
                    return;
                }
                JsonGenerator jg = null;
                try
                {
                    writer = response.GetWriter();
                    response.SetContentType("application/json; charset=utf8");
                    response.SetHeader(AccessControlAllowMethods, "GET");
                    response.SetHeader(AccessControlAllowOrigin, "*");
                    JsonFactory jsonFactory = new JsonFactory();
                    jg = jsonFactory.CreateJsonGenerator(writer);
                    jg.Disable(JsonGenerator.Feature.AutoCloseTarget);
                    jg.UseDefaultPrettyPrinter();
                    jg.WriteStartObject();
                    if (mBeanServer == null)
                    {
                        jg.WriteStringField("result", "ERROR");
                        jg.WriteStringField("message", "No MBeanServer could be found");
                        jg.Close();
                        Log.Error("No MBeanServer could be found.");
                        response.SetStatus(HttpServletResponse.ScNotFound);
                        return;
                    }
                    // query per mbean attribute
                    string getmethod = request.GetParameter("get");
                    if (getmethod != null)
                    {
                        string[] splitStrings = getmethod.Split("\\:\\:");
                        if (splitStrings.Length != 2)
                        {
                            jg.WriteStringField("result", "ERROR");
                            jg.WriteStringField("message", "query format is not as expected.");
                            jg.Close();
                            response.SetStatus(HttpServletResponse.ScBadRequest);
                            return;
                        }
                        ListBeans(jg, new ObjectName(splitStrings[0]), splitStrings[1], response);
                        jg.Close();
                        return;
                    }
                    // query per mbean
                    string qry = request.GetParameter("qry");
                    if (qry == null)
                    {
                        qry = "*:*";
                    }
                    ListBeans(jg, new ObjectName(qry), null, response);
                }
                finally
                {
                    if (jg != null)
                    {
                        jg.Close();
                    }
                    if (writer != null)
                    {
                        writer.Close();
                    }
                }
            }
            catch (IOException e)
            {
                Log.Error("Caught an exception while processing JMX request", e);
                response.SetStatus(HttpServletResponse.ScInternalServerError);
            }
            catch (MalformedObjectNameException e)
            {
                Log.Error("Caught an exception while processing JMX request", e);
                response.SetStatus(HttpServletResponse.ScBadRequest);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }