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"); }
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); } }
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"); } }
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"); } }