Draw service graph
diff --git a/views/ngXosViews/diagnostic/env/default.js b/views/ngXosViews/diagnostic/env/default.js
index e392e57..f139cf2 100644
--- a/views/ngXosViews/diagnostic/env/default.js
+++ b/views/ngXosViews/diagnostic/env/default.js
@@ -8,6 +8,6 @@
module.exports = {
host: 'http://clnode078.clemson.cloudlab.us:9999/',
- xoscsrftoken: 'bOPR48s9Dbax56Lh0IRgnKhAR8QuPZU7',
- xossessionid: 'dzjxtlsxinrnzz2ajhxo2nsn07c4z0vm'
+ xoscsrftoken: '3l5fr6tkXW0dxJ2OqqD0ftEzzD9URc4C',
+ xossessionid: 'tagguvgkn2vpif4eml6ynvdw9vlx6os9'
};
diff --git a/views/ngXosViews/diagnostic/spec/serviceChain.test.js b/views/ngXosViews/diagnostic/spec/serviceChain.test.js
index dcd9da0..af9a701 100644
--- a/views/ngXosViews/diagnostic/spec/serviceChain.test.js
+++ b/views/ngXosViews/diagnostic/spec/serviceChain.test.js
@@ -114,7 +114,7 @@
];
it('should return a tree ordered by relations', () => {
- let tree = Service.buildServiceTree(services, relations);
+ let tree = Service.buildSubscriberServiceTree(services, relations);
expect(tree.name).toBe('fakeSubs');
expect(tree.parent).toBeNull();
@@ -154,4 +154,44 @@
});
});
+ describe('Given a list of services and COARSE tenant', () => {
+
+ const coarseTenants = [
+ {
+ humanReadableName: 'coarse-1',
+ provider_service: 1,
+ subscriber_service: 2
+ },
+ {
+ humanReadableName: 'coarse-2',
+ provider_service: 2,
+ subscriber_service: 3
+ }
+ ];
+
+ const services = [
+ {
+ id: 1,
+ humanReadableName: 'vbng'
+ },
+ {
+ id: 2,
+ humanReadableName: 'vsg'
+ },
+ {
+ id: 3,
+ humanReadableName: 'volt'
+ }
+ ];
+
+ it('should build the tenancy graph', () => {
+ let tree = Service.buildServiceTree(services, coarseTenants);
+
+ expect(tree.type).toBe('subscriber');
+ expect(tree.children[0].humanReadableName).toBe('volt');
+ expect(tree.children[0].children[0].humanReadableName).toBe('vsg');
+ expect(tree.children[0].children[0].children[0].humanReadableName).toBe('vbng');
+ });
+ });
+
});
\ No newline at end of file
diff --git a/views/ngXosViews/diagnostic/src/js/diagnostic.js b/views/ngXosViews/diagnostic/src/js/diagnostic.js
index 938b2f6..f499d4e 100644
--- a/views/ngXosViews/diagnostic/src/js/diagnostic.js
+++ b/views/ngXosViews/diagnostic/src/js/diagnostic.js
@@ -11,7 +11,7 @@
Subscribers.queryWithDevices().$promise
.then((subscribers) => {
this.subscribers = subscribers;
- return ServiceRelation.get(subscribers[0]);
+ return ServiceRelation.get();
})
.then((serviceChain) => {
this.serviceChain = serviceChain;
diff --git a/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js b/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js
index f87e397..8703344 100644
--- a/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js
+++ b/views/ngXosViews/diagnostic/src/js/logicTopologyHelper.js
@@ -66,7 +66,7 @@
+ (step * i) // space between elements
+ (el / 2) // this el width
+ previousElWidth; // previous elements width
- console.log(`${i} elPos: ${previousElWidth}`);
+
xPos.push(svgWidth - elPos);
})
diff --git a/views/ngXosViews/diagnostic/src/js/rest_services.js b/views/ngXosViews/diagnostic/src/js/rest_services.js
index 396439c..6e3771a 100644
--- a/views/ngXosViews/diagnostic/src/js/rest_services.js
+++ b/views/ngXosViews/diagnostic/src/js/rest_services.js
@@ -187,7 +187,7 @@
return tree;
};
- const buildServiceTree = (services, tenants, subscriber = {id: 1, name: 'fakeSubs'}) => {
+ const buildSubscriberServiceTree = (services, tenants, subscriber = {id: 1, name: 'fakeSubs'}) => {
// find the root service
// it is the one attached to subsriber_root
@@ -206,7 +206,43 @@
};
- const get = (subscriber) => {
+ // applying domain knowledge to build the global service tree
+ const buildServiceTree = (services, tenants) => {
+
+ // TODO refactor
+ const buildChild = (services, tenants, currentService) => {
+ let tenant = lodash.find(tenants, {subscriber_service: currentService.id});
+ if(tenant){
+ let next = lodash.find(services, {id: tenant.provider_service});
+ currentService.children = [buildChild(services, tenants, next)];
+ }
+ else {
+ currentService.children = [
+ {
+ name: 'Router',
+ type: 'router',
+ children: []
+ }
+ ]
+ }
+ currentService.type = 'service';
+ delete currentService.id; // conflict with d3
+ return currentService;
+ }
+ let baseService = lodash.find(services, {id: 3});
+
+ const baseData = {
+ name: 'Subscriber',
+ type: 'subscriber',
+ parent: null,
+ children: [buildChild(services, tenants, baseService)]
+ };
+
+ console.log(baseData);
+ return baseData;
+ };
+
+ const getBySubscriber = (subscriber) => {
var deferred = $q.defer();
var services, tenants;
Services.query().$promise
@@ -216,7 +252,7 @@
})
.then((res) => {
tenants = res;
- deferred.resolve(buildServiceTree(services, tenants, subscriber));
+ deferred.resolve(buildSubscriberServiceTree(services, tenants, subscriber));
})
.catch((e) => {
throw new Error(e);
@@ -225,11 +261,32 @@
return deferred.promise;
};
+ const get = () => {
+ var deferred = $q.defer();
+ var services, tenants;
+ Services.query().$promise
+ .then((res) => {
+ services = res;
+ return Tenant.query({kind: 'coarse'}).$promise;
+ })
+ .then((res) => {
+ tenants = res;
+ deferred.resolve(buildServiceTree(services, tenants));
+ })
+ .catch((e) => {
+ throw new Error(e);
+ });
+
+ return deferred.promise;
+ }
+
// export APIs
return {
get: get,
- buildLevel: buildLevel,
buildServiceTree: buildServiceTree,
+ getBySubscriber: getBySubscriber,
+ buildLevel: buildLevel,
+ buildSubscriberServiceTree: buildSubscriberServiceTree,
findLevelRelation: findLevelRelation,
findLevelServices: findLevelServices,
depthOf: depthOf,
diff --git a/views/ngXosViews/diagnostic/src/js/serviceTopologyHelper.js b/views/ngXosViews/diagnostic/src/js/serviceTopologyHelper.js
index 872c778..05ddba7 100644
--- a/views/ngXosViews/diagnostic/src/js/serviceTopologyHelper.js
+++ b/views/ngXosViews/diagnostic/src/js/serviceTopologyHelper.js
@@ -119,7 +119,10 @@
// Enter any new nodes at the parent's previous position.
var nodeEnter = node.enter().append('g')
.attr({
- class: d => `node ${d.type}`,
+ class: d => {
+ console.log(d);
+ return `node ${d.type}`
+ },
transform: `translate(${source.y0}, ${source.x0})`
});