Exemplo n.º 1
0
 internal Introspector(Engine parentEngine, ProjectManager projectManager, NodeManager nodeManager)
 {
     this.parentEngine   = parentEngine;
     this.projectManager = projectManager;
     this.nodeManager    = nodeManager;
     this.ignoreTimeout  = 0;
 }
Exemplo n.º 2
0
        public void RegisterNodeProviders()
        {
                      
            MockNodeProvider ProviderOneNode = new MockNodeProvider();
            ProviderOneNode.NodeDescriptions.Add(new MockNodeDescription("Provider One Node One"));
           
            MockNodeProvider ProviderThreeNodes = new MockNodeProvider();
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node One"));
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node Two"));
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node Three"));

            MockNodeProvider ProviderNoNodes = new MockNodeProvider();

            // Register a node provider with only one node
            NodeManager nodeManager = new NodeManager(1, false, new Engine(@"c:\"));
            nodeManager.RegisterNodeProvider(ProviderOneNode);
            // One from node added by node provider, one for the default 0 local node (null as there is no description)
            Assert.IsTrue(nodeManager.GetNodeDescriptions().Length == 2, "Expected there to be two node Descriptions");
            Assert.AreEqual(2, nodeManager.MaxNodeCount);
            Assert.IsNull(nodeManager.GetNodeDescriptions()[0],"Expected first element to be null");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[1]).NodeDescription, "Provider One Node One", StringComparison.OrdinalIgnoreCase)==0, "Expected node description to be Provider One  Node One");

            // Register a node provider with more than one node
            nodeManager = new NodeManager(1, false, new Engine(@"c:\"));
            nodeManager.RegisterNodeProvider(ProviderThreeNodes);
            // THree from node added by node provider, one for the default 0 local node (null as there is no description)
            Assert.IsTrue(nodeManager.GetNodeDescriptions().Length == 4, "Expected there to be four node Descriptions");
            Assert.AreEqual(4, nodeManager.MaxNodeCount);
            Assert.IsNull(nodeManager.GetNodeDescriptions()[0], "Expected first element to be null");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[1]).NodeDescription, "Provider Two Node One", StringComparison.OrdinalIgnoreCase) == 0, "Expected node description to be Provider Two Node One");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[2]).NodeDescription, "Provider Two Node Two", StringComparison.OrdinalIgnoreCase) == 0, "Expected node description to be Provider Two Node Two");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[3]).NodeDescription, "Provider Two Node Three", StringComparison.OrdinalIgnoreCase) == 0, "Expected node description to be Provider Two Node Three");


            // Register a node provider with more than one node
            nodeManager = new NodeManager(1, false, new Engine(@"c:\"));
            nodeManager.RegisterNodeProvider(ProviderOneNode);
            nodeManager.RegisterNodeProvider(ProviderThreeNodes);
            // THree from node added by node provider, one for the default 0 local node (null as there is no description)
            Assert.IsTrue(nodeManager.GetNodeDescriptions().Length == 5, "Expected there to be four node Descriptions");
            Assert.AreEqual(5, nodeManager.MaxNodeCount);
            Assert.IsNull(nodeManager.GetNodeDescriptions()[0], "Expected first element to be null");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[1]).NodeDescription, "Provider One Node One", StringComparison.OrdinalIgnoreCase) == 0, "Expected node description to be Provider One Node One");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[2]).NodeDescription, "Provider Two Node One", StringComparison.OrdinalIgnoreCase) == 0, "Expected node description to be Provider Two Node One");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[3]).NodeDescription, "Provider Two Node Two", StringComparison.OrdinalIgnoreCase) == 0, "Expected node description to be Provider Two Node Two");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[4]).NodeDescription, "Provider Two Node Three", StringComparison.OrdinalIgnoreCase) == 0, "Expected node description to be Provider Two Node Three");


            // Register a node provider with more than one node
            nodeManager = new NodeManager(1, false, new Engine(@"c:\"));
            nodeManager.RegisterNodeProvider(ProviderThreeNodes);
            nodeManager.RegisterNodeProvider(ProviderOneNode);
            nodeManager.UpdateSettings(true, false, true); // just need to test this once
            // THree from node added by node provider, one for the default 0 local node (null as there is no description)
            Assert.IsTrue(nodeManager.GetNodeDescriptions().Length == 5, "Expected there to be four node Descriptions");
            Assert.AreEqual(5, nodeManager.MaxNodeCount);
            Assert.IsNull(nodeManager.GetNodeDescriptions()[0], "Expected first element to be null");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[1]).NodeDescription, "Provider Two Node One", StringComparison.OrdinalIgnoreCase) == 0, "Expected node description to be Provider Two Node One");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[2]).NodeDescription, "Provider Two Node Two", StringComparison.OrdinalIgnoreCase) == 0, "Expected node description to be Provider Two Node Two");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[3]).NodeDescription, "Provider Two Node Three", StringComparison.OrdinalIgnoreCase) == 0, "Expected node description to be Provider Two Node Three");
            Assert.IsTrue(string.Compare(((MockNodeDescription)nodeManager.GetNodeDescriptions()[4]).NodeDescription, "Provider One Node One", StringComparison.OrdinalIgnoreCase) == 0, "Expected node description to be Provider One Node One");
        }
