예제 #1
0
        public virtual void TestNormalizeRequestWithDominantResourceCalculator()
        {
            ResourceCalculator resourceCalculator = new DominantResourceCalculator();

            Org.Apache.Hadoop.Yarn.Api.Records.Resource minResource = Resources.CreateResource
                                                                          (1024, 1);
            Org.Apache.Hadoop.Yarn.Api.Records.Resource maxResource = Resources.CreateResource
                                                                          (10240, 10);
            Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource
                                                                              (10 * 1024, 10);
            ResourceRequest ask = new ResourceRequestPBImpl();

            // case negative memory/vcores
            ask.SetCapability(Resources.CreateResource(-1024, -1));
            SchedulerUtils.NormalizeRequest(ask, resourceCalculator, clusterResource, minResource
                                            , maxResource);
            NUnit.Framework.Assert.AreEqual(minResource, ask.GetCapability());
            // case zero memory/vcores
            ask.SetCapability(Resources.CreateResource(0, 0));
            SchedulerUtils.NormalizeRequest(ask, resourceCalculator, clusterResource, minResource
                                            , maxResource);
            NUnit.Framework.Assert.AreEqual(minResource, ask.GetCapability());
            NUnit.Framework.Assert.AreEqual(1, ask.GetCapability().GetVirtualCores());
            NUnit.Framework.Assert.AreEqual(1024, ask.GetCapability().GetMemory());
            // case non-zero memory & zero cores
            ask.SetCapability(Resources.CreateResource(1536, 0));
            SchedulerUtils.NormalizeRequest(ask, resourceCalculator, clusterResource, minResource
                                            , maxResource);
            NUnit.Framework.Assert.AreEqual(Resources.CreateResource(2048, 1), ask.GetCapability
                                                ());
            NUnit.Framework.Assert.AreEqual(1, ask.GetCapability().GetVirtualCores());
            NUnit.Framework.Assert.AreEqual(2048, ask.GetCapability().GetMemory());
        }
예제 #2
0
 protected internal virtual void ReleaseContainers(IList <ContainerId> containers,
                                                   SchedulerApplicationAttempt attempt)
 {
     foreach (ContainerId containerId in containers)
     {
         RMContainer rmContainer = GetRMContainer(containerId);
         if (rmContainer == null)
         {
             if (Runtime.CurrentTimeMillis() - ResourceManager.GetClusterTimeStamp() < nmExpireInterval)
             {
                 Log.Info(containerId + " doesn't exist. Add the container" + " to the release request cache as it maybe on recovery."
                          );
                 lock (attempt)
                 {
                     attempt.GetPendingRelease().AddItem(containerId);
                 }
             }
             else
             {
                 RMAuditLogger.LogFailure(attempt.GetUser(), RMAuditLogger.AuditConstants.ReleaseContainer
                                          , "Unauthorized access or invalid container", "Scheduler", "Trying to release container not owned by app or with invalid id."
                                          , attempt.GetApplicationId(), containerId);
             }
         }
         CompletedContainer(rmContainer, SchedulerUtils.CreateAbnormalContainerStatus(containerId
                                                                                      , SchedulerUtils.ReleasedContainer), RMContainerEventType.Released);
     }
 }
예제 #3
0
        public virtual void TestCreateAbnormalContainerStatus()
        {
            ContainerStatus cd = SchedulerUtils.CreateAbnormalContainerStatus(ContainerId.NewContainerId
                                                                                  (ApplicationAttemptId.NewInstance(ApplicationId.NewInstance(Runtime.CurrentTimeMillis
                                                                                                                                                  (), 1), 1), 1), "x");

            NUnit.Framework.Assert.AreEqual(ContainerExitStatus.Aborted, cd.GetExitStatus());
        }
