Skip to content

Commit

Permalink
[BREAKING] Rename @aws-cdk/ec2.Fleet to AutoScalingGroup (#318)
Browse files Browse the repository at this point in the history
There are already several overloads in the AWS landscape for the word `Fleet`,
namely `Spot Fleet`, `EC2 Fleet`, ... We should avoid creating new overloads for
the term. Instead, use the "standard" EC2 semantics of `AutoScalingGroup`.
  • Loading branch information
RomainMuller authored Jul 11, 2018
1 parent d63e9ae commit 28f7905
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.amazonaws.cdk.Stack;
import com.amazonaws.cdk.StackProps;
import com.amazonaws.cdk.Construct;
import com.amazonaws.cdk.ec2.Fleet;
import com.amazonaws.cdk.ec2.FleetProps;
import com.amazonaws.cdk.ec2.AutoScalingGroup;
import com.amazonaws.cdk.ec2.AutoScalingGroupProps;
import com.amazonaws.cdk.ec2.InstanceType;
import com.amazonaws.cdk.ec2.VpcNetwork;
import com.amazonaws.cdk.ec2.WindowsImage;
Expand All @@ -28,8 +28,8 @@ public HelloJavaStack(final App parent, final String name) {

VpcNetwork vpc = new VpcNetwork(this, "VPC");

MyFleetProps fleetProps = new MyFleetProps();
fleetProps.vpc = vpc;
MyAutoScalingGroupProps autoScalingGroupProps = new MyAutoScalingGroupProps();
autoScalingGroupProps.vpc = vpc;

int topicCount = 5;

Expand All @@ -39,18 +39,18 @@ public HelloJavaStack(final App parent, final String name) {
sinkQueue.subscribe(new Topic(this, "Topic" + (i+1)));
}

new MyFleet(this, "MyFleet", fleetProps);
new MyAutoScalingGroup(this, "MyAutoScalingGroup", autoScalingGroupProps);
}

static class MyFleetProps {
static class MyAutoScalingGroupProps {
public VpcNetwork vpc;
}

static class MyFleet extends Construct {
MyFleet(final Construct parent, final String name, final MyFleetProps props) {
static class MyAutoScalingGroup extends Construct {
MyAutoScalingGroup(final Construct parent, final String name, final MyAutoScalingGroupProps props) {
super(parent, name);

new Fleet(this, "Compute", FleetProps.builder()
new AutoScalingGroup(this, "Compute", AutoScalingGroupProps.builder()
.withInstanceType(new InstanceType("t2.micro"))
.withMachineImage(new WindowsImage(WindowsVersion.WindowsServer2016EnglishNanoBase))
.withVpc(props.vpc)
Expand All @@ -59,7 +59,7 @@ static class MyFleet extends Construct {

@Override
public List<String> validate() {
System.err.println("Validating MyFleet...");
System.err.println("Validating MyAutoScalingGroup...");
return Collections.emptyList();
}
}
Expand Down
48 changes: 23 additions & 25 deletions examples/cdk-examples-typescript/ec2/index.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
import { App, Stack, StackProps } from '@aws-cdk/core';
import {
AmazonLinuxImage, ClassicLoadBalancer, Fleet, InstanceClass, InstanceSize,
InstanceTypePair, VpcNetwork, VpcNetworkRefProps } from '@aws-cdk/ec2';
import * as cdk from '@aws-cdk/core';
import * as ec2 from '@aws-cdk/ec2';

class AppWithVpc extends Stack {
constructor(parent: App, name: string, props?: StackProps) {
class AppWithVpc extends cdk.Stack {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);

const vpc = new VpcNetwork(this, 'MyVpc');
const vpc = new ec2.VpcNetwork(this, 'MyVpc');

const fleet = new Fleet(this, 'MyFleet', {
const asg = new ec2.AutoScalingGroup(this, 'MyASG', {
vpc,
instanceType: new InstanceTypePair(InstanceClass.M4, InstanceSize.XLarge),
machineImage: new AmazonLinuxImage()
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.XLarge),
machineImage: new ec2.AmazonLinuxImage()
});

const clb = new ClassicLoadBalancer(this, 'LB', {
const clb = new ec2.ClassicLoadBalancer(this, 'LB', {
vpc,
internetFacing: true
});

clb.addListener({ externalPort: 80 });
clb.addTarget(fleet);
clb.addTarget(asg);
}
}

interface MyAppProps extends StackProps {
interface MyAppProps extends cdk.StackProps {
infra: CommonInfrastructure
}

class MyApp extends Stack {
constructor(parent: App, name: string, props: MyAppProps) {
class MyApp extends cdk.Stack {
constructor(parent: cdk.App, name: string, props: MyAppProps) {
super(parent, name, props);

const vpc = VpcNetwork.import(this, 'VPC', props.infra.vpc);
const vpc = ec2.VpcNetwork.import(this, 'VPC', props.infra.vpc);

const fleet = new Fleet(this, 'MyFleet', {
const fleet = new ec2.AutoScalingGroup(this, 'MyASG', {
vpc,
instanceType: new InstanceTypePair(InstanceClass.M4, InstanceSize.XLarge),
machineImage: new AmazonLinuxImage()
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.XLarge),
machineImage: new ec2.AmazonLinuxImage()
});

const clb = new ClassicLoadBalancer(this, 'LB', {
const clb = new ec2.ClassicLoadBalancer(this, 'LB', {
vpc,
internetFacing: true
});
Expand All @@ -51,18 +49,18 @@ class MyApp extends Stack {
}
}

class CommonInfrastructure extends Stack {
public vpc: VpcNetworkRefProps;
class CommonInfrastructure extends cdk.Stack {
public vpc: ec2.VpcNetworkRefProps;

constructor(parent: App, name: string, props?: StackProps) {
constructor(parent: cdk.App, name: string, props?: cdk.StackProps) {
super(parent, name, props);

const vpc = new VpcNetwork(this, 'VPC');
const vpc = new ec2.VpcNetwork(this, 'VPC');
this.vpc = vpc.export();
}
}

const app = new App(process.argv);
const app = new cdk.App(process.argv);

const infra = new CommonInfrastructure(app, 'infra');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { VpcNetworkRef, VpcPlacementStrategy } from './vpc-ref';
/**
* Properties of a Fleet
*/
export interface FleetProps {
export interface AutoScalingGroupProps {
/**
* Type of instance to launch
*/
Expand Down Expand Up @@ -83,7 +83,7 @@ export interface FleetProps {
*
* The ASG spans all availability zones.
*/
export class Fleet extends Construct implements IClassicLoadBalancerTarget {
export class AutoScalingGroup extends Construct implements IClassicLoadBalancerTarget {
public readonly connectionPeer: IConnectionPeer;

/**
Expand All @@ -106,7 +106,7 @@ export class Fleet extends Construct implements IClassicLoadBalancerTarget {
private readonly securityGroup: SecurityGroup;
private readonly loadBalancerNames: Token[] = [];

constructor(parent: Construct, name: string, props: FleetProps) {
constructor(parent: Construct, name: string, props: AutoScalingGroupProps) {
super(parent, name);

this.securityGroup = new SecurityGroup(this, 'InstanceSecurityGroup', { vpc: props.vpc });
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/ec2/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './auto-scaling-group';
export * from './connection';
export * from './connections';
export * from './fleet';
export * from './instance-types';
export * from './load-balancer';
export * from './machine-image';
Expand Down
27 changes: 13 additions & 14 deletions packages/@aws-cdk/ec2/test/demo.split-stack-vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,37 @@
// support multi-stack deployments since we have no good way of
// ordering stack deployments. So run this test by hand for now
// until we have that.
import { App, Stack } from '@aws-cdk/core';
import { AmazonLinuxImage, AnyIPv4, ClassicLoadBalancer, Fleet, InstanceClass, InstanceSize,
InstanceTypePair, VpcNetwork, VpcNetworkRef } from '../lib';
import * as cdk from '@aws-cdk/core';
import * as ec2 from '../lib';

const app = new App(process.argv);
const vpcStack = new Stack(app, 'VPCStack');
const app = new cdk.App(process.argv);
const vpcStack = new cdk.Stack(app, 'VPCStack');

const exportedVpc = new VpcNetwork(vpcStack, 'VPC', {
const exportedVpc = new ec2.VpcNetwork(vpcStack, 'VPC', {
maxAZs: 3
});

const appStack = new Stack(app, 'AppStack');
const appStack = new cdk.Stack(app, 'AppStack');

const importedVpc = VpcNetworkRef.import(appStack, 'VPC', exportedVpc.export());
const importedVpc = ec2.VpcNetworkRef.import(appStack, 'VPC', exportedVpc.export());

const fleet = new Fleet(appStack, 'Fleet', {
const asg = new ec2.AutoScalingGroup(appStack, 'ASG', {
vpc: importedVpc,
instanceType: new InstanceTypePair(InstanceClass.Burstable2, InstanceSize.Micro),
machineImage: new AmazonLinuxImage()
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Micro),
machineImage: new ec2.AmazonLinuxImage()
});

new ClassicLoadBalancer(appStack, 'LB', {
new ec2.ClassicLoadBalancer(appStack, 'LB', {
vpc: importedVpc,
internetFacing: true,
listeners: [{
externalPort: 80,
allowConnectionsFrom: [new AnyIPv4()]
allowConnectionsFrom: [new ec2.AnyIPv4()]
}],
healthCheck: {
port: 80
},
targets: [fleet]
targets: [asg]
});

process.stdout.write(app.run());
6 changes: 3 additions & 3 deletions packages/@aws-cdk/ec2/test/integ.everything.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import { App, Stack } from '@aws-cdk/core';
import { AmazonLinuxImage, AnyIPv4, ClassicLoadBalancer, Fleet, InstanceClass,
import { AmazonLinuxImage, AnyIPv4, AutoScalingGroup, ClassicLoadBalancer, InstanceClass,
InstanceSize, InstanceTypePair, VpcNetwork } from '../lib';

const app = new App(process.argv);
Expand All @@ -10,7 +10,7 @@ const vpc = new VpcNetwork(stack, 'VPC', {
maxAZs: 3
});

const fleet = new Fleet(stack, 'Fleet', {
const asg = new AutoScalingGroup(stack, 'Fleet', {
vpc,
instanceType: new InstanceTypePair(InstanceClass.Burstable2, InstanceSize.Micro),
machineImage: new AmazonLinuxImage(),
Expand All @@ -26,7 +26,7 @@ new ClassicLoadBalancer(stack, 'LB', {
healthCheck: {
port: 80
},
targets: [fleet]
targets: [asg]
});

process.stdout.write(app.run());
6 changes: 3 additions & 3 deletions packages/@aws-cdk/ec2/test/test.fleet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@aws-cdk/assert';
import { PolicyStatement, Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { AmazonLinuxImage, Fleet, InstanceClass, InstanceSize, InstanceTypePair, VpcNetwork, VpcNetworkId, VpcSubnetId } from '../lib';
import { AmazonLinuxImage, AutoScalingGroup, InstanceClass, InstanceSize, InstanceTypePair, VpcNetwork, VpcNetworkId, VpcSubnetId } from '../lib';

// tslint:disable:object-literal-key-quotes

Expand All @@ -10,7 +10,7 @@ export = {
const stack = new Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' }});
const vpc = mockVpc(stack);

new Fleet(stack, 'MyFleet', {
new AutoScalingGroup(stack, 'MyFleet', {
instanceType: new InstanceTypePair(InstanceClass.M4, InstanceSize.Micro),
machineImage: new AmazonLinuxImage(),
vpc
Expand Down Expand Up @@ -111,7 +111,7 @@ export = {
const stack = new Stack(undefined, 'MyStack', { env: { region: 'us-east-1', account: '1234' }});
const vpc = mockVpc(stack);

const fleet = new Fleet(stack, 'MyFleet', {
const fleet = new AutoScalingGroup(stack, 'MyFleet', {
instanceType: new InstanceTypePair(InstanceClass.M4, InstanceSize.Micro),
machineImage: new AmazonLinuxImage(),
vpc
Expand Down

0 comments on commit 28f7905

Please sign in to comment.