From aa2f9765c3de88baade07360363434d5019c34fa Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Thu, 29 Jun 2017 19:20:07 -0700 Subject: [PATCH 1/3] fix the return value on the route to make it work with the better frontend checker Fix issue where the clusterName values were being re-used --- lib/models/rabbitmq/index.js | 2 +- lib/models/services/cluster-config-service.js | 1 + lib/routes/docker-compose-cluster.js | 37 ++++++++++--------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/models/rabbitmq/index.js b/lib/models/rabbitmq/index.js index ad7253b01..eeb287d9b 100644 --- a/lib/models/rabbitmq/index.js +++ b/lib/models/rabbitmq/index.js @@ -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) { diff --git a/lib/models/services/cluster-config-service.js b/lib/models/services/cluster-config-service.js index 0a111b31b..badfaf4ff 100644 --- a/lib/models/services/cluster-config-service.js +++ b/lib/models/services/cluster-config-service.js @@ -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 */ diff --git a/lib/routes/docker-compose-cluster.js b/lib/routes/docker-compose-cluster.js index 7f0eb2246..9c0f3bcce 100644 --- a/lib/routes/docker-compose-cluster.js +++ b/lib/routes/docker-compose-cluster.js @@ -75,7 +75,7 @@ function makeCreateOptsFromBody (sessionUser, body, mainInstanceServiceName) { isTesting: isTesting || false, testReporters: testReporters || [], clusterName, - shouldNotAutoFork, + shouldNotAutoFork: shouldNotAutoFork || true, parentInputClusterConfigId: parentInputClusterConfigId || '' } } @@ -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} body - Cluster create options + * @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, body, serviceNames) { + return Promise.map(serviceNames, (service) => { + const newBody = Object.assign({name: generateHashClusterName()}, body) + return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, newBody, service)) + .return({ service: service, hash: newBody.name }) + }) +} + /** * Enqueues a Cluster Create job for each build and external main in the Compose File * @@ -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) => { From 17d0456e8c8f9763aceaf6cd8a21a7fdb51383f4 Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Thu, 29 Jun 2017 19:30:02 -0700 Subject: [PATCH 2/3] fix unit tests --- unit/routes/docker-compose-cluster.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unit/routes/docker-compose-cluster.js b/unit/routes/docker-compose-cluster.js index 8b3985db6..4dbca4849 100644 --- a/unit/routes/docker-compose-cluster.js +++ b/unit/routes/docker-compose-cluster.js @@ -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 }) From 3147e1fef646f3961d4359f70b5c818aaeb8d724 Mon Sep 17 00:00:00 2001 From: Nathan219 Date: Fri, 30 Jun 2017 13:39:56 -0700 Subject: [PATCH 3/3] rename --- lib/routes/docker-compose-cluster.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/routes/docker-compose-cluster.js b/lib/routes/docker-compose-cluster.js index 9c0f3bcce..608924210 100644 --- a/lib/routes/docker-compose-cluster.js +++ b/lib/routes/docker-compose-cluster.js @@ -120,17 +120,17 @@ const postRoute = function (req, res, next) { /** * Takes the result from parsing the compose, and turns them into cluster create jobs * @param {SessionUser} sessionUser - This user - * @param {Object} body - Cluster create options + * @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, body, serviceNames) { +function createClusters (sessionUser, createClusterOptions, serviceNames) { return Promise.map(serviceNames, (service) => { - const newBody = Object.assign({name: generateHashClusterName()}, body) - return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, newBody, service)) - .return({ service: service, hash: newBody.name }) + const opts = Object.assign({name: generateHashClusterName()}, createClusterOptions) + return rabbitMQ.createCluster(makeCreateOptsFromBody(sessionUser, opts, service)) + .return({ service: service, hash: opts.name }) }) }