예제 #4
0
        public virtual void TestNormalizeRequest()
        {
            ResourceCalculator resourceCalculator = new DefaultResourceCalculator();
            int minMemory = 1024;
            int maxMemory = 8192;

            Org.Apache.Hadoop.Yarn.Api.Records.Resource minResource = Resources.CreateResource
                                                                          (minMemory, 0);
            Org.Apache.Hadoop.Yarn.Api.Records.Resource maxResource = Resources.CreateResource
                                                                          (maxMemory, 0);
            ResourceRequest ask = new ResourceRequestPBImpl();

            // case negative memory
            ask.SetCapability(Resources.CreateResource(-1024));
            SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource
                                            );
            NUnit.Framework.Assert.AreEqual(minMemory, ask.GetCapability().GetMemory());
            // case zero memory
            ask.SetCapability(Resources.CreateResource(0));
            SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource
                                            );
            NUnit.Framework.Assert.AreEqual(minMemory, ask.GetCapability().GetMemory());
            // case memory is a multiple of minMemory
            ask.SetCapability(Resources.CreateResource(2 * minMemory));
            SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource
                                            );
            NUnit.Framework.Assert.AreEqual(2 * minMemory, ask.GetCapability().GetMemory());
            // case memory is not a multiple of minMemory
            ask.SetCapability(Resources.CreateResource(minMemory + 10));
            SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource
                                            );
            NUnit.Framework.Assert.AreEqual(2 * minMemory, ask.GetCapability().GetMemory());
            // case memory is equal to max allowed
            ask.SetCapability(Resources.CreateResource(maxMemory));
            SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource
                                            );
            NUnit.Framework.Assert.AreEqual(maxMemory, ask.GetCapability().GetMemory());
            // case memory is just less than max
            ask.SetCapability(Resources.CreateResource(maxMemory - 10));
            SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource
                                            );
            NUnit.Framework.Assert.AreEqual(maxMemory, ask.GetCapability().GetMemory());
            // max is not a multiple of min
            maxResource = Resources.CreateResource(maxMemory - 10, 0);
            ask.SetCapability(Resources.CreateResource(maxMemory - 100));
            // multiple of minMemory > maxMemory, then reduce to maxMemory
            SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource
                                            );
            NUnit.Framework.Assert.AreEqual(maxResource.GetMemory(), ask.GetCapability().GetMemory
                                                ());
            // ask is more than max
            maxResource = Resources.CreateResource(maxMemory, 0);
            ask.SetCapability(Resources.CreateResource(maxMemory + 100));
            SchedulerUtils.NormalizeRequest(ask, resourceCalculator, null, minResource, maxResource
                                            );
            NUnit.Framework.Assert.AreEqual(maxResource.GetMemory(), ask.GetCapability().GetMemory
                                                ());
        }
예제 #5
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestNormalizeNodeLabelExpression()
        {
            // mock queue and scheduler
            YarnScheduler        scheduler = Org.Mockito.Mockito.Mock <YarnScheduler>();
            ICollection <string> queueAccessibleNodeLabels = Sets.NewHashSet();
            QueueInfo            queueInfo = Org.Mockito.Mockito.Mock <QueueInfo>();

            Org.Mockito.Mockito.When(queueInfo.GetQueueName()).ThenReturn("queue");
            Org.Mockito.Mockito.When(queueInfo.GetAccessibleNodeLabels()).ThenReturn(queueAccessibleNodeLabels
                                                                                     );
            Org.Mockito.Mockito.When(queueInfo.GetDefaultNodeLabelExpression()).ThenReturn(" x "
                                                                                           );
            Org.Mockito.Mockito.When(scheduler.GetQueueInfo(Matchers.Any <string>(), Matchers.AnyBoolean
                                                                (), Matchers.AnyBoolean())).ThenReturn(queueInfo);
            Org.Apache.Hadoop.Yarn.Api.Records.Resource maxResource = Resources.CreateResource
                                                                          (YarnConfiguration.DefaultRmSchedulerMaximumAllocationMb, YarnConfiguration.DefaultRmSchedulerMaximumAllocationVcores
                                                                          );
            // queue has labels, success cases
            try
            {
                // set queue accessible node labels to [x, y]
                queueAccessibleNodeLabels.Clear();
                Sharpen.Collections.AddAll(queueAccessibleNodeLabels, Arrays.AsList("x", "y"));
                rmContext.GetNodeLabelManager().AddToCluserNodeLabels(ImmutableSet.Of("x", "y"));
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                NUnit.Framework.Assert.IsTrue(resReq.GetNodeLabelExpression().Equals("x"));
                resReq.SetNodeLabelExpression(" y ");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                NUnit.Framework.Assert.IsTrue(resReq.GetNodeLabelExpression().Equals("y"));
            }
            catch (InvalidResourceRequestException e)
            {
                Sharpen.Runtime.PrintStackTrace(e);
                NUnit.Framework.Assert.Fail("Should be valid when request labels is a subset of queue labels"
                                            );
            }
            finally
            {
                rmContext.GetNodeLabelManager().RemoveFromClusterNodeLabels(Arrays.AsList("x", "y"
                                                                                          ));
            }
        }
