Skip to content

Commit

Permalink
Merge branch 'master' into SAN-6464-make-all-iccs-unique
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan219 authored Jun 29, 2017
2 parents fe26f46 + e825b47 commit 44b9450
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
33 changes: 25 additions & 8 deletions lib/routes/docker-compose-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 })
})
}

Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
10 changes: 7 additions & 3 deletions unit/routes/docker-compose-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
})
})
})
Expand Down

0 comments on commit 44b9450

Please sign in to comment.