changeset 223:57a4676a9343

Use JVM mainClass in byteman rule template Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/025159.html
author Andrew Azores <aazores@redhat.com>
date Fri, 22 Sep 2017 14:33:18 -0400
parents 0e10eacbeeb7
children 6568fdab115d
files src/app/components/jvm-info/byteman/byteman.controller.js src/app/components/jvm-info/byteman/byteman.controller.spec.js src/app/components/jvm-info/byteman/byteman.service.js src/app/components/jvm-info/byteman/byteman.service.spec.js src/app/components/jvm-info/byteman/en.locale.yaml
diffstat 5 files changed, 41 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/components/jvm-info/byteman/byteman.controller.js	Fri Sep 22 07:51:59 2017 -0400
+++ b/src/app/components/jvm-info/byteman/byteman.controller.js	Fri Sep 22 14:33:18 2017 -0400
@@ -85,8 +85,11 @@
   }
 
   generateTemplate () {
-    return this._translate('byteman.RULE_TEMPLATE')
-      .then(res => this.ruleText = res);
+    return this._svc.getJvmMainClass(this.systemId, this.jvmId)
+      .then(mainClass => {
+        return this._translate('byteman.RULE_TEMPLATE', { mainClass: mainClass })
+          .then(res => this.ruleText = res);
+      });
   }
 }
 
--- a/src/app/components/jvm-info/byteman/byteman.controller.spec.js	Fri Sep 22 07:51:59 2017 -0400
+++ b/src/app/components/jvm-info/byteman/byteman.controller.spec.js	Fri Sep 22 14:33:18 2017 -0400
@@ -45,7 +45,8 @@
     svc = {
       getLoadedRules: sinon.stub(),
       loadRule: sinon.stub(),
-      unloadRules: sinon.stub()
+      unloadRules: sinon.stub(),
+      getJvmMainClass: sinon.stub()
     };
 
     angular.mock.inject($controller => {
@@ -173,9 +174,14 @@
   });
 
   describe('generateTemplate ()', () => {
-    it('should set rule text from translate service', () => {
+    it('should set rule text to template', () => {
+      svc.getJvmMainClass.returns({
+        then: sinon.stub().yields('com.example.FooClass')
+      });
       translate.then.yields('rule template');
       ctrl.generateTemplate();
+      translate.should.be.calledOnce();
+      translate.should.be.calledWith('byteman.RULE_TEMPLATE', { mainClass: 'com.example.FooClass' });
       ctrl.ruleText.should.equal('rule template');
     });
   });
--- a/src/app/components/jvm-info/byteman/byteman.service.js	Fri Sep 22 07:51:59 2017 -0400
+++ b/src/app/components/jvm-info/byteman/byteman.service.js	Fri Sep 22 14:33:18 2017 -0400
@@ -60,6 +60,10 @@
     return this._sendCmdChanRequest(systemId, jvmId, UNLOAD_RULE_ACTION);
   }
 
+  getJvmMainClass (systemId, jvmId) {
+    return this._getJvmInfo(systemId, jvmId).then(res => res.mainClass);
+  }
+
   _sendCmdChanRequest (systemId, jvmId, action, rule) {
     let defer = this._q.defer();
 
--- a/src/app/components/jvm-info/byteman/byteman.service.spec.js	Fri Sep 22 07:51:59 2017 -0400
+++ b/src/app/components/jvm-info/byteman/byteman.service.spec.js	Fri Sep 22 14:33:18 2017 -0400
@@ -244,5 +244,26 @@
     });
   });
 
+  describe('getJvmMainClass (systemId, jvmId)', () => {
+    it('should resolve mock data', done => {
+      let response = {
+        response: [
+          {
+            mainClass: 'com.example.FooClass'
+          }
+        ]
+      };
+      httpBackend.when('GET', 'http://example.com:1234/jvms/0.0.1/systems/foo-systemId/jvms/foo-jvmId')
+        .respond(response);
+      svc.getJvmMainClass('foo-systemId', 'foo-jvmId').then(res => {
+        res.should.equal(response.response[0].mainClass);
+        done();
+      });
+      httpBackend.expectGET('http://example.com:1234/jvms/0.0.1/systems/foo-systemId/jvms/foo-jvmId');
+      httpBackend.flush();
+      scope.$apply();
+    });
+  });
+
 });
 
--- a/src/app/components/jvm-info/byteman/en.locale.yaml	Fri Sep 22 07:51:59 2017 -0400
+++ b/src/app/components/jvm-info/byteman/en.locale.yaml	Fri Sep 22 14:33:18 2017 -0400
@@ -7,12 +7,12 @@
   UNLOAD_BTN_LABEL: Unload Rule
   GENERATE_RULE_BTN_LABEL: Generate Rule Template
   RULE_TEMPLATE: |
-    RULE Thermostat byteman template rule for com.redhat.thermostat.main.Thermostat
-    CLASS com.redhat.thermostat.main.Thermostat
+    RULE Thermostat byteman template rule for {{mainClass}}
+    CLASS {{mainClass}}
     METHOD main
     HELPER org.jboss.byteman.thermostat.helper.ThermostatHelper
     AT ENTRY
     IF true
     DO
-    send("foo-marker", "action", "com.redhat.thermostat.main.Thermostat.main() called");
+    send("foo-marker", "action", "{{mainClass}}.main() called");
     ENDRULE