Exemplo n.º 3
0
 public void RegisterNullNodeProviders()
 {
      MockNodeProvider nullNodeProvider = null;
      NodeManager nodeManager = new NodeManager(1, false, engine);
      nodeManager.RegisterNodeProvider(nullNodeProvider);
 }
Exemplo n.º 4
0
        public void TestConstructor4()
        {

            NodeManager nodeManager = new NodeManager(4, false, engine);
            Assert.IsTrue(nodeManager.TaskExecutionModule.GetExecutionModuleMode() == TaskExecutionModule.TaskExecutionModuleMode.MultiProcFullNodeMode, "Expected Task Mode to be MultiProc");
        }
Exemplo n.º 5
0
        public void TestGetNodeDescriptions()
        {
            MockNodeProvider ProviderThreeNodes = new MockNodeProvider();
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node One"));
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node Two"));
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node Three"));

            MockNodeProvider ProviderOneNode = new MockNodeProvider();
            ProviderOneNode.NodeDescriptions.Add(new MockNodeDescription("Provider One Node One"));

            NodeManager nodeManager = new NodeManager(1, false, new Engine(@"c:\"));
            nodeManager.RegisterNodeProvider(ProviderThreeNodes);
            nodeManager.RegisterNodeProvider(ProviderOneNode);
            // Cant assert the contents yet as there is no definition inside of a INodeDescription interface
            Assert.IsTrue(nodeManager.GetNodeDescriptions().Length == 5, "Expected there to be five descriptions");
        }
Exemplo n.º 6
0
 public void TestConstructor()
 {
     NodeManager nodeManager = new NodeManager(1, false, engine);
     Assert.IsTrue(nodeManager.TaskExecutionModule.GetExecutionModuleMode() == TaskExecutionModule.TaskExecutionModuleMode.SingleProcMode, "Expected Task Mode to be Single");
     nodeManager.UpdateSettings(true, true, true);
 }
Exemplo n.º 7
0
        public void TestPostBuildRequestToNode()
        {
            MockNodeProvider ProviderThreeNodes = new MockNodeProvider();
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node One"));
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node Two"));
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node Three"));

            MockNodeProvider ProviderOneNode = new MockNodeProvider();
            ProviderOneNode.NodeDescriptions.Add(new MockNodeDescription("Provider One Node One"));

            NodeManager nodeManager = new NodeManager(1, false, new Engine(@"c:\"));
            nodeManager.RegisterNodeProvider(ProviderThreeNodes);
            nodeManager.RegisterNodeProvider(ProviderOneNode);

            nodeManager.PostBuildRequestToNode(1, new BuildRequest(1, "ProjectFile", null, new BuildPropertyGroup(), null, 1, false, false));
            nodeManager.PostBuildRequestToNode(2, new BuildRequest(2, "ProjectFile", null, new BuildPropertyGroup(), null, 2, false, false));
            nodeManager.PostBuildRequestToNode(3, new BuildRequest(3, "ProjectFile", null, new BuildPropertyGroup(), null, 3, false, false));
            nodeManager.PostBuildRequestToNode(4, new BuildRequest(4, "ProjectFile", null, new BuildPropertyGroup(), null, 4, false, false));
            
            Assert.IsTrue(ProviderThreeNodes.buildRequestsSubmittedToProvider.Count == 3, "Expected there to be three build results in the mock provider");
            Assert.IsTrue(ProviderThreeNodes.buildRequestsSubmittedToProvider[0].HandleId == 1, "Expected first NodeProxyId to be 1");
            Assert.IsTrue(ProviderThreeNodes.buildRequestsSubmittedToProvider[1].HandleId == 2, "Expected second NodeProxyId to be 2");
            Assert.IsTrue(ProviderThreeNodes.buildRequestsSubmittedToProvider[2].HandleId == 3, "Expected third NodeProxyId to be 3");
            Assert.IsTrue(ProviderOneNode.buildRequestsSubmittedToProvider.Count == 1, "Expected there to be one build results in the mock provider");
            Assert.IsTrue(ProviderOneNode.buildRequestsSubmittedToProvider[0].HandleId == 4, "Expected first NodeProxyId to be 4");
        }
Exemplo n.º 8
0
        public void TestPostBuildResultToNode()
        {
            MockNodeProvider ProviderThreeNodes = new MockNodeProvider();
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node One"));
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node Two"));
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node Three"));

            MockNodeProvider ProviderOneNode = new MockNodeProvider();
            ProviderOneNode.NodeDescriptions.Add(new MockNodeDescription("Provider One Node One"));

            NodeManager nodeManager = new NodeManager(1, false, new Engine(@"c:\"));
            nodeManager.RegisterNodeProvider(ProviderThreeNodes);
            nodeManager.RegisterNodeProvider(ProviderOneNode);

            nodeManager.PostBuildResultToNode(1, new BuildResult(null, new Hashtable(StringComparer.OrdinalIgnoreCase), false, 2, 1, 6, false, string.Empty, string.Empty, 0, 0, 0));
            nodeManager.PostBuildResultToNode(2, new BuildResult(null, new Hashtable(StringComparer.OrdinalIgnoreCase), false, 3, 2, 7, false, string.Empty, string.Empty, 0, 0, 0));
            nodeManager.PostBuildResultToNode(3, new BuildResult(null, new Hashtable(StringComparer.OrdinalIgnoreCase), false, 4, 3, 8, false, string.Empty, string.Empty, 0, 0, 0));
            nodeManager.PostBuildResultToNode(4, new BuildResult(null, new Hashtable(StringComparer.OrdinalIgnoreCase), false, 5, 4, 9, false, string.Empty, string.Empty, 0, 0, 0));
            Assert.IsTrue(ProviderThreeNodes.buildResultsSubmittedToProvider.Count == 3, "Expected there to be three build results in the mock provider");
            Assert.IsTrue(ProviderThreeNodes.buildResultsSubmittedToProvider[0].HandleId == 2, "Expected first NodeProxyId to be 2");
            Assert.IsTrue(ProviderThreeNodes.buildResultsSubmittedToProvider[1].HandleId == 3, "Expected second NodeProxyId to be 3");
            Assert.IsTrue(ProviderThreeNodes.buildResultsSubmittedToProvider[2].HandleId == 4, "Expected third NodeProxyId to be 4");
            Assert.IsTrue(ProviderOneNode.buildResultsSubmittedToProvider.Count == 1, "Expected there to be one build results in the mock provider");
            Assert.IsTrue(ProviderOneNode.buildResultsSubmittedToProvider[0].HandleId == 5, "Expected first NodeProxyId to be 5");
        }
Exemplo n.º 9
0
        public void TestShutdownNodes()
        {
            MockNodeProvider ProviderThreeNodes = new MockNodeProvider();
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node One"));
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node Two"));
            ProviderThreeNodes.NodeDescriptions.Add(new MockNodeDescription("Provider Two Node Three"));

            NodeManager nodeManager = new NodeManager(1, false, new Engine(@"c:\"));
            nodeManager.RegisterNodeProvider(ProviderThreeNodes);
            nodeManager.ShutdownNodes(Node.NodeShutdownLevel.PoliteShutdown);

            Assert.IsTrue(ProviderThreeNodes.NodeDescriptions.TrueForAll(delegate(INodeDescription o)
                                                                                                     {
                                                                                                         return o == null;
                                                                                                     }
                                                                         ), "Expected all descriptions to be null");

        }
Exemplo n.º 10
0
 public void TestEnableOutOfProcLogging()
 {
     // Register a node provider with more than one node
     MockNodeProvider ProviderOneNode = new MockNodeProvider();
     ProviderOneNode.NodeDescriptions.Add(new MockNodeDescription("Provider One Node One"));
     NodeManager nodeManager = new NodeManager(1, false, new Engine(@"c:\"));
     nodeManager.RegisterNodeProvider(ProviderOneNode);
     nodeManager.UpdateSettings(true,false, true); // just need to test this once
 }
Exemplo n.º 11
0
Arquivo: Node.cs Projeto: xen2/msbuild
        private void NodeLocalEngineLoop()
        {
            buildInProgress = true;

            // Create a logging service for this build request
            localEngine =
                new Engine(parentGlobalProperties, toolsetSearchLocations, 1 /* cpus */, true /* child node */, this.nodeId, parentStartupDirectory, null);
            localEngine.Router.ChildMode  = true;
            localEngine.Router.ParentNode = this;

            this.outProcLoggingService = new EngineLoggingServicesOutProc(this, localEngine.FlushRequestEvent);

            if (nodeLoggers.Length != 0)
            {
                foreach (LoggerDescription loggerDescription in nodeLoggers)
                {
                    IForwardingLogger newLogger = null;
                    bool exitedDueToError       = true;
                    try
                    {
                        newLogger = loggerDescription.CreateForwardingLogger();
                        // Check if the class was not found in the assembly
                        if (newLogger == null)
                        {
                            InternalLoggerException.Throw(null, null, "FatalErrorWhileInitializingLogger", true, loggerDescription.Name);
                        }
                        newLogger.Verbosity  = loggerDescription.Verbosity;
                        newLogger.Parameters = loggerDescription.LoggerSwitchParameters;
                        newLogger.NodeId     = nodeId;
                        EventRedirector newRedirector = new EventRedirector(loggerDescription.LoggerId, outProcLoggingService);
                        newLogger.BuildEventRedirector = newRedirector;
                        exitedDueToError = false;
                    }
                    // Polite logger failure
                    catch (LoggerException e)
                    {
                        ReportUnhandledError(e);
                    }
                    // Logger class was not found
                    catch (InternalLoggerException e)
                    {
                        ReportUnhandledError(e);
                    }
                    catch (Exception e)
                    {
                        // Wrap the exception in a InternalLoggerException and send it to the parent node
                        string errorCode;
                        string helpKeyword;
                        string message = ResourceUtilities.FormatResourceString(out errorCode, out helpKeyword, "FatalErrorWhileInitializingLogger", loggerDescription.Name);
                        ReportUnhandledError(new InternalLoggerException(message, e, null, errorCode, helpKeyword, true));
                    }

                    // If there was a failure registering loggers, null out the engine pointer
                    if (exitedDueToError)
                    {
                        localEngine = null;
                        return;
                    }

                    localEngine.RegisterLogger(newLogger);
                }

                localEngine.ExternalLoggingServices = outProcLoggingService;
            }

            // Hook up logging service to forward all events to the central engine if necessary
            if (centralizedLogging)
            {
                if (nodeLoggers.Length != 0)
                {
                    localEngine.LoggingServices.ForwardingService = outProcLoggingService;
                    localEngine.ExternalLoggingServices           = outProcLoggingService;
                }
                else
                {
                    localEngine.LoggingServices = outProcLoggingService;
                }
            }

            localEngine.LoggingServices.OnlyLogCriticalEvents = this.logOnlyCriticalEvents;

            if (!useBreadthFirstTraversal)
            {
                localEngine.PostEngineCommand(new ChangeTraversalTypeCommand(useBreadthFirstTraversal, true));
            }

            // Post all the requests that passed in while the engine was being constructed
            // into the engine queue
            lock (buildRequests)
            {
                while (buildRequests.Count != 0)
                {
                    BuildRequest buildRequest = buildRequests.Dequeue();
                    localEngine.PostBuildRequest(buildRequest);
                }
            }

            try
            {
                // If there are forwarding loggers registered - generate a custom  build started
                if (nodeLoggers.Length > 0)
                {
                    localEngine.LoggingServices.LogBuildStarted(EngineLoggingServicesInProc.CENTRAL_ENGINE_EVENTSOURCE);
                    localEngine.LoggingServices.ProcessPostedLoggingEvents();
                }

                // Trigger the actual build if shutdown was not called while the engine was being initialized
                if (!nodeShutdown)
                {
                    localEngine.EngineBuildLoop(null);
                }
            }
            catch (Exception e)
            {
                // Unhandled exception during execution. The node has to be shutdown.
                ReportUnhandledError(e);
            }
            finally
            {
                if (localEngine != null)
                {
                    // Flush all the messages associated before shutting down
                    localEngine.LoggingServices.ProcessPostedLoggingEvents();

                    NodeManager nodeManager = localEngine.NodeManager;

                    // If the local engine is already shutting down, the TEM will be nulled out
                    if (nodeManager.TaskExecutionModule != null && nodeManager.TaskExecutionModule.TaskExecutionTime != 0)
                    {
                        TimeSpan taskTimeSpan = new TimeSpan(localEngine.NodeManager.TaskExecutionModule.TaskExecutionTime);
                        totalTaskTime = (int)taskTimeSpan.TotalMilliseconds;
                    }
                    localEngine.Shutdown();
                }
                // Flush all the events to the parent engine
                outProcLoggingService.ProcessPostedLoggingEvents();
                // Indicate that the node logger thread should exit
                exitNodeEvent.Set();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Constructor to init all data except for BinPath which is initialized separately because 
        /// a parameterless constructor is needed for COM interop
        /// </summary>
        internal Engine
        (
            int numberOfCpus, 
            bool isChildNode, 
            int parentNodeId, 
            string localNodeProviderParameters,
            BuildPropertyGroup globalProperties, 
            ToolsetDefinitionLocations locations
        )
        {
            // No need to check whether locations parameter 
            // is null, because it is a value type

            this.startupDirectory = Environment.CurrentDirectory;
            this.engineGlobalProperties = globalProperties == null ? new BuildPropertyGroup() : globalProperties;
            this.environmentProperties = new BuildPropertyGroup();
            this.toolsetStateMap = new Dictionary<string, ToolsetState>(StringComparer.OrdinalIgnoreCase);
            this.toolsets = new ToolsetCollection(this);

            // Every environment variable can be referenced just like a property
            // from the project file.  Here, we go ahead and add all the environment
            // variables to the property bag, so they can be treated just like any
            // other property later on.
            this.environmentProperties.GatherEnvironmentVariables();

            this.projectsLoadedByHost = new Hashtable(StringComparer.OrdinalIgnoreCase);

            this.cacheOfBuildingProjects = new ProjectManager();

            this.eventSource = new EventSource();

            this.buildEnabled = true;

            this.flushRequestEvent = new ManualResetEvent(false);

            this.primaryLoggingServices = new EngineLoggingServicesInProc(eventSource, false, flushRequestEvent);

            // Read any toolsets from the registry and config file
            PopulateToolsetStateMap(locations);

            this.nodeId = parentNodeId;
            this.localNodeProviderParameters = localNodeProviderParameters;
            this.numberOfCpus = numberOfCpus;

            if (this.numberOfCpus == 1 && !isChildNode)
            {
                this.primaryLoggingServices.FlushBuildEventsImmediatly = true;
            }

            this.buildRequests = new DualQueue<BuildRequest>();

            this.taskOutputUpdates = new DualQueue<TaskExecutionContext>();

            this.engineCommands = new DualQueue<EngineCommand>();

            this.engineCallback = new EngineCallback(this);
            this.nodeManager = new NodeManager(this.numberOfCpus, isChildNode, this);
            this.scheduler = new Scheduler(this.nodeId, this);
            this.router = new Router(this, scheduler);
            this.cacheManager = new CacheManager(this.DefaultToolsVersion);

            this.lastUsedLoggerId = EngineLoggingServicesInProc.FIRST_AVAILABLE_LOGGERID;

            this.enabledCentralLogging = false;

            this.introspector = new Introspector(this, cacheOfBuildingProjects, nodeManager);

            // Initialize the node provider
            InitializeLocalNodeProvider(locations);
        }