コード例 #1
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"
                                                                                          ));
            }
        }
コード例 #2
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)
            {
            }
        }
コード例 #3
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"));
            }
        }