def __init__(self): QMainWindow.__init__(self) self.ui = Ui_Vis() self.ui.setupUi(self) self.canvas = VisCanvas(self.ui.graphArea) self.ui.graphArea.setWidget(self.canvas) self.ui.info.setLineWrapMode(QTextEdit.NoWrap) self.canvas.edge_selected.connect(self.ShowEdgeInfo) self.canvas.computer_selected.connect(self.ShowComputerInfo) self.canvas.storage_selected.connect(self.ShowStorageInfo) self.canvas.router_selected.connect(self.ShowRouterInfo)
def __init__(self): QMainWindow.__init__(self) self.ui = Ui_Vis() self.ui.setupUi(self) self.canvas = VisCanvas(self.ui.graphArea) self.ui.graphArea.setWidget(self.canvas) self.ui.info.setLineWrapMode(QTextEdit.NoWrap) self.canvas.edge_selected.connect(self.ShowEdgeInfo) self.canvas.vertex_selected.connect(self.ShowVertexInfo)
class Vis(QMainWindow): xmlfile = None time = 0 def __init__(self): QMainWindow.__init__(self) self.ui = Ui_Vis() self.ui.setupUi(self) self.canvas = VisCanvas(self.ui.graphArea) self.ui.graphArea.setWidget(self.canvas) self.ui.info.setLineWrapMode(QTextEdit.NoWrap) self.canvas.edge_selected.connect(self.ShowEdgeInfo) self.canvas.computer_selected.connect(self.ShowComputerInfo) self.canvas.storage_selected.connect(self.ShowStorageInfo) self.canvas.router_selected.connect(self.ShowRouterInfo) def setData(self, project): self.project = project self.canvas.Clear() r = self.project.resources.GetTimeBounds() self.time = r[0] self.ui.timeSpinBox.setValue(r[0]) self.ui.timeSpinBox.setMinimum(r[0]) self.ui.timeSpinBox.setMaximum(r[1]) self.ui.timeSlider.setValue(r[0]) self.ui.timeSlider.setMinimum(r[0]) self.ui.timeSlider.setMaximum(r[1]) self.ui.info.setText("") timeInt = self.project.resources.GetTimeInterval(self.time) self.ui.assignedDemands.clear() for d in self.project.demands: if d.assigned and (d.startTime <= self.time) and (d.endTime >= self.time): it = QTreeWidgetItem(self.ui.assignedDemands, [d.id]) it.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) self.canvas.Visualize(self.project.resources, timeInt) def resizeEvent(self, e): super(QMainWindow, self).resizeEvent(e) self.canvas.ResizeCanvas() def showEvent(self, e): super(QMainWindow, self).showEvent(e) self.canvas.ResizeCanvas() def ShowRouterInfo(self): v = next(v for v in self.canvas.vertices.keys() if self.canvas.vertices[v] == self.canvas.selectedVertex) timeInt = self.project.resources.GetTimeInterval(self.time) if timeInt == None: return link_num = 0 for d in v.intervals[timeInt].demands.keys(): link_num += len(v.intervals[timeInt].demands[d]) replicalinks = {} for d in self.project.demands: replicalinks[d.id] = [] if d.startTime <= timeInt[0] and d.endTime >= timeInt[1]: for r in d.replicalinks: if r.path.count(v) != 0: link_num += 1 replicalinks[d.id].append(r) str = QString("<b><font size=\"+1\">%1</font></b><br />").arg( self.tr("Statistics")) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Router id")).arg(v.id) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Bandwidth")).arg(v.capacity) str += QString( " %1:<font color=blue> %2 (%3%)</font><br />").arg( self.tr("Used Bandwidth")).arg( v.intervals[timeInt].usedCapacity).arg( v.getUsedCapacityPercent(timeInt)) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Number of assigned requests")).arg( len(v.intervals[timeInt].demands.keys())) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Number of assigned channels")).arg(link_num) str += QString("<b><font size=\"+1\">%1</font></b><br />").arg( self.tr("Assigned Requests")) demands = v.intervals[timeInt].demands.keys() for id in replicalinks.keys(): if demands.count(id) == 0 and replicalinks[id] != []: demands.append(id) demands.sort() for id in demands: d = self.project.FindDemand(id) str += QString( " <font size=\"+1\">%1</font>:<br />").arg(id) if v.intervals[timeInt].demands.has_key(id): for link in v.intervals[timeInt].demands[d.id]: l = d.FindEdge(d.FindVertex(link[0]), d.FindVertex(link[1])) type1 = self.tr("VM") if isinstance( l.e1, VM) else self.tr("Storage") type2 = self.tr("VM") if isinstance( l.e2, VM) else self.tr("Storage") str += QString( " %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />" ).arg(type1).arg(l.e1.id).arg(type2).arg(l.e2.id).arg( l.capacity).arg(self.tr("Channel")).arg( self.tr("Bandwidth")) for r in replicalinks[id]: if r.e1 == r.e2: str += QString( " %1 <font color=blue>%2</font> %3: <font color=blue>%4</font> <br />" ).arg( self. tr("Consistency channel: <font color=blue>Storage</font>" ) ).arg(r.e1.id).arg( self. tr("<font color=blue><---> replica</font>. Bandwidth" )).arg(r.capacity) elif r.toreplica: type1 = self.tr("VM") if isinstance( r.e1, VM) else self.tr("Storage") type2 = self.tr("Replica of storage") str += QString( " %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />" ).arg(type1).arg(r.e1.id).arg(type2).arg(r.e2.id).arg( r.capacity).arg(self.tr("Channel")).arg( self.tr("Bandwidth")) else: type1 = self.tr("Replica of storage") type2 = self.tr("VM") if isinstance( r.e2, VM) else self.tr("Storage") str += QString( " %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />" ).arg(type1).arg(r.e1.id).arg(type2).arg(r.e2.id).arg( r.capacity).arg(self.tr("Channel")).arg( self.tr("Bandwidth")) self.ui.info.setText(str) def ShowComputerInfo(self): v = next(v for v in self.canvas.vertices.keys() if self.canvas.vertices[v] == self.canvas.selectedVertex) timeInt = self.project.resources.GetTimeInterval(self.time) if timeInt == None: return vm_num = 0 for d in v.intervals[timeInt].demands.keys(): vm_num += len(v.intervals[timeInt].demands[d]) str = QString("<b><font size=\"+1\">%1</font></b><br />").arg( self.tr("Statistics")) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Computer id")).arg(v.id) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Performance")).arg(v.speed) str += QString( " %1:<font color=blue> %2 (%3%)</font><br />").arg( self.tr("Used Performance")).arg( v.intervals[timeInt].usedSpeed).arg( v.getUsedSpeedPercent(timeInt)) str += QString( " %1:<font color=blue> %2 (%3%)</font><br />").arg( self.tr("Used RAM")).arg(v.intervals[timeInt].usedRam).arg( v.getUsedRamPercent(timeInt)) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Number of assigned requests")).arg( len(v.intervals[timeInt].demands.keys())) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Number of assigned VMs")).arg(vm_num) str += QString("<b><font size=\"+1\">%1</font></b><br />").arg( self.tr("Assigned Requests")) demands = v.intervals[timeInt].demands.keys() demands.sort() for id in demands: d = self.project.FindDemand(id) str += QString( " <font size=\"+1\">%1</font>:<br />").arg(id) for v1 in v.intervals[timeInt].demands[id]: str += QString( " %3: <font color=blue>%1</font> %4: <font color=blue>%2</font> %5: <font color=blue>%6</font><br />" ).arg(d.FindVertex(v1).id).arg(d.FindVertex(v1).speed).arg( self.tr("VM id")).arg(self.tr("Performance")).arg( self.tr("RAM")).arg(d.FindVertex(v1).ram) self.ui.info.setText(str) def ShowStorageInfo(self): v = next(v for v in self.canvas.vertices.keys() if self.canvas.vertices[v] == self.canvas.selectedVertex) timeInt = self.project.resources.GetTimeInterval(self.time) if timeInt == None: return storage_num = 0 replicas = {} for d in v.intervals[timeInt].demands.keys(): storage_num += len(v.intervals[timeInt].demands[d]) for d in self.project.demands: replicas[d.id] = [] if d.startTime <= timeInt[0] and d.endTime >= timeInt[1]: for r in d.replications: if r.assignedto == v: storage_num += 1 replicas[d.id].append(r) str = QString("<b><font size=\"+1\">%1</font></b><br />").arg( self.tr("Statistics")) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Storage id")).arg(v.id) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Type")).arg(v.type) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Capacity")).arg(v.volume) str += QString( " %1:<font color=blue> %2 (%3%)</font><br />").arg( self.tr("Used Capacity")).arg( v.intervals[timeInt].usedVolume).arg( v.getUsedVolumePercent(timeInt)) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Number of assigned requests")).arg( len(v.intervals[timeInt].demands.keys())) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Number of assigned storages")).arg(storage_num) str += QString("<b><font size=\"+1\">%1</font></b><br />").arg( self.tr("Assigned Requests")) demands = v.intervals[timeInt].demands.keys() for id in replicas.keys(): if demands.count(id) == 0 and replicas[id] != []: demands.append(id) demands.sort() for id in demands: d = self.project.FindDemand(id) str += QString( " <font size=\"+1\">%1</font>:<br />").arg(id) if v.intervals[timeInt].demands.has_key(id): for v1 in v.intervals[timeInt].demands[id]: str += QString( " %3: <font color=blue>%1</font> %4: <font color=blue>%2</font><br />" ).arg( d.FindVertex(v1).id).arg(d.FindVertex(v1).volume).arg( self.tr("Storage id")).arg(self.tr("Capacity")) for r in replicas[id]: str += QString( " %3: <font color=blue>%1</font> %4: <font color=blue>%2</font><br />" ).arg(r.replica.id).arg(r.replica.volume).arg( self.tr("Replica of")).arg(self.tr("Capacity")) self.ui.info.setText(str) def ShowEdgeInfo(self): e = self.canvas.selectedEdge if e == None: return timeInt = self.project.resources.GetTimeInterval(self.time) if timeInt == None: return link_num = 0 for d in e.intervals[timeInt].demands.keys(): link_num += len(e.intervals[timeInt].demands[d]) replicalinks = {} for d in self.project.demands: replicalinks[d.id] = [] if d.startTime <= timeInt[0] and d.endTime >= timeInt[1]: for r in d.replicalinks: if r.path.count(e) != 0: link_num += 1 replicalinks[d.id].append(r) str = QString("<b><font size=\"+1\">%1</font></b><br />").arg( self.tr("Statistics")) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Bandwidth")).arg(e.capacity) str += QString( " %1:<font color=blue> %2 (%3%)</font><br />").arg( self.tr("Used Bandwidth")).arg( e.intervals[timeInt].usedCapacity).arg( e.getUsedCapacityPercent(timeInt)) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Number of assigned requests")).arg( len(e.intervals[timeInt].demands.keys())) str += QString(" %1:<font color=blue> %2</font><br />").arg( self.tr("Number of assigned channels")).arg(link_num) str += QString("<b><font size=\"+1\">%1</font></b><br />").arg( self.tr("Assigned Requests")) demands = e.intervals[timeInt].demands.keys() for id in replicalinks.keys(): if demands.count(id) == 0 and replicalinks[id] != []: demands.append(id) demands.sort() for id in demands: d = self.project.FindDemand(id) str += QString( " <font size=\"+1\">%1</font>:<br />").arg(id) if e.intervals[timeInt].demands.has_key(id): for link in e.intervals[timeInt].demands[id]: l = d.FindEdge(d.FindVertex(link[0]), d.FindVertex(link[1])) type1 = self.tr("VM") if isinstance( l.e1, VM) else self.tr("Storage") type2 = self.tr("VM") if isinstance( l.e2, VM) else self.tr("Storage") str += QString( " %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />" ).arg(type1).arg(l.e1.id).arg(type2).arg(l.e2.id).arg( l.capacity).arg(self.tr("Channel")).arg( self.tr("Bandwidth")) for r in replicalinks[id]: if r.e1 == r.e2: str += QString( " %1 <font color=blue>%2</font> %3: <font color=blue>%4</font> <br />" ).arg( self. tr("Consistency channel: <font color=blue>Storage</font>" ) ).arg(r.e1.id).arg( self. tr("<font color=blue><---> replica</font>. Bandwidth" )).arg(r.capacity) elif r.toreplica: type1 = self.tr("VM") if isinstance( r.e1, VM) else self.tr("Storage") type2 = self.tr("Replica of storage") str += QString( " %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />" ).arg(type1).arg(r.e1.id).arg(type2).arg(r.e2.id).arg( r.capacity).arg(self.tr("Channel")).arg( self.tr("Bandwidth")) else: type1 = self.tr("Replica of storage") type2 = self.tr("VM") if isinstance( r.e2, VM) else self.tr("Storage") str += QString( " %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />" ).arg(type1).arg(r.e1.id).arg(type2).arg(r.e2.id).arg( r.capacity).arg(self.tr("Channel")).arg( self.tr("Bandwidth")) self.ui.info.setText(str) def UpdateTimeFromSlider(self, value): self.time = value self.ui.timeSpinBox.setValue(value) self.Update() def UpdateTimeFromSpinBox(self, value): self.time = value self.ui.timeSlider.setValue(value) self.Update() def Update(self): timeInt = self.project.resources.GetTimeInterval(self.time) self.ui.assignedDemands.clear() for d in self.project.demands: if (d.startTime <= self.time) and (d.endTime >= self.time) and d.assigned: it = QTreeWidgetItem(self.ui.assignedDemands, [d.id]) it.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) self.canvas.demandVertices = [] self.canvas.demandEdges = [] self.canvas.Visualize(self.project.resources, timeInt) self.ShowEdgeInfo() if self.canvas.selectedVertex == None: return v = next(v for v in self.canvas.vertices.keys() if self.canvas.vertices[v] == self.canvas.selectedVertex) if isinstance(v, Router): self.ShowRouterInfo() elif isinstance(v, Computer): self.ShowComputerInfo() elif isinstance(v, Storage): self.ShowStorageInfo() def demandSelected(self): self.canvas.demandVertices = [] self.canvas.demandEdges = [] if self.ui.assignedDemands.selectedItems() == []: timeInt = self.project.resources.GetTimeInterval(self.time) self.canvas.Visualize(self.project.resources, timeInt) return for it in self.ui.assignedDemands.selectedItems(): id = it.text(0) d = self.project.FindDemand(id) for v in d.vertices: self.canvas.demandVertices.append(v.resource) for r in d.replications: self.canvas.demandVertices.append(r.assignedto) links = d.edges + d.replicalinks for e in links: for e1 in e.path[1:len(e.path) - 1]: if isinstance(e1, Router): self.canvas.demandVertices.append(e1) else: self.canvas.demandEdges.append( self.project.resources.FindEdge(e1.e1, e1.e2)) timeInt = self.project.resources.GetTimeInterval(self.time) self.canvas.Visualize(self.project.resources, timeInt)
class Vis(QMainWindow): xmlfile = None time = 0 def __init__(self): QMainWindow.__init__(self) self.ui = Ui_Vis() self.ui.setupUi(self) self.canvas = VisCanvas(self.ui.graphArea) self.ui.graphArea.setWidget(self.canvas) self.ui.info.setLineWrapMode(QTextEdit.NoWrap) self.canvas.edge_selected.connect(self.ShowEdgeInfo) self.canvas.vertex_selected.connect(self.ShowVertexInfo) def setData(self, project): self.project = project self.canvas.Clear() self.ui.info.setText("") self.ui.assignedTenants.clear() for d in self.project.tenants: it = QTreeWidgetItem(self.ui.assignedTenants, [d.name]) it.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) self.canvas.Visualize(self.project.resources) def resizeEvent(self, e): super(QMainWindow, self).resizeEvent(e) self.canvas.ResizeCanvas() def showEvent(self, e): super(QMainWindow, self).showEvent(e) self.canvas.ResizeCanvas() def ShowVertexInfo(self): v = next(v for v in self.canvas.vertices.keys() if self.canvas.vertices[v] == self.canvas.selectedVertex) str = QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Statistics")) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Computer id")).arg(v.id) tenants = list(set([p[1].name for p in v.assignments])) tenants.sort() #str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Performance")).arg(v.speed) #str += QString(" %1:<font color=blue> %2 (%3%)</font><br />").arg(self.tr("Used Performance")).arg(v.intervals[timeInt].usedSpeed).arg(v.getUsedSpeedPercent(timeInt)) #str += QString(" %1:<font color=blue> %2 (%3%)</font><br />").arg(self.tr("Used RAM")).arg(v.intervals[timeInt].usedRam).arg(v.getUsedRamPercent(timeInt)) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned tenants")).arg(len(tenants)) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned VMs")).arg(len(v.assignments)) str += QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Parameters")) for p in v.params.values(): if (p.type == "integer") or (p.type == "real"): name = p.name val = int(p.value) if p.type == "integer" else float(p.value) used = 0 for v1 in v.assignments: for p1 in v1[0].params.values(): if (p1.name == name) and (p1.type == p.type): used += int(p1.value) if p.type == "integer" else float(p1.value) str += QString(" <font size=\"+1\">%1</font>: %5 %2 %6 %3 (%4 %)<br />").arg(name).arg(used).arg(val).arg(int(float(used)/float(val)*100)).arg(self.tr("used")).arg(self.tr("of")) str += QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Assigned Tenants")) for id in tenants: d = self.project.FindTenant(id) str += QString(" <font size=\"+1\">%1</font>:<br />").arg(id) for v1 in v.assignments: if v1[1] == d: str += QString(" ID: <font color=blue>%1</font> <br />").arg(v1[0].id) self.ui.info.setText(str) def ShowEdgeInfo(self): e = self.canvas.selectedEdge if e == None: return tenants = list(set([p[1].name for p in e.assignments])) tenants.sort() used = 0 for v in e.assignments: used += v[0].capacity str = QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Statistics")) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Bandwidth")).arg(e.capacity) str += QString(" %1:<font color=blue> %2 (%3%)</font><br />").arg(self.tr("Used Bandwidth")).arg(used).arg(int(float(used)/float(e.capacity)*100)) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned tenants")).arg(len(tenants)) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned channels")).arg(len(e.assignments)) str += QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Assigned Tenants")) classnames = {VM:u"VM", Storage:u"Storage", Vnf:u"VNF", NetElement:u"NetElement", Domain:u"Domain"} for id in tenants: d = self.project.FindTenant(id) str += QString(" <font size=\"+1\">%1</font>:<br />").arg(id) for l in e.assignments: t1 = classnames[l[0].e1.__class__] t2 = classnames[l[0].e2.__class__] str += QString(" %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />").arg(t1).arg(l[0].e1.id).arg(t2).arg(l[0].e2.id).arg(l[0].capacity).arg(self.tr("Channel")).arg(self.tr("Bandwidth")) self.ui.info.setText(str) def tenantSelected(self): self.canvas.tenantVertices = [] self.canvas.tenantEdges = [] if self.ui.assignedTenants.selectedItems()==[]: self.canvas.Visualize(self.project.resources) return for it in self.ui.assignedTenants.selectedItems(): id = it.text(0) d = self.project.FindTenant(id) for v in d.vertices: self.canvas.tenantVertices.append(v.assigned) links = d.edges '''for e in links: for e1 in e.path[1:len(e.path)-1]: if isinstance(e1,Router): self.canvas.tenantVertices.append(e1) else: self.canvas.tenantEdges.append(self.project.resources.FindEdge(e1.e1, e1.e2))''' self.canvas.Visualize(self.project.resources)
class Vis(QMainWindow): xmlfile = None time = 0 def __init__(self): QMainWindow.__init__(self) self.ui = Ui_Vis() self.ui.setupUi(self) self.canvas = VisCanvas(self.ui.graphArea) self.ui.graphArea.setWidget(self.canvas) self.ui.info.setLineWrapMode(QTextEdit.NoWrap) self.canvas.edge_selected.connect(self.ShowEdgeInfo) self.canvas.computer_selected.connect(self.ShowComputerInfo) self.canvas.storage_selected.connect(self.ShowStorageInfo) self.canvas.router_selected.connect(self.ShowRouterInfo) def setData(self, project): self.project = project self.canvas.Clear() r = self.project.resources.GetTimeBounds() self.time = r[0] self.ui.timeSpinBox.setValue(r[0]) self.ui.timeSpinBox.setMinimum(r[0]) self.ui.timeSpinBox.setMaximum(r[1]) self.ui.timeSlider.setValue(r[0]) self.ui.timeSlider.setMinimum(r[0]) self.ui.timeSlider.setMaximum(r[1]) self.ui.info.setText("") timeInt = self.project.resources.GetTimeInterval(self.time) self.ui.assignedDemands.clear() for d in self.project.demands: if d.assigned and (d.startTime <= self.time) and (d.endTime >= self.time): it = QTreeWidgetItem(self.ui.assignedDemands, [d.id]) it.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) self.canvas.Visualize(self.project.resources, timeInt) def resizeEvent(self, e): super(QMainWindow, self).resizeEvent(e) self.canvas.ResizeCanvas() def showEvent(self, e): super(QMainWindow, self).showEvent(e) self.canvas.ResizeCanvas() def ShowRouterInfo(self): v = next(v for v in self.canvas.vertices.keys() if self.canvas.vertices[v] == self.canvas.selectedVertex) timeInt = self.project.resources.GetTimeInterval(self.time) if timeInt==None: return link_num = 0 for d in v.intervals[timeInt].demands.keys(): link_num += len(v.intervals[timeInt].demands[d]) replicalinks = {} for d in self.project.demands: replicalinks[d.id] = [] if d.startTime<=timeInt[0] and d.endTime>=timeInt[1]: for r in d.replicalinks: if r.path.count(v) != 0: link_num += 1 replicalinks[d.id].append(r) str = QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Statistics")) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Router id")).arg(v.id) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Bandwidth")).arg(v.capacity) str += QString(" %1:<font color=blue> %2 (%3%)</font><br />").arg(self.tr("Used Bandwidth")).arg(v.intervals[timeInt].usedCapacity).arg(v.getUsedCapacityPercent(timeInt)) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned requests")).arg(len(v.intervals[timeInt].demands.keys())) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned channels")).arg(link_num) str += QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Assigned Requests")) demands = v.intervals[timeInt].demands.keys() for id in replicalinks.keys(): if demands.count(id) == 0 and replicalinks[id] != []: demands.append(id) demands.sort() for id in demands: d = self.project.FindDemand(id) str += QString(" <font size=\"+1\">%1</font>:<br />").arg(id) if v.intervals[timeInt].demands.has_key(id): for link in v.intervals[timeInt].demands[d.id]: l = d.FindEdge(d.FindVertex(link[0]),d.FindVertex(link[1])) type1 = self.tr("VM") if isinstance(l.e1,VM) else self.tr("Storage") type2 = self.tr("VM") if isinstance(l.e2,VM) else self.tr("Storage") str += QString(" %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />").arg(type1).arg(l.e1.id).arg(type2).arg(l.e2.id).arg(l.capacity).arg(self.tr("Channel")).arg(self.tr("Bandwidth")) for r in replicalinks[id]: if r.e1 == r.e2: str += QString(" %1 <font color=blue>%2</font> %3: <font color=blue>%4</font> <br />").arg(self.tr("Consistency channel: <font color=blue>Storage</font>")).arg(r.e1.id).arg(self.tr("<font color=blue><---> replica</font>. Bandwidth")).arg(r.capacity) elif r.toreplica: type1 = self.tr("VM") if isinstance(r.e1,VM) else self.tr("Storage") type2 = self.tr("Replica of storage") str += QString(" %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />").arg(type1).arg(r.e1.id).arg(type2).arg(r.e2.id).arg(r.capacity).arg(self.tr("Channel")).arg(self.tr("Bandwidth")) else: type1 = self.tr("Replica of storage") type2 = self.tr("VM") if isinstance(r.e2,VM) else self.tr("Storage") str += QString(" %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />").arg(type1).arg(r.e1.id).arg(type2).arg(r.e2.id).arg(r.capacity).arg(self.tr("Channel")).arg(self.tr("Bandwidth")) self.ui.info.setText(str) def ShowComputerInfo(self): v = next(v for v in self.canvas.vertices.keys() if self.canvas.vertices[v] == self.canvas.selectedVertex) timeInt = self.project.resources.GetTimeInterval(self.time) if timeInt==None: return vm_num = 0 for d in v.intervals[timeInt].demands.keys(): vm_num += len(v.intervals[timeInt].demands[d]) str = QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Statistics")) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Computer id")).arg(v.id) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Performance")).arg(v.speed) str += QString(" %1:<font color=blue> %2 (%3%)</font><br />").arg(self.tr("Used Performance")).arg(v.intervals[timeInt].usedSpeed).arg(v.getUsedSpeedPercent(timeInt)) str += QString(" %1:<font color=blue> %2 (%3%)</font><br />").arg(self.tr("Used RAM")).arg(v.intervals[timeInt].usedRam).arg(v.getUsedRamPercent(timeInt)) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned requests")).arg(len(v.intervals[timeInt].demands.keys())) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned VMs")).arg(vm_num) str += QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Assigned Requests")) demands = v.intervals[timeInt].demands.keys() demands.sort() for id in demands: d = self.project.FindDemand(id) str += QString(" <font size=\"+1\">%1</font>:<br />").arg(id) for v1 in v.intervals[timeInt].demands[id]: str += QString(" %3: <font color=blue>%1</font> %4: <font color=blue>%2</font> %5: <font color=blue>%6</font><br />").arg(d.FindVertex(v1).id).arg(d.FindVertex(v1).speed).arg(self.tr("VM id")).arg(self.tr("Performance")).arg(self.tr("RAM")).arg(d.FindVertex(v1).ram) self.ui.info.setText(str) def ShowStorageInfo(self): v = next(v for v in self.canvas.vertices.keys() if self.canvas.vertices[v] == self.canvas.selectedVertex) timeInt = self.project.resources.GetTimeInterval(self.time) if timeInt==None: return storage_num = 0 replicas = {} for d in v.intervals[timeInt].demands.keys(): storage_num += len(v.intervals[timeInt].demands[d]) for d in self.project.demands: replicas[d.id] = [] if d.startTime<=timeInt[0] and d.endTime>=timeInt[1]: for r in d.replications: if r.assignedto==v: storage_num += 1 replicas[d.id].append(r) str = QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Statistics")) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Storage id")).arg(v.id) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Type")).arg(v.type) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Capacity")).arg(v.volume) str += QString(" %1:<font color=blue> %2 (%3%)</font><br />").arg(self.tr("Used Capacity")).arg(v.intervals[timeInt].usedVolume).arg(v.getUsedVolumePercent(timeInt)) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned requests")).arg(len(v.intervals[timeInt].demands.keys())) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned storages")).arg(storage_num) str += QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Assigned Requests")) demands = v.intervals[timeInt].demands.keys() for id in replicas.keys(): if demands.count(id) == 0 and replicas[id] != []: demands.append(id) demands.sort() for id in demands: d = self.project.FindDemand(id) str += QString(" <font size=\"+1\">%1</font>:<br />").arg(id) if v.intervals[timeInt].demands.has_key(id): for v1 in v.intervals[timeInt].demands[id]: str += QString(" %3: <font color=blue>%1</font> %4: <font color=blue>%2</font><br />").arg(d.FindVertex(v1).id).arg(d.FindVertex(v1).volume).arg(self.tr("Storage id")).arg(self.tr("Capacity")) for r in replicas[id]: str += QString(" %3: <font color=blue>%1</font> %4: <font color=blue>%2</font><br />").arg(r.replica.id).arg(r.replica.volume).arg(self.tr("Replica of")).arg(self.tr("Capacity")) self.ui.info.setText(str) def ShowEdgeInfo(self): e = self.canvas.selectedEdge if e == None: return timeInt = self.project.resources.GetTimeInterval(self.time) if timeInt==None: return link_num = 0 for d in e.intervals[timeInt].demands.keys(): link_num += len(e.intervals[timeInt].demands[d]) replicalinks = {} for d in self.project.demands: replicalinks[d.id] = [] if d.startTime<=timeInt[0] and d.endTime>=timeInt[1]: for r in d.replicalinks: if r.path.count(e) != 0: link_num += 1 replicalinks[d.id].append(r) str = QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Statistics")) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Bandwidth")).arg(e.capacity) str += QString(" %1:<font color=blue> %2 (%3%)</font><br />").arg(self.tr("Used Bandwidth")).arg(e.intervals[timeInt].usedCapacity).arg(e.getUsedCapacityPercent(timeInt)) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned requests")).arg(len(e.intervals[timeInt].demands.keys())) str += QString(" %1:<font color=blue> %2</font><br />").arg(self.tr("Number of assigned channels")).arg(link_num) str += QString("<b><font size=\"+1\">%1</font></b><br />").arg(self.tr("Assigned Requests")) demands = e.intervals[timeInt].demands.keys() for id in replicalinks.keys(): if demands.count(id) == 0 and replicalinks[id] != []: demands.append(id) demands.sort() for id in demands: d = self.project.FindDemand(id) str += QString(" <font size=\"+1\">%1</font>:<br />").arg(id) if e.intervals[timeInt].demands.has_key(id): for link in e.intervals[timeInt].demands[id]: l = d.FindEdge(d.FindVertex(link[0]),d.FindVertex(link[1])) type1 = self.tr("VM") if isinstance(l.e1,VM) else self.tr("Storage") type2 = self.tr("VM") if isinstance(l.e2,VM) else self.tr("Storage") str += QString(" %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />").arg(type1).arg(l.e1.id).arg(type2).arg(l.e2.id).arg(l.capacity).arg(self.tr("Channel")).arg(self.tr("Bandwidth")) for r in replicalinks[id]: if r.e1 == r.e2: str += QString(" %1 <font color=blue>%2</font> %3: <font color=blue>%4</font> <br />").arg(self.tr("Consistency channel: <font color=blue>Storage</font>")).arg(r.e1.id).arg(self.tr("<font color=blue><---> replica</font>. Bandwidth")).arg(r.capacity) elif r.toreplica: type1 = self.tr("VM") if isinstance(r.e1,VM) else self.tr("Storage") type2 = self.tr("Replica of storage") str += QString(" %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />").arg(type1).arg(r.e1.id).arg(type2).arg(r.e2.id).arg(r.capacity).arg(self.tr("Channel")).arg(self.tr("Bandwidth")) else: type1 = self.tr("Replica of storage") type2 = self.tr("VM") if isinstance(r.e2,VM) else self.tr("Storage") str += QString(" %6: <font color=blue>%1: %2 <---> %3: %4</font> %7: <font color=blue>%5</font> <br />").arg(type1).arg(r.e1.id).arg(type2).arg(r.e2.id).arg(r.capacity).arg(self.tr("Channel")).arg(self.tr("Bandwidth")) self.ui.info.setText(str) def UpdateTimeFromSlider(self,value): self.time = value self.ui.timeSpinBox.setValue(value) self.Update() def UpdateTimeFromSpinBox(self,value): self.time = value self.ui.timeSlider.setValue(value) self.Update() def Update(self): timeInt = self.project.resources.GetTimeInterval(self.time) self.ui.assignedDemands.clear() for d in self.project.demands: if (d.startTime <= self.time) and (d.endTime >= self.time) and d.assigned: it = QTreeWidgetItem(self.ui.assignedDemands, [d.id]) it.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) self.canvas.demandVertices = [] self.canvas.demandEdges = [] self.canvas.Visualize(self.project.resources, timeInt) self.ShowEdgeInfo() if self.canvas.selectedVertex == None: return v = next(v for v in self.canvas.vertices.keys() if self.canvas.vertices[v] == self.canvas.selectedVertex) if isinstance(v,Router): self.ShowRouterInfo() elif isinstance(v,Computer): self.ShowComputerInfo() elif isinstance(v,Storage): self.ShowStorageInfo() def demandSelected(self): self.canvas.demandVertices = [] self.canvas.demandEdges = [] if self.ui.assignedDemands.selectedItems()==[]: timeInt = self.project.resources.GetTimeInterval(self.time) self.canvas.Visualize(self.project.resources, timeInt) return for it in self.ui.assignedDemands.selectedItems(): id = it.text(0) d = self.project.FindDemand(id) for v in d.vertices: self.canvas.demandVertices.append(v.resource) for r in d.replications: self.canvas.demandVertices.append(r.assignedto) links = d.edges + d.replicalinks for e in links: for e1 in e.path[1:len(e.path)-1]: if isinstance(e1,Router): self.canvas.demandVertices.append(e1) else: self.canvas.demandEdges.append(self.project.resources.FindEdge(e1.e1, e1.e2)) timeInt = self.project.resources.GetTimeInterval(self.time) self.canvas.Visualize(self.project.resources, timeInt)