Merge lp:~gary/juju-gui/fixSandboxDeployRace into lp:juju-gui/experimental

Proposed by Gary Poster
Status: Merged
Merged at revision: 1191
Proposed branch: lp:~gary/juju-gui/fixSandboxDeployRace
Merge into: lp:juju-gui/experimental
Diff against target: 118 lines (+38/-29)
2 files modified
app/store/env/fakebackend.js (+21/-29)
test/test_fakebackend.js (+17/-0)
To merge this branch: bzr merge lp:~gary/juju-gui/fixSandboxDeployRace
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+194581@code.launchpad.net

Description of the change

Remove a race condition from sandbox deployment

Deploying to the sandbox will sometimes mis-position services, especially when you have a large bundle. I believe the cause is the race condition that this branch fixes.

I also simplified some code that I thought was confusing.

To QA, try deploying some big bundles. At the very least, it shouldn't be worse than it was before. If we're lucky, you'll see that the position is always right for the deployed bundles in the sandbox.

https://codereview.appspot.com/23800044/

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :
Download full text (5.6 KiB)

Reviewers: mp+194581_code.launchpad.net,

Message:
Please take a look.

Description:
Remove a race condition from sandbox deployment

Deploying to the sandbox will sometimes mis-position services,
especially when you have a large bundle. I believe the cause is the race
condition that this branch fixes.

I also simplified some code that I thought was confusing.

To QA, try deploying some big bundles. At the very least, it shouldn't
be worse than it was before. If we're lucky, you'll see that the
position is always right for the deployed bundles in the sandbox.

Contact me if you'd like some big bundles.

https://code.launchpad.net/~gary/juju-gui/fixSandboxDeployRace/+merge/194581

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/23800044/

Affected files (+40, -29 lines):
   [revision details]
   app/store/env/fakebackend.js
   test/test_fakebackend.js

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: test/test_fakebackend.js
=== modified file 'test/test_fakebackend.js'
--- test/test_fakebackend.js 2013-11-01 23:04:50 +0000
+++ test/test_fakebackend.js 2013-11-08 18:57:35 +0000
@@ -337,6 +337,23 @@
            ' auto_id: %n\n' +
            ' ^');
      });
+
+ it('honors annotations', function() {
+ var options = {
+ annotations: {
+ 'gui-x': '-3',
+ 'gui-y': '5'
+ }
+ };
+ fakebackend.deploy('cs:precise/wordpress-15', callback, options);
+ var service = fakebackend.db.services.getById('wordpress');
+ assert.deepEqual(
+ options.annotations,
+ service.get('annotations')
+ );
+ var changes = fakebackend.nextAnnotations();
+ assert.deepEqual(changes.services, {wordpress: service});
+ });
    });

    describe('FakeBackend.setCharm', function() {

Index: app/store/env/fakebackend.js
=== modified file 'app/store/env/fakebackend.js'
--- app/store/env/fakebackend.js 2013-11-01 23:04:50 +0000
+++ app/store/env/fakebackend.js 2013-11-08 18:57:35 +0000
@@ -409,6 +409,8 @@
          constraints = options.constraints;
        }

+ var annotations = options.annotations || {};
+
        // In order for the constraints to support the python back end this
        // needs to be an array, so we are converting it back to an object
        // here so that the GUI displays it properly.
@@ -425,6 +427,17 @@
          constraintsMap = constraints;
        }

