Skip to content

Commit

Permalink
Merge pull request #2038 from CodeNow/Fix-issue-with-clusterNames-not…
Browse files Browse the repository at this point in the history
…-changing

Fix remaining issues with multi-route
  • Loading branch information
Nathan219 authored Jun 30, 2017
2 parents de0c93e + 0966ca7 commit a1d4cbf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/models/rabbitmq/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ RabbitMQ.prototype.contextVersionDeleted = function (data) {
}

RabbitMQ.prototype.createCluster = function (data) {
this._publisher.publishTask('cluster.create', data)
return this._publisher.publishTask('cluster.create', data)
}

RabbitMQ.prototype.deleteCluster = function (data) {
Expand Down
1 change: 1 addition & 0 deletions lib/models/services/cluster-config-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ module.exports = class ClusterConfigService {
* @param {String[]} data.testReporters - array of names of the testReporters
* @param {String} data.clusterName - name of the cluster
* @param {ObjectId=} data.parentInputClusterConfigId - Id of the parent cluster
* @param {Boolean} data.shouldNotAutoFork - True if this cluster should not fork branches
*
* @return {Promise} with object that has AutoIsolationConfig
*/
Expand Down
37 changes: 20 additions & 17 deletions lib/routes/docker-compose-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function makeCreateOptsFromBody (sessionUser, body, mainInstanceServiceName) {
isTesting: isTesting || false,
testReporters: testReporters || [],
clusterName,
shouldNotAutoFork,
shouldNotAutoFork: shouldNotAutoFork || true,
parentInputClusterConfigId: parentInputClusterConfigId || ''
}
}
Expand Down Expand Up @@ -117,6 +117,23 @@ const postRoute = function (req, res, next) {
.asCallback(responseHandler.bind(null, res, next))
}

/**
* Takes the result from parsing the compose, and turns them into cluster create jobs
* @param {SessionUser} sessionUser - This user
* @param {Object} createClusterOptions - From the request body, the options for these new clusters
* @param {Object} serviceNames
* @param {String[]} serviceNames.builds - Clusters created from the owning repo
* @param {String[]} serviceNames.externals - Clusters created from github links
* @param {Number} serviceNames.total - Total number of clusters to be generated
*/
function createClusters (sessionUser, createClusterOptions, serviceNames) {
return Promise.map(serviceNames, (service) => {
const opts = Object.assign({name: generateHashClusterName()}, createClusterOptions)
return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, opts, service))
.return({ service: service, hash: opts.name })
})
}

/**
* Enqueues a Cluster Create job for each build and external main in the Compose File
*
Expand Down Expand Up @@ -150,22 +167,8 @@ const multiClusterCreate = function (sessionUser, body) {
const serviceKeys = ClusterConfigService.getUniqueServicesKeysFromOctobearResults(results)
// Now that we have the main instances, we need to create clusters for each one.
return Promise.props({
builds: Promise.map(serviceKeys.builds, (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) => {
const hash = generateHashClusterName()
body.name = hash
return Promise.try(() => {
return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, body, externalKey))
})
.return({ service: externalKey, hash })
})
builds: createClusters(sessionUser, body, serviceKeys.builds),
externals: createClusters(sessionUser, body, serviceKeys.externals)
})
})
.tap((results) => {
Expand Down
2 changes: 1 addition & 1 deletion unit/routes/docker-compose-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('/docker-compose-cluster', function () {
}
const body = { repo, branch, filePath, name, parentInputClusterConfigId, githubId, shouldNotAutoFork }
beforeEach(function (done) {
createClusterStub = sinon.stub(rabbitMQ, 'createCluster')
createClusterStub = sinon.stub(rabbitMQ, 'createCluster').resolves()
validateOrBoomStub = sinon.spy(joi, 'validateOrBoomAsync')
sinon.stub(ClusterConfigService, 'getUniqueServicesKeysFromOctobearResults').returns(uniqueMains)
sinon.stub(ClusterConfigService, '_parseComposeInfoForConfig').resolves({ mains })
Expand Down

0 comments on commit a1d4cbf

Please sign in to comment.