mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-21 07:49:32 +01:00
Removed id from the DataSet constructor parameters. It can be constructed from the XenObject and the datasource name.
Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
a0bd8a7d46
commit
a95aeceed4
@ -33,6 +33,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
@ -443,8 +444,7 @@ namespace XenAdmin.Controls.CustomDataGraph
|
|||||||
if (LastNode == "name")
|
if (LastNode == "name")
|
||||||
{
|
{
|
||||||
string str = reader.ReadContentAsString();
|
string str = reader.ReadContentAsString();
|
||||||
string id = string.Format("{0}:{1}:{2}", xmo is Host ? "host" : "vm", Helpers.GetUuid(xmo), str);
|
SetsAdded.Add(DataSet.Create(xmo, false, str));
|
||||||
SetsAdded.Add(DataSet.Create(id, xmo, false, str));
|
|
||||||
}
|
}
|
||||||
else if (LastNode == "step")
|
else if (LastNode == "step")
|
||||||
{
|
{
|
||||||
@ -509,7 +509,29 @@ namespace XenAdmin.Controls.CustomDataGraph
|
|||||||
if (LastNode == "entry")
|
if (LastNode == "entry")
|
||||||
{
|
{
|
||||||
string str = reader.ReadContentAsString();
|
string str = reader.ReadContentAsString();
|
||||||
SetsAdded.Add(DataSet.Create(str, xo));
|
DataSet set = null;
|
||||||
|
|
||||||
|
if (DataSet.ParseId(str, out string objType, out string objUuid, out string dataSourceName))
|
||||||
|
{
|
||||||
|
if (objType == "host")
|
||||||
|
{
|
||||||
|
Host host = xo.Connection.Cache.Hosts.FirstOrDefault(h => h.uuid == objUuid);
|
||||||
|
if (host != null)
|
||||||
|
set = DataSet.Create(host, (xo as Host)?.uuid != objUuid, dataSourceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objType == "vm")
|
||||||
|
{
|
||||||
|
VM vm = xo.Connection.Cache.VMs.FirstOrDefault(v => v.uuid == objUuid);
|
||||||
|
if (vm != null)
|
||||||
|
set = DataSet.Create(vm, (xo as VM)?.uuid != objUuid, dataSourceName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (set == null)
|
||||||
|
set = DataSet.Create(null, true, str);
|
||||||
|
|
||||||
|
SetsAdded.Add(set);
|
||||||
}
|
}
|
||||||
else if (LastNode == "t")
|
else if (LastNode == "t")
|
||||||
{
|
{
|
||||||
|
@ -110,7 +110,7 @@ namespace XenAdmin.Controls.CustomDataGraph
|
|||||||
foreach (DataSet set in SetsAdded)
|
foreach (DataSet set in SetsAdded)
|
||||||
{
|
{
|
||||||
Palette.LoadSetColor(set);
|
Palette.LoadSetColor(set);
|
||||||
DataSet copy = DataSet.Create(set.Id, set.XenObject, set.Hide, set.DataSourceName);
|
DataSet copy = DataSet.Create(set.XenObject, set.Hide, set.DataSourceName);
|
||||||
foreach (DataPoint p in set.Points)
|
foreach (DataPoint p in set.Points)
|
||||||
copy.AddPoint(new DataPoint(p.X,p.Y));
|
copy.AddPoint(new DataPoint(p.X,p.Y));
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ namespace XenAdmin.Controls.CustomDataGraph
|
|||||||
public bool Selected;
|
public bool Selected;
|
||||||
public List<DataPoint> CurrentlyDisplayed = new List<DataPoint>();
|
public List<DataPoint> CurrentlyDisplayed = new List<DataPoint>();
|
||||||
public IXenObject XenObject;
|
public IXenObject XenObject;
|
||||||
public readonly string Id;
|
public readonly string Id = "";
|
||||||
public string DataSourceName;
|
public string DataSourceName;
|
||||||
public string FriendlyName { get; }
|
public string FriendlyName { get; }
|
||||||
private int MultiplyingFactor = 1;
|
private int MultiplyingFactor = 1;
|
||||||
@ -61,13 +61,17 @@ namespace XenAdmin.Controls.CustomDataGraph
|
|||||||
public bool Hide { get; }
|
public bool Hide { get; }
|
||||||
|
|
||||||
|
|
||||||
private DataSet(string id, IXenObject xo, bool hide, string datasourceName)
|
private DataSet(IXenObject xo, bool hide, string datasourceName)
|
||||||
{
|
{
|
||||||
XenObject = xo;
|
XenObject = xo;
|
||||||
Hide = hide;
|
Hide = hide;
|
||||||
Id = id;
|
|
||||||
DataSourceName = datasourceName;
|
DataSourceName = datasourceName;
|
||||||
|
|
||||||
|
if (xo is Host host)
|
||||||
|
Id = $"host:{host.uuid}:{datasourceName}";
|
||||||
|
else if (xo is VM vm)
|
||||||
|
Id = $"vm:{vm.uuid}:{datasourceName}";
|
||||||
|
|
||||||
if (datasourceName == "memory_free_kib")
|
if (datasourceName == "memory_free_kib")
|
||||||
FriendlyName = Helpers.GetFriendlyDataSourceName("memory_used_kib", xo);
|
FriendlyName = Helpers.GetFriendlyDataSourceName("memory_used_kib", xo);
|
||||||
else if (datasourceName == "memory_internal_free")
|
else if (datasourceName == "memory_internal_free")
|
||||||
@ -76,9 +80,8 @@ namespace XenAdmin.Controls.CustomDataGraph
|
|||||||
FriendlyName = Helpers.GetFriendlyDataSourceName(datasourceName, xo);
|
FriendlyName = Helpers.GetFriendlyDataSourceName(datasourceName, xo);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Static methods
|
|
||||||
|
|
||||||
public static DataSet Create(string id, IXenObject xo, bool hide, string settype)
|
public static DataSet Create(IXenObject xo, bool hide, string settype)
|
||||||
{
|
{
|
||||||
if(settype == "xapi_open_fds" ||
|
if(settype == "xapi_open_fds" ||
|
||||||
settype == "pool_task_count" ||
|
settype == "pool_task_count" ||
|
||||||
@ -89,7 +92,7 @@ namespace XenAdmin.Controls.CustomDataGraph
|
|||||||
hide = true; //overrides passed in value
|
hide = true; //overrides passed in value
|
||||||
}
|
}
|
||||||
|
|
||||||
var dataSet = new DataSet(id, xo, hide, settype);
|
var dataSet = new DataSet(xo, hide, settype);
|
||||||
|
|
||||||
if (settype.StartsWith("latency") || settype.EndsWith("latency"))
|
if (settype.StartsWith("latency") || settype.EndsWith("latency"))
|
||||||
{
|
{
|
||||||
@ -244,30 +247,6 @@ namespace XenAdmin.Controls.CustomDataGraph
|
|||||||
return dataSet;
|
return dataSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataSet Create(string id, IXenObject xenObject)
|
|
||||||
{
|
|
||||||
if (ParseId(id, out string objType, out string objUuid, out string dataSourceName))
|
|
||||||
{
|
|
||||||
string theId = $"{objType}:{objUuid}:{dataSourceName}";
|
|
||||||
|
|
||||||
if (objType == "host")
|
|
||||||
{
|
|
||||||
Host host = xenObject.Connection.Cache.Find_By_Uuid<Host>(objUuid);
|
|
||||||
if (host != null)
|
|
||||||
return Create(theId, host, (xenObject as Host)?.uuid != objUuid, dataSourceName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (objType == "vm")
|
|
||||||
{
|
|
||||||
VM vm = xenObject.Connection.Cache.Find_By_Uuid<VM>(objUuid);
|
|
||||||
if (vm != null)
|
|
||||||
return Create(theId, vm, (xenObject as VM)?.uuid != objUuid, dataSourceName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Create(id, null, true, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ParseId(string id, out string objType, out string objUuid, out string dataSourceName)
|
public static bool ParseId(string id, out string objType, out string objUuid, out string dataSourceName)
|
||||||
{
|
{
|
||||||
var bits = id.Split(':').ToList();
|
var bits = id.Split(':').ToList();
|
||||||
@ -289,8 +268,6 @@ namespace XenAdmin.Controls.CustomDataGraph
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public List<DataPoint> GetRange(DataTimeRange xrange, long intervalneed, long intervalat)
|
public List<DataPoint> GetRange(DataTimeRange xrange, long intervalneed, long intervalat)
|
||||||
{
|
{
|
||||||
List<DataPoint> fine = BinaryChop(Points, xrange);
|
List<DataPoint> fine = BinaryChop(Points, xrange);
|
||||||
@ -466,7 +443,7 @@ namespace XenAdmin.Controls.CustomDataGraph
|
|||||||
DataSet other = setsAdded.FirstOrDefault(s => s.DataSourceName == "avg_cpu");
|
DataSet other = setsAdded.FirstOrDefault(s => s.DataSourceName == "avg_cpu");
|
||||||
if (other == null)
|
if (other == null)
|
||||||
{
|
{
|
||||||
other = Create(Palette.GetUuid("avg_cpu", XenObject), XenObject, false, "avg_cpu");
|
other = Create(XenObject, false, "avg_cpu");
|
||||||
setsAdded.Add(other);
|
setsAdded.Add(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user