changeset 163:c029b9611981

Add system-network information to system-info table Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-August/024554.html
author Andrew Azores <aazores@redhat.com>
date Thu, 17 Aug 2017 09:12:58 -0400
parents 94e4337238f9
children a5f9d8c66e1b
files mock-api/endpoints/system-network.endpoint.js src/app/components/system-info/en.locale.yaml src/app/components/system-info/system-info.controller.js src/app/components/system-info/system-info.controller.spec.js src/app/components/system-info/system-info.html src/app/components/system-info/system-info.service.js src/app/components/system-info/system-info.service.spec.js
diffstat 7 files changed, 178 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mock-api/endpoints/system-network.endpoint.js	Thu Aug 17 09:12:58 2017 -0400
@@ -0,0 +1,37 @@
+function systemNetwork (server) {
+  let _ = require('lodash');
+  server.init('systemNetwork');
+  server.app.get('/system-network/0.0.1/systems/:systemId', function (req, res, next) {
+    server.logRequest('system-network', req);
+
+    var data = {
+      agentId: 'foo-agentId',
+      timeStamp: new Date().getTime(),
+      interfaces: [
+        {
+          'interfaceName': 'lo',
+          'displayName': 'lo',
+          'ip4Addr': '127.0.0.1',
+          'ip6Addr': '0:0:0:0:0:0:0:1%lo'
+        },
+        {
+          'interfaceName': 'docker0',
+          'displayName': 'docker0',
+          'ip4Addr': '172.17.0.1',
+          'ip6Addr': 'fe80:0:0:0:42:17ff:feff:83f%docker0'         
+        }
+      ],
+      systemId: req.params.systemId
+    };
+
+    res.setHeader('Content-Type', 'application/json');
+    res.send(JSON.stringify(
+      {
+        response: [data]
+      }
+    ));
+    next();
+  });
+}
+
+module.exports = systemNetwork;
--- a/src/app/components/system-info/en.locale.yaml	Fri Aug 18 10:31:04 2017 -0400
+++ b/src/app/components/system-info/en.locale.yaml	Thu Aug 17 09:12:58 2017 -0400
@@ -4,7 +4,7 @@
   ERR_TITLE: Unable to retrieve data.
   ERR_MESSAGE: Error while retrieving system information.
 
-  table:
+  infoTable:
     HEADER: System Information
     KEY_COLUMN_LABEL: Key
     VALUE_COLUMN_LABEL: Value
@@ -16,6 +16,13 @@
     CPU_MODEL_FMT: '{{model}} ({{coreCount}} cores)'
     MEMORY: Memory
 
+  networkTable:
+    HEADER: Network Interfaces
+    DISPLAY_NAME_COLUMN_LABEL: Display Name
+    INTERFACE_NAME_COLUMN_LABEL: Interface Name
+    IPV4_COLUMN_LABEL: IPv4 Address
+    IPV6_COLUMN_LABEL: IPv6 Address
+
   refresh:
     DISABLED: Disabled
     SECONDS: '{SECONDS, plural, =0{0 Seconds} one{1 Second} other{# Seconds}}{DEFAULT, select, true{ (Default)} other{}}'
--- a/src/app/components/system-info/system-info.controller.js	Fri Aug 18 10:31:04 2017 -0400
+++ b/src/app/components/system-info/system-info.controller.js	Thu Aug 17 09:12:58 2017 -0400
@@ -47,6 +47,16 @@
         this.showErr = true;
       }
     );
+
+    systemInfoService.getNetworkInfo(systemId).then(
+      resp => {
+        this.networkInfo = resp.data.response[0];
+        this.showErr = false;
+      },
+      () => {
+        this.showErr = true;
+      }
+    );
   }
 }
 
--- a/src/app/components/system-info/system-info.controller.spec.js	Fri Aug 18 10:31:04 2017 -0400
+++ b/src/app/components/system-info/system-info.controller.spec.js	Thu Aug 17 09:12:58 2017 -0400
@@ -29,18 +29,20 @@
 
   beforeEach(angular.mock.module('systemInfo.controller'));
 
