diff --git a/lib/routes/docker-compose-cluster.js b/lib/routes/docker-compose-cluster.js index b80a31bc8..7f0eb2246 100644 --- a/lib/routes/docker-compose-cluster.js +++ b/lib/routes/docker-compose-cluster.js @@ -122,7 +122,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 @@ -143,19 +151,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)) + }) + .return({ 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)) + }) + .return({ 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 }) }) } @@ -212,7 +229,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)) 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" diff --git a/unit/routes/docker-compose-cluster.js b/unit/routes/docker-compose-cluster.js index 31614bb63..8b3985db6 100644 --- a/unit/routes/docker-compose-cluster.js +++ b/unit/routes/docker-compose-cluster.js @@ -241,9 +241,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 + }) + }) }) }) })