public virtual void TestAuxServicesMeta() { 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)); AuxServices aux = new AuxServices(); aux.Init(conf); int latch = 1; foreach (Org.Apache.Hadoop.Service.Service s in aux.GetServices()) { NUnit.Framework.Assert.AreEqual(Service.STATE.Inited, s.GetServiceState()); if (s is TestAuxServices.ServiceA) { latch *= 2; } else { if (s is TestAuxServices.ServiceB) { latch *= 3; } else { NUnit.Framework.Assert.Fail("Unexpected service type " + s.GetType()); } } } NUnit.Framework.Assert.AreEqual("Invalid mix of services", 6, latch); aux.Start(); foreach (Org.Apache.Hadoop.Service.Service s_1 in aux.GetServices()) { NUnit.Framework.Assert.AreEqual(Service.STATE.Started, s_1.GetServiceState()); } IDictionary <string, ByteBuffer> meta = aux.GetMetaData(); NUnit.Framework.Assert.AreEqual(2, meta.Count); NUnit.Framework.Assert.AreEqual("A", Sharpen.Runtime.GetStringForBytes(((byte[])meta ["Asrv"].Array()))); NUnit.Framework.Assert.AreEqual("B", Sharpen.Runtime.GetStringForBytes(((byte[])meta ["Bsrv"].Array()))); aux.Stop(); foreach (Org.Apache.Hadoop.Service.Service s_2 in aux.GetServices()) { NUnit.Framework.Assert.AreEqual(Service.STATE.Stopped, s_2.GetServiceState()); } }
public virtual void TestAuxServiceRecoverySetup() { Configuration conf = new YarnConfiguration(); conf.SetBoolean(YarnConfiguration.NmRecoveryEnabled, true); conf.Set(YarnConfiguration.NmRecoveryDir, TestDir.ToString()); conf.SetStrings(YarnConfiguration.NmAuxServices, new string[] { "Asrv", "Bsrv" }); conf.SetClass(string.Format(YarnConfiguration.NmAuxServiceFmt, "Asrv"), typeof(TestAuxServices.RecoverableServiceA ), typeof(Org.Apache.Hadoop.Service.Service)); conf.SetClass(string.Format(YarnConfiguration.NmAuxServiceFmt, "Bsrv"), typeof(TestAuxServices.RecoverableServiceB ), typeof(Org.Apache.Hadoop.Service.Service)); try { AuxServices aux = new AuxServices(); aux.Init(conf); NUnit.Framework.Assert.AreEqual(2, aux.GetServices().Count); FilePath auxStorageDir = new FilePath(TestDir, AuxServices.StateStoreRootName); NUnit.Framework.Assert.AreEqual(2, auxStorageDir.ListFiles().Length); aux.Close(); } finally { FileUtil.FullyDelete(TestDir); } }
public virtual void TestAuxServices() { 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)); AuxServices aux = new AuxServices(); aux.Init(conf); int latch = 1; foreach (Org.Apache.Hadoop.Service.Service s in aux.GetServices()) { NUnit.Framework.Assert.AreEqual(Service.STATE.Inited, s.GetServiceState()); if (s is TestAuxServices.ServiceA) { latch *= 2; } else { if (s is TestAuxServices.ServiceB) { latch *= 3; } else { NUnit.Framework.Assert.Fail("Unexpected service type " + s.GetType()); } } } NUnit.Framework.Assert.AreEqual("Invalid mix of services", 6, latch); aux.Start(); foreach (Org.Apache.Hadoop.Service.Service s_1 in aux.GetServices()) { NUnit.Framework.Assert.AreEqual(Service.STATE.Started, s_1.GetServiceState()); } aux.Stop(); foreach (Org.Apache.Hadoop.Service.Service s_2 in aux.GetServices()) { NUnit.Framework.Assert.AreEqual(Service.STATE.Stopped, s_2.GetServiceState()); } }
public virtual void TestAuxUnexpectedStop() { 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)); AuxServices aux = new AuxServices(); aux.Init(conf); aux.Start(); Org.Apache.Hadoop.Service.Service s = aux.GetServices().GetEnumerator().Next(); s.Stop(); NUnit.Framework.Assert.AreEqual("Auxiliary service stopped, but AuxService unaffected." , Service.STATE.Stopped, aux.GetServiceState()); NUnit.Framework.Assert.IsTrue(aux.GetServices().IsEmpty()); }
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); } }