Skip to content

Commit

Permalink
fix: breaking change to deployment config props
Browse files Browse the repository at this point in the history
In #22159, a base class for all
deployment configs was added. Classes that extended this base were
calling static methods returning `IBaseDeploymentConfig` types where
previously they returned more specific types, IE
`IServerDeploymentConfig`. [This
method](6840d8e#diff-93f73231716deb0056687ee155c13d03ccabe2222fd191a33be9caeb7ad87ebaL126)
being previously implemented on `IServerDeploymentConfig` but now
inheriting from `IBaseDeploymentConfig` caused the return type to change
to `IBaseDeploymentConfig`

In Typescript, this is fine as [`IServerDeploymentConfig`](6840d8e#diff-93f73231716deb0056687ee155c13d03ccabe2222fd191a33be9caeb7ad87ebaR12) extends `IBaseDeploymentConfig` with no additional properties. So an instance of `IBaseDeploymentConfig` satisfies the `IServerDeploymentConfig` interface implicitly. However, in Java where interfaces are explicit, this caused the error:

```
incompatible types: IBaseDeploymentConfig cannot be converted to IServerDeploymentConfig
```

Where inputs expect the more specific type.
  • Loading branch information
MrArnoldPalmer committed Oct 19, 2022
1 parent 9ab6d79 commit d27a13d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { arnForDeploymentConfig, validateName } from './utils';
* The base class for ServerDeploymentConfig, EcsDeploymentConfig,
* and LambdaDeploymentConfig deployment configurations.
*/
export interface IBaseDeploymentConfig {
export interface IDeploymentConfig {
/**
* The physical, human-readable name of the Deployment Configuration.
* @attribute
Expand All @@ -24,9 +24,9 @@ export interface IBaseDeploymentConfig {
}

/**
* Construction properties of {@link BaseDeploymentConfig}.
* Construction properties of {@link DeploymentConfig}.
*/
export interface BaseDeploymentConfigOptions {
export interface DeploymentConfigOptions {
/**
* The physical, human-readable name of the Deployment Configuration.
* @default - automatically generated name
Expand Down Expand Up @@ -56,9 +56,9 @@ export enum ComputePlatform {

/**
* Complete base deployment config properties that are required to be supplied by the implementation
* of the BaseDeploymentConfig class.
* of the DeploymentConfig class.
*/
export interface BaseDeploymentConfigProps extends BaseDeploymentConfigOptions {
export interface DeploymentConfigProps extends DeploymentConfigOptions {
/**
* The destination compute platform for the deployment.
*
Expand Down Expand Up @@ -86,7 +86,7 @@ export interface BaseDeploymentConfigProps extends BaseDeploymentConfigOptions {
*
* @resource AWS::CodeDeploy::DeploymentConfig
*/
export abstract class BaseDeploymentConfig extends Resource implements IBaseDeploymentConfig {
export abstract class DeploymentConfig extends Resource implements IDeploymentConfig {
/**
* Import a custom Deployment Configuration for a Deployment Group defined outside the CDK.
*
Expand All @@ -95,7 +95,7 @@ export abstract class BaseDeploymentConfig extends Resource implements IBaseDepl
* @param deploymentConfigName the name of the referenced custom Deployment Configuration
* @returns a Construct representing a reference to an existing custom Deployment Configuration
*/
protected static fromDeploymentConfigName(scope: Construct, id: string, deploymentConfigName: string): IBaseDeploymentConfig {
protected static fromDeploymentConfigName(scope: Construct, id: string, deploymentConfigName: string): IDeploymentConfig {
ignore(id);
const arn = Stack.of(scope).formatArn({
service: 'codedeploy',
Expand All @@ -115,7 +115,7 @@ export abstract class BaseDeploymentConfig extends Resource implements IBaseDepl
* @param name the name of the referenced custom Deployment Configuration
* @returns a reference to an existing custom Deployment Configuration
*/
protected static deploymentConfig(name: string): IBaseDeploymentConfig {
protected static deploymentConfig(name: string): IDeploymentConfig {
return {
deploymentConfigName: name,
deploymentConfigArn: arnForDeploymentConfig(name),
Expand All @@ -134,7 +134,7 @@ export abstract class BaseDeploymentConfig extends Resource implements IBaseDepl
*/
public readonly deploymentConfigArn: string;

public constructor(scope: Construct, id: string, props?: BaseDeploymentConfigProps) {
public constructor(scope: Construct, id: string, props?: DeploymentConfigProps) {
super(scope, id, {
physicalName: props?.deploymentConfigName,
});
Expand Down
22 changes: 3 additions & 19 deletions packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import { Construct } from 'constructs';
import { BaseDeploymentConfig, BaseDeploymentConfigOptions, ComputePlatform, IBaseDeploymentConfig } from '../base-deployment-config';
import { DeploymentConfig, BaseDeploymentConfigOptions, ComputePlatform, IDeploymentConfig } from '../base-deployment-config';
import { TrafficRouting } from '../traffic-routing-config';

/**
* The Deployment Configuration of an ECS Deployment Group.
*
* If you're managing the Deployment Configuration alongside the rest of your CDK resources,
* use the {@link EcsDeploymentConfig} class.
*
* If you want to reference an already existing deployment configuration,
* or one defined in a different CDK Stack,
* use the {@link EcsDeploymentConfig#fromEcsDeploymentConfigName} method.
*
* The default, pre-defined Configurations are available as constants on the {@link EcsDeploymentConfig} class
* (for example, `EcsDeploymentConfig.AllAtOnce`).
*/
export interface IEcsDeploymentConfig extends IBaseDeploymentConfig {
}

/**
* Construction properties of {@link EcsDeploymentConfig}.
*/
Expand All @@ -35,7 +19,7 @@ export interface EcsDeploymentConfigProps extends BaseDeploymentConfigOptions {
*
* @resource AWS::CodeDeploy::DeploymentConfig
*/
export class EcsDeploymentConfig extends BaseDeploymentConfig implements IEcsDeploymentConfig {
export class EcsDeploymentConfig extends DeploymentConfig {
/** CodeDeploy predefined deployment configuration that shifts all traffic to the updated ECS task set at once. */
public static readonly ALL_AT_ONCE = EcsDeploymentConfig.deploymentConfig('CodeDeployDefault.ECSAllAtOnce');
/** CodeDeploy predefined deployment configuration that shifts 10 percent of traffic every minute until all traffic is shifted. */
Expand All @@ -55,7 +39,7 @@ export class EcsDeploymentConfig extends BaseDeploymentConfig implements IEcsDep
* @param ecsDeploymentConfigName the name of the referenced custom Deployment Configuration
* @returns a Construct representing a reference to an existing custom Deployment Configuration
*/
public static fromEcsDeploymentConfigName(scope: Construct, id: string, ecsDeploymentConfigName: string): IEcsDeploymentConfig {
public static fromEcsDeploymentConfigName(scope: Construct, id: string, ecsDeploymentConfigName: string): IDeploymentConfig {
return this.fromDeploymentConfigName(scope, id, ecsDeploymentConfigName);
}

Expand Down
9 changes: 5 additions & 4 deletions packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-group.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { IDeploymentConfig } from '../base-deployment-config';
import { arnForDeploymentGroup } from '../utils';
import { IEcsApplication } from './application';
import { EcsDeploymentConfig, IEcsDeploymentConfig } from './deployment-config';
import { EcsDeploymentConfig } from './deployment-config';

/**
* Interface for an ECS deployment group.
Expand All @@ -28,7 +29,7 @@ export interface IEcsDeploymentGroup extends cdk.IResource {
/**
* The Deployment Configuration this Group uses.
*/
readonly deploymentConfig: IEcsDeploymentConfig;
readonly deploymentConfig: IDeploymentConfig;
}

/**
Expand Down Expand Up @@ -83,14 +84,14 @@ export interface EcsDeploymentGroupAttributes {
*
* @default EcsDeploymentConfig.ALL_AT_ONCE
*/
readonly deploymentConfig?: IEcsDeploymentConfig;
readonly deploymentConfig?: IDeploymentConfig;
}

class ImportedEcsDeploymentGroup extends cdk.Resource implements IEcsDeploymentGroup {
public readonly application: IEcsApplication;
public readonly deploymentGroupName: string;
public readonly deploymentGroupArn: string;
public readonly deploymentConfig: IEcsDeploymentConfig;
public readonly deploymentConfig: IDeploymentConfig;

constructor(scope:Construct, id: string, props: EcsDeploymentGroupAttributes) {
super(scope, id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Duration, Names, Resource } from '@aws-cdk/core';
import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from '@aws-cdk/custom-resources';
import { Construct } from 'constructs';
import { IDeploymentConfig } from '../base-deployment-config';
import { arnForDeploymentConfig, validateName } from '../utils';
import { ILambdaDeploymentConfig } from './deployment-config';

/**
* Lambda Deployment config type
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface CustomLambdaDeploymentConfigProps {
* @resource AWS::CodeDeploy::DeploymentGroup
* @deprecated CloudFormation now supports Lambda deployment configurations without custom resources. Use {@link LambdaDeploymentConfig}.
*/
export class CustomLambdaDeploymentConfig extends Resource implements ILambdaDeploymentConfig {
export class CustomLambdaDeploymentConfig extends Resource implements IDeploymentConfig {

/**
* The name of the deployment config
Expand Down
24 changes: 4 additions & 20 deletions packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import { Construct } from 'constructs';
import { BaseDeploymentConfig, BaseDeploymentConfigOptions, ComputePlatform, IBaseDeploymentConfig } from '../base-deployment-config';
import { DeploymentConfig, BaseDeploymentConfigOptions, ComputePlatform, IDeploymentConfig } from '../base-deployment-config';
import { TrafficRouting } from '../traffic-routing-config';

/**
* The Deployment Configuration of a Lambda Deployment Group.
*
* If you're managing the Deployment Configuration alongside the rest of your CDK resources,
* use the {@link LambdaDeploymentConfig} class.
*
* If you want to reference an already existing deployment configuration,
* or one defined in a different CDK Stack,
* use the {@link LambdaDeploymentConfig#fromLambdaDeploymentConfigName} method.
*
* The default, pre-defined Configurations are available as constants on the {@link LambdaDeploymentConfig} class
* (`LambdaDeploymentConfig.AllAtOnce`, `LambdaDeploymentConfig.Canary10Percent30Minutes`, etc.).
*/
export interface ILambdaDeploymentConfig extends IBaseDeploymentConfig {
}

/**
* Properties of a reference to a CodeDeploy Lambda Deployment Configuration.
*
Expand Down Expand Up @@ -47,7 +31,7 @@ export interface LambdaDeploymentConfigProps extends BaseDeploymentConfigOptions
* A custom Deployment Configuration for a Lambda Deployment Group.
* @resource AWS::CodeDeploy::DeploymentConfig
*/
export class LambdaDeploymentConfig extends BaseDeploymentConfig implements ILambdaDeploymentConfig {
export class LambdaDeploymentConfig extends DeploymentConfig {
/** CodeDeploy predefined deployment configuration that shifts all traffic to the updated Lambda function at once. */
public static readonly ALL_AT_ONCE = LambdaDeploymentConfig.deploymentConfig('CodeDeployDefault.LambdaAllAtOnce');
/** CodeDeploy predefined deployment configuration that shifts 10 percent of traffic in the first increment. The remaining 90 percent is deployed 30 minutes later. */
Expand Down Expand Up @@ -75,7 +59,7 @@ export class LambdaDeploymentConfig extends BaseDeploymentConfig implements ILam
* @param lambdaDeploymentConfigName the name of the Lambda Deployment Configuration to import
* @returns a Construct representing a reference to an existing Lambda Deployment Configuration
*/
public static fromLambdaDeploymentConfigName(scope: Construct, id: string, lambdaDeploymentConfigName: string): ILambdaDeploymentConfig {
public static fromLambdaDeploymentConfigName(scope: Construct, id: string, lambdaDeploymentConfigName: string): IDeploymentConfig {
return this.fromDeploymentConfigName(scope, id, lambdaDeploymentConfigName);
}

Expand All @@ -88,7 +72,7 @@ export class LambdaDeploymentConfig extends BaseDeploymentConfig implements ILam
* @returns a Construct representing a reference to an existing custom Deployment Configuration
* @deprecated use `fromLambdaDeploymentConfigName`
*/
public static import(_scope: Construct, _id: string, props: LambdaDeploymentConfigImportProps): ILambdaDeploymentConfig {
public static import(_scope: Construct, _id: string, props: LambdaDeploymentConfigImportProps): IDeploymentConfig {
return this.fromLambdaDeploymentConfigName(_scope, _id, props.deploymentConfigName);
}

Expand Down
13 changes: 7 additions & 6 deletions packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import * as iam from '@aws-cdk/aws-iam';
import * as lambda from '@aws-cdk/aws-lambda';
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { IDeploymentConfig } from '../base-deployment-config';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { AutoRollbackConfig } from '../rollback-config';
import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration, validateName } from '../utils';
import { ILambdaApplication, LambdaApplication } from './application';
import { ILambdaDeploymentConfig, LambdaDeploymentConfig } from './deployment-config';
import { LambdaDeploymentConfig } from './deployment-config';

/**
* Interface for a Lambda deployment groups.
Expand All @@ -33,7 +34,7 @@ export interface ILambdaDeploymentGroup extends cdk.IResource {
/**
* The Deployment Configuration this Group uses.
*/
readonly deploymentConfig: ILambdaDeploymentConfig;
readonly deploymentConfig: IDeploymentConfig;
}

/**
Expand All @@ -59,7 +60,7 @@ export interface LambdaDeploymentGroupProps {
*
* @default LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES
*/
readonly deploymentConfig?: ILambdaDeploymentConfig;
readonly deploymentConfig?: IDeploymentConfig;

/**
* The CloudWatch alarms associated with this Deployment Group.
Expand Down Expand Up @@ -139,7 +140,7 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
public readonly application: ILambdaApplication;
public readonly deploymentGroupName: string;
public readonly deploymentGroupArn: string;
public readonly deploymentConfig: ILambdaDeploymentConfig;
public readonly deploymentConfig: IDeploymentConfig;
public readonly role: iam.IRole;

private readonly alarms: cloudwatch.IAlarm[];
Expand Down Expand Up @@ -281,14 +282,14 @@ export interface LambdaDeploymentGroupAttributes {
*
* @default LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES
*/
readonly deploymentConfig?: ILambdaDeploymentConfig;
readonly deploymentConfig?: IDeploymentConfig;
}

class ImportedLambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploymentGroup {
public readonly application: ILambdaApplication;
public readonly deploymentGroupName: string;
public readonly deploymentGroupArn: string;
public readonly deploymentConfig: ILambdaDeploymentConfig;
public readonly deploymentConfig: IDeploymentConfig;

constructor(scope:Construct, id: string, props: LambdaDeploymentGroupAttributes) {
super(scope, id);
Expand Down
16 changes: 3 additions & 13 deletions packages/@aws-cdk/aws-codedeploy/lib/server/deployment-config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { Construct } from 'constructs';
import { BaseDeploymentConfig, BaseDeploymentConfigOptions, IBaseDeploymentConfig } from '../base-deployment-config';
import { DeploymentConfig, BaseDeploymentConfigOptions, IDeploymentConfig } from '../base-deployment-config';
import { MinimumHealthyHosts } from '../host-health-config';

/**
* The Deployment Configuration of an EC2/on-premise Deployment Group.
* The default, pre-defined Configurations are available as constants on the {@link ServerDeploymentConfig} class
* (`ServerDeploymentConfig.HALF_AT_A_TIME`, `ServerDeploymentConfig.ALL_AT_ONCE`, etc.).
* To create a custom Deployment Configuration,
* instantiate the {@link ServerDeploymentConfig} Construct.
*/
export interface IServerDeploymentConfig extends IBaseDeploymentConfig {
}

/**
* Construction properties of {@link ServerDeploymentConfig}.
*/
Expand All @@ -27,7 +17,7 @@ export interface ServerDeploymentConfigProps extends BaseDeploymentConfigOptions
*
* @resource AWS::CodeDeploy::DeploymentConfig
*/
export class ServerDeploymentConfig extends BaseDeploymentConfig implements IServerDeploymentConfig {
export class ServerDeploymentConfig extends DeploymentConfig {
/**
* The CodeDeployDefault.OneAtATime predefined deployment configuration for EC2/on-premises compute platform
*
Expand Down Expand Up @@ -59,7 +49,7 @@ export class ServerDeploymentConfig extends BaseDeploymentConfig implements ISer
public static fromServerDeploymentConfigName(
scope: Construct,
id: string,
serverDeploymentConfigName: string): IServerDeploymentConfig {
serverDeploymentConfigName: string): IDeploymentConfig {
return this.fromDeploymentConfigName(scope, id, serverDeploymentConfigName);
}

Expand Down
13 changes: 7 additions & 6 deletions packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/core';
import { ArnFormat } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { IDeploymentConfig } from '../base-deployment-config';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { AutoRollbackConfig } from '../rollback-config';
import { arnForDeploymentGroup, renderAlarmConfiguration, renderAutoRollbackConfiguration, validateName } from '../utils';
import { IServerApplication, ServerApplication } from './application';
import { IServerDeploymentConfig, ServerDeploymentConfig } from './deployment-config';
import { ServerDeploymentConfig } from './deployment-config';
import { LoadBalancer, LoadBalancerGeneration } from './load-balancer';

export interface IServerDeploymentGroup extends cdk.IResource {
Expand All @@ -25,7 +26,7 @@ export interface IServerDeploymentGroup extends cdk.IResource {
* @attribute
*/
readonly deploymentGroupArn: string;
readonly deploymentConfig: IServerDeploymentConfig;
readonly deploymentConfig: IDeploymentConfig;
readonly autoScalingGroups?: autoscaling.IAutoScalingGroup[];
}

Expand All @@ -52,7 +53,7 @@ export interface ServerDeploymentGroupAttributes {
*
* @default ServerDeploymentConfig#OneAtATime
*/
readonly deploymentConfig?: IServerDeploymentConfig;
readonly deploymentConfig?: IDeploymentConfig;
}

/**
Expand All @@ -70,10 +71,10 @@ abstract class ServerDeploymentGroupBase extends cdk.Resource implements IServer
public abstract readonly role?: iam.IRole;
public abstract readonly deploymentGroupName: string;
public abstract readonly deploymentGroupArn: string;
public readonly deploymentConfig: IServerDeploymentConfig;
public readonly deploymentConfig: IDeploymentConfig;
public abstract readonly autoScalingGroups?: autoscaling.IAutoScalingGroup[];

constructor(scope: Construct, id: string, deploymentConfig?: IServerDeploymentConfig, props?: cdk.ResourceProps) {
constructor(scope: Construct, id: string, deploymentConfig?: IDeploymentConfig, props?: cdk.ResourceProps) {
super(scope, id, props);
this.deploymentConfig = deploymentConfig || ServerDeploymentConfig.ONE_AT_A_TIME;
}
Expand Down Expand Up @@ -160,7 +161,7 @@ export interface ServerDeploymentGroupProps {
*
* @default ServerDeploymentConfig#OneAtATime
*/
readonly deploymentConfig?: IServerDeploymentConfig;
readonly deploymentConfig?: IDeploymentConfig;

/**
* The auto-scaling groups belonging to this Deployment Group.
Expand Down

0 comments on commit d27a13d

Please sign in to comment.