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

blueprint: Change blueprints to use Infrastructure

This commit changes all of our internal blueprints to use the
new Infrastructure() constructor.
  • Loading branch information...
kayousterhout authored and kklin committed Oct 6, 2017
1 parent 33ef578 commit 3b321e7ae804d2c5ad1346717e2d32372f55a3c7
Showing with 117 additions and 164 deletions.
  1. +8 −10 cli/command/init/initializerTest.js
  2. +4 −5 cli/command/init/templates/inf_template
  3. +10 −12 docs/_BlueprintWritersGuide.md
  4. +8 −10 examples/floatingIP/floatingIP.js
  5. +25 −26 integration-tester/config/infrastructure.js
  6. +1 −2 integration-tester/config/infrastructureRunner.js
  7. +2 −4 integration-tester/tester_test.go
  8. +5 −6 integration-tester/tests/10-network/network.js
  9. +1 −3 integration-tester/tests/100-logs/logs.js
  10. +2 −3 integration-tester/tests/15-bandwidth/bandwidth.js
  11. +2 −4 integration-tester/tests/20-spark/spark.js
  12. +4 −5 integration-tester/tests/30-mean/mean.js
  13. +2 −3 integration-tester/tests/40-stop/stop.js
  14. +2 −4 integration-tester/tests/60-duplicate-cluster-setup/duplicateClusterSetup.js
  15. +3 −5 integration-tester/tests/61-duplicate-cluster/duplicateCluster.js
  16. +2 −3 integration-tester/tests/build-dockerfile/buildDockerfile.js
  17. +2 −3 integration-tester/tests/connection-credentials/connectionCredentials.js
  18. +3 −4 integration-tester/tests/console-log/consoleLog.js
  19. +4 −5 integration-tester/tests/django/django.js
  20. +2 −4 integration-tester/tests/elasticsearch/elasticsearch.js
  21. +2 −4 integration-tester/tests/etcd/etcd.js
  22. +6 −9 integration-tester/tests/floating-ip/floatingIP.js
  23. +1 −3 integration-tester/tests/haproxy/haproxy.js
  24. +3 −6 integration-tester/tests/inbound-public/inboundPublic.js
  25. +4 −5 integration-tester/tests/load-balancer/loadBalancer.js
  26. +2 −4 integration-tester/tests/lobsters/lobsters.js
  27. +3 −4 integration-tester/tests/outbound-public/outboundPublic.js
  28. +2 −4 integration-tester/tests/redis/redis.js
  29. +2 −4 integration-tester/tests/zookeeper/zookeeper.js
