update dashboard with graph
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Sat, 22 Apr 2017 23:22:59 +0000 (01:22 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Sat, 22 Apr 2017 23:22:59 +0000 (01:22 +0200)
src/emuvim/api/rest/network.py
src/emuvim/api/rest/rest_api_endpoint.py
src/emuvim/dashboard/index.html
src/emuvim/dashboard/js/main.js
src/emuvim/dcemulator/node.py
src/emuvim/examples/demo_topo_3pop.py

index e766e62..65dddc4 100755 (executable)
@@ -121,3 +121,31 @@ class NetworkAction(Resource):
         except Exception as ex:
             logging.exception("API error.")
             return ex.message, 500, CORS_HEADER
+
+
+class DrawD3jsgraph(Resource):
+
+    global net
+
+    def get(self):
+        nodes = list()
+        nodes2 = list()
+        links = list()
+        # add all DCs
+        #for dc in net.dcs:
+        for node_name in net.DCNetwork_graph.nodes():
+            nodes2.append(node_name)
+            node_index = nodes2.index(node_name)
+            node_dict = {"name":node_name,"group":node_index}
+            nodes.append(node_dict)
+
+        # add links between other DCs
+        for node1_name in net.DCNetwork_graph.nodes():
+            node1_index = nodes2.index(node1_name)
+            for node2_name in net.DCNetwork_graph.neighbors(node1_name):
+                node2_index = nodes2.index(node2_name)
+                edge_dict = {"source": node1_index, "target": node2_index, "value": 10}
+                links.append(edge_dict)
+
+        json = {"nodes":nodes, "links":links}
+        return json, 200, CORS_HEADER
\ No newline at end of file
index 71f87b9..f328b8e 100755 (executable)
@@ -38,7 +38,7 @@ from compute import dcs, ComputeList, Compute, ComputeResources, DatacenterList,
 
 # need to import total module to set its global variable net
 import network
-from network import NetworkAction
+from network import NetworkAction, DrawD3jsgraph
 
 import monitor
 from monitor import MonitorInterfaceAction, MonitorFlowAction, MonitorLinkAction, MonitorSkewAction
@@ -85,7 +85,8 @@ class RestApiEndpoint(object):
         # network related actions (setup chaining between VNFs)
         self.api.add_resource(NetworkAction,
                               "/restapi/network")
-
+        self.api.add_resource(DrawD3jsgraph,
+                              "/restapi/network/d3jsgraph")
 
         # monitoring related actions
         # export a network interface traffic rate counter
@@ -103,6 +104,7 @@ class RestApiEndpoint(object):
         self.api.add_resource(MonitorSkewAction,
                               "/restapi/monitor/skewness")
 
+
         logging.debug("Created API endpoint %s(%s:%d)" % (self.__class__.__name__, self.ip, self.port))
 
 
index 6f77d08..8f1258e 100755 (executable)
     <![endif]-->
 
     <script src="js/main.js" type="text/javascript"></script>
+
+
 </head>
+<style>
 
-<body>
+.link {
+  stroke: #ccc;
+}
 
+.node text {
+  pointer-events: none;
+  font: 15px sans-serif;
+}
+
+</style>
+<body>
   <div id="page-top">
     <div class="row">
       <div class="col-sm-8"><h1>MeDICINE Dashboard</h1></div>
   <table class="table table-striped table-hover" id="table_container">
   </table>
 </div>
+
+<div>
+<script src="//d3js.org/d3.v3.min.js"></script>
+<script src="js/graph.js" type="text/javascript"></script>
+</div>
+
+
 </div>
 
 <footer class="footer text-center small">(c) 2017 by SONATA Consortium and Paderborn University</footer>
index 71741f2..9715683 100755 (executable)
@@ -40,7 +40,7 @@ function update_table_datacenter(data)
     // clear table
     $("#table_datacenter").empty();
     // header
-    $("#table_datacenter").append('<tr class="tbl-head"><td>Label</td><td>Int. Name</td><td>Switch</td><td>Num. Containers</td><td>Metadata Items</td></tr>');
+    $("#table_datacenter").append('<tr class="tbl-head"><td>Label</td><td>Int. Name</td><td>Switch</td><td>Num. Containers</td><td>VNFs</td></tr>');
     // fill table
     $.each(data, function(i, item) {
         var row_str = "";
@@ -49,7 +49,8 @@ function update_table_datacenter(data)
         row_str += '<td>' + item.internalname + '</td>';
         row_str += '<td>' + item.switch + '</td>';
         row_str += '<td><span class="badge">' + item.n_running_containers + '</span></td>';
-        row_str += '<td><span class="badge">' + Object.keys(item.metadata).length + '</span></td>';
+        //row_str += '<td><span class="badge">' + Object.keys(item.metadata).length + '</span></td>';
+        row_str += '<td>' + item.vnf_list + '</span></td>';
         row_str += '<tr>';
        $("#table_datacenter").append(row_str);
     });
@@ -105,6 +106,14 @@ function fetch_container()
 }
 
 
