コード例 #1
0
        /// <summary>
        /// Creates a leaf or parent queue based on what is specified in 'queueType'
        /// and places it in the tree.
        /// </summary>
        /// <remarks>
        /// Creates a leaf or parent queue based on what is specified in 'queueType'
        /// and places it in the tree. Creates any parents that don't already exist.
        /// </remarks>
        /// <returns>
        /// the created queue, if successful. null if not allowed (one of the parent
        /// queues in the queue name is already a leaf queue)
        /// </returns>
        private FSQueue CreateQueue(string name, FSQueueType queueType)
        {
            IList <string> newQueueNames = new AList <string>();

            newQueueNames.AddItem(name);
            int           sepIndex = name.Length;
            FSParentQueue parent   = null;

            // Move up the queue tree until we reach one that exists.
            while (sepIndex != -1)
            {
                sepIndex = name.LastIndexOf('.', sepIndex - 1);
                FSQueue queue;
                string  curName = null;
                curName = Sharpen.Runtime.Substring(name, 0, sepIndex);
                queue   = queues[curName];
                if (queue == null)
                {
                    newQueueNames.AddItem(curName);
                }
                else
                {
                    if (queue is FSParentQueue)
                    {
                        parent = (FSParentQueue)queue;
                        break;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            // At this point, parent refers to the deepest existing parent of the
            // queue to create.
            // Now that we know everything worked out, make all the queues
            // and add them to the map.
            AllocationConfiguration queueConf = scheduler.GetAllocationConfiguration();
            FSLeafQueue             leafQueue = null;

            for (int i = newQueueNames.Count - 1; i >= 0; i--)
            {
                string queueName = newQueueNames[i];
                if (i == 0 && queueType != FSQueueType.Parent)
                {
                    leafQueue = new FSLeafQueue(name, scheduler, parent);
                    try
                    {
                        leafQueue.SetPolicy(queueConf.GetDefaultSchedulingPolicy());
                    }
                    catch (AllocationConfigurationException ex)
                    {
                        Log.Warn("Failed to set default scheduling policy " + queueConf.GetDefaultSchedulingPolicy
                                     () + " on new leaf queue.", ex);
                    }
                    parent.AddChildQueue(leafQueue);
                    queues[leafQueue.GetName()] = leafQueue;
                    leafQueues.AddItem(leafQueue);
                    leafQueue.UpdatePreemptionVariables();
                    return(leafQueue);
                }
                else
                {
                    FSParentQueue newParent = new FSParentQueue(queueName, scheduler, parent);
                    try
                    {
                        newParent.SetPolicy(queueConf.GetDefaultSchedulingPolicy());
                    }
                    catch (AllocationConfigurationException ex)
                    {
                        Log.Warn("Failed to set default scheduling policy " + queueConf.GetDefaultSchedulingPolicy
                                     () + " on new parent queue.", ex);
                    }
                    parent.AddChildQueue(newParent);
                    queues[newParent.GetName()] = newParent;
                    newParent.UpdatePreemptionVariables();
                    parent = newParent;
                }
            }
            return(parent);
        }