Skip to content

Commit 97a7ca5

Browse files
committed
refactor(cli): stack monitor uses io-host
1 parent 88e2bdf commit 97a7ca5

File tree

27 files changed

+1548
-1235
lines changed

27 files changed

+1548
-1235
lines changed

packages/@aws-cdk/toolkit-lib/lib/api/io/private/codes.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ export const CODES = {
109109
description: 'Confirm deploy security sensitive changes',
110110
level: 'info',
111111
}),
112+
113+
CDK_TOOLKIT_I5501: codeInfo({
114+
code: 'CDK_TOOLKIT_I5501',
115+
description: 'Stack Monitoring Start',
116+
level: 'debug',
117+
}),
118+
CDK_TOOLKIT_I5502: codeInfo({
119+
code: 'CDK_TOOLKIT_I5502',
120+
description: 'Stack Monitoring Activity event',
121+
level: 'info',
122+
interface: 'StackActivity',
123+
}),
124+
CDK_TOOLKIT_I5503: codeInfo({
125+
code: 'CDK_TOOLKIT_I5503',
126+
description: 'Stack Monitoring End',
127+
level: 'debug',
128+
}),
129+
112130
CDK_TOOLKIT_I5900: codeInfo({
113131
code: 'CDK_TOOLKIT_I5900',
114132
description: 'Deployment results on success',
@@ -121,6 +139,11 @@ export const CODES = {
121139
description: 'No stacks found',
122140
level: 'error',
123141
}),
142+
CDK_TOOLKIT_E5500: codeInfo({
143+
code: 'CDK_TOOLKIT_E5500',
144+
description: 'Stack Monitoring error',
145+
level: 'error',
146+
}),
124147

125148
// 6: Rollback
126149
CDK_TOOLKIT_I6000: codeInfo({

packages/aws-cdk/lib/api/deployments/deploy-stack.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import type { SDK, SdkProvider, ICloudFormationClient } from '../aws-auth';
3636
import type { EnvironmentResources } from '../environment';
3737
import { CfnEvaluationException } from '../evaluate-cloudformation-template';
3838
import { HotswapMode, HotswapPropertyOverrides, ICON } from '../hotswap/common';
39-
import { StackActivityMonitor, type StackActivityProgress } from '../stack-events';
39+
import { StackActivityMonitor } from '../stack-events';
4040
import { StringWithoutPlaceholders } from '../util/placeholders';
4141
import { type TemplateBodyParameter, makeBodyParameter } from '../util/template-body-parameter';
4242

@@ -153,14 +153,6 @@ export interface DeployStackOptions {
153153
*/
154154
readonly usePreviousParameters?: boolean;
155155

156-
/**
157-
* Display mode for stack deployment progress.
158-
*
159-
* @default StackActivityProgress.Bar stack events will be displayed for
160-
* the resource currently being deployed.
161-
*/
162-
readonly progress?: StackActivityProgress;
163-
164156
/**
165157
* Deploy even if the deployed template is identical to the one we are about to deploy.
166158
* @default false
@@ -612,14 +604,16 @@ class FullCloudFormationDeployment {
612604
}
613605

614606
private async monitorDeployment(startTime: Date, expectedChanges: number | undefined): Promise<SuccessfulDeployStackResult> {
615-
const monitor = this.options.quiet
616-
? undefined
617-
: StackActivityMonitor.withDefaultPrinter(this.cfn, this.stackName, this.stackArtifact, {
618-
resourcesTotal: expectedChanges,
619-
progress: this.options.progress,
620-
changeSetCreationTime: startTime,
621-
ci: this.options.ci,
622-
}).start();
607+
const monitor = new StackActivityMonitor({
608+
cfn: this.cfn,
609+
stack: this.stackArtifact,
610+
stackName: this.stackName,
611+
resourcesTotal: expectedChanges,
612+
ioHost: this.ioHost,
613+
action: this.action,
614+
changeSetCreationTime: startTime,
615+
});
616+
await monitor.start();
623617

624618
let finalState = this.cloudFormationStack;
625619
try {
@@ -631,9 +625,9 @@ class FullCloudFormationDeployment {
631625
}
632626
finalState = successStack;
633627
} catch (e: any) {
634-
throw new ToolkitError(suffixWithErrors(formatErrorMessage(e), monitor?.errors));
628+
throw new ToolkitError(suffixWithErrors(formatErrorMessage(e), monitor.errors));
635629
} finally {
636-
await monitor?.stop();
630+
await monitor.stop();
637631
}
638632
debug(this.action, format('Stack %s has completed updating', this.stackName));
639633
return {
@@ -696,11 +690,14 @@ export async function destroyStack(options: DestroyStackOptions, { ioHost, actio
696690
if (!currentStack.exists) {
697691
return;
698692
}
699-
const monitor = options.quiet
700-
? undefined
701-
: StackActivityMonitor.withDefaultPrinter(cfn, deployName, options.stack, {
702-
ci: options.ci,
703-
}).start();
693+
const monitor = new StackActivityMonitor({
694+
cfn,
695+
stack: options.stack,
696+
stackName: deployName,
697+
ioHost,
698+
action,
699+
});
700+
await monitor.start();
704701

705702
try {
706703
await cfn.deleteStack({ StackName: deployName, RoleARN: options.roleArn });
@@ -709,7 +706,7 @@ export async function destroyStack(options: DestroyStackOptions, { ioHost, actio
709706
throw new ToolkitError(`Failed to destroy ${deployName}: ${destroyedStack.stackStatus}`);
710707
}
711708
} catch (e: any) {
712-
throw new ToolkitError(suffixWithErrors(formatErrorMessage(e), monitor?.errors));
709+
throw new ToolkitError(suffixWithErrors(formatErrorMessage(e), monitor.errors));
713710
} finally {
714711
if (monitor) {
715712
await monitor.stop();

packages/aws-cdk/lib/api/deployments/deployments.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { formatErrorMessage } from '../../util/format-error';
3131
import type { SdkProvider } from '../aws-auth/sdk-provider';
3232
import { type EnvironmentResources, EnvironmentAccess } from '../environment';
3333
import { HotswapMode, HotswapPropertyOverrides } from '../hotswap/common';
34-
import { StackActivityMonitor, StackActivityProgress, StackEventPoller, RollbackChoice } from '../stack-events';
34+
import { StackActivityMonitor, StackEventPoller, RollbackChoice } from '../stack-events';
3535
import type { Tag } from '../tags';
3636
import { DEFAULT_TOOLKIT_STACK_NAME } from '../toolkit-info';
3737
import { makeBodyParameter } from '../util/template-body-parameter';
@@ -135,14 +135,6 @@ export interface DeployStackOptions {
135135
*/
136136
readonly usePreviousParameters?: boolean;
137137

138-
/**
139-
* Display mode for stack deployment progress.
140-
*
141-
* @default - StackActivityProgress.Bar - stack events will be displayed for
142-
* the resource currently being deployed.
143-
*/
144-
readonly progress?: StackActivityProgress;
145-
146138
/**
147139
* Whether we are on a CI system
148140
*
@@ -255,14 +247,6 @@ export interface RollbackStackOptions {
255247
*/
256248
readonly orphanLogicalIds?: string[];
257249

258-
/**
259-
* Display mode for stack deployment progress.
260-
*
261-
* @default - StackActivityProgress.Bar - stack events will be displayed for
262-
* the resource currently being deployed.
263-
*/
264-
readonly progress?: StackActivityProgress;
265-
266250
/**
267251
* Whether to validate the version of the bootstrap stack permissions
268252
*
@@ -474,7 +458,6 @@ export class Deployments {
474458
force: options.force,
475459
parameters: options.parameters,
476460
usePreviousParameters: options.usePreviousParameters,
477-
progress: options.progress,
478461
ci: options.ci,
479462
rollback: options.rollback,
480463
hotswap: options.hotswap,
@@ -565,11 +548,14 @@ export class Deployments {
565548
throw new ToolkitError(`Unexpected rollback choice: ${cloudFormationStack.stackStatus.rollbackChoice}`);
566549
}
567550

568-
const monitor = options.quiet
569-
? undefined
570-
: StackActivityMonitor.withDefaultPrinter(cfn, deployName, options.stack, {
571-
ci: options.ci,
572-
}).start();
551+
const monitor = new StackActivityMonitor({
552+
cfn,
553+
stack: options.stack,
554+
stackName: deployName,
555+
ioHost: this.ioHost,
556+
action: this.action,
557+
});
558+
await monitor.start();
573559

574560
let stackErrorMessage: string | undefined = undefined;
575561
let finalStackState = cloudFormationStack;
@@ -582,14 +568,14 @@ export class Deployments {
582568
}
583569
finalStackState = successStack;
584570

585-
const errors = monitor?.errors?.join(', ');
571+
const errors = monitor.errors.join(', ');
586572
if (errors) {
587573
stackErrorMessage = errors;
588574
}
589575
} catch (e: any) {
590-
stackErrorMessage = suffixWithErrors(formatErrorMessage(e), monitor?.errors);
576+
stackErrorMessage = suffixWithErrors(formatErrorMessage(e), monitor.errors);
591577
} finally {
592-
await monitor?.stop();
578+
await monitor.stop();
593579
}
594580

595581
if (finalStackState.stackStatus.isRollbackSuccess || !stackErrorMessage) {

packages/aws-cdk/lib/api/resource-import/importer.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { error, info, warn } from '../../cli/messages';
99
import { IIoHost, ToolkitAction } from '../../toolkit/cli-io-host';
1010
import { ToolkitError } from '../../toolkit/error';
1111
import { assertIsSuccessfulDeployStackResult, type Deployments, DeploymentMethod, ResourceIdentifierProperties, ResourcesToImport } from '../deployments';
12-
import type { StackActivityProgress } from '../stack-events';
1312
import type { Tag } from '../tags';
1413

1514
export interface ResourceImporterProps {
@@ -49,14 +48,6 @@ export interface ImportDeploymentOptions {
4948
*/
5049
readonly usePreviousParameters?: boolean;
5150

52-
/**
53-
* Display mode for stack deployment progress.
54-
*
55-
* @default - StackActivityProgress.Bar - stack events will be displayed for
56-
* the resource currently being deployed.
57-
*/
58-
readonly progress?: StackActivityProgress;
59-
6051
/**
6152
* Rollback failed deployments
6253
*

packages/aws-cdk/lib/api/resource-import/migrator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export class ResourceMigrator {
6767
roleArn: options.roleArn,
6868
deploymentMethod: options.deploymentMethod,
6969
usePreviousParameters: true,
70-
progress: options.progress,
7170
rollback: options.rollback,
7271
});
7372

0 commit comments

Comments
 (0)