/// <summary> /// The create rack server. /// </summary> /// <param name="model"> /// The model. /// </param> /// <returns> /// The <see cref="MPObject"/>. /// </returns> private MPObject CreateRackServer(RackServer model) { var propertys = this.RackClass.PropertyCollection; // 获取到class的属性 var obj = new MPObject(MGroup.Instance, this.RackClass); // 实例化一个class obj[this.HuaweiServerKey].Value = model.DeviceId; obj[propertys["Status"]].Value = model.StatusTxt; obj[propertys["iBMCIPv4Address"]].Value = model.iBMCIPv4Address; obj[propertys["Type"]].Value = model.Type; obj[propertys["UUID"]].Value = model.UUID; obj[propertys["AveragePower"]].Value = model.AveragePower; obj[propertys["PeakPower"]].Value = model.PeakPower; obj[propertys["PowerConsumption"]].Value = model.PowerConsumption; obj[propertys["DNSServerIP"]].Value = model.DNSServerIP; obj[propertys["DNSName"]].Value = model.DNSName; obj[propertys["ProductSn"]].Value = model.ProductSN; obj[propertys["HostName"]].Value = model.HostName; obj[propertys["CPUNums"]].Value = model.CPUNums; obj[propertys["CPUCores"]].Value = model.CPUCores; obj[propertys["CPUModel"]].Value = model.CPUModel; obj[propertys["MemoryCapacity"]].Value = model.MemoryCapacity; obj[propertys["BMCVersion"]].Value = model.BMCVersion; obj[propertys["AssertTag"]].Value = model.AssertTag; obj[propertys["ServerName"]].Value = model.ServerName; obj[propertys["eSight"]].Value = model.ESight; obj[this.DisplayNameField].Value = model.ServerName; return(obj); }
/// <summary> /// The create rack server. /// </summary> /// <param name="model"> /// The model. /// </param> /// <returns> /// The <see cref="MPObject"/>. /// </returns> private MPObject CreateRackServer(RackServer model) { var propertys = this.RackClass.PropertyCollection; // 获取到class的属性 var obj = new MPObject(MGroup.Instance, this.RackClass); // 实例化一个class obj[this.HuaweiServerKey].Value = model.DN; obj[propertys["Status"]].Value = model.Status; obj[propertys["Vendor"]].Value = "HUAWEI"; obj[propertys["Manufacturer"]].Value = model.Manufacturer; obj[propertys["UUID"]].Value = model.UUID; obj[propertys["IPAddress"]].Value = model.IpAddress; obj[propertys["iBMCVersion"]].Value = model.Version; obj[propertys["CPLDVersion"]].Value = string.Empty; obj[propertys["UbootVersion"]].Value = string.Empty; obj[propertys["ProductSn"]].Value = model.ProductSN; obj[propertys["MemoryCapacity"]].Value = model.MemoryCapacity; obj[propertys["CPUNums"]].Value = model.CPUNums; obj[propertys["CPUCores"]].Value = model.CPUCores; obj[propertys["ServerName"]].Value = model.ServerName; obj[propertys["BMCMacAddr"]].Value = model.BmcMacAddr; obj[propertys["eSight"]].Value = model.ESight; obj[this.DisplayNameField].Value = model.Name; return(obj); }
/// <summary> /// Synchronizes the server. /// </summary> /// <param name="model">The model.</param> public void SyncServer(RackServer model) { // 存在则更新 if (ExsitsRackServer(model.DeviceId)) { this.UpdateRack(model, true); } else { this.InsertDetials(model); } }
/// <summary> /// 更新机架 /// </summary> /// <param name="model">The model.</param> public void UpdateRackServer(HWDeviceDetail model) { try { var server = new RackServer(); server.MakeDetail(model, this.ESightIp); RackConnector.Instance.UpdateRack(server); } catch (Exception ex) { this.OnNotifyError($"UpdateRackServer Error.eSight:{this.ESightIp} Dn:{model.DN}. ", ex); } }
/// <summary> /// 更新机架 /// </summary> /// <param name="model">The model.</param> /// <param name="alarmSn">The alarm sn.</param> private void UpdateRackServer(HWDeviceDetail model, int alarmSn) { try { logger.NotifyProcess.Info($"Start Update RackServer:{model.DN}"); var server = new RackServer(); server.MakeDetail(model, this.ESightIp); RackConnector.Instance.UpdateRack(server, false); } catch (Exception ex) { logger.NotifyProcess.Error(ex, $"UpdateRackServer Error.Dn:{model.DN}.[alarmSn:{alarmSn}]"); } }
/// <summary> /// The insert detials. /// </summary> /// <param name="model"> /// The model. /// </param> private void InsertDetials(RackServer model) { try { HWLogger.GetESightSdkLogger(model.ESight).Debug($"Insert Rack:{model.DN}"); var discoveryData = new IncrementalDiscoveryData(); var rackServer = this.CreateRackServer(model); discoveryData.Add(rackServer); discoveryData.Commit(this.MontioringConnector); } catch (Exception e) { HWLogger.GetESightSdkLogger(model.ESight).Error($"Insert (Rack Error:{model.DN}", e); } }
/// <summary> /// The update rack. /// </summary> /// <param name="model">The model.</param> /// <param name="isPolling">是否是轮询</param> /// <exception cref="System.Exception"></exception> /// <exception cref="Exception"></exception> public void UpdateRack(RackServer model, bool isPolling) { try { HWLogger.GetESightSdkLogger(model.ESight).Debug($"Start UpdateRack. [{model.DN}] [isPolling:{isPolling}]"); var oldBlade = this.GetRackServer(model.DeviceId); if (oldBlade == null) { throw new Exception($"Can not find the server:{model.DN}"); } var propertys = this.RackClass.PropertyCollection; // 获取到class的属性 var discoveryData = new IncrementalDiscoveryData(); oldBlade[this.DisplayNameField].Value = model.ServerName; if (model.Status != "-3") { oldBlade[propertys["Status"]].Value = model.StatusTxt; } oldBlade[propertys["iBMCIPv4Address"]].Value = model.iBMCIPv4Address; oldBlade[propertys["Type"]].Value = model.Type; oldBlade[propertys["UUID"]].Value = model.UUID; oldBlade[propertys["AveragePower"]].Value = model.AveragePower; oldBlade[propertys["PeakPower"]].Value = model.PeakPower; oldBlade[propertys["PowerConsumption"]].Value = model.PowerConsumption; oldBlade[propertys["DNSServerIP"]].Value = model.DNSServerIP; oldBlade[propertys["DNSName"]].Value = model.DNSName; oldBlade[propertys["ProductSn"]].Value = model.ProductSN; oldBlade[propertys["HostName"]].Value = model.HostName; oldBlade[propertys["CPUNums"]].Value = model.CPUNums; oldBlade[propertys["CPUCores"]].Value = model.CPUCores; oldBlade[propertys["CPUModel"]].Value = model.CPUModel; oldBlade[propertys["MemoryCapacity"]].Value = model.MemoryCapacity; oldBlade[propertys["AssertTag"]].Value = model.AssertTag; if (isPolling) { oldBlade[propertys["BMCVersion"]].Value = model.BMCVersion; } oldBlade[propertys["eSight"]].Value = model.ESight; discoveryData.Add(oldBlade); discoveryData.Overwrite(this.MontioringConnector); } catch (Exception e) { HWLogger.GetESightSdkLogger(model.ESight).Error($"Update UpdateRack Error.[{model.DN}] [isPolling:{isPolling}]", e); } }
/// <summary> /// 查询机架列表 /// </summary> /// <param name="startPage">The start page.</param> /// <returns>机架列表</returns> public ApiServerList <RackServer> QueryRackServer(int startPage) { var result = new ApiServerList <RackServer>(); var queryDeviceParam = new DeviceParam() { PageSize = 100, StartPage = startPage, ServerType = "rack" }; var reqResult = this.GetServerList(queryDeviceParam); reqResult.Data.ForEach(x => { RackServer rackServer = new RackServer(x); result.Data.Add(rackServer); }); result.TotalSize = reqResult.TotalSize; result.TotalPage = reqResult.TotalPage; return(result); }
/// <summary> /// Queries the rack detial. /// </summary> /// <param name="rack">The rack.</param> public void QueryRackDetial(RackServer rack) { var task = Task.Run(() => { try { var device = this.Session.GetServerDetails(rack.DN); rack.MakeDetail(device, this.ESightIp); RackConnector.Instance.InsertDetials(rack); } catch (Exception ex) { this.OnError($"QueryRackDetial Error: {rack.DN}", ex); } }); this.taskList.Add(task); }
/// <summary> /// Queries the rack detial. /// </summary> /// <param name="rack">The rack.</param> private void QueryRackDetial(RackServer rack) { var task = taskFactory.StartNew(() => { try { var device = this.Session.GetServerDetails(rack.DN); rack.MakeDetail(device, this.ESightIp); RackConnector.Instance.SyncServer(rack); } catch (Exception ex) { OnPollingError($"QueryRackDetial Error: {rack.DN}", ex); } }, cts.Token); this.taskList.Add(task); }
/// <summary> /// The update rack. /// </summary> /// <param name="model"> /// The model. /// </param> /// <exception cref="Exception"> /// Can not find the server /// </exception> public void UpdateRack(RackServer model) { HWLogger.NOTIFICATION_PROCESS.Debug($"Start UpdateRack {model.DN}"); var oldBlade = this.GetRackServer(model.DN); if (oldBlade == null) { throw new Exception($"Can not find the server:{model.DN}"); } var propertys = this.RackClass.PropertyCollection; // 获取到class的属性 var discoveryData = new IncrementalDiscoveryData(); oldBlade[this.DisplayNameField].Value = model.Name; oldBlade[propertys["Status"]].Value = model.Status; oldBlade[propertys["Vendor"]].Value = "HUAWEI"; oldBlade[propertys["Manufacturer"]].Value = model.Manufacturer; oldBlade[propertys["UUID"]].Value = model.UUID; oldBlade[propertys["IPAddress"]].Value = model.IpAddress; // oldBlade[propertys["iBMCVersion"]].Value = model.Version; oldBlade[propertys["CPLDVersion"]].Value = string.Empty; oldBlade[propertys["UbootVersion"]].Value = string.Empty; oldBlade[propertys["ProductSn"]].Value = model.ProductSN; oldBlade[propertys["MemoryCapacity"]].Value = model.MemoryCapacity; oldBlade[propertys["CPUNums"]].Value = model.CPUNums; oldBlade[propertys["CPUCores"]].Value = model.CPUCores; // oldBlade[propertys["ServerName"]].Value = model.ServerName; oldBlade[propertys["BMCMacAddr"]].Value = model.BmcMacAddr; oldBlade[propertys["eSight"]].Value = model.ESight; discoveryData.Add(oldBlade); var fanGroup = oldBlade.GetRelatedMonitoringObjects(this.FanGroupClass).First(); discoveryData.Add(fanGroup); var relatedFanObjects = fanGroup.GetRelatedMonitoringObjects(this.FanClass); var deleteFan = relatedFanObjects.Where( x => model.FanList.All(y => y.UUID != x[this.FanClass.PropertyCollection["UUID"]].Value.ToString())) .ToList(); deleteFan.ForEach(x => { discoveryData.Remove(x); }); model.FanList.ForEach( x => { var fan = this.UpdateFan(x); if (fan == null) { var newFan = this.CreateFan(x); newFan[this.ComputerKey].Value = model.DN; newFan[this.HuaweiServerKey].Value = model.DN; newFan[this.PartGroupKey].Value = fanGroup[this.PartGroupKey].Value; discoveryData.Add(newFan); } else { discoveryData.Add(fan); } }); var psuGroup = oldBlade.GetRelatedMonitoringObjects(this.PowerSupplyGroupClass).First(); discoveryData.Add(psuGroup); var relatedPsuObjects = psuGroup.GetRelatedMonitoringObjects(this.PowerSupplyClass); var deletePsu = relatedPsuObjects.Where( x => model.PowerSupplyList.All( y => y.UUID != x[this.PowerSupplyClass.PropertyCollection["UUID"]].Value.ToString())).ToList(); deletePsu.ForEach(x => { discoveryData.Remove(x); }); model.PowerSupplyList.ForEach( x => { var psu = this.UpdatePowerSupply(x); if (psu == null) { var newpsu = this.CreatePowerSupply(x); newpsu[this.ComputerKey].Value = model.DN; newpsu[this.HuaweiServerKey].Value = model.DN; newpsu[this.PartGroupKey].Value = psuGroup[this.PartGroupKey].Value; discoveryData.Add(newpsu); } else { discoveryData.Add(psu); } }); #region CPU var cpuGroup = oldBlade.GetRelatedMonitoringObjects(this.CpuGroupClass).First(); discoveryData.Add(cpuGroup); var relatedCpuObjects = cpuGroup.GetRelatedMonitoringObjects(this.CpuClass); var deleteCpu = relatedCpuObjects.Where( x => model.CPUList.All(y => y.UUID != x[this.CpuClass.PropertyCollection["UUID"]].Value.ToString())) .ToList(); deleteCpu.ForEach(x => { discoveryData.Remove(x); }); model.CPUList.ForEach( y => { var cpu = this.UpdateCpu(y); if (cpu == null) { var newCpu = this.CreateCpu(y); newCpu[this.ComputerKey].Value = model.DN; newCpu[this.HuaweiServerKey].Value = model.DN; newCpu[this.PartGroupKey].Value = cpuGroup[this.PartGroupKey].Value; discoveryData.Add(newCpu); } else { discoveryData.Add(cpu); } }); #endregion #region Memory var memoryGroup = oldBlade.GetRelatedMonitoringObjects(this.MemoryGroupClass).First(); discoveryData.Add(memoryGroup); var relatedMemoryObjects = memoryGroup.GetRelatedMonitoringObjects(this.MemoryClass); var deleteMemory = relatedMemoryObjects.Where( x => model.MemoryList.All( y => y.UUID != x[this.MemoryClass.PropertyCollection["UUID"]].Value.ToString())).ToList(); deleteMemory.ForEach(x => { discoveryData.Remove(x); }); model.MemoryList.ForEach( y => { var memory = this.UpdateMemory(y); if (memory == null) { var newMemory = this.CreateMemory(y); newMemory[this.ComputerKey].Value = model.DN; newMemory[this.HuaweiServerKey].Value = model.DN; newMemory[this.PartGroupKey].Value = memoryGroup[this.PartGroupKey].Value; discoveryData.Add(newMemory); } else { discoveryData.Add(memory); } }); #endregion #region Disk var diskGroup = oldBlade.GetRelatedMonitoringObjects(this.PhysicalDiskGroupClass).First(); discoveryData.Add(diskGroup); var relatedDiskObjects = diskGroup.GetRelatedMonitoringObjects(this.PhysicalDiskClass); var deleteDisk = relatedDiskObjects.Where( x => model.DiskList.All( y => y.UUID != x[this.PhysicalDiskClass.PropertyCollection["UUID"]].Value.ToString())).ToList(); deleteDisk.ForEach(x => { discoveryData.Remove(x); }); model.DiskList.ForEach( y => { var disk = this.UpdateDisk(y); if (disk == null) { var newDisk = this.CreateDisk(y); newDisk[this.ComputerKey].Value = model.DN; newDisk[this.HuaweiServerKey].Value = model.DN; newDisk[this.PartGroupKey].Value = diskGroup[this.PartGroupKey].Value; discoveryData.Add(newDisk); } else { discoveryData.Add(disk); } }); #endregion #region Raid var raidGroup = oldBlade.GetRelatedMonitoringObjects(this.RaidGroupClass).First(); discoveryData.Add(raidGroup); var relatedRaidObjects = raidGroup.GetRelatedMonitoringObjects(this.RaidClass); var deleteRaid = relatedRaidObjects.Where( x => model.RaidList.All( y => y.UUID != x[this.RaidClass.PropertyCollection["UUID"]].Value.ToString())) .ToList(); deleteRaid.ForEach(x => { discoveryData.Remove(x); }); model.RaidList.ForEach( y => { var raid = this.UpdateRaidControl(y); if (raid == null) { var newRaid = this.CreateRaidControl(y); newRaid[this.ComputerKey].Value = model.DN; newRaid[this.HuaweiServerKey].Value = model.DN; newRaid[this.PartGroupKey].Value = raidGroup[this.PartGroupKey].Value; discoveryData.Add(newRaid); } else { discoveryData.Add(raid); } }); #endregion discoveryData.Overwrite(this.MontioringConnector); HWLogger.NOTIFICATION_PROCESS.Debug($"End UpdateRack {model.DN}"); }
/// <summary> /// The insert detials. /// </summary> /// <param name="model"> /// The model. /// </param> public void InsertDetials(RackServer model) { var discoveryData = new IncrementalDiscoveryData(); var baseComputer = this.GetComputerByDn(model.DN); if (baseComputer == null) { var newBaseComputer = this.CreateComputer(model.DN); discoveryData.Add(newBaseComputer); } else { discoveryData.Add(baseComputer); } var rackServer = this.CreateRackServer(model); rackServer[this.ComputerKey].Value = model.DN; discoveryData.Add(rackServer); #region Fan var fanGroup = this.CreateLogicalGroup(this.FanGroupClass, model.DN); discoveryData.Add(fanGroup); model.FanList.ForEach( x => { var fan = this.CreateFan(x); fan[this.PartGroupKey].Value = fanGroup[this.PartGroupKey].Value; fan[this.HuaweiServerKey].Value = model.DN; fan[this.ComputerKey].Value = model.DN; discoveryData.Add(fan); }); #endregion #region PSU var powerSupplyGroup = this.CreateLogicalGroup(this.PowerSupplyGroupClass, model.DN); discoveryData.Add(powerSupplyGroup); model.PowerSupplyList.ForEach( x => { var powerSupply = this.CreatePowerSupply(x); powerSupply[this.PartGroupKey].Value = powerSupplyGroup[this.PartGroupKey].Value; powerSupply[this.HuaweiServerKey].Value = model.DN; powerSupply[this.ComputerKey].Value = model.DN; discoveryData.Add(powerSupply); }); #endregion #region Raid var raidGroup = this.CreateLogicalGroup(this.RaidGroupClass, model.DN); discoveryData.Add(raidGroup); model.RaidList.ForEach( y => { var raid = this.CreateRaidControl(y); raid[this.PartGroupKey].Value = raidGroup[this.PartGroupKey].Value; raid[this.HuaweiServerKey].Value = model.DN; raid[this.ComputerKey].Value = model.DN; discoveryData.Add(raid); }); #endregion #region CPU var cpuGroup = this.CreateLogicalGroup(this.CpuGroupClass, model.DN); discoveryData.Add(cpuGroup); model.CPUList.ForEach( x => { var cpu = this.CreateCpu(x); cpu[this.PartGroupKey].Value = cpuGroup[this.PartGroupKey].Value; cpu[this.HuaweiServerKey].Value = model.DN; cpu[this.ComputerKey].Value = model.DN; discoveryData.Add(cpu); }); #endregion #region Memory var memoryGroup = this.CreateLogicalGroup(this.MemoryGroupClass, model.DN); discoveryData.Add(memoryGroup); model.MemoryList.ForEach( x => { var memory = this.CreateMemory(x); memory[this.PartGroupKey].Value = memoryGroup[this.PartGroupKey].Value; memory[this.HuaweiServerKey].Value = model.DN; memory[this.ComputerKey].Value = model.DN; discoveryData.Add(memory); }); #endregion #region Disk var diskGroup = this.CreateLogicalGroup(this.PhysicalDiskGroupClass, model.DN); discoveryData.Add(diskGroup); model.DiskList.ForEach( x => { var disk = this.CreateDisk(x); disk[this.PartGroupKey].Value = diskGroup[this.PartGroupKey].Value; disk[this.HuaweiServerKey].Value = model.DN; disk[this.ComputerKey].Value = model.DN; discoveryData.Add(disk); }); #endregion if (!this.ExsitsRackServer(model.DN)) { discoveryData.Commit(this.MontioringConnector); } else { discoveryData.Overwrite(this.MontioringConnector); } }