public void ProcessNodeHealthMessage(NodeInformationMessage nodeInformationMessage) { try { log.Debug("Got the node info from node :" + nodeInformationMessage.NodeName); var nodeInformation = new NodeInfo() { CpuUsage = nodeInformationMessage.CpuUsage, LastCheckinTime = DateTime.UtcNow, NodeAddress = nodeInformationMessage.NodeAddress, NodeId = nodeInformationMessage.NodeId, NodeName = nodeInformationMessage.NodeName, NodePort = nodeInformationMessage.NodePort, NodeType = nodeInformationMessage.NodeType, NumberOfActorsRunning = nodeInformationMessage.NumberOfRunningTask, RegistedActors = nodeInformationMessage.Actros }; if (StaticProperties.NextMasterSelectionManager.NodeId != null) { lock (StaticProperties.NextMasterSelectionManager) { if (StaticProperties.NextMasterSelectionManager.NodeId != null) { StaticProperties.NextMasterSelectionManager = nodeInformation; } } } StaticProperties.HostedNodes.AddOrUpdate( nodeInformation.NodeName, nodeInformation, (key, oldValue) => nodeInformation); TaskMessage taskMessage = null; lock (StaticProperties.TaskMessages) { StaticProperties.TaskMessages.FirstOrDefault(m => nodeInformation.RegistedActors.Any(a => a.ActorName == m.Actor)); } if (taskMessage != null) { Task.Factory.StartNew(async() => { MasterTaskMessageManager masterTaskManager = new MasterTaskMessageManager(); var result = await masterTaskManager.SendTaskToNode(taskMessage, nodeInformation.NodeAddress); if (result) { lock (StaticProperties.TaskMessages) { StaticProperties.TaskMessages.Remove(taskMessage); } } }, CancellationToken.None, TaskCreationOptions.None, TaskSchedulersHolder.SchedulerToSendMissedTaskToNode); } } catch (Exception ex) { log.Error(ex); } }
private async void _SendHealthInfoToMaster() { if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { return; } if (IS_SENDNODEHEALTH_IN_PROGRESS) { return; } IS_SENDNODEHEALTH_IN_PROGRESS = true; int retryCount = 1; RETRY: var nodeInformationMessage = new NodeInformationMessage(); nodeInformationMessage.NodeAddress = StaticProperties.NodeConfig.NodeAddress; nodeInformationMessage.CpuUsage = CpuCounter.NextValue(); lock (StaticProperties.RunningActors) { nodeInformationMessage.NumberOfRunningTask = StaticProperties.RunningActors.Count; } // nodeInformationMessage.RamUsage=Process.GetCurrentProcess(). nodeInformationMessage.NodeId = StaticProperties.NodeConfig.NodeId; nodeInformationMessage.NodeName = StaticProperties.NodeConfig.NodeName; nodeInformationMessage.NodeAddress = "http://" + StaticProperties.NodeConfig.NodeAddress + ":" + StaticProperties.NodeConfig.NodePort; nodeInformationMessage.Actros = StaticProperties.NodeConfig.Actors.Select(a => new NetServeNodeEntity.Actors.ActorModel() { ActorName = a }).ToList(); var result = await this._httpWrapper.DoHttpPost <string, NodeInformationMessage>( StaticProperties.NodeConfig.MasterNodeUri + "/" + SEND_HEALTHINFO_ENDPOINT, nodeInformationMessage); if (result == "OK") { IS_SENDNODEHEALTH_IN_PROGRESS = false; return; } else { if (retryCount < 3) { goto RETRY; } else { SendNodeInfoToMasterTimer.Stop(); this._BroadCastMasterDead(); } } IS_SENDNODEHEALTH_IN_PROGRESS = false; }
public Task <string> IamNode([FromBody] NodeInformationMessage nodeInformationMessage) { this._masterManager.ProcessNodeHealthMessage(nodeInformationMessage); return(Task.FromResult("OK")); }