-  let ctrl, scope, interval, promise, translate;
+  let ctrl, scope, interval, infoPromise, networkPromise, translate;
   beforeEach(inject(($q, $rootScope, $controller) => {
     'ngInject';
     scope = $rootScope;
-    promise = $q.defer();
+    infoPromise = $q.defer();
+    networkPromise = $q.defer();
     interval = sinon.spy();
     translate = sinon.stub().returns({
       then: sinon.stub().yields()
     });
 
     let systemInfoService = {
-      getSystemInfo: () => promise.promise
+      getSystemInfo: () => infoPromise.promise,
+      getNetworkInfo: () => networkPromise.promise
     };
     ctrl = $controller('SystemInfoController', {
       systemId: 'foo-systemId',
@@ -55,29 +57,60 @@
     should.exist(ctrl);
   });
 
-  it('should set systemInfo when service resolves', done => {
-    let response = {
-      osName: 'Linux',
-      osKernel: '4.10.11-200.fc25.x86_64'
-    };
-    promise.resolve({
-      data: {
-        response: [response]
-      }
+  describe('systemInfo', () => {
+    it('should set systemInfo when service resolves', done => {
+      let response = {
+        osName: 'Linux',
+        osKernel: '4.10.11-200.fc25.x86_64'
+      };
+      infoPromise.resolve({
+        data: {
+          response: [response]
+        }
+      });
+      scope.$apply();
+      ctrl.should.have.ownProperty('systemInfo');
+      ctrl.systemInfo.should.deepEqual(response);
+      ctrl.showErr.should.equal(false);
+      done();
     });
-    scope.$apply();
-    ctrl.should.have.ownProperty('systemInfo');
-    ctrl.systemInfo.should.deepEqual(response);
-    ctrl.showErr.should.equal(false);
-    done();
+
+    it('should set error flag when service rejects', done => {
+      infoPromise.reject();
+      scope.$apply();
+      ctrl.should.have.ownProperty('showErr');
+      ctrl.showErr.should.equal(true);
+      done();
+    });
   });
 
-  it('should set error flag when service rejects', done => {
-    promise.reject();
-    scope.$apply();
-    ctrl.should.have.ownProperty('showErr');
-    ctrl.showErr.should.equal(true);
-    done();
+  describe('networkInfo', () => {
+    it('should set networkInfo when service resolves', done => {
+      let response = {
+        interfaceName: 'lo',
+        displayName: 'lo',
+        ip4Addr: '192.168.1.2',
+        ip6Addr: '0:0:0:0:0:0:1%lo'
+      };
+      networkPromise.resolve({
+        data: {
+          response: [response]
+        }
+      });
+      scope.$apply();
+      ctrl.should.have.ownProperty('networkInfo');
+      ctrl.networkInfo.should.deepEqual(response);
+      ctrl.showErr.should.equal(false);
+      done();
+    });
+
+    it('should set error flag when service rejects', done => {
+      networkPromise.reject();
+      scope.$apply();
+      ctrl.should.have.ownProperty('showErr');
+      ctrl.showErr.should.equal(true);
+      done();
+    });
   });
 
 });
--- a/src/app/components/system-info/system-info.html	Fri Aug 18 10:31:04 2017 -0400
+++ b/src/app/components/system-info/system-info.html	Thu Aug 17 09:12:58 2017 -0400
@@ -14,42 +14,69 @@
           <div class="panel panel-default">
             <div class="panel-heading">
               <h4 class="panel-title">
-                <a data-toggle="collapse" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne" translate>systemInfo.table.HEADER</a>
+                <a data-toggle="collapse" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne" translate>systemInfo.infoTable.HEADER</a>
               </h4>
             </div>
             <div id="collapseOne" class="panel-collapse collapse in">
               <table class="table table-fixed table-striped table-bordered">
                 <thead>
                   <tr>
-                    <th translate>systemInfo.table.KEY_COLUMN_LABEL</th>
-                    <th translate>systemInfo.table.VALUE_COLUMN_LABEL</th>
+                    <th translate>systemInfo.infoTable.KEY_COLUMN_LABEL</th>
+                    <th translate>systemInfo.infoTable.VALUE_COLUMN_LABEL</th>
                   </tr>
                 </thead>
                 <tbody class="break-word-wrap">
                   <tr>
-                    <td translate>systemInfo.table.HOSTNAME</td>
+                    <td translate>systemInfo.infoTable.HOSTNAME</td>
                     <td>{{ctrl.systemInfo.hostname}}</td>
                   </tr>
                   <tr>
-                    <td translate>systemInfo.table.OS</td>
+                    <td translate>systemInfo.infoTable.OS</td>
                     <td>{{ctrl.systemInfo.osName}}</td>
                   </tr>
                   <tr>
-                    <td translate>systemInfo.table.KERNEL</td>
+                    <td translate>systemInfo.infoTable.KERNEL</td>
                     <td>{{ctrl.systemInfo.osKernel}}</td>
                   </tr>
                   <tr>
-                    <td translate>systemInfo.table.CPU</td>
-                    <td translate="systemInfo.table.CPU_MODEL_FMT" translate-values="{ model: ctrl.systemInfo.cpuModel, coreCount: ctrl.systemInfo.cpuCount }"></td>
+                    <td translate>systemInfo.infoTable.CPU</td>
+                    <td translate="systemInfo.infoTable.CPU_MODEL_FMT" translate-values="{ model: ctrl.systemInfo.cpuModel, coreCount: ctrl.systemInfo.cpuCount }"></td>
                   </tr>
                   <tr>
-                    <td translate>systemInfo.table.MEMORY</td>
+                    <td translate>systemInfo.infoTable.MEMORY</td>
                     <td>{{ctrl.systemInfo.totalMemory | formatBytes}}</td>
                   </tr>
                 </tbody>
               </table>
             </div>
           </div>
+          <div class="panel panel-default">
+            <div class="panel-heading">
+              <h4 class="panel-title">
+                <a data-toggle="collapse" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo" translate>systemInfo.networkTable.HEADER</a>
+              </h4>
+            </div>
+            <div id="collapseTwo" class="panel-collapse collapse">
+              <table class="table table-fixed table-striped table-bordered">
+                <thead>
+                  <tr>
+                    <th translate>systemInfo.networkTable.DISPLAY_NAME_COLUMN_LABEL</th>
+                    <th translate>systemInfo.networkTable.INTERFACE_NAME_COLUMN_LABEL</th>
+                    <th translate>systemInfo.networkTable.IPV4_COLUMN_LABEL</th>
+                    <th translate>systemInfo.networkTable.IPV6_COLUMN_LABEL</th>
+                  </tr>
+                </thead>
+                <tbody class="break-word-wrap">
+                  <tr ng-repeat="iface in ctrl.networkInfo.interfaces">
+                    <td>{{iface.displayName}}</td>
+                    <td>{{iface.interfaceName}}</td>
+                    <td>{{iface.ip4Addr}}</td>
+                    <td>{{iface.ip6Addr}}</td>
+                  </tr>
+                </tbody>
+              </table>
+            </div>
+          </div>
         </div>
       </div>
     </div>
@@ -121,7 +148,9 @@
           </div>
         </div>
       </div>
+
     </div>
+
   </div>
 </div>
 <!-- /container -->
--- a/src/app/components/system-info/system-info.service.js	Fri Aug 18 10:31:04 2017 -0400
+++ b/src/app/components/system-info/system-info.service.js	Thu Aug 17 09:12:58 2017 -0400
@@ -61,6 +61,15 @@
       }
     });
   }
+
+  getNetworkInfo (systemId) {
+    return this.http.get(urlJoin(this.gatewayUrl, 'system-network', '0.0.1', 'systems', systemId), {
+      params: {
+        sort: '-timeStamp',
+        limit: 1
+      }
+    });
+  }
 }
 
 export default angular
--- a/src/app/components/system-info/system-info.service.spec.js	Fri Aug 18 10:31:04 2017 -0400
+++ b/src/app/components/system-info/system-info.service.spec.js	Thu Aug 17 09:12:58 2017 -0400
@@ -107,4 +107,24 @@
     });
   });
 
+  describe('getNetworkInfo(systemId)', () => {
+    it('should resolve mock data', done => {
+      let expected = {
+        interfaceName: 'lo',
+        displayName: 'lo',
+        ip4Addr: '192.168.1.2',
+        ip6Addr: '0:0:0:0:0:0:1%lo'
+      };
+      httpBackend.when('GET', 'http://example.com:1234/system-network/0.0.1/systems/foo-systemId?limit=1&sort=-timeStamp')
+        .respond(expected);
+      svc.getNetworkInfo('foo-systemId').then(res => {
+        res.data.should.deepEqual(expected);
+        done();
+      });
+      httpBackend.expectGET('http://example.com:1234/system-network/0.0.1/systems/foo-systemId?limit=1&sort=-timeStamp');
+      httpBackend.flush();
+      scope.$apply();
+    });
+  });
+
 });