UNPKG

masson

Version:

Module execution engine for cluster deployments.

120 lines (105 loc) 3.44 kB
// Generated by CoffeeScript 1.7.1 var Context, EventEmitter, flatten, merge, tree, _ref, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, __slice = [].slice; EventEmitter = require('events').EventEmitter; _ref = require('./misc'), flatten = _ref.flatten, merge = _ref.merge; tree = require('./tree'); Context = (function(_super) { __extends(Context, _super); function Context(config, command) { this.config = config; this.command = command; this.PASS = 0; this.PASS_MSG = 'STABLE'; this.OK = 1; this.OK_MSG = 'OK'; this.FAILED = 2; this.FAILED_MSG = 'ERROR'; this.DISABLED = 3; this.DISABLED_MSG = 'DISABLED'; this.TODO = 4; this.TODO_MSG = 'TODO'; this.STARTED = 5; this.STARTED_MSG = 'RUNNING'; this.STOP = 6; this.STOP_MSG = 'STOPPED'; this.TIMEOUT = 7; this.TIMEOUT_MSG = 'TIMEOUT'; this.WARN = 8; this.WARN_MSG = 'WARNING'; this.INAPPLICABLE = 9; this.INAPPLICABLE_MSG = 'SKIPPED'; this.tmp = {}; } Context.prototype.host_with_module = function(module, strict) { var ctx, host, servers, _ref1; servers = []; _ref1 = this.hosts; for (host in _ref1) { ctx = _ref1[host]; if (ctx.modules.indexOf(module) !== -1) { servers.push(host); } } if (servers.length > 1) { throw new Error("Too many hosts with module " + module + ": " + servers.length); } if (strict && servers.length !== 1) { throw new Error("Expect " + qtt + " host(s) for module " + module + " but got " + servers.length); } return servers[0]; }; Context.prototype.hosts_with_module = function(module, qtt, strict) { var ctx, host, servers, _ref1; servers = []; _ref1 = this.hosts; for (host in _ref1) { ctx = _ref1[host]; if (ctx.modules.indexOf(module) !== -1) { servers.push(host); } } if (strict && (qtt != null) && servers.length !== qtt) { throw new Error("Expect " + qtt + " host(s) for module " + module + " but got " + servers.length); } if (qtt === 1) { return servers[0]; } else { return servers; } }; Context.prototype.has_module = function(module) { return this.modules.indexOf(module) !== -1; }; Context.prototype.has_all_modules = function() { var module, modules, _i, _len; modules = 1 <= arguments.length ? __slice.call(arguments, 0) : []; modules = flatten(modules); for (_i = 0, _len = modules.length; _i < _len; _i++) { module = modules[_i]; if (!this.has_module(module)) { return false; } } return true; }; Context.prototype.has_any_modules = function() { var module, modules, _i, _len; modules = 1 <= arguments.length ? __slice.call(arguments, 0) : []; modules = flatten(modules); for (_i = 0, _len = modules.length; _i < _len; _i++) { module = modules[_i]; if (this.has_module(module)) { return true; } } return false; }; return Context; })(EventEmitter); module.exports = function(config, command) { return new Context(config, command); }; module.exports.Context = Context;