@@ -255,7 +255,6 @@ describe('Initializer', () => {
};
const expInfraFile = `function infraGetter(quilt) {
const inf = new quilt.Deployment({namespace: 'quilt-deployment'});
var vmTemplate = new quilt.Machine({
provider: 'provider',
@@ -265,10 +264,10 @@ describe('Initializer', () => {
preemptible: true
});
inf.deploy(vmTemplate.asMaster().replicate(1));
inf.deploy(vmTemplate.asWorker().replicate(2));
return inf;
return new quilt.Infrastructure(
vmTemplate.replicate(1),
vmTemplate.replicate(2),
{namespace: 'quilt-deployment'});
}
module.exports = infraGetter;
@@ -291,7 +290,6 @@ module.exports = infraGetter;
};
const expInfraFile = `function infraGetter(quilt) {
const inf = new quilt.Deployment({namespace: 'quilt-deployment'});
var vmTemplate = new quilt.Machine({
provider: 'provider',
@@ -301,10 +299,10 @@ module.exports = infraGetter;
preemptible: true
});
inf.deploy(vmTemplate.asMaster().replicate(1));
inf.deploy(vmTemplate.asWorker().replicate(2));
return inf;
return new quilt.Infrastructure(
vmTemplate.replicate(1),
vmTemplate.replicate(2),
{namespace: 'quilt-deployment'});
}
module.exports = infraGetter;
@@ -1,5 +1,4 @@
function infraGetter(quilt) {
const inf = new quilt.Deployment({namespace: 'quilt-deployment'});
var vmTemplate = new quilt.Machine({
provider: '{{provider}}',
@@ -18,10 +17,10 @@ function infraGetter(quilt) {
preemptible: {{preemptible}}
});
inf.deploy(vmTemplate.asMaster().replicate({{masterCount}}));
inf.deploy(vmTemplate.asWorker().replicate({{workerCount}}));
return inf;
return new quilt.Infrastructure(
vmTemplate.replicate({{masterCount}}),
vmTemplate.replicate({{workerCount}}),
{namespace: 'quilt-deployment'});
}
module.exports = infraGetter;
@@ -188,24 +188,22 @@ public key "bar":
let baseMachine = new Machine({provider: 'Amazon', sshKeys: ['ssh-rsa bar']});
```
Now, using that base machine, we can deploy a master and a worker machine. All
quilt deployments must have one master, which keeps track of state for all of
the machines in the cluster, and 0 or more workers. To deploy machines and
containers, you must create a deployment object, which maintains state about the
deployment.
Now, using that base machine, we can deploy a master and a worker machine using
Quilt's `Infrastructure` constructor. All infrastructures must have at least
one master, which keeps track of state for all of the machines in the cluster,
and at least one worker. The `Infrastructure` constructor accepts the master(s)
and worker(s) as parameters:
```javascript
const deployment = new Deployment();
deployment.deploy(baseMachine.asMaster());
deployment.deploy(baseMachine.asWorker());
const infra = new Infrastructure(baseMachine, baseMachine);
```
We've now defined a deployment with a master and worker machine. Let's finally
deploy the two containers on that infrastructure:
We've now defined a infrastructure with a master and worker machine. Let's
finally deploy the two containers on that infrastructure:
```javascript
sql.deploy(deployment);
lobsters.deploy(deployment);
sql.deploy(infra);
lobsters.deploy(infra);
```
We're done! Running the blueprint is now trivial. With a quilt daemon running, run
@@ -1,24 +1,22 @@
// AWS: http://docs.aws.amazon.com/cli/latest/reference/ec2/allocate-address.html
// Google: https://cloud.google.com/compute/docs/configure-instance-ip-addresses#reserve_new_static
const { Deployment, Machine } = require('@quilt/quilt');
const { Infrastructure, Machine } = require('@quilt/quilt');
const nginx = require('@quilt/nginx');
const floatingIp = 'xxx.xxx.xxx.xxx (CHANGE ME)';
const deployment = new Deployment();
const app = nginx.createContainer(80);
app.placeOn({ floatingIp });
app.deploy(deployment);
const baseMachine = new Machine({
provider: 'Amazon',
size: 'm4.large',
region: 'us-west-2',
// sshKeys: githubKeys("GITHUB_USERNAME")
});
const workerMachine = baseMachine.clone();
workerMachine.floatingIp = floatingIp;
deployment.deploy(baseMachine.asMaster());
const infra = new Infrastructure(baseMachine, workerMachine);
baseMachine.floatingIp = floatingIp;
deployment.deploy(baseMachine.asWorker());
const app = nginx.createContainer(80);
app.placeOn({ floatingIp });
app.deploy(infra);
@@ -1,37 +1,36 @@
const { Machine } = require('@quilt/quilt');
const { Infrastructure, Machine } = require('@quilt/quilt');
/** The number of worker machines to launch to run the tests on. */
const nWorker = 3;
/**
* Handles deploying the necessary infrastructure to run the tests.
* @constructor
* @param {number} nWorker Number of workers to use to run the tests
* Creates an Infrastructure to use to run the Quilt integration tests.
*
* @returns {Infrastructure} An Infrastructure to use to run the tests.
*/
function MachineDeployer(nWorker) {
this.nWorker = nWorker;
}
MachineDeployer.prototype.deploy = function deploy(deployment) {
function createTestInfrastructure() {
const baseMachine = new Machine({
provider: process.env.PROVIDER || 'Amazon',
size: process.env.SIZE || 'm3.medium',
sshKeys: ['ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCxMuzNUdKJREFgUkS' +
'pD0OPjtgDtbDvHQLDxgqnTrZpSvTw5r8XDd+AFS6eVibBfYv1u+geNF3IEkpO' +
'klDlII37DzhW7wzlRB0SmjUtODxL5hf9hKoScDpvXG3RBD6PBCyOHA5IJBTqP' +
'GpIZUMmOlXDYZA1KLaKQs6GByg7QMp6z1/gLCgcQygTDdiTfESgVMwR1uSQ5M' +
'RjBaL7vcVfrKExyCLxito77lpWFMARGG9W1wTWnmcPrzYR7cLzhzUClakazNJ' +
'mfso/b4Y5m+pNH2dLZdJ/eieLtSEsBDSP8X0GYpmTyFabZycSXZFYP+wBkrUT' +
'mgIh9LQ56U1lvA4UlxHJ'],
'pD0OPjtgDtbDvHQLDxgqnTrZpSvTw5r8XDd+AFS6eVibBfYv1u+geNF3IEkpO' +
'klDlII37DzhW7wzlRB0SmjUtODxL5hf9hKoScDpvXG3RBD6PBCyOHA5IJBTqP' +
'GpIZUMmOlXDYZA1KLaKQs6GByg7QMp6z1/gLCgcQygTDdiTfESgVMwR1uSQ5M' +
'RjBaL7vcVfrKExyCLxito77lpWFMARGG9W1wTWnmcPrzYR7cLzhzUClakazNJ' +
'mfso/b4Y5m+pNH2dLZdJ/eieLtSEsBDSP8X0GYpmTyFabZycSXZFYP+wBkrUT' +
'mgIh9LQ56U1lvA4UlxHJ'],
});
deployment.deploy(baseMachine.asMaster());
const worker = baseMachine.asWorker();
// Preemptible instances are currently only implemented on Amazon.
if (baseMachine.provider === 'Amazon') {
worker.preemptible = true;
const workers = [];
for (let i = 0; i < nWorker; i += 1) {
const worker = baseMachine.clone();
// Preemptible instances are currently only implemented on Amazon.
if (baseMachine.provider === 'Amazon') {
worker.preemptible = true;
}
workers.push(worker);
}
return new Infrastructure(baseMachine, workers);
}
deployment.deploy(worker.replicate(this.nWorker));
};
// We will have three worker machines.
module.exports = new MachineDeployer(3);
module.exports = { createTestInfrastructure, nWorker };
@@ -1,4 +1,3 @@
const { Deployment } = require('@quilt/quilt');
const infrastructure = require('./infrastructure.js');
(new Deployment()).deploy(infrastructure);
infrastructure.createTestInfrastructure();
@@ -39,17 +39,15 @@ func TestUpdateNamespace(t *testing.T) {
blueprintPath := "/test.blueprint"
err := overwrite(blueprintPath, `require("spark");
var deployment = new Deployment({namespace: "replace"});
deployment.deploy(new Machine({}));`)
var infra = new Infrastructure(new Machine(), new Machine(), {namespace: "replace"});`)
if err != nil {
t.Errorf("Unexpected error: %s", err.Error())
}
updateNamespace(blueprintPath, "test-namespace")
res, err := fileContents(blueprintPath)
exp := `require("spark");
var deployment = new Deployment({namespace: "replace"});
deployment.deploy(new Machine({}));; ` +
var infra = new Infrastructure(new Machine(), new Machine(), {namespace: "replace"});; ` +
`require('@quilt/quilt').getDeployment().namespace = "test-namespace";`
if err != nil {
t.Errorf("Unexpected error: %s", err.Error())
@@ -1,8 +1,7 @@
const quilt = require('@quilt/quilt');
const infrastructure = require('../../config/infrastructure.js');
const deployment = new quilt.Deployment();
deployment.deploy(infrastructure);
const infra = infrastructure.createTestInfrastructure();
const image = 'alpine';
const command = ['tail', '-f', '/dev/null'];
@@ -30,7 +29,7 @@ quilt.allow(blueContainers, yellowContainers, 80);
const redLB = new quilt.LoadBalancer('red-lb', redContainers);
redLB.allowFrom(blueContainers, 80);
redContainers.forEach(container => container.deploy(deployment));
yellowContainers.forEach(container => container.deploy(deployment));
blueContainers.forEach(container => container.deploy(deployment));
redLB.deploy(deployment);
redContainers.forEach(container => container.deploy(infra));
yellowContainers.forEach(container => container.deploy(infra));
blueContainers.forEach(container => container.deploy(infra));
redLB.deploy(infra);
@@ -1,5 +1,3 @@
const quilt = require('@quilt/quilt');
const infrastructure = require('../../config/infrastructure.js');
const deployment = new quilt.Deployment();
deployment.deploy(infrastructure);
infrastructure.createTestInfrastructure();
@@ -1,8 +1,7 @@
const quilt = require('@quilt/quilt');
const infrastructure = require('../../config/infrastructure.js');
const deployment = new quilt.Deployment();
deployment.deploy(infrastructure);
const infra = infrastructure.createTestInfrastructure();
// If we deploy nWorker+1 containers, at least one machine is guaranteed to run
// two containers, and thus be able to test intra-machine bandwidth.
@@ -13,4 +12,4 @@ for (let i = 0; i < infrastructure.nWorker + 1; i += 1) {
}));
}
quilt.allow(iperfs, iperfs, 5201);
iperfs.forEach(container => container.deploy(deployment));
iperfs.forEach(container => container.deploy(infra));
@@ -1,4 +1,3 @@
const quilt = require('@quilt/quilt');
const spark = require('@quilt/spark');
const infrastructure = require('../../config/infrastructure.js');
@@ -10,6 +9,5 @@ const sprk = new spark.Spark(1, infrastructure.nWorker - 1)
.exposeUIToPublic()
.job('run-example SparkPi');
const deployment = new quilt.Deployment();
deployment.deploy(infrastructure);
sprk.deploy(deployment);
const infra = infrastructure.createTestInfrastructure();
sprk.deploy(infra);
@@ -4,8 +4,7 @@ const Mongo = require('@quilt/mongo');
const Node = require('@quilt/nodejs');
const infrastructure = require('../../config/infrastructure.js');
const deployment = new quilt.Deployment();
deployment.deploy(infrastructure);
const infra = infrastructure.createTestInfrastructure();
const mongo = new Mongo(3);
const app = new Node({
@@ -22,6 +21,6 @@ const proxy = haproxy.simpleLoadBalancer(app.containers);
mongo.allowFrom(app.containers, mongo.port);
proxy.allowFrom(quilt.publicInternet, haproxy.exposedPort);
app.deploy(deployment);
mongo.deploy(deployment);
proxy.deploy(deployment);
app.deploy(infra);
mongo.deploy(infra);
proxy.deploy(infra);
@@ -1,10 +1,9 @@
const quilt = require('@quilt/quilt');
const infrastructure = require('../../config/infrastructure.js');
const deployment = new quilt.Deployment();
deployment.deploy(infrastructure);
const infra = infrastructure.createTestInfrastructure();
for (let i = 0; i < infrastructure.nWorker; i += 1) {
const container = new quilt.Container('foo', 'google/pause');
container.deploy(deployment);
container.deploy(infra);
}
@@ -1,10 +1,8 @@
const quilt = require('@quilt/quilt');
const spark = require('@quilt/spark');
const infrastructure = require('../../config/infrastructure.js');
const deployment = new quilt.Deployment();
deployment.deploy(infrastructure);
const infra = infrastructure.createTestInfrastructure();
const sprk = new spark.Spark(1, 3);
sprk.deploy(deployment);
sprk.deploy(infra);
@@ -1,12 +1,10 @@
const quilt = require('@quilt/quilt');
const spark = require('@quilt/spark');
const infrastructure = require('../../config/infrastructure.js');
const deployment = new quilt.Deployment();
deployment.deploy(infrastructure);
const infra = infrastructure.createTestInfrastructure();
const sprk = new spark.Spark(1, 3);
const sprk2 = new spark.Spark(1, 3);
sprk.deploy(deployment);
sprk2.deploy(deployment);
sprk.deploy(infra);
sprk2.deploy(infra);
@@ -1,8 +1,7 @@
const quilt = require('@quilt/quilt');
const infrastructure = require('../../config/infrastructure.js');
const deployment = new quilt.Deployment();
deployment.deploy(infrastructure);
const infra = infrastructure.createTestInfrastructure();
for (let workerIndex = 0; workerIndex < infrastructure.nWorker; workerIndex += 1) {
const image = new quilt.Image(`test-custom-image${workerIndex}`,
@@ -13,6 +12,6 @@ for (let workerIndex = 0; workerIndex < infrastructure.nWorker; workerIndex += 1
for (let containerIndex = 0; containerIndex < 2; containerIndex += 1) {
const container = new quilt.Container(
'bar', image, { command: ['tail', '-f', '/dev/null'] });
container.deploy(deployment);
container.deploy(infra);
}
}
@@ -1,8 +1,7 @@
const quilt = require('@quilt/quilt');
const infrastructure = require('../../config/infrastructure.js');
const deployment = new quilt.Deployment();
deployment.deploy(infrastructure);
const infra = infrastructure.createTestInfrastructure();
const container = new quilt.Container('red', 'google/pause');
container.deploy(deployment);
container.deploy(infra);
@@ -1,13 +1,12 @@
const quilt = require('@quilt/quilt');
const infrastructure = require('../../config/infrastructure.js');
const deployment = new quilt.Deployment();
deployment.deploy(infrastructure);
const infra = infrastructure.createTestInfrastructure();
console.log('This should show up in the terminal.');
console.warn('This too.');
const redContainer = new quilt.Container('red', 'google/pause');
redContainer.deploy(deployment);
redContainer.deploy(infra);
const blueContainer = new quilt.Container('blue', 'google/pause');
blueContainer.deploy(deployment);
blueContainer.deploy(infra);
Oops, something went wrong.

0 comments on commit 3b321e7

Please sign in to comment.