← Back to team overview

yellow team mailing list archive

[Merge] lp:~bac/juju-gui/1096230 into lp:juju-gui

 

Brad Crittenden has proposed merging lp:~bac/juju-gui/1096230 into lp:juju-gui.

Requested reviews:
  Juju GUI Hackers (juju-gui)
Related bugs:
  Bug #1096230 in juju-gui: "Implement set annotation call in JS env"
  https://bugs.launchpad.net/juju-gui/+bug/1096230

For more details, see:
https://code.launchpad.net/~bac/juju-gui/1096230/+merge/142513

Add support for _annotation calls to env.

The calls update_annotations, get_annotations, and remove_annotations are
added to the env object.

As a drive-by, in test_env.js the unnecessary use of async calls was
eliminated by removing the 'done' parameter.  Leaving it in place where not
required was confusing.
-- 
https://code.launchpad.net/~bac/juju-gui/1096230/+merge/142513
Your team Juju GUI Hackers is requested to review the proposed merge of lp:~bac/juju-gui/1096230 into lp:juju-gui.
=== modified file 'app/store/env.js'
--- app/store/env.js	2013-01-07 21:38:42 +0000
+++ app/store/env.js	2013-01-09 13:36:25 +0000
@@ -268,9 +268,52 @@
     get_endpoints: function(services, callback) {
       this._send_rpc({'op': 'get_endpoints', 'service_names': services},
                      callback);
+    },
+
+    /**
+     * Update the annotations for an entity by name.
+     *
+     * @param {Object} entity The name of a machine, unit, service, or
+     *   environment.
+     * @param {Object} data A dictionary of key, value pairs.
+     * @return {undefined} Nothing.
+     */
+    update_annotations: function(entity, data, callback) {
+      this._send_rpc({
+        op: 'update_annotations',
+        entity: entity,
+        data: data}, callback);
+    },
+
+    /**
+     * Get the annotations for an entity by name.
+     *
+     * @param {Object} entity The name of a machine, unit, service, or
+     *   environment.
+     * @return {undefined} Nothing.
+     * @return {Object} A dictionary of key,value pairs is returned in the
+     *   callback.  The invocation of this command returns nothing.
+     */
+    get_annotations: function(entity, callback) {
+      this._send_rpc({
+        op: 'get_annotations',
+        entity: entity}, callback);
+    },
+
+    /**
+     * Remove the annotations for an entity by name.
+     *
+     * @param {Object} entity The name of a machine, unit, service, or
+     *   environment.
+     * @return {undefined} Nothing.
+     */
+    remove_annotations: function(entity, keys, callback) {
+      this._send_rpc({
+        op: 'remove_annotations',
+        entity: entity,
+        keys: keys || []}, callback);
     }
 
-
   });
 
 

=== modified file 'test/test_env.js'
--- test/test_env.js	2012-10-14 16:30:50 +0000
+++ test/test_env.js	2013-01-09 13:36:25 +0000
@@ -31,15 +31,14 @@
       done();
     });
 
-    it('can deploy a service', function(done) {
+    it('can deploy a service', function() {
       env.deploy('precise/mysql');
       msg = conn.last_message();
       msg.op.should.equal('deploy');
       msg.charm_url.should.equal('precise/mysql');
-      done();
     });
 
-    it('can deploy a service with a config file', function(done) {
+    it('can deploy a service with a config file', function() {
       /*jshint multistr:true */
       var config_raw = 'tuning-level: \nexpert-mojo';
       /*jshint multistr:false */
@@ -48,16 +47,14 @@
       msg.op.should.equal('deploy');
       msg.charm_url.should.equal('precise/mysql');
       msg.config_raw.should.equal(config_raw);
-      done();
     });
 
-    it('can add a unit', function(done) {
+    it('can add a unit', function() {
       env.add_unit('mysql', 3);
       msg = conn.last_message();
       msg.op.should.equal('add_unit');
       msg.service_name.should.equal('mysql');
       msg.num_units.should.equal(3);
-      done();
     });
 
     it('can accept a callback on its methods', function(done) {
@@ -76,7 +73,7 @@
         'result': {'id': 'cs:precise/mysql'}});
     });
 
-    it('can resolve a problem with a unit', function(done) {
+    it('can resolve a problem with a unit', function() {
       var unit_name = 'mysql/0';
       env.resolved(unit_name);
       msg = conn.last_message();
@@ -84,10 +81,9 @@
       msg.unit_name.should.equal(unit_name);
       var _ = expect(msg.relation_name).to.not.exist;
       msg.retry.should.equal(false);
-      done();
     });
 
-    it('can resolve a problem with a unit relation', function(done) {
+    it('can resolve a problem with a unit relation', function() {
       var unit_name = 'mysql/0';
       var rel_name = 'relation-0000000000';
       env.resolved(unit_name, rel_name);
@@ -96,10 +92,9 @@
       msg.unit_name.should.equal(unit_name);
       msg.relation_name.should.equal(rel_name);
       msg.retry.should.equal(false);
-      done();
     });
 
-    it('can retry a problem with a unit', function(done) {
+    it('can retry a problem with a unit', function() {
       var unit_name = 'mysql/0';
       env.resolved(unit_name, null, true);
       msg = conn.last_message();
@@ -107,7 +102,6 @@
       msg.unit_name.should.equal(unit_name);
       var _ = expect(msg.relation_name).to.not.exist;
       msg.retry.should.equal(true);
-      done();
     });
 
     it('can retry a problem with a unit using a callback', function(done) {
@@ -124,7 +118,7 @@
         request_id: msg.request_id});
     });
 
-    it('will populate the provider type and default series', function(done) {
+    it('will populate the provider type and default series', function() {
       var providerType = 'super provider',
           defaultSeries = 'oneiric',
           evt =
@@ -141,7 +135,6 @@
       // After the message arrives the provider type is set.
       assert.equal(env.get('providerType'), providerType);
       assert.equal(env.get('defaultSeries'), defaultSeries);
-      done();
     });
 
     it('can get endpoints for a service', function() {
@@ -151,6 +144,41 @@
       msg.service_names.should.eql(['mysql']);
     });
 
+    it('can update annotations', function() {
+      var unit_name = 'mysql/0';
+      env.update_annotations(unit_name, {name: 'A'});
+      msg = conn.last_message();
+      msg.op.should.equal('update_annotations');
+      msg.entity.should.equal(unit_name);
+      msg.data.name.should.equal('A');
+    });
+
+    it('can get annotations', function() {
+      var unit_name = 'mysql/0';
+      env.get_annotations(unit_name);
+      msg = conn.last_message();
+      msg.op.should.equal('get_annotations');
+      msg.entity.should.equal(unit_name);
+    });
+
+    it('can remove annotations with specified keys', function() {
+      var unit_name = 'mysql/0';
+      var keys = ['key1', 'key2'];
+      env.remove_annotations(unit_name, keys);
+      msg = conn.last_message();
+      msg.op.should.equal('remove_annotations');
+      msg.entity.should.equal(unit_name);
+      msg.keys.should.eql(keys);
+    });
+
+    it('can remove annotations with no specified keys', function() {
+      var unit_name = 'mysql/0';
+      env.remove_annotations(unit_name);
+      msg = conn.last_message();
+      msg.op.should.equal('remove_annotations');
+      msg.entity.should.equal(unit_name);
+      msg.keys.should.eql([]);
+    });
 
   });
 })();


Follow ups