Ejemplo n.º 1
0
        public void Should_Execute_Plugin()
        {
            IBroker      broker = new Broker();
            IAgentEngine agent  = new AgentEngine( );
            IAllocationDefinition definition = new AllocationDefinition(2);
            IExecutionSlot slot = new ExecutionSlot(definition);

            broker.Add(agent);
            agent.PluginManager.Install(definition);
            agent.ExecutionManager.Add( slot );

            definition.Add(DTO.NewPluginInfoTestPlugin);

            IPlugin completedPlugin = null;
            TestPlugin testPlugin = new TestPlugin(100);

            broker.ExecuteCompleted += delegate(object sender, ObjectEventArgs<IPlugin> eventArgs)
                                        {
                                            completedPlugin = eventArgs.EventObject;
                                        };

            broker.Execute(testPlugin);

            Assert.AreEqual(slot, agent.ExecutionManager[definition]);
            Assert.AreEqual(1, agent.ExecutionManager[definition].UsedSlots, "Slots Used");

            Timing.WaitWhile(() => completedPlugin == null, 1000);

            Assert.AreEqual(testPlugin, completedPlugin);
            Assert.AreEqual(0, agent.ExecutionManager[definition].UsedSlots);
            Assert.AreEqual(PluginStatus.Executed, testPlugin.Status);
        }
Ejemplo n.º 2
0
        protected override void OnStart( string[] args )
        {
            try
            {
                Logging.Instance.Write("Service OnStart");

                if (_Controller != null)
                    OnStop();

                Logging.Instance.Write("Service OnStart - Initializing Controller");

                _Controller = new ControllerEngine(true);

                Logging.Instance.Write("Service OnStart - Controller Initialized");

                IAgent agent = new AgentEngine();

                Logging.Instance.Write("Service OnStart - Agent");

                IAllocationDefinition definition = new AllocationDefinition(2);

                Logging.Instance.Write("Service OnStart - Definition");

                using( OctopusDataContext db = new OctopusDataContext() )
                {
                    Logging.Instance.Write("Service OnStart - Data context");

                    foreach( IPluginInfo pluginInfo in db.PluginInfo_GetAll() )
                    {
                        Logging.Instance.Write("Service OnStart - Adding plugininfo");

                        definition.Add( pluginInfo );

                        Logging.Instance.Write("Service OnStart - PluginInfo added");
                    }
                }

                agent.AddDefinition(definition);

                Logging.Instance.Write("Service OnStart - Definition added");

                _Controller.Broker.Add(agent);

                Logging.Instance.Write("Service OnStart - Agent Added");
            }
            catch (Exception e)
            {
                Logging.Instance.Write("Octopus: {0}, \nStacktrace: {1}", e.Message, e.StackTrace);

                throw;
            }

            Logging.Instance.Write("Service OnStart - Ended");
        }
Ejemplo n.º 3
0
        public AgentEngine( int settingsID ):this(  )
        {
            using( DatabaseDataContext db = new DatabaseDataContext() )
            {
                foreach (var executionSlotData in db.ExecutionSlot_GetBy( null, settingsID, null, null ) )
                {
                    IAllocationDefinition definition = new AllocationDefinition(Convert.ToUInt32(executionSlotData.MaxSlots));

                    foreach (var pluginInfo in db.PluginInfo_GetBy(null, executionSlotData.ID, null, null, null, null, null, null, null, null))
                        definition.Add(pluginInfo);

                    AddDefinition( definition );
                }
            }
        }
Ejemplo n.º 4
0
        public void Should_Send_Queued_Plugins_To_AgentBroker()
        {
            using( IControllerEngine controllerEngine = new ControllerEngine( true ) )
            {
                IAgent                agent      = new AgentEngine();
                IAllocationDefinition definition = new AllocationDefinition(3);

                definition.Add( DTO.NewPluginInfoTestPlugin );
                agent.AddDefinition( definition );

                controllerEngine.Broker.Add( agent );
                controllerEngine.JobManager.SynchronizeOnce();

                Timing.WaitUntil(() => controllerEngine.Broker.GetPluginsOnAgents().ToList().Count > 0, 10000, "Broker has plugins");

                Assert.Greater(controllerEngine.Broker.GetPluginsOnAgents().ToList().Count, 0);
            }
        }
