From e70d80425a686669dfe26e47953709ca7d1aea80 Mon Sep 17 00:00:00 2001 From: Wyatt Preul Date: Wed, 13 Sep 2017 13:30:45 -0500 Subject: [PATCH] fix: only get a single dg for id --- docker-compose.yml | 2 +- docker/api/package.json | 2 +- docker/api/server.js | 7 +++ packages/portal-api/lib/data/index.js | 66 +++++++++++++++------------ packages/portal-api/package.json | 2 +- triton-compose.yml | 2 +- 6 files changed, 48 insertions(+), 33 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 471fe9dc..fdbe5cce 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -66,7 +66,7 @@ frontend: # BACKEND ############################################################################# api: - image: joyent/copilot-api:1.8.6 + image: joyent/copilot-api:1.8.8 mem_limit: 512m links: - consul:consul diff --git a/docker/api/package.json b/docker/api/package.json index d81c5f07..5c2a4c80 100644 --- a/docker/api/package.json +++ b/docker/api/package.json @@ -21,7 +21,7 @@ "joi": "^10.6.0", "joyent-cp-gql-schema": "^1.7.0", "piloted": "^3.1.1", - "portal-api": "^1.8.6", + "portal-api": "^1.8.8", "toppsy": "^1.1.0", "triton": "^5.2.0" } diff --git a/docker/api/server.js b/docker/api/server.js index 8fce81f8..4ceb7cbc 100644 --- a/docker/api/server.js +++ b/docker/api/server.js @@ -119,12 +119,19 @@ const startServer = function ({ docker, rethink }) { const handlerError = function (err) { if (err) { console.error(err); + console.error(err.stack); process.exit(1); } }; +process.on('uncaughtException', (err) => { + console.error(err); + console.error(err.stack); +}); + process.on('unhandledRejection', (err) => { console.error(err); + console.error(err.stack); }); loadConfig(); diff --git a/packages/portal-api/lib/data/index.js b/packages/portal-api/lib/data/index.js index d86efe13..e636f612 100644 --- a/packages/portal-api/lib/data/index.js +++ b/packages/portal-api/lib/data/index.js @@ -460,6 +460,16 @@ class Data extends EventEmitter { getDeploymentGroup (query, cb) { query = query || {}; + if (query.id) { + return this._db.deployment_groups.get(query.id, (err, deploymentGroup) => { + if (err) { + return cb(err); + } + + cb(null, Transform.fromDeploymentGroup(this._getDeploymentGroupFns(deploymentGroup))); + }); + } + this._db.deployment_groups.query(query, (err, deploymentGroups) => { if (err) { return cb(err); @@ -487,16 +497,16 @@ class Data extends EventEmitter { VAsync.parallel({ funcs: [ - (cb) => { + (next) => { if (!res.dg) { - return cb(); + return next(); } - this._db.deployment_groups.remove({ id }, cb); + this._db.deployment_groups.remove({ id }, next); }, - (cb) => { + (next) => { if (!res.services) { - return cb(); + return next(); } VAsync.forEachParallel({ @@ -504,11 +514,11 @@ class Data extends EventEmitter { func: ({ id }, next) => { this._db.services.remove({ id }, next); } - }); + }, next); }, - (cb) => { + (next) => { if (!res.instances) { - return cb(); + return next(); } VAsync.forEachParallel({ @@ -516,67 +526,65 @@ class Data extends EventEmitter { func: ({ id }, next) => { this._db.instances.remove({ id }, next); } - }); + }, next); }, - (cb) => { + (next) => { VAsync.forEachParallel({ inputs: res.versions, func: ({ id }, next) => { this._db.versions.remove({ id }, next); } - }); + }, next); }, - (cb) => { + (next) => { VAsync.forEachParallel({ inputs: res.manifests, func: ({ id }, next) => { this._db.manifests.remove({ id }, next); } - }); + }, next); } ] - }, (err) => { - cb(err, res.cb); - }); + }, cb); }; VAsync.parallel({ funcs: [ - (cb) => { + (next) => { this.getDeploymentGroup({ id }, (err, dg) => { if (internals.isNotFound(err)) { - return cb(null, {}); + return next(null, {}); } - cb(err, { dg }); + next(err, { dg }); }); }, - (cb) => { + (next) => { this.getServices({ deploymentGroupId: id }, (err, services) => { if (internals.isNotFound(err)) { - return cb(null, {}); + return next(null, {}); } - cb(err, { services }); + next(err, { services }); }); }, - (cb) => { + (next) => { this.getInstances({ deploymentGroupId: id }, (err, instances) => { if (internals.isNotFound(err)) { - return cb(null, {}); + return next(null, {}); } - cb(err, { instances }); + next(err, { instances }); }); }, - (cb) => { + (next) => { this.getVersions({ deploymentGroupId: id }, (err, versions) => { - cb(err, { versions }); + next(err, { versions }); }); }, - (cb) => { + (next) => { this.getManifests({ deploymentGroupId: id }, (err, manifests) => { - cb(err, { manifests }); + next(err, { manifests }); }); } ] diff --git a/packages/portal-api/package.json b/packages/portal-api/package.json index ee94b202..e3aa86fb 100644 --- a/packages/portal-api/package.json +++ b/packages/portal-api/package.json @@ -1,6 +1,6 @@ { "name": "portal-api", - "version": "1.8.6", + "version": "1.8.8", "description": "", "main": "./lib/index.js", "scripts": { diff --git a/triton-compose.yml b/triton-compose.yml index f4442411..7378546b 100644 --- a/triton-compose.yml +++ b/triton-compose.yml @@ -81,7 +81,7 @@ frontend: # BACKEND ############################################################################# api: - image: joyent/copilot-api:1.8.6 + image: joyent/copilot-api:1.8.8 mem_limit: 1g expose: - 3000