+function fetch_d3graph()
+{
+    // do HTTP request and trigger gui update on success
+    var request_url = API_HOST + "/restapi/network/d3jsgraph";
+    console.debug("fetching from: " + request_url);
+    //$.getJSON(request_url,  update_graph);
+}
+
 function fetch_loop()
 {
     // only fetch if we are connected
@@ -161,6 +170,9 @@ $(document).ready(function(){
     $("#btn_connect").click(connect);
     $("#btn_disconnect").click(disconnect);
 
+    fetch_datacenter();
+    fetch_container();
+
     // additional refresh on window focus
     $(window).focus(function () {
         if(CONNECTED)
index 1225728..d5a8cdf 100755 (executable)
@@ -223,6 +223,7 @@ class Datacenter(object):
             self.net.addLink(d, self.switch, params1=nw, cls=Link, intfName1=nw.get('id'))
         # do bookkeeping
         self.containers[name] = d
+
         return d  # we might use UUIDs for naming later on
 
     def stopCompute(self, name):
@@ -281,12 +282,14 @@ class Datacenter(object):
         """
         Return a dict with status information about this DC.
         """
+        container_list = [name for name in self.containers]
         return {
             "label": self.label,
             "internalname": self.name,
             "switch": self.switch.name,
             "n_running_containers": len(self.containers),
-            "metadata": self.metadata
+            "metadata": self.metadata,
+            "vnf_list" : container_list
         }
 
     def assignResourceModel(self, rm):
index bf3cc20..4dd011c 100755 (executable)
@@ -49,12 +49,19 @@ def create_topology1():
     # create topology
     net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=True)
     dc1 = net.addDatacenter("dc1")
-
+    dc2 = net.addDatacenter("dc2")
+    dc3 = net.addDatacenter("dc3")
+    s1 = net.addSwitch("s1")
+    net.addLink(dc1, s1)
+    net.addLink(dc2, s1)
+    net.addLink(dc3, s1)
 
     # add the command line interface endpoint to each DC (REST API)
     rapi1 = RestApiEndpoint("0.0.0.0", 5001)
     rapi1.connectDCNetwork(net)
     rapi1.connectDatacenter(dc1)
+    rapi1.connectDatacenter(dc2)
+    rapi1.connectDatacenter(dc3)
     # run API endpoint server (in another thread, don't block)
     rapi1.start()
 
@@ -69,6 +76,8 @@ def create_topology1():
                                           docker_management=True, auto_delete=True,
                                           sap_vnfd_path=sap_vnfd_path)
     sdkg1.connectDatacenter(dc1)
+    sdkg1.connectDatacenter(dc2)
+    sdkg1.connectDatacenter(dc3)
     # run the dummy gatekeeper (in another thread, don't block)
     sdkg1.start()