style: static methods

This commit is contained in:
Sérgio Ramos 2017-08-28 21:31:38 +01:00
parent c7938efd2f
commit 17def8e304
6 changed files with 42 additions and 40 deletions

View File

@ -675,7 +675,7 @@ class Data extends EventEmitter {
}); });
} }
_calcCurrentScale ({ config, currentVersion }, cb) { static _calcCurrentScale ({ config, currentVersion }, cb) {
return config.map(({ name }) => { return config.map(({ name }) => {
const currentScale = Find(ForceArray(currentVersion ? currentVersion.scale : []), [ const currentScale = Find(ForceArray(currentVersion ? currentVersion.scale : []), [
'serviceName', 'serviceName',
@ -696,7 +696,7 @@ class Data extends EventEmitter {
console.error(err); console.error(err);
} }
this._calcCurrentScale({ config, currentVersion }, cb); Data._calcCurrentScale({ config, currentVersion }, cb);
}; };
if (!this._triton) { if (!this._triton) {
@ -1534,7 +1534,7 @@ class Data extends EventEmitter {
return Object.assign({}, branch, { return Object.assign({}, branch, {
instances: this._instancesFilter(branch.instances) instances: this._instancesFilter(branch.instances)
}); });
}).filter(({ name }) => name); }).filter(({ name }) => { return name; });
return cb(null, Transform.fromService({ return cb(null, Transform.fromService({
service, service,
@ -1602,7 +1602,7 @@ class Data extends EventEmitter {
return Object.assign({}, branch, { return Object.assign({}, branch, {
instances: this._instancesFilter(branch.instances) instances: this._instancesFilter(branch.instances)
}); });
}).filter(({ name }) => name); }).filter(({ name }) => { return name; });
return Transform.fromService({ return Transform.fromService({
service, service,
@ -2564,9 +2564,11 @@ class Data extends EventEmitter {
metric.name = metricNameEnum[i]; metric.name = metricNameEnum[i];
} }
metric.metrics = metric.metrics.map((entry) => Object.assign(entry, { metric.metrics = metric.metrics.map((entry) => {
return Object.assign(entry, {
time: entry.time.toISOString() time: entry.time.toISOString()
})); });
});
return Object.assign(metric, { return Object.assign(metric, {
start: metric.metrics[0].time, start: metric.metrics[0].time,
@ -2587,7 +2589,7 @@ class Data extends EventEmitter {
prometheus.getMetrics({ prometheus.getMetrics({
names: formattedNames, names: formattedNames,
instances: ctx.machines.map(({ name }) => name), instances: ctx.machines.map(({ name }) => { return name; }),
start, start,
end end
}, (err, metrics) => { }, (err, metrics) => {

View File

@ -311,7 +311,7 @@ module.exports = class ContainerPilotWatcher extends Events {
}, cb); }, cb);
} }
_resolveServiceConnections ({ services, service }) { static _resolveServiceConnections ({ services, service }) {
const watches = Uniq( const watches = Uniq(
Flatten( Flatten(
ForceArray(service.instances).map(({ watches }) => { ForceArray(service.instances).map(({ watches }) => {
@ -348,7 +348,7 @@ module.exports = class ContainerPilotWatcher extends Events {
}); });
} }
_resolveInstanceHealth ({ name }, instance) { static _resolveInstanceHealth ({ name }, instance) {
if (!instance) { if (!instance) {
return 'UNAVAILABLE'; return 'UNAVAILABLE';
} }
@ -379,7 +379,7 @@ module.exports = class ContainerPilotWatcher extends Events {
return 'UNKNOWN'; return 'UNKNOWN';
} }
_resolveServiceBranches ({ name, slug, instances }) { static _resolveServiceBranches ({ name, slug, instances }) {
if (instances.length <= 1) { if (instances.length <= 1) {
return []; return [];
} }
@ -437,7 +437,7 @@ module.exports = class ContainerPilotWatcher extends Events {
return Object.values(branches).concat(defaultBranch); return Object.values(branches).concat(defaultBranch);
} }
_resolveDeploymentGroups (dgs) { static _resolveDeploymentGroups (dgs) {
return dgs return dgs
.filter(Boolean) .filter(Boolean)
.map((dg) => { .map((dg) => {
@ -451,7 +451,7 @@ module.exports = class ContainerPilotWatcher extends Events {
}); });
return Object.assign({}, instance, { return Object.assign({}, instance, {
healthy: this._resolveInstanceHealth(service, instance), healthy: ContainerPilotWatcher._resolveInstanceHealth(service, instance),
jobs, jobs,
watches watches
}); });
@ -464,8 +464,8 @@ module.exports = class ContainerPilotWatcher extends Events {
return Object.assign({}, dg, { return Object.assign({}, dg, {
services: ForceArray(dg.services).map((service) => { services: ForceArray(dg.services).map((service) => {
return Object.assign({}, service, { return Object.assign({}, service, {
branches: this._resolveServiceBranches(service), branches: ContainerPilotWatcher._resolveServiceBranches(service),
connections: this._resolveServiceConnections({ connections: ContainerPilotWatcher._resolveServiceConnections({
services: dg.services, services: dg.services,
service service
}) })
@ -485,7 +485,7 @@ module.exports = class ContainerPilotWatcher extends Events {
this.emit('error', err); this.emit('error', err);
} }
const dgs = this._resolveDeploymentGroups( const dgs = ContainerPilotWatcher._resolveDeploymentGroups(
ForceArray((results || {}).successes) ForceArray((results || {}).successes)
); );

View File

@ -141,7 +141,7 @@ module.exports = class MachineWatcher {
}); });
} }
getInstances (service, cb) { static getInstances (service, cb) {
service.instances() service.instances()
.then((instances) => { .then((instances) => {
return cb(null, instances); return cb(null, instances);
@ -151,7 +151,7 @@ module.exports = class MachineWatcher {
}); });
} }
getVersion (deploymentGroup, cb) { static getVersion (deploymentGroup, cb) {
if (typeof deploymentGroup.version !== 'function') { if (typeof deploymentGroup.version !== 'function') {
return cb(new Error('version must be a function')); return cb(new Error('version must be a function'));
} }
@ -578,12 +578,12 @@ module.exports = class MachineWatcher {
service, service,
deploymentGroup deploymentGroup
}, cb) => { }, cb) => {
this.getInstances(service, (err, instances = []) => { MachineWatcher.getInstances(service, (err, instances = []) => {
if (err && !isNotFound(err)) { if (err && !isNotFound(err)) {
return cb(err); return cb(err);
} }
this.getVersion(deploymentGroup, (err, version) => { MachineWatcher.getVersion(deploymentGroup, (err, version) => {
if (err) { if (err) {
return cb(err); return cb(err);
} }

View File

@ -42,13 +42,13 @@ server.register([
options: { namespace: 'portal', subsystem: 'api' } options: { namespace: 'portal', subsystem: 'api' }
} }
], ],
(err) => { (err) => {
handlerError(err); handlerError(err);
server.start((err) => { server.start((err) => {
handlerError(err); handlerError(err);
console.log(`server started at http://localhost:${server.info.port}`); console.log(`server started at http://localhost:${server.info.port}`);
}); });
} }
); );
function handlerError (error) { function handlerError (error) {

View File

@ -97,7 +97,7 @@ describe('graphql', () => {
server.inject({ method: 'POST', url: '/graphql', payload }, (res) => { server.inject({ method: 'POST', url: '/graphql', payload }, (res) => {
expect(res.statusCode).to.equal(200); expect(res.statusCode).to.equal(200);
console.log(res.result.data) console.log(res.result.data);
const deploymentGroup = res.result.data.portal.deploymentGroups[0]; const deploymentGroup = res.result.data.portal.deploymentGroups[0];
expect(deploymentGroup.name).to.equal('test'); expect(deploymentGroup.name).to.equal('test');
expect(deploymentGroup.services[0].name).to.equal('service'); expect(deploymentGroup.services[0].name).to.equal('service');