# HG changeset patch # User Andrew Azores # Date 1507748349 14400 # Node ID 71f13dfad69127cf5217b9db9099fa5ca0703588 # Parent 87a683af97e89cdfaed0d301707e2bdec9fc83b1 Move jvm-memory response data unwrapping from controller to service Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-October/025371.html diff -r 87a683af97e8 -r 71f13dfad691 src/app/components/jvm-info/jvm-memory/jvm-memory.controller.js --- a/src/app/components/jvm-info/jvm-memory/jvm-memory.controller.js Tue Oct 24 15:51:36 2017 -0400 +++ b/src/app/components/jvm-info/jvm-memory/jvm-memory.controller.js Wed Oct 11 14:59:09 2017 -0400 @@ -44,9 +44,7 @@ this._bigIntToString = bigIntToStringFilter; this._stringToNumber = stringToNumberFilter; this._scaleBytes = scaleBytesService; - } - $onInit () { this.metaspaceData = { used: 0, total: 0 @@ -59,7 +57,9 @@ this.generationData = {}; this._refreshRate = 2000; + } + $onInit () { this._start(); } @@ -95,7 +95,7 @@ multichartMetaspace () { return new Promise(resolve => this._jvmMemoryService.getJvmMemory(this.jvmId).then(resp => - resolve(this.convertMemStat(resp.data.response[0].metaspaceUsed)) + resolve(this.convertMemStat(resp[0].metaspaceUsed)) ) ); } @@ -105,8 +105,7 @@ this._jvmMemoryService.getJvmMemory(this.jvmId).then(resp => { generationIndex = parseInt(generationIndex); spaceIndex = parseInt(spaceIndex); - let data = resp.data.response[0]; - let generation = data.generations[generationIndex]; + let generation = resp[0].generations[generationIndex]; let space = generation.spaces[spaceIndex]; resolve(this.convertMemStat(space.used)); }) @@ -115,8 +114,7 @@ _update () { this._jvmMemoryService.getJvmMemory(this.jvmId).then(resp => { - let data = resp.data.response[0]; - + let data = resp[0]; let metaspaceScale = this._scaleBytes.format(data.metaspaceUsed); this.metaspaceData.used = this.convertMemStat(data.metaspaceUsed, metaspaceScale.scale); this.metaspaceData.total = this.convertMemStat(data.metaspaceCapacity, metaspaceScale.scale); diff -r 87a683af97e8 -r 71f13dfad691 src/app/components/jvm-info/jvm-memory/jvm-memory.controller.spec.js --- a/src/app/components/jvm-info/jvm-memory/jvm-memory.controller.spec.js Tue Oct 24 15:51:36 2017 -0400 +++ b/src/app/components/jvm-info/jvm-memory/jvm-memory.controller.spec.js Wed Oct 11 14:59:09 2017 -0400 @@ -151,38 +151,32 @@ let data, func; beforeEach(() => { func = promise.then.args[0][0]; - data = { - data: { - response: [ - { - agentId: 'foo-agentId', - jvmId: 'foo-jvmId', - timeStamp: 100, - metaspaceMaxCapacity: { $numberLong: '0' }, - metaspaceMinCapacity: { $numberLong: '0' }, - metaspaceCapacity: { $numberLong: (40 * 1024 * 1024).toString() }, - metaspaceUsed: { $numberLong: (20 * 1024 * 1024).toString() }, - generations: [ - { - capacity: { $numberLong: (10 * 1024 * 1024).toString() }, - collector: 'Shenandoah', - maxCapacity: { $numberLong: (60 * 1024 * 1024).toString() }, - name: 'Generation 0', - spaces: [ - { - capacity: { $numberLong: (50 * 1024 * 1024).toString() }, - index: 0, - maxCapacity: { $numberLong: (80 * 1024 * 1024).toString() }, - name: 'Gen 0 Space 0', - used: { $numberLong: (30 * 1024 * 1024).toString() } - } - ] - } - ] - } - ] - } - }; + data = [{ + agentId: 'foo-agentId', + jvmId: 'foo-jvmId', + timeStamp: 100, + metaspaceMaxCapacity: { $numberLong: '0' }, + metaspaceMinCapacity: { $numberLong: '0' }, + metaspaceCapacity: { $numberLong: (40 * 1024 * 1024).toString() }, + metaspaceUsed: { $numberLong: (20 * 1024 * 1024).toString() }, + generations: [ + { + capacity: { $numberLong: (10 * 1024 * 1024).toString() }, + collector: 'Shenandoah', + maxCapacity: { $numberLong: (60 * 1024 * 1024).toString() }, + name: 'Generation 0', + spaces: [ + { + capacity: { $numberLong: (50 * 1024 * 1024).toString() }, + index: 0, + maxCapacity: { $numberLong: (80 * 1024 * 1024).toString() }, + name: 'Gen 0 Space 0', + used: { $numberLong: (30 * 1024 * 1024).toString() } + } + ] + } + ] + }]; func(data); }); @@ -215,7 +209,7 @@ }); it('should update generationData on repeated calls', () => { - let generation = data.data.response[0].generations[0]; + let generation = data[0].generations[0]; let space = generation.spaces[0]; space.capacity = { $numberLong: (100 * 1024 * 1024).toString() }; space.used = { $numberLong: (50 * 1024 * 1024).toString() }; @@ -257,15 +251,9 @@ }); promise.then.should.be.calledTwice(); let prom = promise.then.secondCall.args[0]; - prom({ - data: { - response: [ - { - metaspaceUsed: { $numberLong: '9001' } - } - ] - } - }); + prom([{ + metaspaceUsed: { $numberLong: '9001' } + }]); }); }); @@ -284,40 +272,34 @@ }); promise.then.should.be.calledTwice(); let prom = promise.then.secondCall.args[0]; - prom({ - data: { - response: [ - { - generations: [ - { - spaces: [ - { - used: 100, - total: 150 - }, - { - used: 200, - total: 250 - } - ] - }, - { - spaces: [ - { - used: 300, - total: 350 - }, - { - used: 400, - total: 450 - } - ] - } - ] - } - ] - } - }); + prom([{ + generations: [ + { + spaces: [ + { + used: 100, + total: 150 + }, + { + used: 200, + total: 250 + } + ] + }, + { + spaces: [ + { + used: 300, + total: 350 + }, + { + used: 400, + total: 450 + } + ] + } + ] + }]); }); }); diff -r 87a683af97e8 -r 71f13dfad691 src/app/components/jvm-info/jvm-memory/jvm-memory.service.js --- a/src/app/components/jvm-info/jvm-memory/jvm-memory.service.js Tue Oct 24 15:51:36 2017 -0400 +++ b/src/app/components/jvm-info/jvm-memory/jvm-memory.service.js Wed Oct 11 14:59:09 2017 -0400 @@ -41,7 +41,7 @@ limit: 1, sort: '-timeStamp' } - }); + }).then(res => res.data.response); } } diff -r 87a683af97e8 -r 71f13dfad691 src/app/components/jvm-info/jvm-memory/jvm-memory.service.spec.js --- a/src/app/components/jvm-info/jvm-memory/jvm-memory.service.spec.js Tue Oct 24 15:51:36 2017 -0400 +++ b/src/app/components/jvm-info/jvm-memory/jvm-memory.service.spec.js Wed Oct 11 14:59:09 2017 -0400 @@ -57,12 +57,16 @@ describe('getJvmMemory(jvmId)', () => { it('should resolve mock data', done => { let expected = { - metaspace: 100 + response: [ + { + metaspace: 100 + } + ] }; httpBackend.when('GET', 'http://example.com:1234/jvm-memory/0.0.3/jvms/foo-jvmId?limit=1&sort=-timeStamp') .respond(expected); svc.getJvmMemory('foo-jvmId').then(res => { - res.data.should.deepEqual(expected); + res.should.deepEqual(expected.response); done(); }); httpBackend.expectGET('http://example.com:1234/jvm-memory/0.0.3/jvms/foo-jvmId?limit=1&sort=-timeStamp');