/// <summary>test xml generation</summary>
        /// <exception cref="Javax.Xml.Parsers.ParserConfigurationException"/>
        /// <exception cref="System.Exception"></exception>
        public virtual void TestQueueConfigurationParser()
        {
            JobQueueInfo info       = new JobQueueInfo("root", "rootInfo");
            JobQueueInfo infoChild1 = new JobQueueInfo("child1", "child1Info");
            JobQueueInfo infoChild2 = new JobQueueInfo("child2", "child1Info");

            info.AddChild(infoChild1);
            info.AddChild(infoChild2);
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.NewInstance();
            DocumentBuilder        builder           = docBuilderFactory.NewDocumentBuilder();
            Document document = builder.NewDocument();
            // test QueueConfigurationParser.getQueueElement
            Element e = QueueConfigurationParser.GetQueueElement(document, info);
            // transform result to string for check
            DOMSource          domSource   = new DOMSource(e);
            StringWriter       writer      = new StringWriter();
            StreamResult       result      = new StreamResult(writer);
            TransformerFactory tf          = TransformerFactory.NewInstance();
            Transformer        transformer = tf.NewTransformer();

            transformer.Transform(domSource, result);
            string str = writer.ToString();

            NUnit.Framework.Assert.IsTrue(str.EndsWith("<queue><name>root</name><properties/><state>running</state><queue><name>child1</name><properties/><state>running</state></queue><queue><name>child2</name><properties/><state>running</state></queue></queue>"
                                                       ));
        }
Exemple #2
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();
        }
Exemple #3
0
        /// <summary>
        /// Create an instance that supports hierarchical queues, defined in
        /// the passed in configuration file.
        /// </summary>
        /// <remarks>
        /// Create an instance that supports hierarchical queues, defined in
        /// the passed in configuration file.
        /// <p>
        /// This is mainly used for testing purposes and should not called from
        /// production code.
        /// </remarks>
        /// <param name="confFile">File where the queue configuration is found.</param>
        internal QueueManager(string confFile, bool areAclsEnabled)
        {
            this.areAclsEnabled = areAclsEnabled;
            QueueConfigurationParser cp = new QueueConfigurationParser(confFile, areAclsEnabled
                                                                       );

            Initialize(cp);
        }
Exemple #4
0
        /// <summary>Refresh acls, state and scheduler properties for the configured queues.</summary>
        /// <remarks>
        /// Refresh acls, state and scheduler properties for the configured queues.
        /// <p>
        /// This method reloads configuration related to queues, but does not
        /// support changes to the list of queues or hierarchy. The expected usage
        /// is that an administrator can modify the queue configuration file and
        /// fire an admin command to reload queue configuration. If there is a
        /// problem in reloading configuration, then this method guarantees that
        /// existing queue configuration is untouched and in a consistent state.
        /// </remarks>
        /// <param name="schedulerRefresher"/>
        /// <exception cref="System.IO.IOException">when queue configuration file is invalid.
        ///     </exception>
        internal virtual void RefreshQueues(Configuration conf, QueueRefresher schedulerRefresher
                                            )
        {
            lock (this)
            {
                // Create a new configuration parser using the passed conf object.
                QueueConfigurationParser cp = GetQueueConfigurationParser(conf, true, areAclsEnabled
                                                                          );

                /*
                 * (1) Validate the refresh of properties owned by QueueManager. As of now,
                 * while refreshing queue properties, we only check that the hierarchy is
                 * the same w.r.t queue names, ACLs and state for each queue and don't
                 * support adding new queues or removing old queues
                 */
                if (!root.IsHierarchySameAs(cp.GetRoot()))
                {
                    Log.Warn(MsgRefreshFailureWithChangeOfHierarchy);
                    throw new IOException(MsgRefreshFailureWithChangeOfHierarchy);
                }

                /*
                 * (2) QueueManager owned properties are validated. Now validate and
                 * refresh the properties of scheduler in a single step.
                 */
                if (schedulerRefresher != null)
                {
                    try
                    {
                        schedulerRefresher.RefreshQueues(cp.GetRoot().GetJobQueueInfo().GetChildren());
                    }
                    catch (Exception e)
                    {
                        StringBuilder msg = new StringBuilder("Scheduler's refresh-queues failed with the exception : "
                                                              + StringUtils.StringifyException(e));
                        msg.Append("\n");
                        msg.Append(MsgRefreshFailureWithSchedulerFailure);
                        Log.Error(msg.ToString());
                        throw new IOException(msg.ToString());
                    }
                }

                /*
                 * (3) Scheduler has validated and refreshed its queues successfully, now
                 * refresh the properties owned by QueueManager
                 */
                // First copy the scheduling information recursively into the new
                // queue-hierarchy. This is done to retain old scheduling information. This
                // is done after scheduler refresh and not before it because during refresh,
                // schedulers may wish to change their scheduling info objects too.
                cp.GetRoot().CopySchedulingInfo(this.root);
                // Now switch roots.
                Initialize(cp);
                Log.Info("Queue configuration is refreshed successfully.");
            }
        }
Exemple #5
0
 /// <summary>
 /// Initialize the queue-manager with the queue hierarchy specified by the
 /// given
 /// <see cref="QueueConfigurationParser"/>
 /// .
 /// </summary>
 /// <param name="cp"/>
 private void Initialize(QueueConfigurationParser cp)
 {
     this.root = cp.GetRoot();
     leafQueues.Clear();
     allQueues.Clear();
     //At this point we have root populated
     //update data structures leafNodes.
     leafQueues = GetRoot().GetLeafQueues();
     allQueues.PutAll(GetRoot().GetInnerQueues());
     allQueues.PutAll(leafQueues);
     Log.Info("AllQueues : " + allQueues + "; LeafQueues : " + leafQueues);
 }