removeInstances(models) { winston.debug('[ProviderLocal] removeInstances: models=', _.map(models, (model) => model.toString()) ); return Promise.map(models, (model) => { this._locals.delete(model.providerOpts.name); return this.removeInstance(model); }); }
/** * For testing purpose */ crashRandomInstance() { const names = Array.from(this._managedInstances.keys()); const randomName = names[Math.floor(Math.random() * names.length)]; winston.debug('[Manager] crashRandomInstance: name=%s', randomName); const instance = this._managedInstances.get(randomName); return instance.remove(); }
listen() { winston.debug('[LocalProxy/%s] proxy listen at port %d', this._name, this._port); return new Promise((resolve, reject) => { this._server.listen(this._port, (err) => { if (err) { return reject(err); } resolve(); }); }); }
shutdown() { winston.debug('[Main] shutdown'); this._master.shutdown(); this._commander.shutdown(); return this._manager .stop() .then(() => winston.info('[Main] All instances are stopped.')); }
removeInstance(model) { winston.debug('[ProviderLocal] removeInstance: model=', model.toString()); return new Promise((resolve) => { const local = model.providerOpts; if (!local.child || local.child.killed) { resolve(); } local.child.on('close', () => resolve()); local.child.kill(); local.child = void 0; }); }
listen() { winston.debug('[Main] listen'); // Start Commander return this._commander .listen() .then(() => { // Start Manager this._manager.start(); // Start Master return this._master.listen(); }); }
stop() { winston.debug('[TestServer] stop'); return new Promise((resolve) => { if (!this._child || this._child.killed) { resolve(); } this._child.on('close', () => resolve()); this._child.kill(); this._child = void 0; }); }
_changeAlive(alive) { winston.debug('[Instance/%s] changeAlive: %s => %s', this._model.name, this._alive, alive); if (this._alive !== alive) { this._alive = alive; this.emit('alive:updated', alive); } }
waitForAliveInstances(count) { winston.debug('[Manager] waitForAliveInstances: count=%d', count); if (this._aliveInstances.length === count) { return Promise.resolve(); } else { return Promise .delay(2000) .then(() => this.waitForAliveInstances(count)); } }
listenAndWait() { winston.debug('[Main] listenAndWait'); return this .listen() .then(() => this._manager.waitForAliveInstances(this._config.instance.scaling.min)); }
startInstance(model) { winston.debug('[ProviderDigitalOcean] startInstance: model=', model.toString()); return this._api.powerOnDroplet(model.providerOpts.id); }
shutdown() { winston.debug('[Master] shutdown'); this._server.close(); }
removeInstance(model) { winston.debug('[ProviderAWSEC2] removeInstance (asked): model=', model.toString()); this._modelsToRemove.push(model); return Promise.resolve(); }
shutdown() { winston.debug('[LocalProxy/%s] shutdown proxy listen at port %d', this._name, this._port); this._server.close(); }
startInstance(model) { winston.debug('[ProviderVscale] startInstance: model=', model.toString()); return this._api.startScalet(model.providerOpts.id); }