This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

blueprint: Accept single machines in Infrastructure

This commit changes the Infrastructure constructor to be more forgiving,
and accept single machines, in addition to lists of machines, as the masters
and workers.
  • Loading branch information...
kayousterhout authored and kklin committed Oct 6, 2017
1 parent 78c2394 commit 33ef578b8a4e5969dea1d67237c91ee247208978
Showing with 35 additions and 7 deletions.
  1. +10 −7 blueprint/bindings.js
  2. +25 −0 blueprint/bindingsTest.js
View
@@ -49,9 +49,10 @@ class Infrastructure extends Deployment {
* Creates a new Infrastructure with the given options.
* @constructor
*
* @param {Machine[]} masters - List of machines to use as the masters.
* @param {Machine[]} workers - List of machines to use as the workers.
* Worker machines are responsible for running application containers.
* @param {Machine|Machine[]} masters - One or more machines that should be launched to
* use as the masters.
* @param {Machine|Machine[]} workers - One or more machines that should be launched to
* use as the workers. Worker machines are responsible for running application containers.
* @param {Object} [opts] - Optional arguments to tweak the behavior
* of the infrastructure.
* @param {string} [opts.namespace=default-namespace] - The name of the
@@ -66,15 +67,17 @@ class Infrastructure extends Deployment {
*/
constructor(masters, workers, opts = {}) {
super(opts);
if (masters.length < 1) {
const boxedMasters = boxObjects(masters, Machine);
const boxedWorkers = boxObjects(workers, Machine);
if (boxedMasters.length < 1) {
throw new Error('masters must include 1 or more Machines to use as ' +
'Quilt masters.');
} else if (workers.length < 1) {
} else if (boxedWorkers.length < 1) {
throw new Error('workers must include 1 or more Machines to use as ' +
'Quilt workers.');
}
masters.forEach(master => this.machines.push(master.asMaster()));
workers.forEach(worker => this.machines.push(worker.asWorker()));
boxedMasters.forEach(master => this.machines.push(master.asMaster()));
boxedWorkers.forEach(worker => this.machines.push(worker.asWorker()));
}
}
View
@@ -711,6 +711,22 @@ describe('Bindings', () => {
region: 'us-west-2',
}]);
});
it('accepts non-array master and worker as arguments', () => {
const machine = new b.Machine({
provider: 'Amazon',
region: 'us-west-2',
});
deployment = new b.Infrastructure(machine, machine);
checkMachines([{
role: 'Master',
provider: 'Amazon',
region: 'us-west-2',
}, {
role: 'Worker',
provider: 'Amazon',
region: 'us-west-2',
}]);
});
it('errors when no masters are given', () => {
const machine = new b.Machine({
provider: 'Amazon',
@@ -725,6 +741,15 @@ describe('Bindings', () => {
expect(() => new b.Infrastructure([machine], []))
.to.throw('workers must include 1 or more');
});
it('errors when a non-Machine is given as the master', () => {
const machine = new b.Machine({
provider: 'Amazon',
});
expect(() => new b.Infrastructure(['not a Machine'], [machine]))
.to.throw('not an array of Machines; item at index 0 ("not a Machine") is not a Machine');
expect(() => new b.Infrastructure(3, [machine]))
.to.throw('not an array of Machines (was 3)');
});
});
describe('Query', () => {
it('namespace', () => {

0 comments on commit 33ef578

Please sign in to comment.