예제 #6
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.InvalidResourceRequestException
 ///     "/>
 public static void NormalizeAndValidateRequest(ResourceRequest resReq, Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                maximumResource, string queueName, YarnScheduler scheduler, bool isRecovery, RMContext
                                                rmContext, QueueInfo queueInfo)
 {
     if (queueInfo == null)
     {
         try
         {
             queueInfo = scheduler.GetQueueInfo(queueName, false, false);
         }
         catch (IOException)
         {
         }
     }
     // it is possible queue cannot get when queue mapping is set, just ignore
     // the queueInfo here, and move forward
     SchedulerUtils.NormalizeNodeLabelExpressionInRequest(resReq, queueInfo);
     if (!isRecovery)
     {
         ValidateResourceRequest(resReq, maximumResource, queueInfo, rmContext);
     }
 }
예제 #7
0
 public virtual void RecoverContainersOnNode(IList <NMContainerStatus> containerReports
                                             , RMNode nm)
 {
     lock (this)
     {
         if (!rmContext.IsWorkPreservingRecoveryEnabled() || containerReports == null || (
                 containerReports != null && containerReports.IsEmpty()))
         {
             return;
         }
         foreach (NMContainerStatus container in containerReports)
         {
             ApplicationId appId = container.GetContainerId().GetApplicationAttemptId().GetApplicationId
                                       ();
             RMApp rmApp = rmContext.GetRMApps()[appId];
             if (rmApp == null)
             {
                 Log.Error("Skip recovering container " + container + " for unknown application.");
                 KillOrphanContainerOnNode(nm, container);
                 continue;
             }
             // Unmanaged AM recovery is addressed in YARN-1815
             if (rmApp.GetApplicationSubmissionContext().GetUnmanagedAM())
             {
                 Log.Info("Skip recovering container " + container + " for unmanaged AM." + rmApp.
                          GetApplicationId());
                 KillOrphanContainerOnNode(nm, container);
                 continue;
             }
             SchedulerApplication <T> schedulerApp = applications[appId];
             if (schedulerApp == null)
             {
                 Log.Info("Skip recovering container  " + container + " for unknown SchedulerApplication. Application current state is "
                          + rmApp.GetState());
                 KillOrphanContainerOnNode(nm, container);
                 continue;
             }
             Log.Info("Recovering container " + container);
             SchedulerApplicationAttempt schedulerAttempt = schedulerApp.GetCurrentAppAttempt(
                 );
             if (!rmApp.GetApplicationSubmissionContext().GetKeepContainersAcrossApplicationAttempts
                     ())
             {
                 // Do not recover containers for stopped attempt or previous attempt.
                 if (schedulerAttempt.IsStopped() || !schedulerAttempt.GetApplicationAttemptId().Equals
                         (container.GetContainerId().GetApplicationAttemptId()))
                 {
                     Log.Info("Skip recovering container " + container + " for already stopped attempt."
                              );
                     KillOrphanContainerOnNode(nm, container);
                     continue;
                 }
             }
             // create container
             RMContainer rmContainer = RecoverAndCreateContainer(container, nm);
             // recover RMContainer
             rmContainer.Handle(new RMContainerRecoverEvent(container.GetContainerId(), container
                                                            ));
             // recover scheduler node
             nodes[nm.GetNodeID()].RecoverContainer(rmContainer);
             // recover queue: update headroom etc.
             Queue queue = schedulerAttempt.GetQueue();
             queue.RecoverContainer(clusterResource, schedulerAttempt, rmContainer);
             // recover scheduler attempt
             schedulerAttempt.RecoverContainer(rmContainer);
             // set master container for the current running AMContainer for this
             // attempt.
             RMAppAttempt appAttempt = rmApp.GetCurrentAppAttempt();
             if (appAttempt != null)
             {
                 Container masterContainer = appAttempt.GetMasterContainer();
                 // Mark current running AMContainer's RMContainer based on the master
                 // container ID stored in AppAttempt.
                 if (masterContainer != null && masterContainer.GetId().Equals(rmContainer.GetContainerId
                                                                                   ()))
                 {
                     ((RMContainerImpl)rmContainer).SetAMContainer(true);
                 }
             }
             lock (schedulerAttempt)
             {
                 ICollection <ContainerId> releases = schedulerAttempt.GetPendingRelease();
                 if (releases.Contains(container.GetContainerId()))
                 {
                     // release the container
                     rmContainer.Handle(new RMContainerFinishedEvent(container.GetContainerId(), SchedulerUtils
                                                                     .CreateAbnormalContainerStatus(container.GetContainerId(), SchedulerUtils.ReleasedContainer
                                                                                                    ), RMContainerEventType.Released));
                     releases.Remove(container.GetContainerId());
                     Log.Info(container.GetContainerId() + " is released by application.");
                 }
             }
         }
     }
 }
