private bool IsNodeUsableByQueue(ICollection <string> nodeLabels, RMNodeLabelsManager.Queue
                                  q)
 {
     // node without any labels can be accessed by any queue
     if (nodeLabels == null || nodeLabels.IsEmpty() || (nodeLabels.Count == 1 && nodeLabels
                                                        .Contains(NoLabel)))
     {
         return(true);
     }
     foreach (string label in nodeLabels)
     {
         if (q.acccessibleNodeLabels.Contains(label))
         {
             return(true);
         }
     }
     return(false);
 }
 public virtual void ReinitializeQueueLabels(IDictionary <string, ICollection <string
                                                                               > > queueToLabels)
 {
     try
     {
         writeLock.Lock();
         // clear before set
         this.queueCollections.Clear();
         foreach (KeyValuePair <string, ICollection <string> > entry in queueToLabels)
         {
             string queue = entry.Key;
             RMNodeLabelsManager.Queue q = new RMNodeLabelsManager.Queue();
             this.queueCollections[queue] = q;
             ICollection <string> labels = entry.Value;
             if (labels.Contains(Any))
             {
                 continue;
             }
             Sharpen.Collections.AddAll(q.acccessibleNodeLabels, labels);
             foreach (CommonNodeLabelsManager.Host host in nodeCollections.Values)
             {
                 foreach (KeyValuePair <NodeId, CommonNodeLabelsManager.Node> nentry in host.nms)
                 {
                     NodeId nodeId = nentry.Key;
                     CommonNodeLabelsManager.Node nm = nentry.Value;
                     if (nm.running && IsNodeUsableByQueue(GetLabelsByNode(nodeId), q))
                     {
                         Resources.AddTo(q.resource, nm.resource);
                     }
                 }
             }
         }
     }
     finally
     {
         writeLock.Unlock();
     }
 }
 public virtual Org.Apache.Hadoop.Yarn.Api.Records.Resource GetQueueResource(string
                                                                             queueName, ICollection <string> queueLabels, Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                             clusterResource)
 {
     try
     {
         readLock.Lock();
         if (queueLabels.Contains(Any))
         {
             return(clusterResource);
         }
         RMNodeLabelsManager.Queue q = queueCollections[queueName];
         if (null == q)
         {
             return(Resources.None());
         }
         return(q.resource);
     }
     finally
     {
         readLock.Unlock();
     }
 }