Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #188 from hatched/esm-setconfig
Browse files Browse the repository at this point in the history
This branch adds hierarchical command functionality to the ECS along with the set_config env method.

__To QA__
- Open the GUI using the `ecs` flag.
- Drag the liferay from the charmbrowser and click the deploy button once.
- Open the console and run `app.ecs.changeSet` and make note of the id (service-xxx).
- Run the following substituting the id with the appropriate one `app.ecs.setConfig('service-xxx', {'http-port': "80802"}, null, {'http-port': "8080"}, function() {});`.
- Run `app.ecs.changeSet` and there should now be two entries in the 'commands' array the second of which should have the method property set to 'set_config'.
  • Loading branch information
jujugui committed Mar 21, 2014
2 parents 3906121 + 3959bed commit 21ee0c8
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 47 deletions.
85 changes: 79 additions & 6 deletions app/utils/environment-change-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ YUI.add('environment-change-set', function(Y) {
return key;
},

/**
Adds a new command to an existing record.
@method _addToRecrod
@param {String} key The key to add the command to.
@param {Object} command The command that's to be executed lazily.
@return {String} The key to which the command was added.
*/
_addToRecord: function(key, command) {
command = this._wrapCallback(command);
var changeSet = this.changeSet[key];
var length = changeSet.commands.push(command);
// Add next function to execute to previous next() command.
changeSet.commands[length - 2].next = this._execute.bind(this, command);
return key;
},

/**
Wraps the last function parameter so that we can be notified when it's
called.
Expand All @@ -122,6 +139,10 @@ YUI.add('environment-change-set', function(Y) {
// under. In most cases this will be `env`.
var result = callback.apply(this, self._getArgs(arguments));
self.fire('taskComplete', command);
// Execute the next command.
if (command.next) {
command.next();
}
return result;
}
args[index] = _callbackWrapper;
Expand All @@ -132,25 +153,28 @@ YUI.add('environment-change-set', function(Y) {
Executes the passed in command on the environment.
@method _execute
@param {Object} command An object of the command to execute.
@param {Object} command The individual command object from the changeSet.
*/
_execute: function(command) {
var env = this.get('env');
env[command.method].apply(env, command.args);
},

/**
Executes all of the commands stored in the changeSet.
Starts the processing of all of the top level
commands stored in the changeSet.
@method commit
*/
commit: function() {
var changeSet = this.changeSet;
var commands;

Object.keys(changeSet).forEach(function(key) {
changeSet[key].commands.forEach(function(command) {
this._execute(command);
this.fire('commit', command);
}, this);
commands = changeSet[key].commands;
// Trigger the series to start executing.
this._execute(commands[0]);
this.fire('commit', commands);
}, this);
},

Expand All @@ -176,6 +200,30 @@ YUI.add('environment-change-set', function(Y) {
return this._createNewRecord('service', command);
},

/**
Creates a new entry in the queue for setting a services config.
Receives all the parameters it's public method 'set_config' was called
with with the exception of the ECS options oject.
@method _lazySetConfig
@param {Array} args The arguments to set the config with.
*/
_lazySetConfig: function(args) {
var serviceName = args[0];
var queued = this.changeSet[serviceName];
var command = {
method: 'set_config', // This needs to match the method name in env.
executed: false,
args: args
};
// If it's a queued service then we need to add to that service's record.
if (queued) {
return this._addToRecord(serviceName, command);
}
return this._createNewRecord('setConfig', command);
},

/* End private environment methods. */

/* Public environment methods. */
Expand All @@ -198,6 +246,31 @@ YUI.add('environment-change-set', function(Y) {
} else {
this._lazyDeploy(args);
}
},

/**
Calls the environments set_config method or creates a new set_config
record in the queue.
THe parameters match the parameters for the env deploy method.
@method setConfig
*/
setConfig: function(serviceName, config, data, serviceConfig, callback,
options) {
var env = this.get('env'),
args = this._getArgs(arguments);
if (options && options.immediate) {
// Need to check that the serviceName is a real service name and not
// a queued service id before allowing immediate or not.
if (this.changeSet[serviceName]) {
throw 'You cannot immediately setConfig on a queued service';
} else {
env.set_config.apply(env, args);
}
} else {
this._lazySetConfig(args);
}
}

/* End Public environment methods. */
Expand Down
4 changes: 3 additions & 1 deletion app/views/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ YUI.add('juju-view-environment', function(Y) {

var db = this.get('db'),
env = this.get('env'),
ecs = this.get('ecs'),
topo = this.topo,
charm = db.charms.getById(model.get('charm')),
inspector = {};
Expand All @@ -102,7 +103,7 @@ YUI.add('juju-view-environment', function(Y) {
db: db,
model: model,
env: env,
ecs: this.get('ecs'),
ecs: ecs,
environment: this,
charmModel: charm,
topo: topo,
Expand All @@ -113,6 +114,7 @@ YUI.add('juju-view-environment', function(Y) {
db: db,
model: model,
env: env,
ecs: ecs,
environment: this,
enableDatabinding: true,
topo: topo,
Expand Down
16 changes: 14 additions & 2 deletions app/views/viewlets/service-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ YUI.add('service-config-view', function(Y) {
*/
saveConfig: function() {
var inspector = this.viewletManager,
env = inspector.get('env'),
db = inspector.get('db'),
service = inspector.get('model'),
charmUrl = service.get('charm'),
Expand All @@ -167,7 +166,20 @@ YUI.add('service-config-view', function(Y) {
}

if (Y.Object.isEmpty(errors)) {
env.set_config(
var setConfigMethod;
if (window.flags.ecs) {
// When this flag is removed and the method is being called
// directly it doesn't need to be bound.
var ecs = this.get('ecs');
setConfigMethod = ecs.setConfig.bind(ecs);
} else {
var env = inspector.get('env');
setConfigMethod = env.set_config.bind(env);
}

setConfigMethod(
// When we have a ghost service model this id will have to be the
// changeSet id so that we know which service to modify.
service.get('id'),
config,
inspector.configFileContent,
Expand Down

0 comments on commit 21ee0c8

Please sign in to comment.