Exemple #1
0
        public Task <IActionResult> HeartBeat(NodeHeartBeatModel model)
        {
            return(this.ResultAsync(async() =>
            {
                bool ret = false;
                if (model.IsModelValid())
                {
                    INodeModel node = null;
                    if (!String.IsNullOrEmpty(model.Address))
                    {
                        node = await this.Db.Nodes.GetBy(model.Address);
                        if (null != node)
                        {
                            node.CopyPropertiesFrom(model);
                            node.LastConnectionTime = DateTime.Now;

                            var usage = NodeResourceUsages.Instance.Get(node.Address);
                            usage.Add(node.CpuUsage, node.MemoryUsage);

                            node.CpuUsage = usage.CpuUsage;
                            node.MemoryUsage = usage.MemoryUsage;
                            node.TotalBeatsCount = usage.TotalBeatsCount;

                            await this.Db.Nodes.Save(node);

                            ret = true;
                        }
                    }
                }

                return ret;
            }));
        }
Exemple #2
0
        public Task <IActionResult> Register([FromBody] NodeRegisterModel node)
        {
            return(this.ResultAsync(async() =>
            {
                bool ret = false;
                if (node.IsModelValid())
                {
                    INodeModel model = null;
                    if (!String.IsNullOrEmpty(node.Address))
                    {
                        model = await this.Db.Nodes.GetBy(node.Address);
                    }

                    if (null == model)
                    {
                        model = this.Db.ModelFactory.CreateNodeModel();
                    }

                    model.CopyPropertiesFrom(node);

                    model.ConnectionStatus = NodeConnectionStatus.Online;
                    model.LastConnectionTime = DateTime.Now;

                    model.CpuUsage = 0;
                    model.MemoryUsage = 0;
                    model.TotalBeatsCount = 0;

                    model = await this.Db.Nodes.Save(model);

                    NodeResourceUsages.Instance.Get(model.Address)?.Reset();

                    _ = this.HandleOfflineData(node.Address);

                    ret = true;

                    if (!_hasAny)
                    {
                        _hasAny = true;
                        StartNanoServices();
                    }
                }

                return ret;
            }));
        }