public LoadBalancer(Illuminate.Contexts.AgentContext context, string logName) { _dataService = context.NodeDataService; LOGNAME = logName; _sentWarningMessages = new Dictionary<string, List<LoadBalancingWarning.WarningTypeEnum>>(); _systemLoads = new Dictionary<string, Illuminate.Node.Entities.ISystemLoad>(); _nodeAgentManagement = new NodeAgentManagement(_dataService, LOGNAME); _nodeAgentManagement.OnSendWarning += new NodeAgentManagement.OnSendWarningDelegate(QueueWarningEmail); _warningMessages = new List<LoadBalancingWarning>(); _nodeWarningSendTime = new Dictionary<string, DateTime>(); string warningDisplayName = _dataService.Monitor.GetSetting(Illuminate.Node.Managers.Settings.LoadBalancerDisplayName); if (!string.IsNullOrEmpty(warningDisplayName)) _warningDisplayName = warningDisplayName; Logger.WriteLine("LoadBalancerDisplayName: " + _warningDisplayName, Logger.Severity.Debug, LOGNAME); _warningFromAddress = _dataService.Monitor.GetSetting(Illuminate.Node.Managers.Settings.LoadBalancerFromAddress); if (string.IsNullOrEmpty(_warningFromAddress)) throw new Illuminate.Exceptions.ErrorException("LoadBalancerFromAddress either not defined or invalid."); Logger.WriteLine("LoadBalancerFromAddress: " + _warningFromAddress, Logger.Severity.Debug, LOGNAME); _warningToAddress = _dataService.Monitor.GetSetting(Illuminate.Node.Managers.Settings.LoadBalancerWarningDest); if (string.IsNullOrEmpty(_warningToAddress)) throw new Illuminate.Exceptions.ErrorException("LoadBalancerWarningTo either not defined or invalid."); Logger.WriteLine("LoadBalancerWarningTo: " + _warningToAddress, Logger.Severity.Debug, LOGNAME); if (!int.TryParse(_dataService.Monitor.GetSetting(Illuminate.Node.Managers.Settings.MaxWaitBeforeDead), out _maxWaitBeforeDead)) throw new Illuminate.Exceptions.ErrorException("MaxWaitBeforeDead either not defined or invalid."); Logger.WriteLine("MaxWaitBeforeDead: " + _maxWaitBeforeDead.ToString(), Logger.Severity.Debug, LOGNAME); if (!double.TryParse(_dataService.Monitor.GetSetting(Illuminate.Node.Managers.Settings.OptimalSystemLoad), out _optimalSystemLoad)) throw new Illuminate.Exceptions.ErrorException("OptimalSystemLoad either not defined or invalid."); Logger.WriteLine("OptimalSystemLoad: " + _optimalSystemLoad.ToString(), Logger.Severity.Debug, LOGNAME); if (!double.TryParse(_dataService.Monitor.GetSetting(Illuminate.Node.Managers.Settings.OptimalLoadWindowSize), out _optimalLoadWindowSize)) throw new Illuminate.Exceptions.ErrorException("OptimalLoadWindowSize either not defined or invalid."); Logger.WriteLine("OptimalLoadWindowSize: " + _optimalLoadWindowSize.ToString(), Logger.Severity.Debug, LOGNAME); _optimalSystemLoadLowerBound = _optimalSystemLoad - _optimalLoadWindowSize; _optimalSystemLoadUpperBound = _optimalSystemLoad + _optimalLoadWindowSize; string extendedLoadBalancer = _dataService.Monitor.GetSetting(Illuminate.Node.Managers.Settings.ExtendedLoadBalancer); if (!string.IsNullOrEmpty(extendedLoadBalancer)) { Logger.WriteLine("ExtendedLoadBalancer: " + extendedLoadBalancer, Logger.Severity.Information, LOGNAME); try { Invoker inv = new Invoker(); _extendedLoadBalancer = (ILoadBalancer)inv.Invoke(context.AgentPath + extendedLoadBalancer, typeof(ILoadBalancer)); _extendedLoadBalancer.InitializePlugin(_dataService, LOGNAME); } catch (Exception ex) { Logger.WriteLine("Unable to load extended load balancer: " + ex.Message, Logger.Severity.Error, LOGNAME); _extendedLoadBalancer = null; } } //load initial data UpdateSystemLoadCache(); }
/// <summary> /// Initializes the Agent /// </summary> public void Initialize() { //try //{ _status = AgentStatus.Init; Logger.WriteLine("Initializing Agent...", Logger.Severity.Debug, LOGNAME); //Get the Agent from the event reference Illuminate.Tools.Invoker inv = new Illuminate.Tools.Invoker(); _agent = (Illuminate.Interfaces.IAgent)inv.Invoke(_agentPath, typeof(Illuminate.Interfaces.IAgent)); Logger.WriteLine("Agent Invoked...", Logger.Severity.Debug, LOGNAME); if (_agent != null) { Logger.WriteLine("Initializing Invoked Plugin...", Logger.Severity.Debug, LOGNAME); Logger.WriteLine("Starting Agent...", Logger.Severity.Debug); Contexts.AgentContext context = new Contexts.AgentContext(_nodeId, _sectionName, AgentId, _com, this); context.LogName = LOGNAME; _standard = (AgentStandard)_agent; _standard.InitializeAgent(context); _agent.InitializeAgent(context); Logger.WriteLine("Invoked Plugin Initialized...", Logger.Severity.Debug, LOGNAME); } else { Logger.WriteLine("Invoked Agent is NULL...", Logger.Severity.Debug, LOGNAME); } //} //catch (Exception e) //{ // _status = AgentStatus.ErrorInitializing; // string ErrorMsg = "Error trying to initialize agent: " + _agentPath + " " + e.Message.Replace("\r", "").Replace("\n", ""); // throw new Illuminate.Exceptions.ErrorException(ErrorMsg); //} }
private IAgent InvokeJob(string path) { Illuminate.Tools.Invoker invoker = new Illuminate.Tools.Invoker(); IAgent job; try { job = (IAgent)invoker.Invoke(path, typeof(IAgent)); } catch (System.IO.FileNotFoundException) { Logger.WriteLine("Active Job Agent was not able to find DLL: " + path, Logger.Severity.Error, LOGNAME); job = null; //treat unknown dll and not able to find the type in a dll as the same case } return job; }