예제 #8
0
        public virtual void TestValidateResourceRequest()
        {
            YarnScheduler mockScheduler = Org.Mockito.Mockito.Mock <YarnScheduler>();

            Org.Apache.Hadoop.Yarn.Api.Records.Resource maxResource = Resources.CreateResource
                                                                          (YarnConfiguration.DefaultRmSchedulerMaximumAllocationMb, YarnConfiguration.DefaultRmSchedulerMaximumAllocationVcores
                                                                          );
            // zero memory
            try
            {
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, null, mockScheduler
                                                           , rmContext);
            }
            catch (InvalidResourceRequestException)
            {
                NUnit.Framework.Assert.Fail("Zero memory should be accepted");
            }
            // zero vcores
            try
            {
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(YarnConfiguration
                                                                                                .DefaultRmSchedulerMinimumAllocationMb, 0);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, null, mockScheduler
                                                           , rmContext);
            }
            catch (InvalidResourceRequestException)
            {
                NUnit.Framework.Assert.Fail("Zero vcores should be accepted");
            }
            // max memory
            try
            {
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(YarnConfiguration
                                                                                                .DefaultRmSchedulerMaximumAllocationMb, YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores
                                                                                                );
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, null, mockScheduler
                                                           , rmContext);
            }
            catch (InvalidResourceRequestException)
            {
                NUnit.Framework.Assert.Fail("Max memory should be accepted");
            }
            // max vcores
            try
            {
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(YarnConfiguration
                                                                                                .DefaultRmSchedulerMinimumAllocationMb, YarnConfiguration.DefaultRmSchedulerMaximumAllocationVcores
                                                                                                );
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, null, mockScheduler
                                                           , rmContext);
            }
            catch (InvalidResourceRequestException)
            {
                NUnit.Framework.Assert.Fail("Max vcores should not be accepted");
            }
            // negative memory
            try
            {
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(-
                                                                                                1, YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, null, mockScheduler
                                                           , rmContext);
                NUnit.Framework.Assert.Fail("Negative memory should not be accepted");
            }
            catch (InvalidResourceRequestException)
            {
            }
            // expected
            // negative vcores
            try
            {
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(YarnConfiguration
                                                                                                .DefaultRmSchedulerMinimumAllocationMb, -1);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, null, mockScheduler
                                                           , rmContext);
                NUnit.Framework.Assert.Fail("Negative vcores should not be accepted");
            }
            catch (InvalidResourceRequestException)
            {
            }
            // expected
            // more than max memory
            try
            {
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(YarnConfiguration
                                                                                                .DefaultRmSchedulerMaximumAllocationMb + 1, YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores
                                                                                                );
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, null, mockScheduler
                                                           , rmContext);
                NUnit.Framework.Assert.Fail("More than max memory should not be accepted");
            }
            catch (InvalidResourceRequestException)
            {
            }
            // expected
            // more than max vcores
            try
            {
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(YarnConfiguration
                                                                                                .DefaultRmSchedulerMinimumAllocationMb, YarnConfiguration.DefaultRmSchedulerMaximumAllocationVcores
                                                                                                + 1);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, null, mockScheduler
                                                           , rmContext);
                NUnit.Framework.Assert.Fail("More than max vcores should not be accepted");
            }
            catch (InvalidResourceRequestException)
            {
            }
        }
