def get(trans): data = [] connections = list(db.NodePair.select(connection=trans)) nodes = list(handler.get_activenodes(trans)) lastgoodver = db.getLastGoodVer(trans) goodnodes = [] for node in nodes: if node.lastGoodVersion >= lastgoodver: goodnodes.append(node.id) else: print("%s is bad!" % node.name) #print "good nodes are:" #print goodnodes if not goodnodes: print "NO GOOD NODES!!!" for conn in connections: if conn.node1.id in goodnodes and conn.node2.id in goodnodes: left = {} right = {} left['identity'] = conn.node1.identity left['location'] = conn.node1.location right['identity'] = conn.node2.identity right['location'] = conn.node2.location data.append((left, right)) else: print('Droping conn: %s-%s' % (conn.node1.name, conn.node2.name)) return data
def get(trans): data=[] connections = list(db.NodePair.select(connection=trans)) nodes = list(handler.get_activenodes(trans)) lastgoodver = db.getLastGoodVer(trans) goodnodes=[] for node in nodes: if node.lastGoodVersion >= lastgoodver: goodnodes.append(node.id) else: print("%s is bad!" % node.name) #print "good nodes are:" #print goodnodes if not goodnodes: print "NO GOOD NODES!!!" for conn in connections: if conn.node1.id in goodnodes and conn.node2.id in goodnodes: left={} right={} left['identity'] = conn.node1.identity left['location'] = conn.node1.location right['identity'] = conn.node2.identity right['location'] = conn.node2.location data.append( (left, right) ) else: print ('Droping conn: %s-%s' % (conn.node1.name,conn.node2.name) ) return data
def gentopology(self,trans): #NodePair.createTable( ifNotExists=True ) node_pairs = list(db.NodePair.select(connection=trans)) if not node_pairs: print "node_pairs is empty" nodes = list( handler.get_activenodes(trans)) if not nodes: print "got empty active nodes list!" #number of edges and nodes in grapgh nnum=len(nodes) enum=len(node_pairs) nstate = self.getnstate(nodes) if not nstate: print "got empty nstate list" g=pydot.Dot(type='digraph', labelloc='tl', label='Nodes: %s, Edges: %s, Time: %s' % (nnum, enum, datetime.now()) , overlap='scale' , splines='true', mindist='1.0') lastgoodver = db.getLastGoodVer(trans) #counts edges for a node #edge_count={} for node in nodes: #edge_count[node.name]=0 nodecolor=self.nodeOK transinfosize=self.defaultSize nversion = self.regver.match(node.version).group(1) if node.lastGoodVersion < lastgoodver: nodecolor=self.nodeOUTDATED # elif db.number_edges(node) < self.minEdges: # nodecolor=self.nodeLCONNS if node.requests != '0' or node.inserts != '0' or node.transferring_requests != '0': transinfosize="22" gnode = pydot.Node(node.name, style='filled', color=nodecolor , label='''\ < <table CELLBORDER="0" border="0" CELLPADDING="2" CELLSPACING="3"> <tr><td align="left"><FONT point-size="%s">%s</FONT></td> </tr> <tr><td align="left"><FONT point-size="%s">%s</FONT></td></tr> <tr><td align="left"><FONT point-size="%s">R:%s I:%s TR:%s</FONT></td></tr> <tr><td align="left"><FONT point-size="10">Ver. %s</FONT></td></tr> </table> >''' % (transinfosize, node.name,transinfosize, node.location[0:7], transinfosize, node.requests, node.inserts, node.transferring_requests,nversion)) g.add_node(gnode) #there are no dublicate edges in the database for node_pair in node_pairs: #assert node_pair.node1.name in edge_count #edge_count[node_pair.node1.name]+=1 #assert node_pair.node2.name in edge_count #edge_count[node_pair.node2.name]+=1 edgecolor = self.edgeOK node1loc = float(node_pair.node1.location) node2loc = float(node_pair.node2.location) distance = self.compute_distance(node1loc, node2loc) if node_pair.backoffcur_node1 != '0' or node_pair.backoffcur_node2 != '0': edgecolor= self.edgeBLOCKED elif node_pair.backoffmax_node1 != '5000' or node_pair.backoffmax_node2 != '5000': edgecolor= self.edgeCRITICAL #print "adding %s-%s" % (node_pair.node1.name,node_pair.node2.name) gedge = pydot.Edge(node_pair.node1.name , node_pair.node2.name, color=edgecolor, fontcolor=edgecolor, label='d: %0.3f' % distance, fontsize='16',arrowhead='none') #node1 is tail, node2 is head if edgecolor == self.edgeBLOCKED: if node_pair.backoffcur_node1 != '0': gedge.taillabel='%s (%s)' % (node_pair.backoffmax_node1, node_pair.backoffcur_node1 ) gedge.arrowtail='tee' if node_pair.backoffcur_node2 != '0': gedge.headlabel='%s (%s)' % (node_pair.backoffmax_node2, node_pair.backoffcur_node2 ) gedge.arrowhead='tee' elif edgecolor == self.edgeCRITICAL: if node_pair.backoffmax_node1 != '5000': gedge.taillabel='%s' % (node_pair.backoffmax_node1) if node_pair.backoffmax_node2 != '5000': gedge.headlabel='%s' % (node_pair.backoffmax_node2) g.add_edge(gedge) # for node_name in edge_count.keys(): # if edge_count[node_name] < self.minEdges: # if g.get_node(node_name).color != self.nodeOUTDATED: # g.get_node(node_name).color=self.nodeLCONNS if self.oldnstate: for identity in nstate.keys(): if identity in self.oldnstate: if self.oldnstate[identity] != nstate[identity]: print('\nLOCATION SWAP detected!!!!!!!!!!!!!!!!!!!!!!\n') self.find_and_addswapedge(g, nodes, identity, nstate) else: print "oldnstate empty!" print "writing big image..." g.write_png('/home/freeviz/public_html/output.png',prog='circo') print "done" g.size="16,18" g.ratio="fill" g.fontsize="36" print "writing small image" g.write_png('/home/freeviz/public_html/output_small.png',prog='circo') print "done" self.oldnstate = nstate
def gentopology(self, trans): #NodePair.createTable( ifNotExists=True ) node_pairs = list(db.NodePair.select(connection=trans)) if not node_pairs: print "node_pairs is empty" nodes = list(handler.get_activenodes(trans)) if not nodes: print "got empty active nodes list!" #number of edges and nodes in grapgh nnum = len(nodes) enum = len(node_pairs) nstate = self.getnstate(nodes) if not nstate: print "got empty nstate list" g = pydot.Dot(type='digraph', labelloc='tl', label='Nodes: %s, Edges: %s, Time: %s' % (nnum, enum, datetime.now()), overlap='scale', splines='true', mindist='1.0') lastgoodver = db.getLastGoodVer(trans) #counts edges for a node #edge_count={} for node in nodes: #edge_count[node.name]=0 nodecolor = self.nodeOK transinfosize = self.defaultSize nversion = self.regver.match(node.version).group(1) if node.lastGoodVersion < lastgoodver: nodecolor = self.nodeOUTDATED # elif db.number_edges(node) < self.minEdges: # nodecolor=self.nodeLCONNS if node.requests != '0' or node.inserts != '0' or node.transferring_requests != '0': transinfosize = "22" gnode = pydot.Node(node.name, style='filled', color=nodecolor, label='''\ < <table CELLBORDER="0" border="0" CELLPADDING="2" CELLSPACING="3"> <tr><td align="left"><FONT point-size="%s">%s</FONT></td> </tr> <tr><td align="left"><FONT point-size="%s">%s</FONT></td></tr> <tr><td align="left"><FONT point-size="%s">R:%s I:%s TR:%s</FONT></td></tr> <tr><td align="left"><FONT point-size="10">Ver. %s</FONT></td></tr> </table> >''' % (transinfosize, node.name, transinfosize, node.location[0:7], transinfosize, node.requests, node.inserts, node.transferring_requests, nversion)) g.add_node(gnode) #there are no dublicate edges in the database for node_pair in node_pairs: #assert node_pair.node1.name in edge_count #edge_count[node_pair.node1.name]+=1 #assert node_pair.node2.name in edge_count #edge_count[node_pair.node2.name]+=1 edgecolor = self.edgeOK node1loc = float(node_pair.node1.location) node2loc = float(node_pair.node2.location) distance = self.compute_distance(node1loc, node2loc) if node_pair.backoffcur_node1 != '0' or node_pair.backoffcur_node2 != '0': edgecolor = self.edgeBLOCKED elif node_pair.backoffmax_node1 != '5000' or node_pair.backoffmax_node2 != '5000': edgecolor = self.edgeCRITICAL #print "adding %s-%s" % (node_pair.node1.name,node_pair.node2.name) gedge = pydot.Edge(node_pair.node1.name, node_pair.node2.name, color=edgecolor, fontcolor=edgecolor, label='d: %0.3f' % distance, fontsize='16', arrowhead='none') #node1 is tail, node2 is head if edgecolor == self.edgeBLOCKED: if node_pair.backoffcur_node1 != '0': gedge.taillabel = '%s (%s)' % (node_pair.backoffmax_node1, node_pair.backoffcur_node1) gedge.arrowtail = 'tee' if node_pair.backoffcur_node2 != '0': gedge.headlabel = '%s (%s)' % (node_pair.backoffmax_node2, node_pair.backoffcur_node2) gedge.arrowhead = 'tee' elif edgecolor == self.edgeCRITICAL: if node_pair.backoffmax_node1 != '5000': gedge.taillabel = '%s' % (node_pair.backoffmax_node1) if node_pair.backoffmax_node2 != '5000': gedge.headlabel = '%s' % (node_pair.backoffmax_node2) g.add_edge(gedge) # for node_name in edge_count.keys(): # if edge_count[node_name] < self.minEdges: # if g.get_node(node_name).color != self.nodeOUTDATED: # g.get_node(node_name).color=self.nodeLCONNS if self.oldnstate: for identity in nstate.keys(): if identity in self.oldnstate: if self.oldnstate[identity] != nstate[identity]: print( '\nLOCATION SWAP detected!!!!!!!!!!!!!!!!!!!!!!\n' ) self.find_and_addswapedge(g, nodes, identity, nstate) else: print "oldnstate empty!" print "writing big image..." g.write_png('/home/freeviz/public_html/output.png', prog='circo') print "done" g.size = "16,18" g.ratio = "fill" g.fontsize = "36" print "writing small image" g.write_png('/home/freeviz/public_html/output_small.png', prog='circo') print "done" self.oldnstate = nstate