Пример #1
0
        public virtual void TestValidAuxServiceName()
        {
            AuxServices   aux  = new AuxServices();
            Configuration conf = new Configuration();

            conf.SetStrings(YarnConfiguration.NmAuxServices, new string[] { "Asrv1", "Bsrv_2" });
            conf.SetClass(string.Format(YarnConfiguration.NmAuxServiceFmt, "Asrv1"), typeof(TestAuxServices.ServiceA
                                                                                            ), typeof(Org.Apache.Hadoop.Service.Service));
            conf.SetClass(string.Format(YarnConfiguration.NmAuxServiceFmt, "Bsrv_2"), typeof(
                              TestAuxServices.ServiceB), typeof(Org.Apache.Hadoop.Service.Service));
            try
            {
                aux.Init(conf);
            }
            catch (Exception)
            {
                NUnit.Framework.Assert.Fail("Should not receive the exception.");
            }
            //Test bad auxService Name
            AuxServices aux1 = new AuxServices();

            conf.SetStrings(YarnConfiguration.NmAuxServices, new string[] { "1Asrv1" });
            conf.SetClass(string.Format(YarnConfiguration.NmAuxServiceFmt, "1Asrv1"), typeof(
                              TestAuxServices.ServiceA), typeof(Org.Apache.Hadoop.Service.Service));
            try
            {
                aux1.Init(conf);
                NUnit.Framework.Assert.Fail("Should receive the exception.");
            }
            catch (Exception ex)
            {
                NUnit.Framework.Assert.IsTrue(ex.Message.Contains("The ServiceName: 1Asrv1 set in "
                                                                  + "yarn.nodemanager.aux-services is invalid.The valid service name " + "should only contain a-zA-Z0-9_ and can not start with numbers"
                                                                  ));
            }
        }
Пример #2
0
        public virtual void TestAuxEventDispatch()
        {
            Configuration conf = new Configuration();

            conf.SetStrings(YarnConfiguration.NmAuxServices, new string[] { "Asrv", "Bsrv" });
            conf.SetClass(string.Format(YarnConfiguration.NmAuxServiceFmt, "Asrv"), typeof(TestAuxServices.ServiceA
                                                                                           ), typeof(Org.Apache.Hadoop.Service.Service));
            conf.SetClass(string.Format(YarnConfiguration.NmAuxServiceFmt, "Bsrv"), typeof(TestAuxServices.ServiceB
                                                                                           ), typeof(Org.Apache.Hadoop.Service.Service));
            conf.SetInt("A.expected.init", 1);
            conf.SetInt("B.expected.stop", 1);
            AuxServices aux = new AuxServices();

            aux.Init(conf);
            aux.Start();
            ApplicationId appId1 = ApplicationId.NewInstance(0, 65);
            ByteBuffer    buf    = ByteBuffer.Allocate(6);

            buf.PutChar('A');
            buf.PutInt(65);
            buf.Flip();
            AuxServicesEvent @event = new AuxServicesEvent(AuxServicesEventType.ApplicationInit
                                                           , "user0", appId1, "Asrv", buf);

            aux.Handle(@event);
            ApplicationId appId2 = ApplicationId.NewInstance(0, 66);

            @event = new AuxServicesEvent(AuxServicesEventType.ApplicationStop, "user0", appId2
                                          , "Bsrv", null);
            // verify all services got the stop event
            aux.Handle(@event);
            ICollection <AuxiliaryService> servs = aux.GetServices();

            foreach (AuxiliaryService serv in servs)
            {
                AList <int> appIds = ((TestAuxServices.LightService)serv).GetAppIdsStopped();
                NUnit.Framework.Assert.AreEqual("app not properly stopped", 1, appIds.Count);
                NUnit.Framework.Assert.IsTrue("wrong app stopped", appIds.Contains((int)66));
            }
            foreach (AuxiliaryService serv_1 in servs)
            {
                NUnit.Framework.Assert.IsNull(((TestAuxServices.LightService)serv_1).containerId);
                NUnit.Framework.Assert.IsNull(((TestAuxServices.LightService)serv_1).resource);
            }
            ApplicationAttemptId     attemptId = ApplicationAttemptId.NewInstance(appId1, 1);
            ContainerTokenIdentifier cti       = new ContainerTokenIdentifier(ContainerId.NewContainerId
                                                                                  (attemptId, 1), string.Empty, string.Empty, Resource.NewInstance(1, 1), 0, 0, 0,
                                                                              Priority.NewInstance(0), 0);

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container container
                = new ContainerImpl(null, null, null, null, null, null, cti);
            ContainerId containerId = container.GetContainerId();
            Resource    resource    = container.GetResource();

            @event = new AuxServicesEvent(AuxServicesEventType.ContainerInit, container);
            aux.Handle(@event);
            foreach (AuxiliaryService serv_2 in servs)
            {
                NUnit.Framework.Assert.AreEqual(containerId, ((TestAuxServices.LightService)serv_2
                                                              ).containerId);
                NUnit.Framework.Assert.AreEqual(resource, ((TestAuxServices.LightService)serv_2).
                                                resource);
                ((TestAuxServices.LightService)serv_2).containerId = null;
                ((TestAuxServices.LightService)serv_2).resource    = null;
            }
            @event = new AuxServicesEvent(AuxServicesEventType.ContainerStop, container);
            aux.Handle(@event);
            foreach (AuxiliaryService serv_3 in servs)
            {
                NUnit.Framework.Assert.AreEqual(containerId, ((TestAuxServices.LightService)serv_3
                                                              ).containerId);
                NUnit.Framework.Assert.AreEqual(resource, ((TestAuxServices.LightService)serv_3).
                                                resource);
            }
        }