fix composer bug 10/7110/2
authorlombardofr <lombardo@everyup.it>
Fri, 18 Jan 2019 11:50:22 +0000 (12:50 +0100)
committerlombardofr <lombardo@everyup.it>
Fri, 18 Jan 2019 15:33:48 +0000 (16:33 +0100)
Change-Id: If7c754ccf3e63e95bc06817b35a66c504bb9dc5c

descriptorhandler/views.py
lib/osm/osm_rdcl_parser.py
lib/osm/osm_util.py
static/TopologyComposer/js/model_graph_editor.js
static/src/descriptorhandler/composer.js
static/src/descriptorhandler/controller.js
static/src/instancehandler/instance_topology_view.js
static/src/osm_gui_properties.js

index 4c49a6d..912df09 100644 (file)
@@ -114,43 +114,36 @@ def removeElement(request, descriptor_type=None, descriptor_id=None, element_typ
 def updateElement(request, descriptor_type=None, descriptor_id=None, element_type=None):
     user = osmutils.get_user(request)
     client = Client()
+    payload = request.POST.dict()
+    util = OsmUtil()
+
     if descriptor_type == 'nsd':
         descriptor_result = client.nsd_get(user.get_token(), descriptor_id)
-        util = OsmUtil()
-        payload = request.POST.dict()
-        if element_type == 'graph_params':
-            descriptor_updated = util.update_graph_params('nsd', descriptor_result, json.loads(payload['update']))
-        else:
-            descriptor_updated = util.update_node('nsd', descriptor_result, element_type, json.loads(payload['old']), json.loads(payload['update']))
-        result = client.nsd_update(user.get_token(), descriptor_id, descriptor_updated)
-        if result['error'] == True:
-            return __response_handler(request, result['data'], url=None,
-                                      status=result['data']['status'] if 'status' in result['data'] else 500)
-        else:
-            parser = OsmParser()
-            # print nsr_object
-            if descriptor_type == 'nsd':
-                result_graph = parser.nsd_to_graph(descriptor_updated)
-    if descriptor_type == 'vnfd':
+    elif descriptor_type == 'vnfd':
         descriptor_result = client.vnfd_get(user.get_token(), descriptor_id)
-        util = OsmUtil()
-        payload = request.POST.dict()
-        if element_type == 'graph_params':
-            descriptor_updated = util.update_graph_params('vnfd', descriptor_result, json.loads(payload['update']))
-        else:
-            descriptor_updated = util.update_node('vnfd', descriptor_result, element_type, json.loads(payload['old']), json.loads(payload['update']))
+    
+    if element_type == 'graph_params':
+        descriptor_updated = util.update_graph_params(descriptor_type, descriptor_result, json.loads(payload['update']))
+    else:
+        descriptor_updated = util.update_node(descriptor_type, descriptor_result, element_type, json.loads(payload['old']), json.loads(payload['update']))
+
+    if descriptor_type == 'nsd':
+        result = client.nsd_update(user.get_token(), descriptor_id, descriptor_updated)
+    elif descriptor_type == 'vnfd':
         result = client.vnfd_update(user.get_token(), descriptor_id, descriptor_updated)
-        if result['error'] == True:
+    if result['error'] == True:
             return __response_handler(request, result['data'], url=None,
                                       status=result['data']['status'] if 'status' in result['data'] else 500)
-        else:
-            parser = OsmParser()
-            if descriptor_type == 'vnfd':
-                result_graph = parser.vnfd_to_graph(descriptor_updated)
-
+    else:
+        parser = OsmParser()
+        if descriptor_type == 'vnfd':
+            result_graph = parser.vnfd_to_graph(descriptor_updated)
+        elif descriptor_type == 'nsd':
+            result_graph = parser.nsd_to_graph(descriptor_updated)
         return __response_handler(request, result_graph, url=None, status=200)
 
 
+
 @login_required
 def edit_descriptor(request, descriptor_id=None, descriptor_type=None):
     user = osmutils.get_user(request)
index a6c6f0f..48ffcbc 100644 (file)
@@ -257,8 +257,12 @@ class OsmParser(RdclGraph):
             self.add_node(ns_vld['id'], 'ns_vl', None, None, graph,
                           {'property': {'custom_label': ns_vld['name']}, 'osm': ns_vld})
             for cp_ref in ns_vld['vnfd-connection-point-ref']:
-                self.add_link(map_vnf_index_to_id[str(cp_ref['member-vnf-index-ref'])], ns_vld['id'], 'nsr', None,
-                              graph)
+                ns_vld['id']+ ':' + str(cp_ref['member-vnf-index-ref']) + ':' + cp_ref['vnfd-connection-point-ref']
+                cp_id = ns_vld['id']+ ':' + str(cp_ref['member-vnf-index-ref']) + ':' + cp_ref['vnfd-connection-point-ref']             
+                cp_label = str(cp_ref['vnfd-connection-point-ref'])
+                self.add_node(cp_id,'ns_cp','nsd',None,graph, {'property': {'custom_label': cp_label}, 'osm': cp_ref})
+                self.add_link(cp_id, ns_vld['id'], 'nsr', None, graph)
+                self.add_link(cp_id, map_vnf_index_to_id[str(cp_ref['member-vnf-index-ref'])], 'nsr', None, graph)
 
         return graph
 
@@ -400,7 +404,9 @@ class OsmParser(RdclGraph):
                             "addable": {"callback": "addNode"},
                             "removable": {"callback": "removeNode"}
                         },