예제 #9
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestValidateResourceRequestWithErrorLabelsPermission()
        {
            // mock queue and scheduler
            YarnScheduler        scheduler = Org.Mockito.Mockito.Mock <YarnScheduler>();
            ICollection <string> queueAccessibleNodeLabels = Sets.NewHashSet();
            QueueInfo            queueInfo = Org.Mockito.Mockito.Mock <QueueInfo>();

            Org.Mockito.Mockito.When(queueInfo.GetQueueName()).ThenReturn("queue");
            Org.Mockito.Mockito.When(queueInfo.GetAccessibleNodeLabels()).ThenReturn(queueAccessibleNodeLabels
                                                                                     );
            Org.Mockito.Mockito.When(scheduler.GetQueueInfo(Matchers.Any <string>(), Matchers.AnyBoolean
                                                                (), Matchers.AnyBoolean())).ThenReturn(queueInfo);
            Org.Apache.Hadoop.Yarn.Api.Records.Resource maxResource = Resources.CreateResource
                                                                          (YarnConfiguration.DefaultRmSchedulerMaximumAllocationMb, YarnConfiguration.DefaultRmSchedulerMaximumAllocationVcores
                                                                          );
            // queue has labels, success cases
            try
            {
                // set queue accessible node labesl to [x, y]
                queueAccessibleNodeLabels.Clear();
                Sharpen.Collections.AddAll(queueAccessibleNodeLabels, Arrays.AsList("x", "y"));
                rmContext.GetNodeLabelManager().AddToCluserNodeLabels(ImmutableSet.Of("x", "y"));
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                resReq.SetNodeLabelExpression("x");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                resReq.SetNodeLabelExpression("y");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                resReq.SetNodeLabelExpression(string.Empty);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                resReq.SetNodeLabelExpression(" ");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
            }
            catch (InvalidResourceRequestException e)
            {
                Sharpen.Runtime.PrintStackTrace(e);
                NUnit.Framework.Assert.Fail("Should be valid when request labels is a subset of queue labels"
                                            );
            }
            finally
            {
                rmContext.GetNodeLabelManager().RemoveFromClusterNodeLabels(Arrays.AsList("x", "y"
                                                                                          ));
            }
            // same as above, but cluster node labels don't contains label being
            // requested. should fail
            try
            {
                // set queue accessible node labesl to [x, y]
                queueAccessibleNodeLabels.Clear();
                Sharpen.Collections.AddAll(queueAccessibleNodeLabels, Arrays.AsList("x", "y"));
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                resReq.SetNodeLabelExpression("x");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                NUnit.Framework.Assert.Fail("Should fail");
            }
            catch (InvalidResourceRequestException)
            {
            }
            // queue has labels, failed cases (when ask a label not included by queue)
            try
            {
                // set queue accessible node labesl to [x, y]
                queueAccessibleNodeLabels.Clear();
                Sharpen.Collections.AddAll(queueAccessibleNodeLabels, Arrays.AsList("x", "y"));
                rmContext.GetNodeLabelManager().AddToCluserNodeLabels(ImmutableSet.Of("x", "y"));
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                resReq.SetNodeLabelExpression("z");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                NUnit.Framework.Assert.Fail("Should fail");
            }
            catch (InvalidResourceRequestException)
            {
            }
            finally
            {
                rmContext.GetNodeLabelManager().RemoveFromClusterNodeLabels(Arrays.AsList("x", "y"
                                                                                          ));
            }
            // we don't allow specify more than two node labels in a single expression
            // now
            try
            {
                // set queue accessible node labesl to [x, y]
                queueAccessibleNodeLabels.Clear();
                Sharpen.Collections.AddAll(queueAccessibleNodeLabels, Arrays.AsList("x", "y"));
                rmContext.GetNodeLabelManager().AddToCluserNodeLabels(ImmutableSet.Of("x", "y"));
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                resReq.SetNodeLabelExpression("x && y");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                NUnit.Framework.Assert.Fail("Should fail");
            }
            catch (InvalidResourceRequestException)
            {
            }
            finally
            {
                rmContext.GetNodeLabelManager().RemoveFromClusterNodeLabels(Arrays.AsList("x", "y"
                                                                                          ));
            }
            // queue doesn't have label, succeed (when request no label)
            queueAccessibleNodeLabels.Clear();
            try
            {
                // set queue accessible node labels to empty
                queueAccessibleNodeLabels.Clear();
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                resReq.SetNodeLabelExpression(string.Empty);
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                resReq.SetNodeLabelExpression("  ");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
            }
            catch (InvalidResourceRequestException e)
            {
                Sharpen.Runtime.PrintStackTrace(e);
                NUnit.Framework.Assert.Fail("Should be valid when request labels is empty");
            }
            // queue doesn't have label, failed (when request any label)
            try
            {
                // set queue accessible node labels to empty
                queueAccessibleNodeLabels.Clear();
                rmContext.GetNodeLabelManager().AddToCluserNodeLabels(ImmutableSet.Of("x"));
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                resReq.SetNodeLabelExpression("x");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                NUnit.Framework.Assert.Fail("Should fail");
            }
            catch (InvalidResourceRequestException)
            {
            }
            finally
            {
                rmContext.GetNodeLabelManager().RemoveFromClusterNodeLabels(Arrays.AsList("x"));
            }
            // queue is "*", always succeeded
            try
            {
                // set queue accessible node labels to empty
                queueAccessibleNodeLabels.Clear();
                queueAccessibleNodeLabels.AddItem(RMNodeLabelsManager.Any);
                rmContext.GetNodeLabelManager().AddToCluserNodeLabels(ImmutableSet.Of("x", "y", "z"
                                                                                      ));
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                resReq.SetNodeLabelExpression("x");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                resReq.SetNodeLabelExpression("y");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                resReq.SetNodeLabelExpression("z");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
            }
            catch (InvalidResourceRequestException e)
            {
                Sharpen.Runtime.PrintStackTrace(e);
                NUnit.Framework.Assert.Fail("Should be valid when queue can access any labels");
            }
            finally
            {
                rmContext.GetNodeLabelManager().RemoveFromClusterNodeLabels(Arrays.AsList("x", "y"
                                                                                          , "z"));
            }
            // same as above, but cluster node labels don't contains label, should fail
            try
            {
                // set queue accessible node labels to empty
                queueAccessibleNodeLabels.Clear();
                queueAccessibleNodeLabels.AddItem(RMNodeLabelsManager.Any);
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), ResourceRequest.Any, resource, 1);
                resReq.SetNodeLabelExpression("x");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                NUnit.Framework.Assert.Fail("Should fail");
            }
            catch (InvalidResourceRequestException)
            {
            }
            // we don't allow resource name other than ANY and specify label
            try
            {
                // set queue accessible node labesl to [x, y]
                queueAccessibleNodeLabels.Clear();
                Sharpen.Collections.AddAll(queueAccessibleNodeLabels, Arrays.AsList("x", "y"));
                rmContext.GetNodeLabelManager().AddToCluserNodeLabels(ImmutableSet.Of("x", "y"));
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), "rack", resource, 1);
                resReq.SetNodeLabelExpression("x");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                NUnit.Framework.Assert.Fail("Should fail");
            }
            catch (InvalidResourceRequestException)
            {
            }
            finally
            {
                rmContext.GetNodeLabelManager().RemoveFromClusterNodeLabels(Arrays.AsList("x", "y"
                                                                                          ));
            }
            // we don't allow resource name other than ANY and specify label even if
            // queue has accessible label = *
            try
            {
                // set queue accessible node labesl to *
                queueAccessibleNodeLabels.Clear();
                Sharpen.Collections.AddAll(queueAccessibleNodeLabels, Arrays.AsList(CommonNodeLabelsManager
                                                                                    .Any));
                rmContext.GetNodeLabelManager().AddToCluserNodeLabels(ImmutableSet.Of("x"));
                Org.Apache.Hadoop.Yarn.Api.Records.Resource resource = Resources.CreateResource(0
                                                                                                , YarnConfiguration.DefaultRmSchedulerMinimumAllocationVcores);
                ResourceRequest resReq = BuilderUtils.NewResourceRequest(Org.Mockito.Mockito.Mock
                                                                         <Priority>(), "rack", resource, 1);
                resReq.SetNodeLabelExpression("x");
                SchedulerUtils.NormalizeAndvalidateRequest(resReq, maxResource, "queue", scheduler
                                                           , rmContext);
                NUnit.Framework.Assert.Fail("Should fail");
            }
            catch (InvalidResourceRequestException)
            {
            }
            finally
            {
                rmContext.GetNodeLabelManager().RemoveFromClusterNodeLabels(Arrays.AsList("x"));
            }
        }