+ // We need to set charm default values for the options that have not
+ // been explicitly provided.
+ var charmOptions = charm.get('options') || {};
+ // "config" will hold the service's config values--it will be the
+ // result of this processing.
+ var config = {};
+ var explicitConfig = options.config || {};
+ Object.keys(charmOptions).forEach(function(key) {
+ config[key] = explicitConfig[key] || charmOptions[k...

Read more...

Revision history for this message
Brad Crittenden (bac) wrote :
Revision history for this message
Gary Poster (gary) wrote :

*** Submitted:

Remove a race condition from sandbox deployment

Deploying to the sandbox will sometimes mis-position services,
especially when you have a large bundle. I believe the cause is the race
condition that this branch fixes.

I also simplified some code that I thought was confusing.

To QA, try deploying some big bundles. At the very least, it shouldn't
be worse than it was before. If we're lucky, you'll see that the
position is always right for the deployed bundles in the sandbox.

R=bac
CC=
https://codereview.appspot.com/23800044

https://codereview.appspot.com/23800044/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/store/env/fakebackend.js'
2--- app/store/env/fakebackend.js 2013-11-01 23:04:50 +0000
3+++ app/store/env/fakebackend.js 2013-11-08 19:58:38 +0000
4@@ -409,6 +409,8 @@
5 constraints = options.constraints;
6 }
7
8+ var annotations = options.annotations || {};
9+
10 // In order for the constraints to support the python back end this
11 // needs to be an array, so we are converting it back to an object
12 // here so that the GUI displays it properly.
13@@ -425,6 +427,17 @@
14 constraintsMap = constraints;
15 }
16
17+ // We need to set charm default values for the options that have not
18+ // been explicitly provided.
19+ var charmOptions = charm.get('options') || {};
20+ // "config" will hold the service's config values--it will be the
21+ // result of this processing.
22+ var config = {};
23+ var explicitConfig = options.config || {};
24+ Object.keys(charmOptions).forEach(function(key) {
25+ config[key] = explicitConfig[key] || charmOptions[key]['default'];
26+ });
27+
28 var service = this.db.services.add({
29 id: options.name,
30 name: options.name,
31@@ -432,22 +445,13 @@
32 constraints: constraintsMap,
33 exposed: false,
34 subordinate: charm.get('is_subordinate'),
35- // Because we only send the user changed options now
36- // we need to mix those values in to the charm config
37- // options when creating a new model.
38- config: (function() {
39- var charmOptions = charm.get('options') || {};
40- var config = {};
41- if (!options.config) { options.config = {}; }
42- Object.keys(charmOptions).forEach(function(key) {
43- config[key] =
44- options.config[key] ||
45- (charmOptions[key] ? charmOptions[key]['default'] : undefined);
46- });
47- return config;
48- })()
49+ annotations: annotations,
50+ config: config
51 });
52 this.changes.services[service.get('id')] = [service, true];
53+ if (Object.keys(annotations).length) {
54+ this.annotations.services[service.get('id')] = service;
55+ }
56
57 var unitCount = options.unitCount;
58 if (!Y.Lang.isValue(unitCount) && !charm.get('is_subordinate')) {
59@@ -1522,28 +1526,16 @@
60
61 Y.batch.apply(this, servicePromises)
62 .then(function(serviceDeployResult) {
63+ // Expose, if requested.
64 serviceDeployResult.forEach(function(sdr) {
65- // Update export elements that 'deploy'
66- // doesn't handle
67- var service = sdr.service;
68- var serviceId = service.get('id');
69+ var serviceId = sdr.service.get('id');
70 var serviceData = ingestedData.services[serviceId];
71-
72- // Force the annotation update (deploy doesn't handle this).
73- var anno = serviceData.annotations;
74- if (anno) {
75- self.updateAnnotations(service.get('id'), anno);
76- }
77-
78- // Expose
79 if (serviceData.expose) {
80 self.expose(serviceId);
81 }
82-
83- self.changes.services[sdr.service.get('id')] = [
84- sdr.service, true];
85 });
86
87+ // Create requested relations.
88 ingestedData.relations.forEach(function(relationData) {
89 var relResult = self.addRelation(
90 relationData[0], relationData[1], true);
91
92=== modified file 'test/test_fakebackend.js'
93--- test/test_fakebackend.js 2013-11-01 23:04:50 +0000
94+++ test/test_fakebackend.js 2013-11-08 19:58:38 +0000
95@@ -337,6 +337,23 @@
96 ' auto_id: %n\n' +
97 ' ^');
98 });
99+
100+ it('honors annotations', function() {
101+ var options = {
102+ annotations: {
103+ 'gui-x': '-3',
104+ 'gui-y': '5'
105+ }
106+ };
107+ fakebackend.deploy('cs:precise/wordpress-15', callback, options);
108+ var service = fakebackend.db.services.getById('wordpress');
109+ assert.deepEqual(
110+ options.annotations,
111+ service.get('annotations')
112+ );
113+ var changes = fakebackend.nextAnnotations();
114+ assert.deepEqual(changes.services, {wordpress: service});
115+ });
116 });
117
118 describe('FakeBackend.setCharm', function() {

Subscribers

People subscribed via source and target branches