-                        "cp": {},
+                        "ns_cp": {
+                            "removable": {"callback": "removeNode"}
+                        },
                         "ns_vl": {
                             "addable": {
                                 "callback": "addNode"
@@ -411,29 +417,44 @@ class OsmParser(RdclGraph):
                         }
                     },
                     "allowed_edges": {
-                        "cp": {
+                        "vnf":{
                             "destination": {
-                                "vnfd": {
+                                "ns_cp": {
+                                    "direct_edge": False,
+                                    "removable" : {
+                                        "callback": "removeLink",
+                                    }
+                                },
+                                "ns_vl": {
                                     "direct_edge": False,
+                                    "callback": "addLink",
                                 }
                             }
                         },
-                        "vnf":{
+                        "ns_vl": {
                             "destination": {
-                                "ns_vl": {
+                                "ns_cp": {
                                     "direct_edge": False,
-                                    "callback": "addLink",
-                                    "removable" : {
+                                    "removable": {
                                         "callback": "removeLink",
                                     }
+                                },
+                                "vnf": {
+                                    "direct_edge": False,
+                                    "callback": "addLink",
                                 }
                             }
                         },
-                        "ns_vl": {
+                        "ns_cp": {
                             "destination": {
+                                "ns_vl": {
+                                    "direct_edge": False,
+                                    "removable": {
+                                        "callback": "removeLink",
+                                    }
+                                },
                                 "vnf": {
                                     "direct_edge": False,
-                                    "callback": "addLink",
                                     "removable": {
                                         "callback": "removeLink",
                                     }
@@ -523,7 +544,15 @@ class OsmParser(RdclGraph):
                 if 'vnfd-connection-point-ref' in vld:
                     for cp_ref in vld['vnfd-connection-point-ref']:
                         vnfd_id = cp_ref['vnfd-id-ref'] + ':' + str(cp_ref['member-vnf-index-ref'])
-                        self.add_link(vld['id'], vnfd_id, 'nsd', None, graph)
+                        cp_id = vld['id']+ ':' + str(cp_ref['member-vnf-index-ref']) + ':' + cp_ref['vnfd-connection-point-ref']
+                        cp_label = vld['id']+ ':' + cp_ref['vnfd-connection-point-ref']
+                        node_payload = {'vld_id': vld['id']}
+                        node_payload.update(cp_ref)
+                        self.add_node(cp_id,'ns_cp',None,None,graph,
+                        {'property': {'custom_label': cp_label}, 'osm': node_payload})
+                        
+                        self.add_link(cp_id, vld['id'], 'nsd', None, graph)
+                        self.add_link(cp_id, vnfd_id, 'nsd', None, graph)
         return graph
 
 
index 21b4ac7..6296d78 100644 (file)
@@ -22,7 +22,7 @@ class OsmUtil():
                                                                 str(item['member-vnf-index-ref']) != str(
                                                                     args['member-vnf-index']) or str(
                                                                     item['vnfd-id-ref']) != str(args['vnfd-id-ref'])]
-            elif node_type == 'cp':
+            elif node_type == 'ns_cp':
                 for vld in nsd['vld']:
                     if vld['id'] == args['vld_id']:
                         vld['vnfd-connection-point-ref'] = [item for item in vld['vnfd-connection-point-ref'] if
index 4ec7650..700b432 100644 (file)
@@ -296,6 +296,7 @@ TCD3.ModelGraphEditor = (function () {
         var source_type = s.info.type;
         var destination_type = d.info.type;
         var current_layer = self.getCurrentView();
+        console.log(self.model.layer[current_layer])
         if (self.model.layer[current_layer].allowed_edges && self.model.layer[current_layer].allowed_edges[source_type] && self.model.layer[current_layer].allowed_edges[source_type].destination[destination_type] &&
             self.model.layer[current_layer].allowed_edges[source_type].destination[destination_type].removable
         ) {
@@ -303,10 +304,12 @@ TCD3.ModelGraphEditor = (function () {
                 var callback = self.model.layer[current_layer].allowed_edges[source_type].destination[destination_type].removable.callback;
                 var c = self.model.callback[callback].class;
                 var controller = new  TCD3.OsmController();
-                controller[callback](self, link, function () {
+                controller[callback](self, link, function (result) {
                     self._deselectAllNodes();
                     self._deselectAllLinks();
-                    self.parent.removeLink.call(self, link.index);
+                    
+                    self.updateData(result);
+                    // success && success();
                     success && success();
                 }, error);
             } else {
index b3d849e..ecafe77 100644 (file)
@@ -18,7 +18,7 @@
 var graph_editor = new TCD3.ModelGraphEditor();
 
 var type_view = {
-    "nsd": ["vnf", "ns_vl"],
+    "nsd": ["vnf", "ns_vl", "ns_cp"],
     "vnfd": ["vdu", "cp", "vnf_vl", "int_cp"]
 };
 
@@ -201,6 +201,9 @@ function refreshElementInfo(event, element) {
             case 'int_cp':
                 intcpDetails(element.info.osm);
                 break;
+            case 'ns_cp':
+                nscpDetails(element.info.osm);
+                break;
             case 'cp':
                 cpDetails(element.info.osm);
                 break;
@@ -343,6 +346,15 @@ function cpDetails(cp) {
     side.append(cp_template);
 }
 
+function nscpDetails(cp) {
+    var side = $('#side_form');
+    var cp_template = getMainSection('Connection Point');
+
+    cp_template += getChildrenTable(cp, true);
+    side.empty();
+    side.append(cp_template);
+}
+
 function vlDetails(vl) {
     var side = $('#side_form');
     var vl_template = getMainSectionWithSubmitButton('Virtual Link');
index fd22411..f127ea7 100644 (file)
@@ -210,17 +210,13 @@ TCD3.OsmController = (function (global) {
         var desc_type = getUrlParameter('type');
 
         if (desc_type === 'nsd') {
-            var element_type = 'cp';
+            var element_type = 'ns_cp';
             var data_form = new FormData();
-
-            var vnfd_node = (link.source.info.type === 'vnf') ? link.source : link.target;
-            var vld_node = (link.source.info.type === 'ns_vl') ? link.source : link.target;
-
+            var ns_cp = (link.source.info.type === 'ns_cp') ? link.source : link.target;
             data_form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
-            //data_form.append('vnfd-connection-point-ref', 'cp_temp');
-            data_form.append('member-vnf-index-ref', vnfd_node.info.osm['member-vnf-index']);
-            data_form.append('vnfd-id-ref', vnfd_node.info.osm['vnfd-id-ref']);
-            data_form.append('vld_id', vld_node.info.osm['id']);
+            data_form.append('member-vnf-index-ref', ns_cp.info.osm['member-vnf-index-ref']);
+            data_form.append('vnfd-id-ref', ns_cp.info.osm['vnfd-id-ref']);
+            data_form.append('vld_id', ns_cp.info.osm['vld_id']);
 
             $.ajax({
                 url: '/projects/descriptors/' + desc_type + '/' + desc_id + '/removeElement/' + element_type,
index 95239e3..716a619 100644 (file)
@@ -40,7 +40,7 @@ var layer_map = {
 };
 
 var type_view = {
-    "nsr": ["vnfr", "ns_vl"],
+    "nsr": ["vnfr", "ns_vl", "ns_cp"],
     "vnfr": ["vdur", "cp", "vnf_vl"]
 };
 
index 0060e13..1ebf214 100644 (file)
@@ -26,6 +26,13 @@ var osm_gui_properties = {
                 "height": 20,
                 "name": "VDU"
             },
+            "ns_cp": {
+                //"image": "cp-80.png",
+                 "shape": "square",
+                "color": "#3c8dbc",
+                "size": 20,
+                "name": "CP"
+            },
             "cp": {
                 //"image": "cp-80.png",
                  "shape": "square",