From 6b44958d6eadb2a6231118d7082e960c195a964d Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Wed, 28 Jun 2017 11:24:32 -0700 Subject: [PATCH 1/4] Change the return value to include all of the random names --- lib/routes/docker-compose-cluster.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/routes/docker-compose-cluster.js b/lib/routes/docker-compose-cluster.js index f5fe79ed0..b65179116 100644 --- a/lib/routes/docker-compose-cluster.js +++ b/lib/routes/docker-compose-cluster.js @@ -140,19 +140,28 @@ const multiClusterCreate = function (sessionUser, body) { // Now that we have the main instances, we need to create clusters for each one. return Promise.props({ builds: Promise.map(serviceKeys.builds, (buildKey) => { - body.name = generateHashClusterName() - return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, body, buildKey)) + const hash = generateHashClusterName() + body.name = hash + return Promise.try(() => { + return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, body, buildKey)) + }) + .returns({ service: buildKey, hash }) }), externals: Promise.map(serviceKeys.externals, (externalKey) => { - body.name = generateHashClusterName() - return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, body, externalKey)) + const hash = generateHashClusterName() + body.name = hash + return Promise.try(() => { + return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, body, externalKey)) + }) + .returns({ service: externalKey, hash }) }) }) }) - .then((results) => { + .tap((results) => { const buildKeys = results.builds const externals = results.externals - return buildKeys.length + externals.length + results.total = buildKeys.length + externals.length + log.info(`Created ${results.total} clusters`, { results }) }) } @@ -209,7 +218,7 @@ function multiCreateRoute (req, res, next) { return multiClusterCreate(sessionUser, body) .then((results) => { - const message = `${results} cluster.create jobs enqueued` + const message = `${results.total} cluster.create jobs enqueued` return { json: { message, created: results }, status: 202 } }) .asCallback(responseHandler.bind(null, res, next)) From e2dd1ebc2ad80c4e4ec84c804f777bb480f94e7f Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Wed, 28 Jun 2017 11:27:53 -0700 Subject: [PATCH 2/4] FIx tests --- lib/routes/docker-compose-cluster.js | 4 ++-- unit/routes/docker-compose-cluster.js | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/routes/docker-compose-cluster.js b/lib/routes/docker-compose-cluster.js index b65179116..ad7f4dd28 100644 --- a/lib/routes/docker-compose-cluster.js +++ b/lib/routes/docker-compose-cluster.js @@ -145,7 +145,7 @@ const multiClusterCreate = function (sessionUser, body) { return Promise.try(() => { return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, body, buildKey)) }) - .returns({ service: buildKey, hash }) + .return({ service: buildKey, hash }) }), externals: Promise.map(serviceKeys.externals, (externalKey) => { const hash = generateHashClusterName() @@ -153,7 +153,7 @@ const multiClusterCreate = function (sessionUser, body) { return Promise.try(() => { return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, body, externalKey)) }) - .returns({ service: externalKey, hash }) + .return({ service: externalKey, hash }) }) }) }) diff --git a/unit/routes/docker-compose-cluster.js b/unit/routes/docker-compose-cluster.js index f6c565a7b..c2f7efdf5 100644 --- a/unit/routes/docker-compose-cluster.js +++ b/unit/routes/docker-compose-cluster.js @@ -237,9 +237,13 @@ describe('/docker-compose-cluster', function () { sinon.assert.calledOnce(resMock.status) sinon.assert.calledWith(resMock.status, 202) sinon.assert.calledOnce(resMock.json) - sinon.assert.calledWith(resMock.json, - { message: sinon.match.string, created: sinon.match.number } - ) + sinon.assert.calledWith(resMock.json, { + message: sinon.match.string, + created: sinon.match({ + builds: sinon.match.array, + externals: sinon.match.array + }) + }) }) }) }) From 4bf6b6a83af5b52a9b02fdd1b1823a48544cb081 Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Wed, 28 Jun 2017 15:56:53 -0700 Subject: [PATCH 3/4] Add to the JSDoc --- lib/routes/docker-compose-cluster.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/routes/docker-compose-cluster.js b/lib/routes/docker-compose-cluster.js index ad7f4dd28..418c96ce9 100644 --- a/lib/routes/docker-compose-cluster.js +++ b/lib/routes/docker-compose-cluster.js @@ -119,7 +119,15 @@ const postRoute = function (req, res, next) { * * @param {SessionUser} sessionUser - this user * @param {Object} body - cluster create options - * @resolves {Number} The number of cluster create jobs created + * + * @resolves {Object} results + * {Object[]} results.builds - Clusters created from the owning repo + * {String} results.builds.service - Service name + * {String} results.builds.hash - Random Hash generated for this cluster + * {Object[]} results.externals - Clusters created from github links + * {String} results.externals.service - Service name + * {String} results.externals.hash - Random Hash generated for this cluster + * {Number} results.total - Total number of clusters to be generated */ const multiClusterCreate = function (sessionUser, body) { // First, we need to fetch the file(s), and get all of the mains From e825b4794a98fca57452e02b8533d9851d0ee4cf Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Thu, 29 Jun 2017 16:24:51 -0700 Subject: [PATCH 4/4] 12.10.4 --- npm-shrinkwrap.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 6053d4ef3..115f17917 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "api", - "version": "12.10.3", + "version": "12.10.4", "dependencies": { "101": { "version": "1.6.2", diff --git a/package.json b/package.json index 5f55fe765..c68e6bdbb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "api", "description": "Runnable API Server", - "version": "12.10.3", + "version": "12.10.4", "repository": { "type": "git", "url": "http://github.com/CodeNow/api.git"