Skip to content

Commit

Permalink
[api] Support clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki committed May 9, 2013
1 parent 231dccf commit ba14059
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
49 changes: 42 additions & 7 deletions lib/remote-dependencies.js
Expand Up @@ -10,6 +10,7 @@ var path = require('path'),
cycle = require('cycle'),
utile = require('utile'),
wtfos = require('wtfos'),
deepEqual = require('deep-equal'),
async = utile.async,
validate = require('./validate');

Expand Down Expand Up @@ -217,11 +218,7 @@ exports.verifyRunlist = function (options, callback) {
var runlist = options.runlist,
client = options.client;

if (!runlist || !runlist.length || !client || !client.servers) {
return callback();
}

client.servers(function (err, config) {
function onConfig(err, config) {
if (err) {
return callback(err);
}
Expand Down Expand Up @@ -255,7 +252,45 @@ exports.verifyRunlist = function (options, callback) {
}

callback(null, satisfying);
});
}

function getClusterConfig(callback) {
async.map(options.clusters, client.servers.bind(client), function (err, configs) {
if (err) {
return callback(err);
}

var result = {};

configs.forEach(function (config) {
Object.keys(config).forEach(function (system) {
if (!result[system]) {
result[system] = [];
}

config[system].filter(function (server) {
//
// Make sure results are unique.
// TODO: push more matching systems up.
//
return !result[system].some(deepEqual.bind(this, server));
}).forEach(function (server) {
result[system].push(server);
});
});
});

callback(null, result);
});
}

if (!runlist || !runlist.length || !client || !client.servers) {
return callback();
}

return options.clusters
? getClusterConfig(onConfig)
: client.servers(onConfig);
};

//
Expand Down Expand Up @@ -332,4 +367,4 @@ exports.cycles = function (systems) {
});

return circular;
};
};
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -20,7 +20,8 @@
"cycle": "~1.0.2",
"semver": "~1.1.4",
"utile": "~0.1.7",
"wtfos": "~0.0.3"
"wtfos": "~0.0.3",
"deep-equal": "0.0.0"
},
"devDependencies": {
"composer-api": "~1.0.0",
Expand Down

0 comments on commit ba14059

Please sign in to comment.