Resolved policy contracts 90/39890/2
authorDaniel Malachovsky <dmalacho@cisco.com>
Mon, 6 Jun 2016 15:49:42 +0000 (17:49 +0200)
committerDaniel Malachovsky <dmalacho@cisco.com>
Wed, 8 Jun 2016 12:28:07 +0000 (14:28 +0200)
resolved-policy data grouped by source and destination epg and contract

Change-Id: I040cfd8e10afbc7b491c063d812d794f69761d33
Signed-off-by: Daniel Malachovsky <dmalacho@cisco.com>
groupbasedpolicy-ui/module/src/main/resources/gbp/common/topology/next_topology.directive.js
groupbasedpolicy-ui/module/src/main/resources/gbp/common/topology/next_topology.service.js
groupbasedpolicy-ui/module/src/main/resources/gbp/resolved-policy/resolved-policy.controller.js

index bd495d5791324fdd6ece340302cacb68f61e3b60..e32a381ad3bd599ad6f8034cc24b7feada2bc3e7 100644 (file)
@@ -37,11 +37,17 @@ define(['next-ui'], function() {
                                        // register "font" icon
                                        nx.graphic.Icons.registerFontIcon('devicedown', 'FontAwesome', "\uf057", 20);
 
+                    var circle = "<defs xmlns='http://www.w3.org/2000/svg'><marker id='circle' viewBox='-3 -3 6 6' markerWidth='6' markerHeight='6' orient='auto'> <circle r='3' fill='#68BD6B'></circle></marker></defs>";
+
                                        var app = new nx.ui.Application();
                                        // set app containter
                                        document.getElementById('graph-container').innerHTML = '';
                                        app.container(document.getElementById('graph-container'));
 
+                    scope.topo = NextTopologyService.getNxTopClass(scope.topoColors);
+                    scope.setTopoEvents();
+                    scope.topo.stage().addDefString(circle);
+
                                        extendLinkClass();
                                        extendNodeClass();
                                        extendedTooltip();
@@ -49,8 +55,7 @@ define(['next-ui'], function() {
                                        //createNodeStatusLayer();
                                        defineCustomEvents();
 
-                                       scope.topo = NextTopologyService.getNxTopClass(scope.topoColors);
-                                       scope.setTopoEvents();
+
 
                                        // App events - if app is resized
                                        app.on('resize', function(){
@@ -270,13 +275,16 @@ define(['next-ui'], function() {
                                                        },
                                                        // when topology's updated
                                                        update: function(){
+                                                               /*
                                                                this.inherited();
+
                                                                // ECMP badge settings
                                                                var badge = this.view('badge');
                                                                var badgeText = this.view('badgeText');
                                                                var badgeBg = this.view('badgeBg');
                                                                var statusIcon = this.view('statusIcon');
                                                                var status = this.model()._data.status;
+                                                               ECMP, not needed here
                                                                if( this.model()._data.gLinks.length > 2 ) {
                                                                        badgeText.sets({
                                                                                text: status.operational + '/' + status.configured,
@@ -300,7 +308,9 @@ define(['next-ui'], function() {
 
                                 //set correct link color
                                 this.set('color',this.getColor());
+                                */
 
+                                this.setProviderStyleLine();
                                                        },
                                                        // generate the color for a link
                                                        getColor: function(){
@@ -309,7 +319,23 @@ define(['next-ui'], function() {
                                                                // make it available outside next
                                                                this.model()._data.linkColor = color;
                                                                return color;
-                                                       }
+                            },
+
+                            setProviderStyleLine: function() {
+                                var _offset = this.getOffset();
+                                var offset = new nx.geometry.Vector(0, _offset);
+                                var stageScale = this.stageScale();
+                                var line = this.reverse() ? this.line().negate() : this.line();
+                                var lineEl = this.view('line');
+                                var newLine = line.translate(offset).pad(25 * stageScale, stageScale);
+                                lineEl.sets({
+                                    x1: newLine.start.x,
+                                    y1: newLine.start.y,
+                                    x2: newLine.end.x,
+                                    y2: newLine.end.y
+                                });
+                                lineEl.setStyle('marker-start', 'url(#circle)');
+                            }
                                                }
                                        });
                                }
@@ -349,7 +375,6 @@ define(['next-ui'], function() {
                                        });
                                }
 
-
                                // TODO: remove when come to decision about depiction of node status
                                ///**
                                // * Creating new node status layer - circles representing device status - up, down
@@ -385,4 +410,4 @@ define(['next-ui'], function() {
        NextTopology.$inject=['NextTopologyService'];
 
        return NextTopology;
-});
\ No newline at end of file
+});
index 67ef19f86b00a3ee1df681bc2cd3600530f26832..4b18baaaae85733b5c621470789cc4873d45d637 100644 (file)
@@ -24,7 +24,7 @@ define(['next-ui'], function () {
                         linkConfig: {
                             // connected to hosts links have different colors
                             width: function (model, link) {
-                                return model._data.gLinks.length > 2 ? 5 : 3;
+                                return (model._data.gLinks && model._data.gLinks.length > 2) ? 5 : 3;
                             },
                             linkType: 'curve'
                         },
index 4a13e887316d1cff03ae15e0010572a8ce0d0ce1..001ffb09689874604ceafcb237bc541e617d9731 100644 (file)
@@ -12,6 +12,8 @@ define(['app/gbp/resolved-policy/resolved-policy.service'], function () {
             links: [],
         };
 
+        $scope.resolvedPolicy = {};
+
         $scope.cbkFunctions = {
             clickNode: function(node){
                 var epg = EpgService.createObject();
@@ -31,10 +33,11 @@ define(['app/gbp/resolved-policy/resolved-policy.service'], function () {
                 // NextTopologyService.fadeInAllLayers();
             },
             clickLink: function(link){
-                var contract = ContractService.createObject();
-                contract.get(link['_data-id'], link['_model']['_data']['tenantId'], 'operational');
-                contract.data.parentTenant = link['_model']['_data']['tenantId'];
-                $scope.openSidePanel('resolved-policy/contract-sidepanel', contract, null);
+                //var contract = ContractService.createObject();
+                //contract.get(link['_model']['_data'].contract, link['_model']['_data'].tenant, 'operational');
+                //contract.data.parentTenant = link['_model']['_data'].tenant;
+                var resolvedContract = $scope.resolvedPolicy[link['_model']['_data'].id];
+                $scope.openSidePanel('resolved-policy/contract-sidepanel', resolvedContract, null);
                 $scope.$apply();
             },
             // topologyGenerated: function(){
@@ -57,16 +60,54 @@ define(['app/gbp/resolved-policy/resolved-policy.service'], function () {
 
         function fillTopologyData() {
             var topoData = {nodes: [], links: [],};
+
             resolvedPolicies.data.forEach(function(rp) {
                 topoData.nodes.push(createNode(rp['consumer-epg-id'], rp['consumer-tenant-id']));
                 topoData.nodes.push(createNode(rp['provider-epg-id'], rp['provider-tenant-id']));
-                // topoData.links.push(createLink(rp['policy-rule-group-with-endpoint-constraints'][0]['policy-rule-group'][0]['contract-id'], rp['consumer-epg-id'], rp['provider-epg-id']));
+
+                fillResolvedPolicy(rp);
+                topoData.links = getContracts(rp);
             });
 
             $scope.topologyData = topoData;
             $scope.topologyLoaded = true;
         }
 
+        function fillResolvedPolicy(data) {
+            if(data['policy-rule-group-with-endpoint-constraints']) {
+                processPolicyRuleGroupWithEpConstraints(
+                    data['policy-rule-group-with-endpoint-constraints'],
+                    data['provider-epg-id'],
+                    data['consumer-epg-id']);
+            }
+
+        }
+
+        function processPolicyRuleGroupWithEpConstraints(data, providerEpgId, consumerEpgId) {
+            data.forEach(function(element) {
+                element['policy-rule-group'].forEach(function(el) {
+                    var linkId = generateLinkId(el['contract-id'], providerEpgId, consumerEpgId);
+
+                    if(!$scope.resolvedPolicy.hasOwnProperty(linkId)) {
+                        $scope.resolvedPolicy[linkId] = {
+                            'contract-id': el['contract-id'],
+                            'subjects': {},
+                        };
+                    }
+
+                    if(!$scope.resolvedPolicy[linkId].subjects.hasOwnProperty(el['subject-name'])) {
+                        $scope.resolvedPolicy[linkId].subjects[el['subject-name']] = {'resolved-rule': []};
+                    }
+
+                    $scope.resolvedPolicy[linkId].subjects[el['subject-name']]['resolved-rule'].push(el['resolved-rule']);
+                })
+            })
+        }
+
+        function generateLinkId(contractId, providerEpgId, consumerEpgId) {
+            return contractId + '_' + providerEpgId + '_' + consumerEpgId;
+        }
+
         function createNode(nodeName, tenantId) {
             return {
                 'id': nodeName,
@@ -76,13 +117,34 @@ define(['app/gbp/resolved-policy/resolved-policy.service'], function () {
             };
         }
 
-        function createLink(linkName, source, target) {
+        function createLink( source, target, contract, tenant) {
             return {
-                'id' : linkName,
-                'source' : source,
-                'target' : target,
+                'id': generateLinkId(contract, source, target),
+                'source': source,
+                'target': target,
+                'tenant': tenant,
             };
         }
+
+        function getContracts(data) {
+            var retVal = [];
+
+            if( data['policy-rule-group-with-endpoint-constraints'] &&
+                data['policy-rule-group-with-endpoint-constraints'][0]['policy-rule-group']) {
+                data['policy-rule-group-with-endpoint-constraints'][0]['policy-rule-group'].forEach(function(prg) {
+                        retVal.push(
+                            createLink(
+                                data['provider-epg-id'],
+                                data['consumer-epg-id'],
+                                prg['contract-id'],
+                                prg['tenant-id']
+                            )
+                        )
+                    });
+            }
+
+            return retVal;
+        }
     }
 
 });