Ejemplo n.º 1
0
        /// <summary>
        /// Creates and sets up a new instance Pyxis container
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"><paramref name="c"/> is <see langword="null" />.</exception>
        /// <exception cref="InvalidOperationException">Failed to setup container instance</exception>
        public static IContainer Setup(Action<IContainerConfiguration> c)
        {
            if (c == null)
            {
                throw new ArgumentNullException(nameof(c));
            }
            var conf = new FluentContainerConfigurator();

            try
            {
                c(conf);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException("Failed to setup container instance", exception);
            }

            var container = new ContainerImpl(conf);

            // register container instance
            conf.Register<IContainer>().Using(container);
            conf.Register<IServiceProvider>().Using(container);

            container.Build();
            return container;
        }
Ejemplo n.º 2
0
 public void Verify(ContainerVerification options, ContainerImpl container)
 {
     if (options.HasFlag(ContainerVerification.SingletonsUsingOnlySingletons))
     {
         var context = new GenerationContext(container, _wrapping, new BuildContext(container));
         context.VerifySingletonUsingOnlySingletons(_implementationType);
     }
 }
Ejemplo n.º 3
0
        public virtual void TestLogFileWithDriveLetter()
        {
            ContainerImpl       container = Org.Mockito.Mockito.Mock <ContainerImpl>();
            ApplicationIdPBImpl appId     = Org.Mockito.Mockito.Mock <ApplicationIdPBImpl>();

            Org.Mockito.Mockito.When(appId.ToString()).ThenReturn("appId");
            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = Org.Mockito.Mockito.Mock <Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                                                >();
            Org.Mockito.Mockito.When(app.GetAppId()).ThenReturn(appId);
            ApplicationAttemptIdPBImpl appAttemptId = Org.Mockito.Mockito.Mock <ApplicationAttemptIdPBImpl
                                                                                >();

            Org.Mockito.Mockito.When(appAttemptId.GetApplicationId()).ThenReturn(appId);
            ConcurrentMap <ApplicationId, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                           > applications = new ConcurrentHashMap <ApplicationId, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                                                                   >();

            applications[appId] = app;
            ContainerId containerId = Org.Mockito.Mockito.Mock <ContainerIdPBImpl>();

            Org.Mockito.Mockito.When(containerId.ToString()).ThenReturn("containerId");
            Org.Mockito.Mockito.When(containerId.GetApplicationAttemptId()).ThenReturn(appAttemptId
                                                                                       );
            ConcurrentMap <ContainerId, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container
                           > containers = new ConcurrentHashMap <ContainerId, Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Container.Container
                                                                 >();

            containers[containerId] = container;
            LocalDirsHandlerService localDirs = Org.Mockito.Mockito.Mock <LocalDirsHandlerService
                                                                          >();

            Org.Mockito.Mockito.When(localDirs.GetLogPathToRead("appId" + Path.Separator + "containerId"
                                                                + Path.Separator + "fileName")).ThenReturn(new Path("F:/nmlogs/appId/containerId/fileName"
                                                                                                                    ));
            NodeManager.NMContext context = Org.Mockito.Mockito.Mock <NodeManager.NMContext>();
            Org.Mockito.Mockito.When(context.GetLocalDirsHandler()).ThenReturn(localDirs);
            Org.Mockito.Mockito.When(context.GetApplications()).ThenReturn(applications);
            Org.Mockito.Mockito.When(context.GetContainers()).ThenReturn(containers);
            FilePath logFile = ContainerLogsUtils.GetContainerLogFile(containerId, "fileName"
                                                                      , null, context);

            NUnit.Framework.Assert.IsTrue("logFile lost drive letter " + logFile, logFile.ToString
                                              ().IndexOf("F:" + FilePath.separator + "nmlogs") > -1);
        }
Ejemplo n.º 4
0
 public void Verify(ContainerVerification options, ContainerImpl container)
 {
 }
Ejemplo n.º 5
0
        public object BuildFuncOfT(ContainerImpl container, Type funcType)
        {
            var obj = container.Instances[_instanceIndex];

            return(ClosureOfObjBuilder.Build(funcType, obj));
        }
Ejemplo n.º 6
0
 public FactoryImpl(ContainerImpl container, Func <object> buildFunc, Type type)
 {
     _type          = type;
     _instanceIndex = container.AddInstance(buildFunc);
 }
Ejemplo n.º 7
0
        public object?BuildFuncOfT(ContainerImpl container, Type funcType)
        {
            var obj = container.Singletons[_singletonIndex];

            return(obj == null ? null : ClosureOfObjBuilder.Build(funcType, obj));
        }
Ejemplo n.º 8
0
 public object BuildFuncOfT(ContainerImpl container, Type funcType)
 {
     var obj = container.Instances[_instanceIndex];
     return ClosureOfObjBuilder.Build(funcType, obj);
 }
Ejemplo n.º 9
0
 public object BuildFuncOfT(ContainerImpl container, Type funcType)
 {
     var obj = container.Singletons[_singletonIndex];
     return obj == null ? null : ClosureOfObjBuilder.Build(funcType, obj);
 }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
 public FactoryImpl(ContainerImpl container, Func<object> buildFunc, Type type)
 {
     _type = type;
     _instanceIndex = container.AddInstance(buildFunc);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates an instance of <c>ServiceInstantiationGraph</c>
 /// </summary>
 /// <param name="container"></param>
 public ServiceInstantiationGraph(ContainerImpl container)
 {
     _container = container;
 }