Ejemplo n.º 5
0
        public void Should_Send_A_Job_To_Commit_When_All_Plugins_Are_Executed()
        {
            using (IControllerEngine controllerEngine = new ControllerEngine(true))
            {
                IAgent agent = new AgentEngine();
                IAllocationDefinition definition = new AllocationDefinition(3);

                definition.Add(DTO.NewPluginInfoTestPlugin);
                agent.AddDefinition(definition);
                controllerEngine.Broker.Add(agent);
                controllerEngine.JobManager.SynchronizeOnce();

                Timing.WaitUntil(delegate
                                 	{
                                        if( controllerEngine.JobManager.Count == 0 )
                                            return false;

                                 		foreach (IJob job in controllerEngine.JobManager)
                                 		{
                                 			foreach (IPlugin plugin in job.GetAllPlugins())
                                 			{
                                 				if (plugin.Status != PluginStatus.Committed)
                                 					return false;
                                 			}
                                 		}

                                 		return true;
                                 	}, 20000, "Testing if all plugins are committed");

                IList<IPlugin> plugins = new List<IPlugin>();
                IList<IPlugin> executedPlugins = new List<IPlugin>();

                foreach (IJob job in controllerEngine.JobManager)
                {
                    foreach (IPlugin plugin in job.GetAllPlugins())
                    {
                        if (plugin.Status == PluginStatus.Committed)
                            executedPlugins.Add(plugin);

                        plugins.Add(plugin);
                    }
                }

                Assert.AreEqual(11, plugins.Count);
                Assert.AreEqual(plugins.Count, executedPlugins.Count, "Total should be equal comitted count");
            }
        }
Ejemplo n.º 6
0
        public void Should_Rollback_Plugins_If_Error_Occurs()
        {
            using (IControllerEngine controllerEngine = new ControllerEngine(true))
            {
                IAgent                agent      = new AgentEngine();
                IAllocationDefinition definition = new AllocationDefinition(3);
                IJob                  job        = new Job(DTO.ErrorJobData);

                definition.Add( DTO.NewPluginInfoTestPlugin  );
                definition.Add( DTO.NewPluginInfoTestPlugin2 );

                agent.AddDefinition( definition );
                controllerEngine.Broker.Add( agent );

                _DB.Job_Insert( job.StatusID, job.JobXML.ToString() );
                controllerEngine.JobManager.SynchronizeOnce();

                bool isCompleted = false;
                bool isFailed    = false;
                bool isSynced    = false;

                controllerEngine.JobManager.SyncCompleted += (sender, eventArgs) => isSynced    = true;

                Timing.WaitUntil(() => isSynced, 20000, "Waiting for the sync failed");

                controllerEngine.JobManager.Last().JobRolledback   += (sender, eventArgs) => isCompleted = true;
                controllerEngine.JobManager.Last().JobCommitFailed += (sender, eventArgs) => isFailed    = true;

                Timing.WaitUntil( () => isCompleted, 20000, "Wait til last job rolledback");

                controllerEngine.JobManager.SynchronizeOnce();

                Assert.IsTrue(isCompleted);
                Assert.IsFalse(isFailed, "Rollback failed");
            }
        }
Ejemplo n.º 7
0
        public void Should_Throw_Exception_When_No_Slots_Are_Available_For_Rollback()
        {
            IBroker broker = new Broker();
            IAgentEngine agent = new AgentEngine();
            IAllocationDefinition definition = new AllocationDefinition(2);
            IExecutionSlot slot = new ExecutionSlot(definition);

            broker.Add(agent);
            definition.Add(DTO.NewPluginInfoTestPlugin);
            agent.PluginManager.Install(definition);
            agent.ExecutionManager.Add(slot);

            broker.Rollback(new TestPlugin(600));
            broker.Rollback(new TestPlugin(600));
            broker.Rollback(new TestPlugin(600));
        }