@cdkd/cli 0.370.1 → 0.370.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ambient-client-defaults-tZDuM2co.js → ambient-client-defaults-DrXlF8Pt.js} +3 -3
- package/dist/{ambient-client-defaults-tZDuM2co.js.map → ambient-client-defaults-DrXlF8Pt.js.map} +1 -1
- package/dist/{asg-provider-RrQcEEg6.js → asg-provider-aBYgPPKr.js} +8 -6
- package/dist/asg-provider-aBYgPPKr.js.map +1 -0
- package/dist/cli.js +3 -3
- package/dist/{resource-deadline-CCOMsXbq.js → created-resource-sink-EfKmjZ9y.js} +5 -186
- package/dist/created-resource-sink-EfKmjZ9y.js.map +1 -0
- package/dist/{custom-resource-runtime-DFlVlsm0.js → custom-resource-runtime-NOjxl0Bg.js} +6 -6
- package/dist/{custom-resource-runtime-DFlVlsm0.js.map → custom-resource-runtime-NOjxl0Bg.js.map} +1 -1
- package/dist/{db-associated-roles-DScze2Gm.js → db-associated-roles-BMhOZXNJ.js} +2 -2
- package/dist/{db-associated-roles-DScze2Gm.js.map → db-associated-roles-BMhOZXNJ.js.map} +1 -1
- package/dist/{delete-started-BLH3blZC.js → delete-started-DgH5I_uu.js} +5 -214
- package/dist/delete-started-DgH5I_uu.js.map +1 -0
- package/dist/{deploy-engine-CjPj4mWd.js → deploy-engine-xMBjpqJF.js} +182 -115
- package/dist/deploy-engine-xMBjpqJF.js.map +1 -0
- package/dist/ec2-termination-protection-BB_YJnSI.js +227 -0
- package/dist/ec2-termination-protection-BB_YJnSI.js.map +1 -0
- package/dist/{ecr-uri-CXRdFygz.js → ecr-uri-DuhByrkK.js} +2 -2
- package/dist/{ecr-uri-CXRdFygz.js.map → ecr-uri-DuhByrkK.js.map} +1 -1
- package/dist/emr-cluster-provider-CxM25Nws.js +2373 -0
- package/dist/emr-cluster-provider-CxM25Nws.js.map +1 -0
- package/dist/{expected-bucket-owner-BbU5xGZW.js → expected-bucket-owner-BydJISOl.js} +2 -2
- package/dist/{expected-bucket-owner-BbU5xGZW.js.map → expected-bucket-owner-BydJISOl.js.map} +1 -1
- package/dist/{iam-role-provider-CnrvifnX.js → iam-role-provider-D3zJfrDs.js} +38 -18
- package/dist/iam-role-provider-D3zJfrDs.js.map +1 -0
- package/dist/identity-read-denied-DLY_VaC5.js +214 -0
- package/dist/identity-read-denied-DLY_VaC5.js.map +1 -0
- package/dist/{image-plan-TZhXZ1PB.js → image-plan-BIfE5ZGk.js} +8 -8
- package/dist/{image-plan-TZhXZ1PB.js.map → image-plan-BIfE5ZGk.js.map} +1 -1
- package/dist/index.js +5 -5
- package/dist/{logger-CS-YglVv.js → logger-CK3LLcjk.js} +11 -2
- package/dist/logger-CK3LLcjk.js.map +1 -0
- package/dist/{neptune-provider-Cc5YKqPa.js → neptune-provider-OdQgH5Gi.js} +9 -7
- package/dist/neptune-provider-OdQgH5Gi.js.map +1 -0
- package/dist/{program-Bxtxr-a2.js → program-DNUZrYVX.js} +19 -15
- package/dist/program-DNUZrYVX.js.map +1 -0
- package/dist/{provider-classes-BzKLZwtY.js → provider-classes-hpgIpmU7.js} +829 -3185
- package/dist/provider-classes-hpgIpmU7.js.map +1 -0
- package/dist/{rds-provider-ZtlLePqa.js → rds-provider-Czow3UKD.js} +13 -10
- package/dist/rds-provider-Czow3UKD.js.map +1 -0
- package/dist/{read-replica-WOLC0PN2.js → read-replica-X_V9EI2o.js} +3 -3
- package/dist/{read-replica-WOLC0PN2.js.map → read-replica-X_V9EI2o.js.map} +1 -1
- package/dist/redacted-delete-address-ukytEFP1.js +30 -0
- package/dist/redacted-delete-address-ukytEFP1.js.map +1 -0
- package/dist/{replacement-rules-CpJuKIfa.js → replacement-rules-zF6GbYRD.js} +3 -3
- package/dist/{replacement-rules-CpJuKIfa.js.map → replacement-rules-zF6GbYRD.js.map} +1 -1
- package/dist/resource-deadline-DaujVbLw.js +186 -0
- package/dist/resource-deadline-DaujVbLw.js.map +1 -0
- package/dist/{restore-source-guard-CoMJb7cu.js → restore-source-guard-DMMZupSb.js} +9 -101
- package/dist/restore-source-guard-DMMZupSb.js.map +1 -0
- package/dist/{run-cli-DbveetO_.js → run-cli-D5VRk-_y.js} +2 -2
- package/dist/{run-cli-DbveetO_.js.map → run-cli-D5VRk-_y.js.map} +1 -1
- package/dist/{ec2-termination-protection-snZAaTKf.js → secret-reference-immutable-C6iEFnXq.js} +8 -230
- package/dist/secret-reference-immutable-C6iEFnXq.js.map +1 -0
- package/dist/{settle-own-write-members-CWj7GaSq.js → settle-own-write-members-B6fW8lbf.js} +13 -12
- package/dist/settle-own-write-members-B6fW8lbf.js.map +1 -0
- package/dist/tag-list-BZz_uApL.js +100 -0
- package/dist/tag-list-BZz_uApL.js.map +1 -0
- package/dist/{version-Dho_cBw1.js → version-yrN76_Vc.js} +2 -2
- package/dist/{version-Dho_cBw1.js.map → version-yrN76_Vc.js.map} +1 -1
- package/package.json +1 -1
- package/dist/asg-provider-RrQcEEg6.js.map +0 -1
- package/dist/delete-started-BLH3blZC.js.map +0 -1
- package/dist/deploy-engine-CjPj4mWd.js.map +0 -1
- package/dist/ec2-termination-protection-snZAaTKf.js.map +0 -1
- package/dist/iam-role-provider-CnrvifnX.js.map +0 -1
- package/dist/logger-CS-YglVv.js.map +0 -1
- package/dist/neptune-provider-Cc5YKqPa.js.map +0 -1
- package/dist/program-Bxtxr-a2.js.map +0 -1
- package/dist/provider-classes-BzKLZwtY.js.map +0 -1
- package/dist/rds-provider-ZtlLePqa.js.map +0 -1
- package/dist/resource-deadline-CCOMsXbq.js.map +0 -1
- package/dist/restore-source-guard-CoMJb7cu.js.map +0 -1
- package/dist/settle-own-write-members-CWj7GaSq.js.map +0 -1
|
@@ -0,0 +1,2373 @@
|
|
|
1
|
+
import { d as describeAwsStatusReason, n as getLogger, u as describeAwsFailure } from "./logger-CK3LLcjk.js";
|
|
2
|
+
import { G as markRedactedCause, O as relayedNameCollision, W as markNonRetryable, _ as ResourceUpdateNotSupportedError, at as ProvisioningError, t as ambientClientDefaults } from "./ambient-client-defaults-DrXlF8Pt.js";
|
|
3
|
+
import { Ft as isSecretDerivedValue, Jt as markCreatedBeforeFailure, L as deleteWithProtectionCompensation, Lt as maskerOrIdentity, N as resolveExplicitPhysicalId, Nt as createMaskedLogSinks, O as normalizeAwsTagsToCfn, Y as ProtectionFlipRegistry, Z as protectionFlipKey, _ as withoutServerErrorRetries, b as assertRegionMatch, c as AmbiguousCreateLatch, d as ambiguousAttemptLead, h as replayedSendWindow, i as reportCreatedResource, o as retractCreatedResource, ot as pasteableAwsCommand, p as isInsideWindow, st as protectedReplacementAdvice, u as RecentIdSet, y as RESOURCE_NOT_FOUND, z as observeThenDisableProtection } from "./created-resource-sink-EfKmjZ9y.js";
|
|
4
|
+
import { f as ambientRegion } from "./aws-client-defaults-DAebi99J.js";
|
|
5
|
+
import { a as emrClusterInstancesReplaced } from "./replacement-rules-zF6GbYRD.js";
|
|
6
|
+
import { n as unchangedBehindSecretReference, t as onlySecretReferencesDiffer } from "./secret-reference-immutable-C6iEFnXq.js";
|
|
7
|
+
import { P as safeMsg, T as asIsMessage, c as deployReplaceCommand, s as commandHole } from "./version-yrN76_Vc.js";
|
|
8
|
+
import { a as refuseMalformedDesiredTags, r as planTagDiff, s as tagPlanWarning } from "./tag-list-BZz_uApL.js";
|
|
9
|
+
import { n as isRedactedRecordedValue } from "./redacted-delete-address-ukytEFP1.js";
|
|
10
|
+
import { n as isPermissionDenial } from "./identity-read-denied-DLY_VaC5.js";
|
|
11
|
+
import { AddInstanceFleetCommand, AddInstanceGroupsCommand, AddTagsCommand, DescribeClusterCommand, EMRClient, GetAutoTerminationPolicyCommand, GetManagedScalingPolicyCommand, InvalidRequestException, ListClustersCommand, ListInstanceFleetsCommand, ListInstanceGroupsCommand, ModifyClusterCommand, ModifyInstanceFleetCommand, ModifyInstanceGroupsCommand, PutAutoScalingPolicyCommand, PutAutoTerminationPolicyCommand, PutManagedScalingPolicyCommand, RemoveAutoScalingPolicyCommand, RemoveAutoTerminationPolicyCommand, RemoveManagedScalingPolicyCommand, RemoveTagsCommand, RunJobFlowCommand, SetTerminationProtectionCommand, SetUnhealthyNodeReplacementCommand, SetVisibleToAllUsersCommand, TerminateJobFlowsCommand } from "@aws-sdk/client-emr";
|
|
12
|
+
|
|
13
|
+
// src/provisioning/providers/orphan-report.ts
|
|
14
|
+
async function orphanCommandRegionArg(client, aws) {
|
|
15
|
+
let region;
|
|
16
|
+
try {
|
|
17
|
+
region = await client.config.region();
|
|
18
|
+
} catch {
|
|
19
|
+
region = void 0;
|
|
20
|
+
}
|
|
21
|
+
return region ? aws` --region ${region}` : aws``;
|
|
22
|
+
}
|
|
23
|
+
const MAX_ORPHAN_LIST_PAGES = 20;
|
|
24
|
+
const MAX_REPORTED_ORPHANS = 5;
|
|
25
|
+
async function collectOrphanIds(fetchPage, keep) {
|
|
26
|
+
const ids = [];
|
|
27
|
+
let token;
|
|
28
|
+
let pages = 0;
|
|
29
|
+
do {
|
|
30
|
+
const page = await fetchPage(token);
|
|
31
|
+
for (const item of page.items) {
|
|
32
|
+
const id = keep(item);
|
|
33
|
+
if (id !== void 0) ids.push(id);
|
|
34
|
+
}
|
|
35
|
+
token = page.next;
|
|
36
|
+
pages++;
|
|
37
|
+
} while (token && pages < 20);
|
|
38
|
+
return {
|
|
39
|
+
ids,
|
|
40
|
+
truncated: Boolean(token)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function reportPossibleOrphans(logicalId, window, log, lookup) {
|
|
44
|
+
const since = new Date(window.floorMs).toISOString();
|
|
45
|
+
const until = new Date(window.ceilingMs).toISOString();
|
|
46
|
+
const remove = lookup.remove;
|
|
47
|
+
const service = lookup.service ?? "API Gateway";
|
|
48
|
+
const afterward = window.replayedInSend === true ? "cdkd recorded the one the create returned." : lookup.afterward ?? "Creating a new one now.";
|
|
49
|
+
const lead = ambiguousAttemptLead(lookup.action, logicalId, window);
|
|
50
|
+
const when = remove !== void 0 ? `between ${since} and ${until}` : `at ${since}`;
|
|
51
|
+
let found;
|
|
52
|
+
try {
|
|
53
|
+
found = await lookup.list();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
const failure = describeAwsFailure(error);
|
|
56
|
+
log.debug(`${lookup.listAction} failed with: ${log.value(failure.detail)}`);
|
|
57
|
+
log.warn(`${lead} (${when}), so ${service} may have created ${lookup.subject} that no cdkd state records, and cdkd could not look for it (${lookup.listAction}: ${failure.summary}). ${window.replayedInSend === true ? "Check" : "Creating it again; check"} for a duplicate.`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const incomplete = found.truncated ? ` The search was incomplete: the list was cut at ${20} pages.` : "";
|
|
61
|
+
if (found.ids.length === 0) {
|
|
62
|
+
const line = `No listed ${lookup.noun} matching ${lookup.subject} is unrecorded by this deploy, so the listing shows no orphan of the ${window.replayedInSend === true ? "replayed" : "earlier ambiguous"} ${lookup.action} attempt for ${logicalId} (${when}).${incomplete}`;
|
|
63
|
+
if (found.truncated) log.warn(line);
|
|
64
|
+
else log.debug(line);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const shown = found.ids.slice(0, MAX_REPORTED_ORPHANS);
|
|
68
|
+
const more = found.ids.length > shown.length ? ", ..." : "";
|
|
69
|
+
const inspect = [...new Set(shown.map((id) => lookup.inspect(id)))].join(" ; ");
|
|
70
|
+
if (remove !== void 0) {
|
|
71
|
+
const deletion = [...new Set(shown.map((id) => remove(id)))].join(" ; ");
|
|
72
|
+
log.warn(`${lead}, and ${service} may have created ${lookup.subject} then that no cdkd state records. ${found.ids.length} ${lookup.noun} were created ${when} that this deploy did not record: ${shown.join(", ")}${more}. cdkd does not adopt or delete them: nothing listed proves which deploy created one. ${afterward} First inspect each candidate: ${inspect}. Only after confirming one is this deploy's orphan and not another deploy's, ${lookup.removeVerb ?? "delete it"}: ${deletion}.${incomplete}`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
log.warn(`${lead} (${when}), and ${service} may have created ${lookup.subject} then that no cdkd state records. ${found.ids.length} ${lookup.noun} match that this deploy did not record: ${shown.join(", ")}${more}. ${service} reports no creation time for them, so any of them may instead be this stack's own recorded one, another stack's, or older than this deploy; cdkd does not adopt or delete them. ${afterward} Inspect each before deleting anything: ${inspect}.${incomplete}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/provisioning/drift-declared-projection.ts
|
|
79
|
+
function filledDefaultsFrom(table) {
|
|
80
|
+
const matches = (key, value) => {
|
|
81
|
+
if (Object.hasOwn(table, key)) {
|
|
82
|
+
const json = JSON.stringify(value);
|
|
83
|
+
if (table[key].some((d) => JSON.stringify(d) === json)) return true;
|
|
84
|
+
}
|
|
85
|
+
return isPlainObject$1(value) && Object.keys(value).length > 0 && Object.entries(value).every(([k, v]) => matches(k, v));
|
|
86
|
+
};
|
|
87
|
+
return matches;
|
|
88
|
+
}
|
|
89
|
+
const NO_FILLED_DEFAULTS = () => false;
|
|
90
|
+
function isPlainObject$1(value) {
|
|
91
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
92
|
+
}
|
|
93
|
+
function isScalar(value) {
|
|
94
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
95
|
+
}
|
|
96
|
+
function projectOntoDeclared(declared, actual, isFilled = NO_FILLED_DEFAULTS) {
|
|
97
|
+
if (isPlainObject$1(declared) && isPlainObject$1(actual)) {
|
|
98
|
+
const out = {};
|
|
99
|
+
let changed = false;
|
|
100
|
+
for (const [key, value] of Object.entries(actual)) {
|
|
101
|
+
if (!Object.hasOwn(declared, key)) {
|
|
102
|
+
if (isFilled(key, value)) changed = true;
|
|
103
|
+
else out[key] = value;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const projected = projectOntoDeclared(declared[key], value, isFilled);
|
|
107
|
+
if (projected !== value) changed = true;
|
|
108
|
+
out[key] = projected;
|
|
109
|
+
}
|
|
110
|
+
return changed ? out : actual;
|
|
111
|
+
}
|
|
112
|
+
if (Array.isArray(declared) && Array.isArray(actual)) {
|
|
113
|
+
let changed = false;
|
|
114
|
+
const out = actual.map((element, i) => {
|
|
115
|
+
if (i >= declared.length) return element;
|
|
116
|
+
const projected = projectOntoDeclared(declared[i], element, isFilled);
|
|
117
|
+
if (projected !== element) changed = true;
|
|
118
|
+
return projected;
|
|
119
|
+
});
|
|
120
|
+
return changed ? out : actual;
|
|
121
|
+
}
|
|
122
|
+
if (isScalar(declared) && isScalar(actual) && typeof declared !== typeof actual && String(declared) === String(actual)) return declared;
|
|
123
|
+
return actual;
|
|
124
|
+
}
|
|
125
|
+
function holdsUnsentValue(value) {
|
|
126
|
+
if (typeof value === "string") return value === "***" || value.includes("{{resolve:");
|
|
127
|
+
if (Array.isArray(value)) return value.some(holdsUnsentValue);
|
|
128
|
+
if (isPlainObject$1(value)) return Object.values(value).some(holdsUnsentValue);
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
function projectDeclaredDriftPair(keys, baseline, aws, properties, isFilled = NO_FILLED_DEFAULTS, fillUnread = false) {
|
|
132
|
+
let nextBaseline = baseline;
|
|
133
|
+
let nextAws = aws;
|
|
134
|
+
for (const key of keys) {
|
|
135
|
+
const declared = properties?.[key];
|
|
136
|
+
if (declared === void 0 || declared === null) continue;
|
|
137
|
+
const fallback = holdsUnsentValue(declared) ? aws[key] : declared;
|
|
138
|
+
if (!Object.hasOwn(baseline, key) && fallback === void 0) continue;
|
|
139
|
+
const projectedBase = projectOntoDeclared(declared, Object.hasOwn(baseline, key) ? baseline[key] : fallback, isFilled);
|
|
140
|
+
if (!Object.hasOwn(baseline, key) || projectedBase !== baseline[key]) {
|
|
141
|
+
if (nextBaseline === baseline) nextBaseline = { ...baseline };
|
|
142
|
+
nextBaseline[key] = projectedBase;
|
|
143
|
+
}
|
|
144
|
+
if (Object.hasOwn(aws, key)) {
|
|
145
|
+
const projectedAws = projectOntoDeclared(declared, aws[key], isFilled);
|
|
146
|
+
if (projectedAws !== aws[key]) {
|
|
147
|
+
if (nextAws === aws) nextAws = { ...aws };
|
|
148
|
+
nextAws[key] = projectedAws;
|
|
149
|
+
}
|
|
150
|
+
} else if (fillUnread && Object.hasOwn(nextBaseline, key)) {
|
|
151
|
+
if (nextAws === aws) nextAws = { ...aws };
|
|
152
|
+
nextAws[key] = nextBaseline[key];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
baseline: nextBaseline,
|
|
157
|
+
aws: nextAws
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function undeclaredDriftKeys(keys, properties) {
|
|
161
|
+
if (properties === void 0 || Object.keys(properties).length === 0) return [...keys];
|
|
162
|
+
return keys.filter((key) => properties[key] === void 0 || properties[key] === null);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/provisioning/providers/emr-cluster/shared.ts
|
|
166
|
+
const DEFAULT_MAX_WAIT_MS$2 = 36e5;
|
|
167
|
+
const DEFAULT_POLL_INTERVAL_MS$2 = 15e3;
|
|
168
|
+
const CREATE_READY_STATES = /* @__PURE__ */ new Set(["WAITING", "RUNNING"]);
|
|
169
|
+
const TERMINAL_STATES = /* @__PURE__ */ new Set(["TERMINATED", "TERMINATED_WITH_ERRORS"]);
|
|
170
|
+
const MUTABLE_TOP_LEVEL_PROPS = /* @__PURE__ */ new Set([
|
|
171
|
+
"Tags",
|
|
172
|
+
"VisibleToAllUsers",
|
|
173
|
+
"StepConcurrencyLevel",
|
|
174
|
+
"ManagedScalingPolicy",
|
|
175
|
+
"AutoTerminationPolicy"
|
|
176
|
+
]);
|
|
177
|
+
const LEFT_IN_PLACE_ON_REMOVAL$1 = ["StepConcurrencyLevel"];
|
|
178
|
+
const leftInPlaceWarning$1 = (logicalId, names, caller) => {
|
|
179
|
+
const one = names.length === 1;
|
|
180
|
+
const subject = one ? "property" : "properties";
|
|
181
|
+
const verb = one ? "is" : "are";
|
|
182
|
+
return caller === "rollback" ? safeMsg`${logicalId} (AWS::EMR::Cluster): ${subject} ${names.join(", ")} ${verb} absent from the state being restored; ModifyCluster keeps a setting it is not sent, so the rollback leaves the value the failed deploy applied in place.` : safeMsg`${logicalId} (AWS::EMR::Cluster): ${subject} ${names.join(", ")} ${one ? "was" : "were"} removed from the template and ${one ? "keeps its" : "keep their"} current AWS value, as CloudFormation leaves ${one ? "it" : "them"}; ModifyCluster keeps a setting it is not sent. Declare the intended value explicitly to change it.`;
|
|
183
|
+
};
|
|
184
|
+
const toNumber$2 = (v) => {
|
|
185
|
+
if (v === void 0) return void 0;
|
|
186
|
+
const n = Number(v);
|
|
187
|
+
return Number.isNaN(n) ? void 0 : n;
|
|
188
|
+
};
|
|
189
|
+
const toBoolean = (v) => {
|
|
190
|
+
if (v === void 0) return void 0;
|
|
191
|
+
if (typeof v === "string") return v.toLowerCase() === "true";
|
|
192
|
+
return Boolean(v);
|
|
193
|
+
};
|
|
194
|
+
const MONITORING_CONFIGURATION_MEMBERS = /* @__PURE__ */ new Set(["CloudWatchLogConfiguration"]);
|
|
195
|
+
const CLOUDWATCH_LOG_CONFIGURATION_MEMBERS = /* @__PURE__ */ new Set([
|
|
196
|
+
"Enabled",
|
|
197
|
+
"LogGroupName",
|
|
198
|
+
"LogStreamNamePrefix",
|
|
199
|
+
"EncryptionKeyArn",
|
|
200
|
+
"LogTypes"
|
|
201
|
+
]);
|
|
202
|
+
const toSdkMonitoringConfiguration = (value, onUnknown) => {
|
|
203
|
+
if (value === void 0 || value === null) return void 0;
|
|
204
|
+
if (!isPlainObject(value)) return value;
|
|
205
|
+
for (const key of Object.keys(value)) if (!MONITORING_CONFIGURATION_MEMBERS.has(key)) onUnknown(`MonitoringConfiguration.${key}`);
|
|
206
|
+
const cw = value["CloudWatchLogConfiguration"];
|
|
207
|
+
if (cw === void 0 || cw === null) return {};
|
|
208
|
+
if (!isPlainObject(cw)) return { CloudWatchLogConfiguration: cw };
|
|
209
|
+
for (const key of Object.keys(cw)) if (!CLOUDWATCH_LOG_CONFIGURATION_MEMBERS.has(key)) onUnknown(`MonitoringConfiguration.CloudWatchLogConfiguration.${key}`);
|
|
210
|
+
return { CloudWatchLogConfiguration: {
|
|
211
|
+
Enabled: toBoolean(cw["Enabled"]),
|
|
212
|
+
LogGroupName: cw["LogGroupName"],
|
|
213
|
+
LogStreamNamePrefix: cw["LogStreamNamePrefix"],
|
|
214
|
+
EncryptionKeyArn: cw["EncryptionKeyArn"],
|
|
215
|
+
LogTypes: cw["LogTypes"]
|
|
216
|
+
} };
|
|
217
|
+
};
|
|
218
|
+
const jsonEqual$2 = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
219
|
+
const isPlainObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
220
|
+
function withRecordedReferences(next, prev, mask) {
|
|
221
|
+
if (typeof prev === "string" && typeof next === "string") return next !== prev && onlySecretReferencesDiffer(next, prev, mask) ? prev : next;
|
|
222
|
+
if (Array.isArray(prev) && Array.isArray(next) && prev.length === next.length) return next.map((item, i) => withRecordedReferences(item, prev[i], mask));
|
|
223
|
+
if (isPlainObject(prev) && isPlainObject(next)) return Object.fromEntries(Object.entries(next).map(([key, value]) => [key, withRecordedReferences(value, prev[key], mask)]));
|
|
224
|
+
return next;
|
|
225
|
+
}
|
|
226
|
+
const NO_INSTANCES_TARGETS = {
|
|
227
|
+
groups: [],
|
|
228
|
+
fleets: []
|
|
229
|
+
};
|
|
230
|
+
const ENDED_GROUP_STATES = /* @__PURE__ */ new Set([
|
|
231
|
+
"TERMINATING",
|
|
232
|
+
"TERMINATED",
|
|
233
|
+
"SHUTTING_DOWN",
|
|
234
|
+
"ENDED"
|
|
235
|
+
]);
|
|
236
|
+
const ENDED_FLEET_STATES = /* @__PURE__ */ new Set(["TERMINATING", "TERMINATED"]);
|
|
237
|
+
const IDENTITY_MASK = maskerOrIdentity(void 0);
|
|
238
|
+
const EMPTY_INSTANCES_PLAN = {
|
|
239
|
+
terminationProtected: false,
|
|
240
|
+
unhealthyNodeReplacement: false,
|
|
241
|
+
groups: [],
|
|
242
|
+
fleets: []
|
|
243
|
+
};
|
|
244
|
+
const GROUP_IN_PLACE_MEMBERS = ["InstanceCount", "AutoScalingPolicy"];
|
|
245
|
+
const FLEET_IN_PLACE_MEMBERS = ["TargetOnDemandCapacity", "TargetSpotCapacity"];
|
|
246
|
+
function planInstancesInPlace(prev, next) {
|
|
247
|
+
const moved = (a, b, keys) => keys.some((key) => !jsonEqual$2(isPlainObject(a) ? a[key] : void 0, isPlainObject(b) ? b[key] : void 0));
|
|
248
|
+
const asBag = (value) => isPlainObject(value) ? value : {};
|
|
249
|
+
const entries = (single, list, keys) => {
|
|
250
|
+
const out = [];
|
|
251
|
+
if (next[single] !== void 0 && moved(prev[single], next[single], keys)) out.push({
|
|
252
|
+
type: "CORE",
|
|
253
|
+
path: single,
|
|
254
|
+
prev: asBag(prev[single]),
|
|
255
|
+
next: asBag(next[single])
|
|
256
|
+
});
|
|
257
|
+
const prevList = Array.isArray(prev[list]) ? prev[list] : [];
|
|
258
|
+
(Array.isArray(next[list]) ? next[list] : []).forEach((entry, i) => {
|
|
259
|
+
if (moved(prevList[i], entry, keys)) out.push({
|
|
260
|
+
type: "TASK",
|
|
261
|
+
path: list + "[" + String(i) + "]",
|
|
262
|
+
prev: asBag(prevList[i]),
|
|
263
|
+
next: asBag(entry)
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
return out;
|
|
267
|
+
};
|
|
268
|
+
return {
|
|
269
|
+
terminationProtected: !jsonEqual$2(prev["TerminationProtected"], next["TerminationProtected"]),
|
|
270
|
+
unhealthyNodeReplacement: !jsonEqual$2(prev["UnhealthyNodeReplacement"], next["UnhealthyNodeReplacement"]),
|
|
271
|
+
groups: entries("CoreInstanceGroup", "TaskInstanceGroups", GROUP_IN_PLACE_MEMBERS),
|
|
272
|
+
fleets: entries("CoreInstanceFleet", "TaskInstanceFleets", FLEET_IN_PLACE_MEMBERS)
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
const LIVE_CLUSTER_STATES = [
|
|
276
|
+
"STARTING",
|
|
277
|
+
"BOOTSTRAPPING",
|
|
278
|
+
"RUNNING",
|
|
279
|
+
"WAITING"
|
|
280
|
+
];
|
|
281
|
+
const CLUSTER_ID_PATTERN = /^j-[0-9A-Z]+$/;
|
|
282
|
+
const runJobFlowLatch = new AmbiguousCreateLatch("emr:RunJobFlow");
|
|
283
|
+
const clustersCreatedByThisProcess = new RecentIdSet();
|
|
284
|
+
function emrClusterProtectionSite(physicalId, region) {
|
|
285
|
+
return {
|
|
286
|
+
subject: "EMR Cluster",
|
|
287
|
+
guardName: "TerminationProtected",
|
|
288
|
+
noun: "cluster",
|
|
289
|
+
isNotFound: (error) => typeof error === "object" && error !== null && error.name === "InvalidRequestException",
|
|
290
|
+
notFoundMeaning: "EMR answered InvalidRequestException. That can mean the cluster is gone, that it is not in this region or account, or that EMR refused the request for another reason.",
|
|
291
|
+
commands: () => {
|
|
292
|
+
const aws = pasteableAwsCommand();
|
|
293
|
+
const regionArg = region ? aws` --region ${region}` : aws``;
|
|
294
|
+
const restore = aws`aws emr modify-cluster-attributes --cluster-id ${physicalId}${regionArg} --termination-protected`;
|
|
295
|
+
return {
|
|
296
|
+
check: aws`aws emr describe-cluster --cluster-id ${physicalId}${regionArg}`.render(),
|
|
297
|
+
restoreAfterNotFound: restore.render(),
|
|
298
|
+
restoreLive: restore.render()
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// src/provisioning/providers/emr-cluster/core.ts
|
|
305
|
+
function wrapStatusReasonError(mask, reason, fallback, build) {
|
|
306
|
+
const text = describeAwsStatusReason(reason, fallback);
|
|
307
|
+
if (!text.redacted) return build(text.detail, void 0);
|
|
308
|
+
const m = maskerOrIdentity(mask);
|
|
309
|
+
const cause = new Error(text.detail);
|
|
310
|
+
this.logger.debug(m(build(m(text.detail), cause).message));
|
|
311
|
+
return markRedactedCause(build(m(text.summary), cause));
|
|
312
|
+
}
|
|
313
|
+
function wrapCaughtError(mask, error, build) {
|
|
314
|
+
const failure = describeAwsFailure(error);
|
|
315
|
+
if (!(error instanceof Error) || !failure.redacted) return build(failure.detail);
|
|
316
|
+
const m = maskerOrIdentity(mask);
|
|
317
|
+
this.logger.debug(m(build(m(failure.detail)).message));
|
|
318
|
+
return markRedactedCause(build(`${m(failure.summary)}${relayedNameCollision(failure.detail)}`));
|
|
319
|
+
}
|
|
320
|
+
function cleanupFailureText(head, error, mask) {
|
|
321
|
+
const m = maskerOrIdentity(mask);
|
|
322
|
+
const failure = describeAwsFailure(error);
|
|
323
|
+
if (!failure.redacted) return m(failure.detail);
|
|
324
|
+
this.logger.debug(m(`${head}${m(failure.detail)}`));
|
|
325
|
+
return m(failure.summary);
|
|
326
|
+
}
|
|
327
|
+
function getClient() {
|
|
328
|
+
if (!this.client) this.client = new EMRClient({
|
|
329
|
+
...ambientClientDefaults(),
|
|
330
|
+
...this.providerRegion ? { region: this.providerRegion } : {}
|
|
331
|
+
});
|
|
332
|
+
return this.client;
|
|
333
|
+
}
|
|
334
|
+
function getCreateClient() {
|
|
335
|
+
if (!this.createClient) this.createClient = withoutServerErrorRetries(new EMRClient({
|
|
336
|
+
...ambientClientDefaults(),
|
|
337
|
+
...this.providerRegion ? { region: this.providerRegion } : {}
|
|
338
|
+
}));
|
|
339
|
+
return this.createClient;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/provisioning/emr-configuration.ts
|
|
343
|
+
function isRecord(value) {
|
|
344
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
345
|
+
}
|
|
346
|
+
function toSdkConfiguration(raw) {
|
|
347
|
+
if (!isRecord(raw)) return raw;
|
|
348
|
+
const { ConfigurationProperties, Configurations, ...rest } = raw;
|
|
349
|
+
return {
|
|
350
|
+
...rest,
|
|
351
|
+
...ConfigurationProperties !== void 0 ? { Properties: ConfigurationProperties } : {},
|
|
352
|
+
...Configurations !== void 0 ? { Configurations: toSdkConfigurations(Configurations) } : {}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function toSdkConfigurations(value) {
|
|
356
|
+
if (value === void 0) return void 0;
|
|
357
|
+
if (!Array.isArray(value)) return value;
|
|
358
|
+
return value.map(toSdkConfiguration);
|
|
359
|
+
}
|
|
360
|
+
function toSdkStepConfigs(value) {
|
|
361
|
+
if (value === void 0) return void 0;
|
|
362
|
+
if (!Array.isArray(value)) return value;
|
|
363
|
+
return value.map((step) => {
|
|
364
|
+
if (!isRecord(step)) return step;
|
|
365
|
+
const hadoopJarStep = step["HadoopJarStep"];
|
|
366
|
+
if (!isRecord(hadoopJarStep) || hadoopJarStep["StepProperties"] === void 0) return step;
|
|
367
|
+
const { StepProperties, ...restHadoopJarStep } = hadoopJarStep;
|
|
368
|
+
return {
|
|
369
|
+
...step,
|
|
370
|
+
HadoopJarStep: {
|
|
371
|
+
...restHadoopJarStep,
|
|
372
|
+
Properties: StepProperties
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
function toSdkInstanceTypeConfigs(value) {
|
|
378
|
+
if (value === void 0) return void 0;
|
|
379
|
+
if (!Array.isArray(value)) return value;
|
|
380
|
+
return value.map((instanceTypeConfig) => {
|
|
381
|
+
if (!isRecord(instanceTypeConfig) || instanceTypeConfig["Configurations"] === void 0) return instanceTypeConfig;
|
|
382
|
+
return {
|
|
383
|
+
...instanceTypeConfig,
|
|
384
|
+
Configurations: toSdkConfigurations(instanceTypeConfig["Configurations"])
|
|
385
|
+
};
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// src/provisioning/providers/emr-cluster/create.ts
|
|
390
|
+
async function create$1(logicalId, resourceType, properties, context) {
|
|
391
|
+
if (resourceType !== "AWS::EMR::Cluster") throw new ProvisioningError(`Unsupported resource type: ${resourceType}`, resourceType, logicalId);
|
|
392
|
+
this.logger.debug(`Creating EMR Cluster ${logicalId}`);
|
|
393
|
+
const desiredTags = refuseMalformedDesiredTags(properties["Tags"], resourceType, logicalId);
|
|
394
|
+
let clusterId;
|
|
395
|
+
try {
|
|
396
|
+
const tags = properties["Tags"] !== void 0 && properties["Tags"] !== null ? desiredTags : void 0;
|
|
397
|
+
const input = {
|
|
398
|
+
Name: properties["Name"],
|
|
399
|
+
ReleaseLabel: properties["ReleaseLabel"],
|
|
400
|
+
ServiceRole: properties["ServiceRole"],
|
|
401
|
+
JobFlowRole: properties["JobFlowRole"],
|
|
402
|
+
LogUri: properties["LogUri"],
|
|
403
|
+
LogEncryptionKmsKeyId: properties["LogEncryptionKmsKeyId"],
|
|
404
|
+
AdditionalInfo: properties["AdditionalInfo"],
|
|
405
|
+
AutoScalingRole: properties["AutoScalingRole"],
|
|
406
|
+
ScaleDownBehavior: properties["ScaleDownBehavior"],
|
|
407
|
+
CustomAmiId: properties["CustomAmiId"],
|
|
408
|
+
OSReleaseLabel: properties["OSReleaseLabel"],
|
|
409
|
+
SecurityConfiguration: properties["SecurityConfiguration"],
|
|
410
|
+
EbsRootVolumeSize: toNumber$2(properties["EbsRootVolumeSize"]),
|
|
411
|
+
EbsRootVolumeIops: toNumber$2(properties["EbsRootVolumeIops"]),
|
|
412
|
+
EbsRootVolumeThroughput: toNumber$2(properties["EbsRootVolumeThroughput"]),
|
|
413
|
+
StepConcurrencyLevel: toNumber$2(properties["StepConcurrencyLevel"]),
|
|
414
|
+
VisibleToAllUsers: toBoolean(properties["VisibleToAllUsers"]),
|
|
415
|
+
Applications: properties["Applications"],
|
|
416
|
+
Configurations: toSdkConfigurations(properties["Configurations"]),
|
|
417
|
+
BootstrapActions: properties["BootstrapActions"],
|
|
418
|
+
Steps: toSdkStepConfigs(properties["Steps"]),
|
|
419
|
+
KerberosAttributes: properties["KerberosAttributes"],
|
|
420
|
+
PlacementGroupConfigs: properties["PlacementGroupConfigs"],
|
|
421
|
+
ManagedScalingPolicy: this.toManagedScalingPolicy(properties["ManagedScalingPolicy"]),
|
|
422
|
+
AutoTerminationPolicy: this.toAutoTerminationPolicy(properties["AutoTerminationPolicy"]),
|
|
423
|
+
MonitoringConfiguration: toSdkMonitoringConfiguration(properties["MonitoringConfiguration"], (path) => {
|
|
424
|
+
const text = safeMsg`${path} is not a CloudFormation property of AWS::EMR::Cluster, so CloudFormation rejects this template; remove it.`;
|
|
425
|
+
if (context?.replayingState) {
|
|
426
|
+
this.logger.warn(safeMsg`${logicalId}: ${asIsMessage(text)} Dropped from the rollback's RunJobFlow.`);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
throw markNonRetryable(new ProvisioningError(safeMsg`Cannot create EMR Cluster ${logicalId}: ${asIsMessage(text)}`, resourceType, logicalId));
|
|
430
|
+
}),
|
|
431
|
+
SessionEnabled: toBoolean(properties["SessionEnabled"]),
|
|
432
|
+
Tags: tags?.map((t) => ({
|
|
433
|
+
Key: t.Key,
|
|
434
|
+
Value: t.Value
|
|
435
|
+
})),
|
|
436
|
+
Instances: this.toJobFlowInstancesConfig(properties["Instances"])
|
|
437
|
+
};
|
|
438
|
+
const reportOrphans = async (lookupWindow) => {
|
|
439
|
+
const log = createMaskedLogSinks(this.logger, context?.maskSecrets);
|
|
440
|
+
const aws = pasteableAwsCommand(log.mask);
|
|
441
|
+
const regionArg = await orphanCommandRegionArg(this.getClient(), aws);
|
|
442
|
+
const name = input.Name;
|
|
443
|
+
const protectedCluster = input.Instances?.TerminationProtected === true;
|
|
444
|
+
await reportPossibleOrphans(logicalId, lookupWindow, log, {
|
|
445
|
+
action: "RunJobFlow",
|
|
446
|
+
service: "EMR",
|
|
447
|
+
listAction: "ListClusters",
|
|
448
|
+
subject: `a cluster named ${log.value(name)}`,
|
|
449
|
+
noun: "cluster(s)",
|
|
450
|
+
list: () => collectOrphanIds(async (marker) => {
|
|
451
|
+
const page = await this.getClient().send(new ListClustersCommand({
|
|
452
|
+
CreatedAfter: new Date(lookupWindow.floorMs),
|
|
453
|
+
CreatedBefore: new Date(lookupWindow.ceilingMs),
|
|
454
|
+
ClusterStates: LIVE_CLUSTER_STATES,
|
|
455
|
+
...marker && { Marker: marker }
|
|
456
|
+
}));
|
|
457
|
+
return {
|
|
458
|
+
items: page.Clusters ?? [],
|
|
459
|
+
next: page.Marker
|
|
460
|
+
};
|
|
461
|
+
}, (c) => c.Id && c.Name === name && isInsideWindow(c.Status?.Timeline?.CreationDateTime, lookupWindow) && !clustersCreatedByThisProcess.has(c.Id) ? c.Id : void 0),
|
|
462
|
+
inspect: (id) => aws`aws emr describe-cluster --cluster-id ${id}${regionArg}`.render(),
|
|
463
|
+
remove: (id) => aws`aws emr terminate-clusters --cluster-ids ${id}${regionArg}`.render(),
|
|
464
|
+
removeVerb: protectedCluster ? `terminate it (this template turns termination protection on, so if describe-cluster shows it on for the candidate, first run ${aws`aws emr modify-cluster-attributes --cluster-id`.render()} ${commandHole("id")} ${aws`--no-termination-protected${regionArg}`.render()} with its id)` : "terminate it"
|
|
465
|
+
});
|
|
466
|
+
};
|
|
467
|
+
const orphanWindow = runJobFlowLatch.take(logicalId);
|
|
468
|
+
if (orphanWindow !== void 0) await reportOrphans(orphanWindow);
|
|
469
|
+
const attemptStartMs = Date.now();
|
|
470
|
+
let response;
|
|
471
|
+
try {
|
|
472
|
+
response = await this.getCreateClient().send(new RunJobFlowCommand(input));
|
|
473
|
+
} catch (error) {
|
|
474
|
+
runJobFlowLatch.noteFailure(logicalId, error, attemptStartMs, orphanWindow);
|
|
475
|
+
throw error;
|
|
476
|
+
}
|
|
477
|
+
clusterId = response.JobFlowId;
|
|
478
|
+
if (clusterId) clustersCreatedByThisProcess.add(clusterId);
|
|
479
|
+
reportCreatedResource(logicalId, resourceType, clusterId ?? "");
|
|
480
|
+
const replayWindow = replayedSendWindow(response, attemptStartMs);
|
|
481
|
+
if (replayWindow !== void 0) await reportOrphans(replayWindow);
|
|
482
|
+
if (!clusterId) throw new ProvisioningError(`EMR RunJobFlow for ${logicalId} returned no JobFlowId`, resourceType, logicalId);
|
|
483
|
+
const cluster = await this.waitForClusterReady(clusterId, logicalId, resourceType, context?.maskSecrets);
|
|
484
|
+
this.logger.debug(`Successfully created EMR Cluster ${logicalId}: ${clusterId}`);
|
|
485
|
+
return {
|
|
486
|
+
physicalId: clusterId,
|
|
487
|
+
attributes: this.buildAttributes(cluster)
|
|
488
|
+
};
|
|
489
|
+
} catch (error) {
|
|
490
|
+
let survivorId;
|
|
491
|
+
if (clusterId !== void 0) try {
|
|
492
|
+
await this.getClient().send(new SetTerminationProtectionCommand({
|
|
493
|
+
JobFlowIds: [clusterId],
|
|
494
|
+
TerminationProtected: false
|
|
495
|
+
}));
|
|
496
|
+
await this.getClient().send(new TerminateJobFlowsCommand({ JobFlowIds: [clusterId] }));
|
|
497
|
+
retractCreatedResource(logicalId, resourceType, clusterId);
|
|
498
|
+
this.logger.warn(`Rolled back partially-created EMR Cluster ${clusterId}`);
|
|
499
|
+
} catch (cleanupError) {
|
|
500
|
+
survivorId = clusterId;
|
|
501
|
+
const cleanupHead = `Failed to roll back partially-created EMR Cluster ${clusterId}: `;
|
|
502
|
+
this.logger.warn(maskerOrIdentity(context?.maskSecrets)(`${cleanupHead}${this.cleanupFailureText(cleanupHead, cleanupError, context?.maskSecrets)} — terminate it manually to stop billing`));
|
|
503
|
+
}
|
|
504
|
+
if (error instanceof ProvisioningError) {
|
|
505
|
+
if (survivorId !== void 0) {
|
|
506
|
+
markCreatedBeforeFailure(error, logicalId, resourceType, survivorId);
|
|
507
|
+
markNonRetryable(error);
|
|
508
|
+
}
|
|
509
|
+
throw error;
|
|
510
|
+
}
|
|
511
|
+
const cause = error instanceof Error ? error : void 0;
|
|
512
|
+
const thrown = this.wrapCaughtError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to create EMR Cluster ${logicalId}: ${text}`, resourceType, logicalId, void 0, cause));
|
|
513
|
+
if (survivorId !== void 0) {
|
|
514
|
+
markCreatedBeforeFailure(thrown, logicalId, resourceType, survivorId);
|
|
515
|
+
markNonRetryable(thrown);
|
|
516
|
+
}
|
|
517
|
+
throw thrown;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function toJobFlowInstancesConfig(config) {
|
|
521
|
+
if (!config) return void 0;
|
|
522
|
+
const instanceGroups = [];
|
|
523
|
+
const pushGroup = (raw, role) => {
|
|
524
|
+
if (raw === void 0 || raw === null) return;
|
|
525
|
+
instanceGroups.push(this.toInstanceGroupConfig(raw, role));
|
|
526
|
+
};
|
|
527
|
+
pushGroup(config["MasterInstanceGroup"], "MASTER");
|
|
528
|
+
pushGroup(config["CoreInstanceGroup"], "CORE");
|
|
529
|
+
for (const task of config["TaskInstanceGroups"] ?? []) pushGroup(task, "TASK");
|
|
530
|
+
const instanceFleets = [];
|
|
531
|
+
const pushFleet = (raw, type) => {
|
|
532
|
+
if (raw === void 0 || raw === null) return;
|
|
533
|
+
instanceFleets.push(this.toInstanceFleetConfig(raw, type));
|
|
534
|
+
};
|
|
535
|
+
pushFleet(config["MasterInstanceFleet"], "MASTER");
|
|
536
|
+
pushFleet(config["CoreInstanceFleet"], "CORE");
|
|
537
|
+
for (const task of config["TaskInstanceFleets"] ?? []) pushFleet(task, "TASK");
|
|
538
|
+
return {
|
|
539
|
+
InstanceGroups: instanceGroups.length > 0 ? instanceGroups : void 0,
|
|
540
|
+
InstanceFleets: instanceFleets.length > 0 ? instanceFleets : void 0,
|
|
541
|
+
Ec2KeyName: config["Ec2KeyName"],
|
|
542
|
+
Ec2SubnetId: config["Ec2SubnetId"],
|
|
543
|
+
Ec2SubnetIds: config["Ec2SubnetIds"],
|
|
544
|
+
HadoopVersion: config["HadoopVersion"],
|
|
545
|
+
Placement: config["Placement"],
|
|
546
|
+
KeepJobFlowAliveWhenNoSteps: toBoolean(config["KeepJobFlowAliveWhenNoSteps"]),
|
|
547
|
+
TerminationProtected: toBoolean(config["TerminationProtected"]),
|
|
548
|
+
UnhealthyNodeReplacement: toBoolean(config["UnhealthyNodeReplacement"]),
|
|
549
|
+
EmrManagedMasterSecurityGroup: config["EmrManagedMasterSecurityGroup"],
|
|
550
|
+
EmrManagedSlaveSecurityGroup: config["EmrManagedSlaveSecurityGroup"],
|
|
551
|
+
ServiceAccessSecurityGroup: config["ServiceAccessSecurityGroup"],
|
|
552
|
+
AdditionalMasterSecurityGroups: config["AdditionalMasterSecurityGroups"],
|
|
553
|
+
AdditionalSlaveSecurityGroups: config["AdditionalSlaveSecurityGroups"]
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
function toInstanceGroupConfig(raw, role) {
|
|
557
|
+
return {
|
|
558
|
+
InstanceRole: role,
|
|
559
|
+
InstanceType: raw["InstanceType"],
|
|
560
|
+
InstanceCount: toNumber$2(raw["InstanceCount"]),
|
|
561
|
+
Name: raw["Name"],
|
|
562
|
+
Market: raw["Market"],
|
|
563
|
+
BidPrice: raw["BidPrice"],
|
|
564
|
+
Configurations: toSdkConfigurations(raw["Configurations"]),
|
|
565
|
+
EbsConfiguration: raw["EbsConfiguration"],
|
|
566
|
+
AutoScalingPolicy: raw["AutoScalingPolicy"],
|
|
567
|
+
CustomAmiId: raw["CustomAmiId"]
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function toInstanceFleetConfig$1(raw, type) {
|
|
571
|
+
return {
|
|
572
|
+
InstanceFleetType: type,
|
|
573
|
+
Name: raw["Name"],
|
|
574
|
+
TargetOnDemandCapacity: toNumber$2(raw["TargetOnDemandCapacity"]),
|
|
575
|
+
TargetSpotCapacity: toNumber$2(raw["TargetSpotCapacity"]),
|
|
576
|
+
InstanceTypeConfigs: toSdkInstanceTypeConfigs(raw["InstanceTypeConfigs"]),
|
|
577
|
+
LaunchSpecifications: raw["LaunchSpecifications"],
|
|
578
|
+
ResizeSpecifications: raw["ResizeSpecifications"]
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function toManagedScalingPolicy(config) {
|
|
582
|
+
if (!config) return void 0;
|
|
583
|
+
const limits = config["ComputeLimits"];
|
|
584
|
+
if (!limits) return void 0;
|
|
585
|
+
return {
|
|
586
|
+
ComputeLimits: {
|
|
587
|
+
UnitType: limits["UnitType"],
|
|
588
|
+
MinimumCapacityUnits: toNumber$2(limits["MinimumCapacityUnits"]),
|
|
589
|
+
MaximumCapacityUnits: toNumber$2(limits["MaximumCapacityUnits"]),
|
|
590
|
+
MaximumOnDemandCapacityUnits: toNumber$2(limits["MaximumOnDemandCapacityUnits"]),
|
|
591
|
+
MaximumCoreCapacityUnits: toNumber$2(limits["MaximumCoreCapacityUnits"])
|
|
592
|
+
},
|
|
593
|
+
UtilizationPerformanceIndex: toNumber$2(config["UtilizationPerformanceIndex"]),
|
|
594
|
+
ScalingStrategy: config["ScalingStrategy"]
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function toAutoTerminationPolicy(config) {
|
|
598
|
+
if (!config) return void 0;
|
|
599
|
+
return { IdleTimeout: toNumber$2(config["IdleTimeout"]) };
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// src/provisioning/providers/emr-instance-group-config/remove-scaling-policy.ts
|
|
603
|
+
async function removeScalingPolicyForDelete(client, clusterId, instanceGroupId) {
|
|
604
|
+
try {
|
|
605
|
+
await client.send(new RemoveAutoScalingPolicyCommand({
|
|
606
|
+
ClusterId: clusterId,
|
|
607
|
+
InstanceGroupId: instanceGroupId
|
|
608
|
+
}));
|
|
609
|
+
return true;
|
|
610
|
+
} catch (error) {
|
|
611
|
+
const e = error;
|
|
612
|
+
if (e?.name === "ValidationException" && typeof e.message === "string" && /policy was not found/i.test(e.message)) return false;
|
|
613
|
+
throw error;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// src/provisioning/providers/emr-instance-group-config/read-state.ts
|
|
618
|
+
const CLUSTER_ID$1 = /^j-[A-Z0-9]+$/;
|
|
619
|
+
async function readCurrentState$2(physicalId, resourceType, properties) {
|
|
620
|
+
if (resourceType !== "AWS::EMR::InstanceGroupConfig") return void 0;
|
|
621
|
+
const clusterId = properties?.["JobFlowId"];
|
|
622
|
+
if (typeof clusterId !== "string" || !CLUSTER_ID$1.test(clusterId)) return void 0;
|
|
623
|
+
let group;
|
|
624
|
+
try {
|
|
625
|
+
let marker;
|
|
626
|
+
do {
|
|
627
|
+
const resp = await this.getClient().send(new ListInstanceGroupsCommand({
|
|
628
|
+
ClusterId: clusterId,
|
|
629
|
+
...marker && { Marker: marker }
|
|
630
|
+
}));
|
|
631
|
+
group = (resp.InstanceGroups ?? []).find((g) => g.Id === physicalId);
|
|
632
|
+
marker = group === void 0 ? resp.Marker : void 0;
|
|
633
|
+
} while (marker);
|
|
634
|
+
} catch (error) {
|
|
635
|
+
if (error instanceof InvalidRequestException) return void 0;
|
|
636
|
+
throw error;
|
|
637
|
+
}
|
|
638
|
+
const state = group?.Status?.State;
|
|
639
|
+
if (group === void 0 || state === "TERMINATED" || state === "ENDED") return RESOURCE_NOT_FOUND;
|
|
640
|
+
const out = { JobFlowId: clusterId };
|
|
641
|
+
if (group.InstanceGroupType !== void 0) out["InstanceRole"] = group.InstanceGroupType;
|
|
642
|
+
if (group.InstanceType !== void 0) out["InstanceType"] = group.InstanceType;
|
|
643
|
+
if (group.RequestedInstanceCount !== void 0) out["InstanceCount"] = group.RequestedInstanceCount;
|
|
644
|
+
if (group.Name !== void 0) out["Name"] = group.Name;
|
|
645
|
+
if (group.Market !== void 0) out["Market"] = group.Market;
|
|
646
|
+
if (group.BidPrice !== void 0) out["BidPrice"] = group.BidPrice;
|
|
647
|
+
if (group.CustomAmiId !== void 0) out["CustomAmiId"] = group.CustomAmiId;
|
|
648
|
+
if (group.Configurations !== void 0 && group.Configurations.length > 0) out["Configurations"] = group.Configurations.map(configurationOf$1);
|
|
649
|
+
const ebs = ebsConfigurationOf$1(group.EbsBlockDevices, group.EbsOptimized);
|
|
650
|
+
if (ebs !== void 0) out["EbsConfiguration"] = ebs;
|
|
651
|
+
if (group.AutoScalingPolicy !== void 0) out["AutoScalingPolicy"] = definedOnly$1({
|
|
652
|
+
Constraints: group.AutoScalingPolicy.Constraints,
|
|
653
|
+
Rules: group.AutoScalingPolicy.Rules
|
|
654
|
+
});
|
|
655
|
+
return out;
|
|
656
|
+
}
|
|
657
|
+
function definedOnly$1(value) {
|
|
658
|
+
if (Array.isArray(value)) return value.map(definedOnly$1);
|
|
659
|
+
if (typeof value !== "object" || value === null) return value;
|
|
660
|
+
return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== void 0).map(([k, v]) => [k, definedOnly$1(v)]));
|
|
661
|
+
}
|
|
662
|
+
function configurationOf$1(c) {
|
|
663
|
+
const out = {};
|
|
664
|
+
if (c.Classification !== void 0) out["Classification"] = c.Classification;
|
|
665
|
+
if (c.Properties !== void 0) out["ConfigurationProperties"] = { ...c.Properties };
|
|
666
|
+
if (c.Configurations !== void 0 && c.Configurations.length > 0) out["Configurations"] = c.Configurations.map(configurationOf$1);
|
|
667
|
+
return out;
|
|
668
|
+
}
|
|
669
|
+
function ebsConfigurationOf$1(devices, ebsOptimized) {
|
|
670
|
+
const configs = [];
|
|
671
|
+
for (const device of devices ?? []) {
|
|
672
|
+
const spec = definedOnly$1({
|
|
673
|
+
VolumeType: device.VolumeSpecification?.VolumeType,
|
|
674
|
+
SizeInGB: device.VolumeSpecification?.SizeInGB,
|
|
675
|
+
Iops: device.VolumeSpecification?.Iops,
|
|
676
|
+
Throughput: device.VolumeSpecification?.Throughput
|
|
677
|
+
});
|
|
678
|
+
const last = configs[configs.length - 1];
|
|
679
|
+
if (last !== void 0 && JSON.stringify(last.VolumeSpecification) === JSON.stringify(spec)) last.VolumesPerInstance += 1;
|
|
680
|
+
else configs.push({
|
|
681
|
+
VolumeSpecification: spec,
|
|
682
|
+
VolumesPerInstance: 1
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
if (configs.length === 0 && ebsOptimized === void 0) return void 0;
|
|
686
|
+
const out = {};
|
|
687
|
+
if (configs.length > 0) out["EbsBlockDeviceConfigs"] = configs;
|
|
688
|
+
if (ebsOptimized !== void 0) out["EbsOptimized"] = ebsOptimized;
|
|
689
|
+
return out;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// src/provisioning/providers/emr-instance-group-config/find-group.ts
|
|
693
|
+
async function findGroupForPoll(clusterId, groupId, transientState, maxConsecutiveTransient = 5) {
|
|
694
|
+
try {
|
|
695
|
+
let marker;
|
|
696
|
+
do {
|
|
697
|
+
const resp = await this.getClient().send(new ListInstanceGroupsCommand({
|
|
698
|
+
ClusterId: clusterId,
|
|
699
|
+
...marker && { Marker: marker }
|
|
700
|
+
}));
|
|
701
|
+
const found = (resp.InstanceGroups ?? []).find((g) => g.Id === groupId);
|
|
702
|
+
if (found) {
|
|
703
|
+
transientState.count = 0;
|
|
704
|
+
return found;
|
|
705
|
+
}
|
|
706
|
+
marker = resp.Marker;
|
|
707
|
+
} while (marker);
|
|
708
|
+
transientState.count = 0;
|
|
709
|
+
return;
|
|
710
|
+
} catch (error) {
|
|
711
|
+
const name = error instanceof Error ? error.name : "";
|
|
712
|
+
const msg = describeAwsFailure(error).detail;
|
|
713
|
+
if ((name === "ThrottlingException" || name === "InternalServerException" || name === "InternalServerError" || name === "TimeoutError" || /rate exceeded|too many requests|throttl|timed? ?out|ECONNRESET|EPIPE|socket hang up/i.test(msg)) && transientState.count < maxConsecutiveTransient) {
|
|
714
|
+
transientState.count += 1;
|
|
715
|
+
this.logger.debug(safeMsg`Transient ListInstanceGroups error while polling ${groupId} (${transientState.count}/${maxConsecutiveTransient}): ${msg} — retrying`);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
throw error;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// src/provisioning/providers/emr-instance-group-config-provider.ts
|
|
723
|
+
const DEFAULT_MAX_WAIT_MS$1 = 36e5;
|
|
724
|
+
const DEFAULT_POLL_INTERVAL_MS$1 = 15e3;
|
|
725
|
+
const READY_STATES$1 = /* @__PURE__ */ new Set(["RUNNING"]);
|
|
726
|
+
const FAILED_STATES$1 = /* @__PURE__ */ new Set([
|
|
727
|
+
"ARRESTED",
|
|
728
|
+
"ENDED",
|
|
729
|
+
"SUSPENDED",
|
|
730
|
+
"TERMINATED"
|
|
731
|
+
]);
|
|
732
|
+
const toNumber$1 = (v) => {
|
|
733
|
+
if (v === void 0) return void 0;
|
|
734
|
+
const n = Number(v);
|
|
735
|
+
return Number.isNaN(n) ? void 0 : n;
|
|
736
|
+
};
|
|
737
|
+
const jsonEqual$1 = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
738
|
+
const addInstanceGroupsLatch = new AmbiguousCreateLatch("emr:AddInstanceGroups");
|
|
739
|
+
const groupsCreatedByThisProcess = new RecentIdSet();
|
|
740
|
+
const MOVING_GROUP_STATES = /* @__PURE__ */ new Set([
|
|
741
|
+
"PROVISIONING",
|
|
742
|
+
"BOOTSTRAPPING",
|
|
743
|
+
"RESIZING",
|
|
744
|
+
"RECONFIGURING"
|
|
745
|
+
]);
|
|
746
|
+
var EMRInstanceGroupConfigProvider = class {
|
|
747
|
+
client;
|
|
748
|
+
createClient;
|
|
749
|
+
providerRegion = ambientRegion();
|
|
750
|
+
logger = getLogger().child("EMRInstanceGroupConfigProvider");
|
|
751
|
+
pollIntervalMs;
|
|
752
|
+
maxWaitMs;
|
|
753
|
+
constructor(options) {
|
|
754
|
+
this.pollIntervalMs = options?.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS$1;
|
|
755
|
+
this.maxWaitMs = options?.maxWaitMs ?? DEFAULT_MAX_WAIT_MS$1;
|
|
756
|
+
}
|
|
757
|
+
wrapStatusReasonError(mask, reason, fallback, build) {
|
|
758
|
+
const text = describeAwsStatusReason(reason, fallback);
|
|
759
|
+
if (!text.redacted) return build(text.detail, void 0);
|
|
760
|
+
const m = maskerOrIdentity(mask);
|
|
761
|
+
const cause = new Error(text.detail);
|
|
762
|
+
this.logger.debug(m(build(m(text.detail), cause).message));
|
|
763
|
+
return markRedactedCause(build(m(text.summary), cause));
|
|
764
|
+
}
|
|
765
|
+
wrapCaughtError(mask, error, build) {
|
|
766
|
+
const failure = describeAwsFailure(error);
|
|
767
|
+
if (!(error instanceof Error) || !failure.redacted) return build(failure.detail);
|
|
768
|
+
const m = maskerOrIdentity(mask);
|
|
769
|
+
this.logger.debug(m(build(m(failure.detail)).message));
|
|
770
|
+
return markRedactedCause(build(`${m(failure.summary)}${relayedNameCollision(failure.detail)}`));
|
|
771
|
+
}
|
|
772
|
+
cleanupFailureText(head, error, mask) {
|
|
773
|
+
const m = maskerOrIdentity(mask);
|
|
774
|
+
const failure = describeAwsFailure(error);
|
|
775
|
+
if (!failure.redacted) return m(failure.detail);
|
|
776
|
+
this.logger.debug(m(`${head}${m(failure.detail)}`));
|
|
777
|
+
return m(failure.summary);
|
|
778
|
+
}
|
|
779
|
+
handledProperties = /* @__PURE__ */ new Map([["AWS::EMR::InstanceGroupConfig", /* @__PURE__ */ new Set([
|
|
780
|
+
"AutoScalingPolicy",
|
|
781
|
+
"BidPrice",
|
|
782
|
+
"Configurations",
|
|
783
|
+
"CustomAmiId",
|
|
784
|
+
"EbsConfiguration",
|
|
785
|
+
"InstanceCount",
|
|
786
|
+
"InstanceRole",
|
|
787
|
+
"InstanceType",
|
|
788
|
+
"JobFlowId",
|
|
789
|
+
"Market",
|
|
790
|
+
"Name"
|
|
791
|
+
])]]);
|
|
792
|
+
getClient() {
|
|
793
|
+
if (!this.client) this.client = new EMRClient({
|
|
794
|
+
...ambientClientDefaults(),
|
|
795
|
+
...this.providerRegion ? { region: this.providerRegion } : {}
|
|
796
|
+
});
|
|
797
|
+
return this.client;
|
|
798
|
+
}
|
|
799
|
+
getCreateClient() {
|
|
800
|
+
if (!this.createClient) this.createClient = withoutServerErrorRetries(new EMRClient({
|
|
801
|
+
...ambientClientDefaults(),
|
|
802
|
+
...this.providerRegion ? { region: this.providerRegion } : {}
|
|
803
|
+
}));
|
|
804
|
+
return this.createClient;
|
|
805
|
+
}
|
|
806
|
+
getMinResourceTimeoutMs() {
|
|
807
|
+
return this.maxWaitMs + this.pollIntervalMs;
|
|
808
|
+
}
|
|
809
|
+
async create(logicalId, resourceType, properties, context) {
|
|
810
|
+
if (resourceType !== "AWS::EMR::InstanceGroupConfig") throw new ProvisioningError(`Unsupported resource type: ${resourceType}`, resourceType, logicalId);
|
|
811
|
+
const jobFlowId = properties["JobFlowId"];
|
|
812
|
+
if (!jobFlowId) throw new ProvisioningError(`EMR InstanceGroupConfig ${logicalId} is missing JobFlowId (the parent cluster id)`, resourceType, logicalId);
|
|
813
|
+
this.logger.debug(`Adding EMR instance group ${logicalId} to cluster ${jobFlowId}`);
|
|
814
|
+
let createdGroupId;
|
|
815
|
+
try {
|
|
816
|
+
const group = this.toInstanceGroupConfig(properties);
|
|
817
|
+
const reportOrphans = async (lookupWindow) => {
|
|
818
|
+
const log = createMaskedLogSinks(this.logger, context?.maskSecrets);
|
|
819
|
+
const aws = pasteableAwsCommand(log.mask);
|
|
820
|
+
const regionArg = await orphanCommandRegionArg(this.getClient(), aws);
|
|
821
|
+
const name = group.Name;
|
|
822
|
+
await reportPossibleOrphans(logicalId, lookupWindow, log, {
|
|
823
|
+
action: "AddInstanceGroups",
|
|
824
|
+
service: "EMR",
|
|
825
|
+
listAction: "ListInstanceGroups",
|
|
826
|
+
subject: `a TASK instance group${name !== void 0 ? ` named ${log.value(name)}` : ""} in cluster ${log.value(jobFlowId)}`,
|
|
827
|
+
noun: "TASK instance group(s)",
|
|
828
|
+
list: () => collectOrphanIds(async (marker) => {
|
|
829
|
+
const page = await this.getClient().send(new ListInstanceGroupsCommand({
|
|
830
|
+
ClusterId: jobFlowId,
|
|
831
|
+
...marker && { Marker: marker }
|
|
832
|
+
}));
|
|
833
|
+
return {
|
|
834
|
+
items: page.InstanceGroups ?? [],
|
|
835
|
+
next: page.Marker
|
|
836
|
+
};
|
|
837
|
+
}, (item) => item.Id && item.InstanceGroupType === "TASK" && (name === void 0 || item.Name === name) && isInsideWindow(item.Status?.Timeline?.CreationDateTime, lookupWindow) && !groupsCreatedByThisProcess.has(item.Id) ? item.Id : void 0),
|
|
838
|
+
inspect: () => aws`aws emr list-instance-groups --cluster-id ${jobFlowId}${regionArg}`.render(),
|
|
839
|
+
remove: (id) => aws`aws emr modify-instance-groups --cluster-id ${jobFlowId} --instance-groups InstanceGroupId=${id},InstanceCount=0${regionArg}`.render(),
|
|
840
|
+
removeVerb: "scale it to zero, which releases its instances (EMR has no call that removes an instance group; it ends with its cluster)"
|
|
841
|
+
});
|
|
842
|
+
};
|
|
843
|
+
const orphanWindow = addInstanceGroupsLatch.take(logicalId);
|
|
844
|
+
if (orphanWindow !== void 0 && group.InstanceRole === "TASK") await reportOrphans(orphanWindow);
|
|
845
|
+
const attemptStartMs = Date.now();
|
|
846
|
+
let response;
|
|
847
|
+
try {
|
|
848
|
+
response = await this.getCreateClient().send(new AddInstanceGroupsCommand({
|
|
849
|
+
JobFlowId: jobFlowId,
|
|
850
|
+
InstanceGroups: [group]
|
|
851
|
+
}));
|
|
852
|
+
} catch (error) {
|
|
853
|
+
addInstanceGroupsLatch.noteFailure(logicalId, error, attemptStartMs, orphanWindow);
|
|
854
|
+
throw error;
|
|
855
|
+
}
|
|
856
|
+
const groupId = response.InstanceGroupIds?.[0];
|
|
857
|
+
if (groupId) groupsCreatedByThisProcess.add(groupId);
|
|
858
|
+
createdGroupId = groupId;
|
|
859
|
+
reportCreatedResource(logicalId, resourceType, groupId ?? "");
|
|
860
|
+
const replayWindow = replayedSendWindow(response, attemptStartMs);
|
|
861
|
+
if (replayWindow !== void 0 && group.InstanceRole === "TASK") await reportOrphans(replayWindow);
|
|
862
|
+
if (!groupId) throw new ProvisioningError(`EMR AddInstanceGroups for ${logicalId} returned no instance group id`, resourceType, logicalId);
|
|
863
|
+
await this.waitForGroupReady(jobFlowId, groupId, logicalId, resourceType, toNumber$1(properties["InstanceCount"]) ?? 0, false, context?.maskSecrets);
|
|
864
|
+
this.logger.debug(`Successfully added EMR instance group ${logicalId}: ${groupId}`);
|
|
865
|
+
return {
|
|
866
|
+
physicalId: groupId,
|
|
867
|
+
attributes: {
|
|
868
|
+
Id: groupId,
|
|
869
|
+
InstanceGroupId: groupId
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
} catch (error) {
|
|
873
|
+
const thrown = error instanceof ProvisioningError ? error : this.wrapCaughtError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to add EMR instance group ${logicalId}: ${text}`, resourceType, logicalId, void 0, error instanceof Error ? error : void 0));
|
|
874
|
+
let leftBehindGroupId = createdGroupId;
|
|
875
|
+
if (leftBehindGroupId && properties["InstanceRole"] === "TASK") {
|
|
876
|
+
const log = createMaskedLogSinks(this.logger, context?.maskSecrets);
|
|
877
|
+
try {
|
|
878
|
+
await this.getClient().send(new ModifyInstanceGroupsCommand({
|
|
879
|
+
ClusterId: jobFlowId,
|
|
880
|
+
InstanceGroups: [{
|
|
881
|
+
InstanceGroupId: leftBehindGroupId,
|
|
882
|
+
InstanceCount: 0
|
|
883
|
+
}]
|
|
884
|
+
}));
|
|
885
|
+
log.warn(safeMsg`Scaled partially-created EMR TASK instance group ${logicalId} (${leftBehindGroupId}) to 0; EMR has no delete API, so the empty group stays on cluster ${log.value(jobFlowId)} until it terminates`);
|
|
886
|
+
retractCreatedResource(logicalId, resourceType, leftBehindGroupId);
|
|
887
|
+
leftBehindGroupId = void 0;
|
|
888
|
+
} catch (cleanupError) {
|
|
889
|
+
const cleanupHead = safeMsg`Failed to scale partially-created EMR TASK instance group ${logicalId} (${leftBehindGroupId}) to 0: `;
|
|
890
|
+
log.warn(safeMsg`${cleanupHead}${this.cleanupFailureText(cleanupHead, cleanupError, log.mask)} — its instances are released when the parent cluster terminates`);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if (leftBehindGroupId) {
|
|
894
|
+
markCreatedBeforeFailure(thrown, logicalId, resourceType, leftBehindGroupId);
|
|
895
|
+
markNonRetryable(thrown);
|
|
896
|
+
}
|
|
897
|
+
throw thrown;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
toInstanceGroupConfig(properties) {
|
|
901
|
+
return {
|
|
902
|
+
InstanceRole: properties["InstanceRole"],
|
|
903
|
+
InstanceType: properties["InstanceType"],
|
|
904
|
+
InstanceCount: toNumber$1(properties["InstanceCount"]),
|
|
905
|
+
Name: properties["Name"],
|
|
906
|
+
Market: properties["Market"],
|
|
907
|
+
BidPrice: properties["BidPrice"],
|
|
908
|
+
Configurations: toSdkConfigurations(properties["Configurations"]),
|
|
909
|
+
EbsConfiguration: properties["EbsConfiguration"],
|
|
910
|
+
AutoScalingPolicy: properties["AutoScalingPolicy"],
|
|
911
|
+
CustomAmiId: properties["CustomAmiId"]
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
async update(logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
915
|
+
const changed = (key) => !jsonEqual$1(properties[key], previousProperties[key]);
|
|
916
|
+
const MUTABLE = /* @__PURE__ */ new Set(["InstanceCount", "AutoScalingPolicy"]);
|
|
917
|
+
for (const key of Object.keys({
|
|
918
|
+
...properties,
|
|
919
|
+
...previousProperties
|
|
920
|
+
})) {
|
|
921
|
+
if (!changed(key)) continue;
|
|
922
|
+
if (!MUTABLE.has(key) && (key === "JobFlowId" || !await unchangedBehindSecretReference({
|
|
923
|
+
resourceType,
|
|
924
|
+
key,
|
|
925
|
+
desired: properties[key],
|
|
926
|
+
previous: previousProperties[key],
|
|
927
|
+
maskSecrets: context?.maskSecrets
|
|
928
|
+
}))) throw new ResourceUpdateNotSupportedError(resourceType, logicalId, `AWS EMR InstanceGroupConfig ${key} is immutable on AWS — it is fixed when the instance group is created. Re-deploy with ${deployReplaceCommand()}, or destroy + redeploy the stack.`);
|
|
929
|
+
}
|
|
930
|
+
const instanceCountChanged = changed("InstanceCount");
|
|
931
|
+
const autoScalingChanged = changed("AutoScalingPolicy");
|
|
932
|
+
if (!instanceCountChanged && !autoScalingChanged) {
|
|
933
|
+
this.logger.debug(`No mutable diff for EMR instance group ${logicalId}, skipping update`);
|
|
934
|
+
return {
|
|
935
|
+
physicalId,
|
|
936
|
+
wasReplaced: false,
|
|
937
|
+
attributes: {
|
|
938
|
+
Id: physicalId,
|
|
939
|
+
InstanceGroupId: physicalId
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
const jobFlowId = properties["JobFlowId"];
|
|
944
|
+
this.logger.debug(`Updating EMR instance group ${logicalId}: ${physicalId}`);
|
|
945
|
+
try {
|
|
946
|
+
if (instanceCountChanged) {
|
|
947
|
+
context?.markUnsettled?.("InstanceCount");
|
|
948
|
+
await this.getClient().send(new ModifyInstanceGroupsCommand({
|
|
949
|
+
...jobFlowId && { ClusterId: jobFlowId },
|
|
950
|
+
InstanceGroups: [{
|
|
951
|
+
InstanceGroupId: physicalId,
|
|
952
|
+
InstanceCount: toNumber$1(properties["InstanceCount"]) ?? 0
|
|
953
|
+
}]
|
|
954
|
+
}));
|
|
955
|
+
if (jobFlowId) await this.waitForGroupReady(jobFlowId, physicalId, logicalId, resourceType, toNumber$1(properties["InstanceCount"]) ?? 0, true, context?.maskSecrets);
|
|
956
|
+
}
|
|
957
|
+
if (autoScalingChanged) {
|
|
958
|
+
if (!jobFlowId) throw new ProvisioningError(`EMR InstanceGroupConfig ${logicalId} AutoScalingPolicy update needs JobFlowId (the cluster id), which is absent`, resourceType, logicalId, physicalId);
|
|
959
|
+
const policy = properties["AutoScalingPolicy"];
|
|
960
|
+
context?.markUnsettled?.("AutoScalingPolicy");
|
|
961
|
+
if (policy) await this.getClient().send(new PutAutoScalingPolicyCommand({
|
|
962
|
+
ClusterId: jobFlowId,
|
|
963
|
+
InstanceGroupId: physicalId,
|
|
964
|
+
AutoScalingPolicy: policy
|
|
965
|
+
}));
|
|
966
|
+
else await this.getClient().send(new RemoveAutoScalingPolicyCommand({
|
|
967
|
+
ClusterId: jobFlowId,
|
|
968
|
+
InstanceGroupId: physicalId
|
|
969
|
+
}));
|
|
970
|
+
}
|
|
971
|
+
this.logger.debug(`Successfully updated EMR instance group ${logicalId}`);
|
|
972
|
+
return {
|
|
973
|
+
physicalId,
|
|
974
|
+
wasReplaced: false,
|
|
975
|
+
attributes: {
|
|
976
|
+
Id: physicalId,
|
|
977
|
+
InstanceGroupId: physicalId
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
} catch (error) {
|
|
981
|
+
if (error instanceof ProvisioningError || error instanceof ResourceUpdateNotSupportedError) throw error;
|
|
982
|
+
const cause = error instanceof Error ? error : void 0;
|
|
983
|
+
throw this.wrapCaughtError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to update EMR instance group ${logicalId}: ${text}`, resourceType, logicalId, physicalId, cause));
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
async delete(logicalId, physicalId, resourceType, properties, context) {
|
|
987
|
+
const role = properties?.["InstanceRole"];
|
|
988
|
+
const jobFlowId = properties?.["JobFlowId"];
|
|
989
|
+
if (role === "TASK" && jobFlowId && isRedactedRecordedValue(jobFlowId)) this.logger.warn(safeMsg`EMR instance group ${logicalId}: JobFlowId is redacted in state, so the ` + "best-effort scale-to-0 was not attempted — its instances are released when the parent cluster terminates");
|
|
990
|
+
else if (role === "TASK" && jobFlowId) {
|
|
991
|
+
if (properties?.["AutoScalingPolicy"] !== void 0) try {
|
|
992
|
+
await removeScalingPolicyForDelete(this.getClient(), jobFlowId, physicalId);
|
|
993
|
+
} catch (error) {
|
|
994
|
+
if (error instanceof InvalidRequestException) this.logger.debug(safeMsg`EMR instance group ${physicalId} policy removal skipped (cluster/group gone)`);
|
|
995
|
+
else {
|
|
996
|
+
const head = safeMsg`Removing the automatic scaling policy of EMR instance group ${physicalId} failed: `;
|
|
997
|
+
const text = this.cleanupFailureText(head, error, context?.maskSecrets);
|
|
998
|
+
this.logger.warn(maskerOrIdentity(context?.maskSecrets)(safeMsg`${head}${text}`));
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
try {
|
|
1002
|
+
await this.getClient().send(new ModifyInstanceGroupsCommand({
|
|
1003
|
+
ClusterId: jobFlowId,
|
|
1004
|
+
InstanceGroups: [{
|
|
1005
|
+
InstanceGroupId: physicalId,
|
|
1006
|
+
InstanceCount: 0
|
|
1007
|
+
}]
|
|
1008
|
+
}));
|
|
1009
|
+
this.logger.debug(`Scaled EMR TASK instance group ${physicalId} to 0 to release its instances (no standalone delete API exists)`);
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
if (error instanceof InvalidRequestException) {
|
|
1012
|
+
const clientRegion = await this.getClient().config.region();
|
|
1013
|
+
assertRegionMatch(clientRegion, context?.expectedRegion, resourceType, logicalId, physicalId);
|
|
1014
|
+
this.logger.debug(`EMR instance group ${physicalId} scale-to-0 skipped (cluster/group gone): ${error.message}`);
|
|
1015
|
+
} else {
|
|
1016
|
+
const head = `Best-effort scale-to-0 of EMR instance group ${physicalId} failed: `;
|
|
1017
|
+
this.logger.warn(maskerOrIdentity(context?.maskSecrets)(`${head}${this.cleanupFailureText(head, error, context?.maskSecrets)} — its instances are released when the parent cluster terminates`));
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
this.logger.debug(`EMR instance group ${physicalId} (role ${role ?? "unknown"}) has no standalone delete API; its instances are released when the parent cluster terminates. Removing cdkd state only.`);
|
|
1023
|
+
}
|
|
1024
|
+
async getAttribute(physicalId, _resourceType, attributeName) {
|
|
1025
|
+
if (attributeName === "Id" || attributeName === "InstanceGroupId") return physicalId;
|
|
1026
|
+
}
|
|
1027
|
+
async waitForGroupReady(clusterId, groupId, logicalId, resourceType, expectedCount, toleratesStaleFailedState = false, mask) {
|
|
1028
|
+
const startTime = Date.now();
|
|
1029
|
+
const transientState = { count: 0 };
|
|
1030
|
+
let initialState;
|
|
1031
|
+
let hasLeftInitialState = false;
|
|
1032
|
+
while (Date.now() - startTime < this.maxWaitMs) {
|
|
1033
|
+
const group = await this.findGroupForPoll(clusterId, groupId, transientState);
|
|
1034
|
+
const state = group?.Status?.State;
|
|
1035
|
+
if (state) {
|
|
1036
|
+
if (initialState === void 0) initialState = state;
|
|
1037
|
+
else if (state !== initialState) hasLeftInitialState = true;
|
|
1038
|
+
}
|
|
1039
|
+
if (state && READY_STATES$1.has(state) && group?.RunningInstanceCount === expectedCount) return;
|
|
1040
|
+
const enforceFailedStates = !toleratesStaleFailedState || hasLeftInitialState;
|
|
1041
|
+
if (state && enforceFailedStates && FAILED_STATES$1.has(state)) {
|
|
1042
|
+
const reason = group?.Status?.StateChangeReason;
|
|
1043
|
+
throw this.wrapStatusReasonError(mask, {
|
|
1044
|
+
code: reason?.Code,
|
|
1045
|
+
message: reason?.Message
|
|
1046
|
+
}, "no state-change reason reported", (text, cause) => new ProvisioningError(`EMR instance group ${groupId} entered failed state ${state}: ${text}`, resourceType, logicalId, groupId, cause));
|
|
1047
|
+
}
|
|
1048
|
+
if (state && !enforceFailedStates && FAILED_STATES$1.has(state)) this.logger.debug(`EMR instance group ${groupId} still reads ${state} from before the resize; waiting for it to leave that state before treating it as failed`);
|
|
1049
|
+
this.logger.debug(`EMR instance group ${groupId} state: ${state ?? "unknown"}, running ${group?.RunningInstanceCount ?? "?"}/${expectedCount}, waiting...`);
|
|
1050
|
+
await new Promise((resolve) => setTimeout(resolve, this.pollIntervalMs));
|
|
1051
|
+
}
|
|
1052
|
+
throw new ProvisioningError(`Timed out waiting for EMR instance group ${groupId} to reach RUNNING with ${expectedCount} instance(s) (${Math.round(this.maxWaitMs / 6e4)} min)`, resourceType, logicalId, groupId);
|
|
1053
|
+
}
|
|
1054
|
+
readCurrentState(physicalId, _logicalId, resourceType, properties) {
|
|
1055
|
+
return readCurrentState$2.call(this, physicalId, resourceType, properties);
|
|
1056
|
+
}
|
|
1057
|
+
async readUnsettled(physicalId, logicalId, resourceType, _names, recordedProperties) {
|
|
1058
|
+
const jobFlowId = recordedProperties?.["JobFlowId"];
|
|
1059
|
+
if (typeof jobFlowId !== "string" || jobFlowId === "") throw new ProvisioningError(`EMR InstanceGroupConfig ${logicalId} has no JobFlowId (the cluster id) recorded, so cdkd cannot read the group to converge what an earlier failed update left unsettled`, resourceType, logicalId, physicalId);
|
|
1060
|
+
const group = await this.findGroupForPoll(jobFlowId, physicalId, { count: 0 }, 0);
|
|
1061
|
+
if (group === void 0) return void 0;
|
|
1062
|
+
return {
|
|
1063
|
+
...group.RunningInstanceCount !== void 0 && { InstanceCount: group.RunningInstanceCount },
|
|
1064
|
+
...group.AutoScalingPolicy !== void 0 && { AutoScalingPolicy: group.AutoScalingPolicy }
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
async unsettledInTransition(physicalId, _logicalId, _resourceType, names, recordedProperties) {
|
|
1068
|
+
if (!names.has("InstanceCount")) return /* @__PURE__ */ new Set();
|
|
1069
|
+
const jobFlowId = recordedProperties?.["JobFlowId"];
|
|
1070
|
+
if (typeof jobFlowId !== "string" || jobFlowId === "") return /* @__PURE__ */ new Set();
|
|
1071
|
+
try {
|
|
1072
|
+
const state = (await this.findGroupForPoll(jobFlowId, physicalId, { count: 0 }, 0))?.Status?.State;
|
|
1073
|
+
return state !== void 0 && MOVING_GROUP_STATES.has(state) ? /* @__PURE__ */ new Set(["InstanceCount"]) : /* @__PURE__ */ new Set();
|
|
1074
|
+
} catch {
|
|
1075
|
+
return /* @__PURE__ */ new Set(["InstanceCount"]);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
findGroupForPoll(clusterId, groupId, transientState, maxConsecutiveTransient) {
|
|
1079
|
+
return findGroupForPoll.call(this, clusterId, groupId, transientState, maxConsecutiveTransient);
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
|
|
1083
|
+
// src/provisioning/providers/emr-instance-fleet-config/shared.ts
|
|
1084
|
+
const DEFAULT_MAX_WAIT_MS = 36e5;
|
|
1085
|
+
const DEFAULT_POLL_INTERVAL_MS = 15e3;
|
|
1086
|
+
const READY_STATES = /* @__PURE__ */ new Set(["RUNNING"]);
|
|
1087
|
+
const FAILED_STATES = /* @__PURE__ */ new Set(["SUSPENDED", "TERMINATED"]);
|
|
1088
|
+
const toNumber = (v) => {
|
|
1089
|
+
if (v === void 0) return void 0;
|
|
1090
|
+
const n = Number(v);
|
|
1091
|
+
return Number.isNaN(n) ? void 0 : n;
|
|
1092
|
+
};
|
|
1093
|
+
const jsonEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
1094
|
+
const LEFT_IN_PLACE_ON_REMOVAL = ["ResizeSpecifications", "InstanceTypeConfigs"];
|
|
1095
|
+
const leftInPlaceWarning = (logicalId, names, caller) => {
|
|
1096
|
+
const one = names.length === 1;
|
|
1097
|
+
const subject = one ? "property" : "properties";
|
|
1098
|
+
const verb = one ? "is" : "are";
|
|
1099
|
+
return caller === "rollback" ? safeMsg`${logicalId} (AWS::EMR::InstanceFleetConfig): ${subject} ${names.join(", ")} ${verb} absent from the state being restored; ModifyInstanceFleet keeps a setting it is not sent, so the rollback leaves the value the failed deploy applied in place.` : safeMsg`${logicalId} (AWS::EMR::InstanceFleetConfig): ${subject} ${names.join(", ")} ${one ? "was" : "were"} removed from the template and ${one ? "keeps its" : "keep their"} current AWS value, as CloudFormation leaves ${one ? "it" : "them"}; ModifyInstanceFleet keeps a setting it is not sent. Declare the intended value explicitly to change it.`;
|
|
1100
|
+
};
|
|
1101
|
+
const addInstanceFleetLatch = new AmbiguousCreateLatch("emr:AddInstanceFleet");
|
|
1102
|
+
const fleetsCreatedByThisProcess = new RecentIdSet();
|
|
1103
|
+
|
|
1104
|
+
// src/provisioning/providers/emr-instance-fleet-config/create.ts
|
|
1105
|
+
async function create(logicalId, resourceType, properties, context) {
|
|
1106
|
+
if (resourceType !== "AWS::EMR::InstanceFleetConfig") throw new ProvisioningError(`Unsupported resource type: ${resourceType}`, resourceType, logicalId);
|
|
1107
|
+
const clusterId = properties["ClusterId"];
|
|
1108
|
+
if (!clusterId) throw new ProvisioningError(`EMR InstanceFleetConfig ${logicalId} is missing ClusterId (the parent cluster id)`, resourceType, logicalId);
|
|
1109
|
+
this.logger.debug(`Adding EMR instance fleet ${logicalId} to cluster ${clusterId}`);
|
|
1110
|
+
let createdFleetId;
|
|
1111
|
+
try {
|
|
1112
|
+
const fleet = this.toInstanceFleetConfig(properties);
|
|
1113
|
+
const reportOrphans = async (lookupWindow) => {
|
|
1114
|
+
const log = createMaskedLogSinks(this.logger, context?.maskSecrets);
|
|
1115
|
+
const aws = pasteableAwsCommand(log.mask);
|
|
1116
|
+
const regionArg = await orphanCommandRegionArg(this.getClient(), aws);
|
|
1117
|
+
const name = fleet.Name;
|
|
1118
|
+
await reportPossibleOrphans(logicalId, lookupWindow, log, {
|
|
1119
|
+
action: "AddInstanceFleet",
|
|
1120
|
+
service: "EMR",
|
|
1121
|
+
listAction: "ListInstanceFleets",
|
|
1122
|
+
subject: `a TASK instance fleet${name !== void 0 ? ` named ${log.value(name)}` : ""} in cluster ${log.value(clusterId)}`,
|
|
1123
|
+
noun: "TASK instance fleet(s)",
|
|
1124
|
+
list: () => collectOrphanIds(async (marker) => {
|
|
1125
|
+
const page = await this.getClient().send(new ListInstanceFleetsCommand({
|
|
1126
|
+
ClusterId: clusterId,
|
|
1127
|
+
...marker && { Marker: marker }
|
|
1128
|
+
}));
|
|
1129
|
+
return {
|
|
1130
|
+
items: page.InstanceFleets ?? [],
|
|
1131
|
+
next: page.Marker
|
|
1132
|
+
};
|
|
1133
|
+
}, (item) => item.Id && item.InstanceFleetType === "TASK" && (name === void 0 || item.Name === name) && isInsideWindow(item.Status?.Timeline?.CreationDateTime, lookupWindow) && !fleetsCreatedByThisProcess.has(item.Id) ? item.Id : void 0),
|
|
1134
|
+
inspect: () => aws`aws emr list-instance-fleets --cluster-id ${clusterId}${regionArg}`.render(),
|
|
1135
|
+
remove: (id) => aws`aws emr modify-instance-fleet --cluster-id ${clusterId} --instance-fleet InstanceFleetId=${id},TargetOnDemandCapacity=0,TargetSpotCapacity=0${regionArg}`.render(),
|
|
1136
|
+
removeVerb: "scale it to zero, which releases its instances (EMR has no call that removes an instance fleet; it ends with its cluster)"
|
|
1137
|
+
});
|
|
1138
|
+
};
|
|
1139
|
+
const orphanWindow = addInstanceFleetLatch.take(logicalId);
|
|
1140
|
+
if (orphanWindow !== void 0 && fleet.InstanceFleetType === "TASK") await reportOrphans(orphanWindow);
|
|
1141
|
+
const attemptStartMs = Date.now();
|
|
1142
|
+
let response;
|
|
1143
|
+
try {
|
|
1144
|
+
response = await this.getCreateClient().send(new AddInstanceFleetCommand({
|
|
1145
|
+
ClusterId: clusterId,
|
|
1146
|
+
InstanceFleet: fleet
|
|
1147
|
+
}));
|
|
1148
|
+
} catch (error) {
|
|
1149
|
+
addInstanceFleetLatch.noteFailure(logicalId, error, attemptStartMs, orphanWindow);
|
|
1150
|
+
throw error;
|
|
1151
|
+
}
|
|
1152
|
+
const fleetId = response.InstanceFleetId;
|
|
1153
|
+
if (fleetId) fleetsCreatedByThisProcess.add(fleetId);
|
|
1154
|
+
createdFleetId = fleetId;
|
|
1155
|
+
reportCreatedResource(logicalId, resourceType, fleetId ?? "");
|
|
1156
|
+
const replayWindow = replayedSendWindow(response, attemptStartMs);
|
|
1157
|
+
if (replayWindow !== void 0 && fleet.InstanceFleetType === "TASK") await reportOrphans(replayWindow);
|
|
1158
|
+
if (!fleetId) throw new ProvisioningError(`EMR AddInstanceFleet for ${logicalId} returned no instance fleet id`, resourceType, logicalId);
|
|
1159
|
+
await this.waitForFleetReady(clusterId, fleetId, logicalId, resourceType, this.targetCapacities(properties), {
|
|
1160
|
+
onDemand: 0,
|
|
1161
|
+
spot: 0
|
|
1162
|
+
}, false, context?.maskSecrets);
|
|
1163
|
+
this.logger.debug(`Successfully added EMR instance fleet ${logicalId}: ${fleetId}`);
|
|
1164
|
+
return {
|
|
1165
|
+
physicalId: fleetId,
|
|
1166
|
+
attributes: {
|
|
1167
|
+
Id: fleetId,
|
|
1168
|
+
InstanceFleetId: fleetId
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
} catch (error) {
|
|
1172
|
+
const thrown = error instanceof ProvisioningError ? error : this.wrapCaughtError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to add EMR instance fleet ${logicalId}: ${text}`, resourceType, logicalId, void 0, error instanceof Error ? error : void 0));
|
|
1173
|
+
if (createdFleetId) {
|
|
1174
|
+
markCreatedBeforeFailure(thrown, logicalId, resourceType, createdFleetId);
|
|
1175
|
+
markNonRetryable(thrown);
|
|
1176
|
+
}
|
|
1177
|
+
throw thrown;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
function toInstanceFleetConfig(properties) {
|
|
1181
|
+
return {
|
|
1182
|
+
InstanceFleetType: properties["InstanceFleetType"],
|
|
1183
|
+
Name: properties["Name"],
|
|
1184
|
+
TargetOnDemandCapacity: toNumber(properties["TargetOnDemandCapacity"]),
|
|
1185
|
+
TargetSpotCapacity: toNumber(properties["TargetSpotCapacity"]),
|
|
1186
|
+
InstanceTypeConfigs: toSdkInstanceTypeConfigs(properties["InstanceTypeConfigs"]),
|
|
1187
|
+
LaunchSpecifications: properties["LaunchSpecifications"],
|
|
1188
|
+
ResizeSpecifications: properties["ResizeSpecifications"]
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
// src/provisioning/providers/emr-instance-fleet-config/update.ts
|
|
1193
|
+
async function update$1(logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
1194
|
+
const changed = (key) => !jsonEqual(properties[key], previousProperties[key]);
|
|
1195
|
+
const MUTABLE = /* @__PURE__ */ new Set([
|
|
1196
|
+
"TargetOnDemandCapacity",
|
|
1197
|
+
"TargetSpotCapacity",
|
|
1198
|
+
"ResizeSpecifications",
|
|
1199
|
+
"InstanceTypeConfigs"
|
|
1200
|
+
]);
|
|
1201
|
+
for (const key of Object.keys({
|
|
1202
|
+
...properties,
|
|
1203
|
+
...previousProperties
|
|
1204
|
+
})) {
|
|
1205
|
+
if (!changed(key)) continue;
|
|
1206
|
+
if (!MUTABLE.has(key) && (key === "ClusterId" || !await unchangedBehindSecretReference({
|
|
1207
|
+
resourceType,
|
|
1208
|
+
key,
|
|
1209
|
+
desired: properties[key],
|
|
1210
|
+
previous: previousProperties[key],
|
|
1211
|
+
maskSecrets: context?.maskSecrets
|
|
1212
|
+
}))) throw new ResourceUpdateNotSupportedError(resourceType, logicalId, `AWS EMR InstanceFleetConfig ${key} is immutable on AWS — it is fixed when the instance fleet is created. Re-deploy with ${deployReplaceCommand()}, or destroy + redeploy the stack.`);
|
|
1213
|
+
}
|
|
1214
|
+
const removed = context?.removedProperties;
|
|
1215
|
+
const leftInPlaceNames = LEFT_IN_PLACE_ON_REMOVAL.filter((key) => removed !== void 0 ? removed.has(key) : properties[key] === void 0 && previousProperties[key] !== void 0);
|
|
1216
|
+
const warnLeftInPlace = () => {
|
|
1217
|
+
if (leftInPlaceNames.length === 0 || context?.desiredFromAwsReadback) return;
|
|
1218
|
+
this.logger.warn(leftInPlaceWarning(logicalId, leftInPlaceNames, context?.replayingState ? "rollback" : "deploy"));
|
|
1219
|
+
};
|
|
1220
|
+
const leftInPlace = new Set(LEFT_IN_PLACE_ON_REMOVAL);
|
|
1221
|
+
if (![...MUTABLE].some((k) => changed(k) && !(leftInPlace.has(k) && properties[k] === void 0))) {
|
|
1222
|
+
this.logger.debug(`No mutable diff for EMR instance fleet ${logicalId}, skipping update`);
|
|
1223
|
+
warnLeftInPlace();
|
|
1224
|
+
return {
|
|
1225
|
+
physicalId,
|
|
1226
|
+
wasReplaced: false,
|
|
1227
|
+
attributes: {
|
|
1228
|
+
Id: physicalId,
|
|
1229
|
+
InstanceFleetId: physicalId
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
const clusterId = properties["ClusterId"];
|
|
1234
|
+
if (!clusterId) throw new ProvisioningError(`EMR InstanceFleetConfig ${logicalId} update needs ClusterId (the cluster id), which is absent`, resourceType, logicalId, physicalId);
|
|
1235
|
+
this.logger.debug(`Updating EMR instance fleet ${logicalId}: ${physicalId}`);
|
|
1236
|
+
try {
|
|
1237
|
+
const modify = {
|
|
1238
|
+
InstanceFleetId: physicalId,
|
|
1239
|
+
TargetOnDemandCapacity: toNumber(properties["TargetOnDemandCapacity"]) ?? 0,
|
|
1240
|
+
TargetSpotCapacity: toNumber(properties["TargetSpotCapacity"]) ?? 0,
|
|
1241
|
+
ResizeSpecifications: properties["ResizeSpecifications"],
|
|
1242
|
+
InstanceTypeConfigs: toSdkInstanceTypeConfigs(properties["InstanceTypeConfigs"])
|
|
1243
|
+
};
|
|
1244
|
+
await this.getClient().send(new ModifyInstanceFleetCommand({
|
|
1245
|
+
ClusterId: clusterId,
|
|
1246
|
+
InstanceFleet: modify
|
|
1247
|
+
}));
|
|
1248
|
+
await this.waitForFleetReady(clusterId, physicalId, logicalId, resourceType, this.targetCapacities(properties), this.targetCapacities(previousProperties), true, context?.maskSecrets);
|
|
1249
|
+
this.logger.debug(`Successfully updated EMR instance fleet ${logicalId}`);
|
|
1250
|
+
warnLeftInPlace();
|
|
1251
|
+
return {
|
|
1252
|
+
physicalId,
|
|
1253
|
+
wasReplaced: false,
|
|
1254
|
+
attributes: {
|
|
1255
|
+
Id: physicalId,
|
|
1256
|
+
InstanceFleetId: physicalId
|
|
1257
|
+
}
|
|
1258
|
+
};
|
|
1259
|
+
} catch (error) {
|
|
1260
|
+
if (error instanceof ProvisioningError || error instanceof ResourceUpdateNotSupportedError) throw error;
|
|
1261
|
+
const cause = error instanceof Error ? error : void 0;
|
|
1262
|
+
throw this.wrapCaughtError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to update EMR instance fleet ${logicalId}: ${text}`, resourceType, logicalId, physicalId, cause));
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
// src/provisioning/providers/emr-instance-fleet-config/delete.ts
|
|
1267
|
+
async function deleteImpl$1(logicalId, physicalId, resourceType, properties, context) {
|
|
1268
|
+
const fleetType = properties?.["InstanceFleetType"];
|
|
1269
|
+
const clusterId = properties?.["ClusterId"];
|
|
1270
|
+
if (fleetType === "TASK" && clusterId && isRedactedRecordedValue(clusterId)) this.logger.warn(safeMsg`EMR instance fleet ${logicalId}: ClusterId is redacted in state, so the ` + "best-effort scale-to-0 was not attempted — its instances are released when the parent cluster terminates");
|
|
1271
|
+
else if (fleetType === "TASK" && clusterId) {
|
|
1272
|
+
try {
|
|
1273
|
+
await this.getClient().send(new ModifyInstanceFleetCommand({
|
|
1274
|
+
ClusterId: clusterId,
|
|
1275
|
+
InstanceFleet: {
|
|
1276
|
+
InstanceFleetId: physicalId,
|
|
1277
|
+
TargetOnDemandCapacity: 0,
|
|
1278
|
+
TargetSpotCapacity: 0
|
|
1279
|
+
}
|
|
1280
|
+
}));
|
|
1281
|
+
this.logger.debug(`Scaled EMR TASK instance fleet ${physicalId} to 0 to release its instances (no standalone delete API exists)`);
|
|
1282
|
+
} catch (error) {
|
|
1283
|
+
if (error instanceof InvalidRequestException) {
|
|
1284
|
+
const clientRegion = await this.getClient().config.region();
|
|
1285
|
+
assertRegionMatch(clientRegion, context?.expectedRegion, resourceType, logicalId, physicalId);
|
|
1286
|
+
this.logger.debug(`EMR instance fleet ${physicalId} scale-to-0 skipped (cluster/fleet gone): ${error.message}`);
|
|
1287
|
+
} else {
|
|
1288
|
+
const head = `Best-effort scale-to-0 of EMR instance fleet ${physicalId} failed: `;
|
|
1289
|
+
this.logger.warn(maskerOrIdentity(context?.maskSecrets)(`${head}${this.cleanupFailureText(head, error, context?.maskSecrets)} — its instances are released when the parent cluster terminates`));
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
this.logger.debug(`EMR instance fleet ${physicalId} (type ${fleetType ?? "unknown"}) has no standalone delete API; its instances are released when the parent cluster terminates. Removing cdkd state only.`);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
// src/provisioning/providers/emr-instance-fleet-config/read-state.ts
|
|
1298
|
+
const CLUSTER_ID = /^j-[A-Z0-9]+$/;
|
|
1299
|
+
async function readCurrentState$1(physicalId, _logicalId, resourceType, properties) {
|
|
1300
|
+
if (resourceType !== "AWS::EMR::InstanceFleetConfig") return void 0;
|
|
1301
|
+
const clusterId = properties?.["ClusterId"];
|
|
1302
|
+
if (typeof clusterId !== "string" || !CLUSTER_ID.test(clusterId)) return void 0;
|
|
1303
|
+
let fleet;
|
|
1304
|
+
try {
|
|
1305
|
+
let marker;
|
|
1306
|
+
do {
|
|
1307
|
+
const resp = await this.getClient().send(new ListInstanceFleetsCommand({
|
|
1308
|
+
ClusterId: clusterId,
|
|
1309
|
+
...marker && { Marker: marker }
|
|
1310
|
+
}));
|
|
1311
|
+
fleet = (resp.InstanceFleets ?? []).find((f) => f.Id === physicalId);
|
|
1312
|
+
marker = fleet === void 0 ? resp.Marker : void 0;
|
|
1313
|
+
} while (marker);
|
|
1314
|
+
} catch (error) {
|
|
1315
|
+
if (error instanceof InvalidRequestException) return void 0;
|
|
1316
|
+
throw error;
|
|
1317
|
+
}
|
|
1318
|
+
if (fleet === void 0 || fleet.Status?.State === "TERMINATED") return RESOURCE_NOT_FOUND;
|
|
1319
|
+
const out = { ClusterId: clusterId };
|
|
1320
|
+
if (fleet.InstanceFleetType !== void 0) out["InstanceFleetType"] = fleet.InstanceFleetType;
|
|
1321
|
+
if (fleet.Name !== void 0) out["Name"] = fleet.Name;
|
|
1322
|
+
if (fleet.TargetOnDemandCapacity !== void 0) out["TargetOnDemandCapacity"] = fleet.TargetOnDemandCapacity;
|
|
1323
|
+
if (fleet.TargetSpotCapacity !== void 0) out["TargetSpotCapacity"] = fleet.TargetSpotCapacity;
|
|
1324
|
+
if (fleet.InstanceTypeSpecifications !== void 0) out["InstanceTypeConfigs"] = inRecordedOrder(fleet.InstanceTypeSpecifications.map(instanceTypeConfigOf), properties?.["InstanceTypeConfigs"]);
|
|
1325
|
+
if (fleet.LaunchSpecifications !== void 0) out["LaunchSpecifications"] = definedOnly(fleet.LaunchSpecifications);
|
|
1326
|
+
if (fleet.ResizeSpecifications !== void 0) out["ResizeSpecifications"] = definedOnly(fleet.ResizeSpecifications);
|
|
1327
|
+
return out;
|
|
1328
|
+
}
|
|
1329
|
+
function definedOnly(value) {
|
|
1330
|
+
if (Array.isArray(value)) return value.map(definedOnly);
|
|
1331
|
+
if (typeof value !== "object" || value === null) return value;
|
|
1332
|
+
return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== void 0).map(([k, v]) => [k, definedOnly(v)]));
|
|
1333
|
+
}
|
|
1334
|
+
function instanceTypeConfigOf(spec) {
|
|
1335
|
+
const out = {};
|
|
1336
|
+
if (spec.InstanceType !== void 0) out["InstanceType"] = spec.InstanceType;
|
|
1337
|
+
if (spec.WeightedCapacity !== void 0) out["WeightedCapacity"] = spec.WeightedCapacity;
|
|
1338
|
+
if (spec.BidPrice !== void 0) out["BidPrice"] = spec.BidPrice;
|
|
1339
|
+
if (spec.BidPriceAsPercentageOfOnDemandPrice !== void 0) out["BidPriceAsPercentageOfOnDemandPrice"] = spec.BidPriceAsPercentageOfOnDemandPrice;
|
|
1340
|
+
if (spec.CustomAmiId !== void 0) out["CustomAmiId"] = spec.CustomAmiId;
|
|
1341
|
+
if (spec.Priority !== void 0) out["Priority"] = spec.Priority;
|
|
1342
|
+
if (spec.Configurations !== void 0 && spec.Configurations.length > 0) out["Configurations"] = spec.Configurations.map(configurationOf);
|
|
1343
|
+
const ebs = ebsConfigurationOf(spec.EbsBlockDevices, spec.EbsOptimized);
|
|
1344
|
+
if (ebs !== void 0) out["EbsConfiguration"] = ebs;
|
|
1345
|
+
return out;
|
|
1346
|
+
}
|
|
1347
|
+
function configurationOf(c) {
|
|
1348
|
+
const out = {};
|
|
1349
|
+
if (c.Classification !== void 0) out["Classification"] = c.Classification;
|
|
1350
|
+
if (c.Properties !== void 0) out["ConfigurationProperties"] = { ...c.Properties };
|
|
1351
|
+
if (c.Configurations !== void 0 && c.Configurations.length > 0) out["Configurations"] = c.Configurations.map(configurationOf);
|
|
1352
|
+
return out;
|
|
1353
|
+
}
|
|
1354
|
+
function ebsConfigurationOf(devices, ebsOptimized) {
|
|
1355
|
+
const configs = [];
|
|
1356
|
+
for (const device of devices ?? []) {
|
|
1357
|
+
const spec = definedOnly({
|
|
1358
|
+
VolumeType: device.VolumeSpecification?.VolumeType,
|
|
1359
|
+
SizeInGB: device.VolumeSpecification?.SizeInGB,
|
|
1360
|
+
Iops: device.VolumeSpecification?.Iops,
|
|
1361
|
+
Throughput: device.VolumeSpecification?.Throughput
|
|
1362
|
+
});
|
|
1363
|
+
const last = configs[configs.length - 1];
|
|
1364
|
+
if (last !== void 0 && JSON.stringify(last.VolumeSpecification) === JSON.stringify(spec)) last.VolumesPerInstance += 1;
|
|
1365
|
+
else configs.push({
|
|
1366
|
+
VolumeSpecification: spec,
|
|
1367
|
+
VolumesPerInstance: 1
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
if (configs.length === 0 && ebsOptimized === void 0) return void 0;
|
|
1371
|
+
const out = {};
|
|
1372
|
+
if (configs.length > 0) out["EbsBlockDeviceConfigs"] = configs;
|
|
1373
|
+
if (ebsOptimized !== void 0) out["EbsOptimized"] = ebsOptimized;
|
|
1374
|
+
return out;
|
|
1375
|
+
}
|
|
1376
|
+
function inRecordedOrder(read, recorded) {
|
|
1377
|
+
if (!Array.isArray(recorded)) return read;
|
|
1378
|
+
const left = [...read];
|
|
1379
|
+
const out = [];
|
|
1380
|
+
for (const entry of recorded) {
|
|
1381
|
+
const type = entry?.["InstanceType"];
|
|
1382
|
+
const i = left.findIndex((r) => r["InstanceType"] === type);
|
|
1383
|
+
if (i >= 0) out.push(...left.splice(i, 1));
|
|
1384
|
+
}
|
|
1385
|
+
return [...out, ...left];
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
// src/provisioning/providers/emr-instance-fleet-config/wait.ts
|
|
1389
|
+
function targetCapacities(properties) {
|
|
1390
|
+
return {
|
|
1391
|
+
onDemand: toNumber(properties["TargetOnDemandCapacity"]) ?? 0,
|
|
1392
|
+
spot: toNumber(properties["TargetSpotCapacity"]) ?? 0
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
async function waitForFleetReady(clusterId, fleetId, logicalId, resourceType, target, previous, toleratesStaleFailedState = false, mask) {
|
|
1396
|
+
const startTime = Date.now();
|
|
1397
|
+
const transientState = { count: 0 };
|
|
1398
|
+
let initialState;
|
|
1399
|
+
let hasLeftInitialState = false;
|
|
1400
|
+
const settled = (provisioned, want, had) => want >= had ? provisioned >= want : provisioned <= want;
|
|
1401
|
+
while (Date.now() - startTime < this.maxWaitMs) {
|
|
1402
|
+
const fleet = await this.findFleetForPoll(clusterId, fleetId, transientState);
|
|
1403
|
+
const state = fleet?.Status?.State;
|
|
1404
|
+
const onDemand = fleet?.ProvisionedOnDemandCapacity ?? 0;
|
|
1405
|
+
const spot = fleet?.ProvisionedSpotCapacity ?? 0;
|
|
1406
|
+
const provisioned = onDemand + spot;
|
|
1407
|
+
const capacityReady = settled(onDemand, target.onDemand, previous.onDemand) && settled(spot, target.spot, previous.spot);
|
|
1408
|
+
if (state) {
|
|
1409
|
+
if (initialState === void 0) initialState = state;
|
|
1410
|
+
else if (state !== initialState) hasLeftInitialState = true;
|
|
1411
|
+
}
|
|
1412
|
+
if (state && READY_STATES.has(state) && capacityReady) return;
|
|
1413
|
+
const enforceFailedStates = !toleratesStaleFailedState || hasLeftInitialState;
|
|
1414
|
+
if (state && enforceFailedStates && FAILED_STATES.has(state)) {
|
|
1415
|
+
const reason = fleet?.Status?.StateChangeReason;
|
|
1416
|
+
throw this.wrapStatusReasonError(mask, {
|
|
1417
|
+
code: reason?.Code,
|
|
1418
|
+
message: reason?.Message
|
|
1419
|
+
}, "no state-change reason reported", (text, cause) => new ProvisioningError(`EMR instance fleet ${fleetId} entered failed state ${state}: ${text}`, resourceType, logicalId, fleetId, cause));
|
|
1420
|
+
}
|
|
1421
|
+
if (state && !enforceFailedStates && FAILED_STATES.has(state)) this.logger.debug(`EMR instance fleet ${fleetId} still reads ${state} from before the resize; waiting for it to leave that state before treating it as failed`);
|
|
1422
|
+
this.logger.debug(`EMR instance fleet ${fleetId} state: ${state ?? "unknown"}, provisioned ${onDemand}/${target.onDemand} on-demand + ${spot}/${target.spot} spot (${provisioned} total), waiting...`);
|
|
1423
|
+
await new Promise((resolve) => setTimeout(resolve, this.pollIntervalMs));
|
|
1424
|
+
}
|
|
1425
|
+
throw new ProvisioningError(`Timed out waiting for EMR instance fleet ${fleetId} to reach RUNNING with capacity ${target.onDemand} on-demand / ${target.spot} spot (${Math.round(this.maxWaitMs / 6e4)} min)`, resourceType, logicalId, fleetId);
|
|
1426
|
+
}
|
|
1427
|
+
async function findFleetForPoll(clusterId, fleetId, transientState, maxConsecutiveTransient = 5) {
|
|
1428
|
+
try {
|
|
1429
|
+
let marker;
|
|
1430
|
+
do {
|
|
1431
|
+
const resp = await this.getClient().send(new ListInstanceFleetsCommand({
|
|
1432
|
+
ClusterId: clusterId,
|
|
1433
|
+
...marker && { Marker: marker }
|
|
1434
|
+
}));
|
|
1435
|
+
const found = (resp.InstanceFleets ?? []).find((f) => f.Id === fleetId);
|
|
1436
|
+
if (found) {
|
|
1437
|
+
transientState.count = 0;
|
|
1438
|
+
return found;
|
|
1439
|
+
}
|
|
1440
|
+
marker = resp.Marker;
|
|
1441
|
+
} while (marker);
|
|
1442
|
+
transientState.count = 0;
|
|
1443
|
+
return;
|
|
1444
|
+
} catch (error) {
|
|
1445
|
+
const name = error instanceof Error ? error.name : "";
|
|
1446
|
+
const msg = describeAwsFailure(error).detail;
|
|
1447
|
+
if ((name === "ThrottlingException" || name === "InternalServerException" || name === "InternalServerError" || name === "TimeoutError" || /rate exceeded|too many requests|throttl|timed? ?out|ECONNRESET|EPIPE|socket hang up/i.test(msg)) && transientState.count < maxConsecutiveTransient) {
|
|
1448
|
+
transientState.count += 1;
|
|
1449
|
+
this.logger.debug(`Transient ListInstanceFleets error while polling ${fleetId} (${transientState.count}/${maxConsecutiveTransient}): ${msg} — retrying`);
|
|
1450
|
+
return;
|
|
1451
|
+
}
|
|
1452
|
+
throw error;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
// src/provisioning/providers/emr-instance-fleet-config-provider.ts
|
|
1457
|
+
var EMRInstanceFleetConfigProvider = class {
|
|
1458
|
+
client;
|
|
1459
|
+
createClient;
|
|
1460
|
+
providerRegion = ambientRegion();
|
|
1461
|
+
logger = getLogger().child("EMRInstanceFleetConfigProvider");
|
|
1462
|
+
pollIntervalMs;
|
|
1463
|
+
maxWaitMs;
|
|
1464
|
+
constructor(options) {
|
|
1465
|
+
this.pollIntervalMs = options?.pollIntervalMs ?? 15e3;
|
|
1466
|
+
this.maxWaitMs = options?.maxWaitMs ?? 36e5;
|
|
1467
|
+
}
|
|
1468
|
+
wrapStatusReasonError(mask, reason, fallback, build) {
|
|
1469
|
+
const text = describeAwsStatusReason(reason, fallback);
|
|
1470
|
+
if (!text.redacted) return build(text.detail, void 0);
|
|
1471
|
+
const m = maskerOrIdentity(mask);
|
|
1472
|
+
const cause = new Error(text.detail);
|
|
1473
|
+
this.logger.debug(m(build(m(text.detail), cause).message));
|
|
1474
|
+
return markRedactedCause(build(m(text.summary), cause));
|
|
1475
|
+
}
|
|
1476
|
+
wrapCaughtError(mask, error, build) {
|
|
1477
|
+
const failure = describeAwsFailure(error);
|
|
1478
|
+
if (!(error instanceof Error) || !failure.redacted) return build(failure.detail);
|
|
1479
|
+
const m = maskerOrIdentity(mask);
|
|
1480
|
+
this.logger.debug(m(build(m(failure.detail)).message));
|
|
1481
|
+
return markRedactedCause(build(`${m(failure.summary)}${relayedNameCollision(failure.detail)}`));
|
|
1482
|
+
}
|
|
1483
|
+
cleanupFailureText(head, error, mask) {
|
|
1484
|
+
const m = maskerOrIdentity(mask);
|
|
1485
|
+
const failure = describeAwsFailure(error);
|
|
1486
|
+
if (!failure.redacted) return m(failure.detail);
|
|
1487
|
+
this.logger.debug(m(`${head}${m(failure.detail)}`));
|
|
1488
|
+
return m(failure.summary);
|
|
1489
|
+
}
|
|
1490
|
+
handledProperties = /* @__PURE__ */ new Map([["AWS::EMR::InstanceFleetConfig", /* @__PURE__ */ new Set([
|
|
1491
|
+
"ClusterId",
|
|
1492
|
+
"InstanceFleetType",
|
|
1493
|
+
"InstanceTypeConfigs",
|
|
1494
|
+
"LaunchSpecifications",
|
|
1495
|
+
"Name",
|
|
1496
|
+
"ResizeSpecifications",
|
|
1497
|
+
"TargetOnDemandCapacity",
|
|
1498
|
+
"TargetSpotCapacity"
|
|
1499
|
+
])]]);
|
|
1500
|
+
removalHandledInUpdate = /* @__PURE__ */ new Map([["AWS::EMR::InstanceFleetConfig", /* @__PURE__ */ new Set([
|
|
1501
|
+
"ClusterId",
|
|
1502
|
+
"InstanceFleetType",
|
|
1503
|
+
"LaunchSpecifications",
|
|
1504
|
+
"Name",
|
|
1505
|
+
"TargetOnDemandCapacity",
|
|
1506
|
+
"TargetSpotCapacity",
|
|
1507
|
+
...LEFT_IN_PLACE_ON_REMOVAL
|
|
1508
|
+
])]]);
|
|
1509
|
+
getClient() {
|
|
1510
|
+
if (!this.client) this.client = new EMRClient({
|
|
1511
|
+
...ambientClientDefaults(),
|
|
1512
|
+
...this.providerRegion ? { region: this.providerRegion } : {}
|
|
1513
|
+
});
|
|
1514
|
+
return this.client;
|
|
1515
|
+
}
|
|
1516
|
+
getCreateClient() {
|
|
1517
|
+
if (!this.createClient) this.createClient = withoutServerErrorRetries(new EMRClient({
|
|
1518
|
+
...ambientClientDefaults(),
|
|
1519
|
+
...this.providerRegion ? { region: this.providerRegion } : {}
|
|
1520
|
+
}));
|
|
1521
|
+
return this.createClient;
|
|
1522
|
+
}
|
|
1523
|
+
getMinResourceTimeoutMs() {
|
|
1524
|
+
return this.maxWaitMs + this.pollIntervalMs;
|
|
1525
|
+
}
|
|
1526
|
+
create(logicalId, resourceType, properties, context) {
|
|
1527
|
+
return create.call(this, logicalId, resourceType, properties, context);
|
|
1528
|
+
}
|
|
1529
|
+
toInstanceFleetConfig(properties) {
|
|
1530
|
+
return toInstanceFleetConfig.call(this, properties);
|
|
1531
|
+
}
|
|
1532
|
+
update(logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
1533
|
+
return update$1.call(this, logicalId, physicalId, resourceType, properties, previousProperties, context);
|
|
1534
|
+
}
|
|
1535
|
+
delete(logicalId, physicalId, resourceType, properties, context) {
|
|
1536
|
+
return deleteImpl$1.call(this, logicalId, physicalId, resourceType, properties, context);
|
|
1537
|
+
}
|
|
1538
|
+
async getAttribute(physicalId, _resourceType, attributeName) {
|
|
1539
|
+
if (attributeName === "Id" || attributeName === "InstanceFleetId") return physicalId;
|
|
1540
|
+
}
|
|
1541
|
+
readCurrentState(physicalId, logicalId, resourceType, properties) {
|
|
1542
|
+
return readCurrentState$1.call(this, physicalId, logicalId, resourceType, properties);
|
|
1543
|
+
}
|
|
1544
|
+
targetCapacities(properties) {
|
|
1545
|
+
return targetCapacities.call(this, properties);
|
|
1546
|
+
}
|
|
1547
|
+
waitForFleetReady(clusterId, fleetId, logicalId, resourceType, target, previous, toleratesStaleFailedState, mask) {
|
|
1548
|
+
return waitForFleetReady.call(this, clusterId, fleetId, logicalId, resourceType, target, previous, toleratesStaleFailedState, mask);
|
|
1549
|
+
}
|
|
1550
|
+
findFleetForPoll(clusterId, fleetId, transientState, maxConsecutiveTransient) {
|
|
1551
|
+
return findFleetForPoll.call(this, clusterId, fleetId, transientState, maxConsecutiveTransient);
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
// src/provisioning/providers/emr-cluster/update.ts
|
|
1556
|
+
async function resolveInstancesTargets(logicalId, clusterId, plan) {
|
|
1557
|
+
const refuse = (resize, why) => {
|
|
1558
|
+
throw new ProvisioningError(safeMsg`Cannot apply Instances.${resize.path} to EMR cluster ${clusterId}: ` + why, "AWS::EMR::Cluster", logicalId, clusterId);
|
|
1559
|
+
};
|
|
1560
|
+
const pick = (candidates, resize, kind, shapeOf) => {
|
|
1561
|
+
const name = resize.next["Name"];
|
|
1562
|
+
const matchKey = typeof name === "string" ? "Name" : "InstanceType";
|
|
1563
|
+
if (resize.type === "TASK" && isSecretDerivedValue(resize.prev[matchKey], IDENTITY_MASK)) refuse(resize, `its ${matchKey} is a secret reference, which cannot address an instance ${kind}; declare it literally`);
|
|
1564
|
+
let matches = candidates;
|
|
1565
|
+
let byShape = false;
|
|
1566
|
+
if (resize.type === "TASK") {
|
|
1567
|
+
if (typeof name === "string") matches = candidates.filter((c) => c.Name === name);
|
|
1568
|
+
else {
|
|
1569
|
+
const want = {
|
|
1570
|
+
InstanceType: resize.next["InstanceType"],
|
|
1571
|
+
Market: resize.next["Market"] ?? "ON_DEMAND",
|
|
1572
|
+
...resize.next["BidPrice"] !== void 0 && { BidPrice: resize.next["BidPrice"] }
|
|
1573
|
+
};
|
|
1574
|
+
matches = candidates.filter((c) => {
|
|
1575
|
+
const shape = shapeOf(c);
|
|
1576
|
+
return shape === void 0 || Object.entries(want).every(([key, value]) => key === "BidPrice" ? Number.parseFloat(String(shape[key])) === Number.parseFloat(String(value)) : shape[key] === value);
|
|
1577
|
+
});
|
|
1578
|
+
byShape = true;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
if (matches.length !== 1 || matches[0].Id === void 0) refuse(resize, `found ${String(matches.length)} matching ${resize.type} instance ${kind}s, expected exactly one` + (byShape && matches.length > 1 ? " (cdkd cannot tell them apart; giving the entry a Name now would replace the cluster)" : ""));
|
|
1582
|
+
return matches[0].Id;
|
|
1583
|
+
};
|
|
1584
|
+
const groups = plan.groups.length > 0 ? (await this.listInstanceGroups(clusterId)).filter((g) => !ENDED_GROUP_STATES.has(g.Status?.State ?? "")) : [];
|
|
1585
|
+
const fleets = plan.fleets.length > 0 ? (await this.listInstanceFleets(clusterId)).filter((f) => !ENDED_FLEET_STATES.has(f.Status?.State ?? "")) : [];
|
|
1586
|
+
return {
|
|
1587
|
+
groups: plan.groups.map((resize) => ({
|
|
1588
|
+
resize,
|
|
1589
|
+
id: pick(groups.filter((g) => g.InstanceGroupType === resize.type), resize, "group", (g) => ({
|
|
1590
|
+
InstanceType: g.InstanceType,
|
|
1591
|
+
Market: g.Market,
|
|
1592
|
+
BidPrice: g.BidPrice
|
|
1593
|
+
}))
|
|
1594
|
+
})),
|
|
1595
|
+
fleets: plan.fleets.map((resize) => ({
|
|
1596
|
+
resize,
|
|
1597
|
+
id: pick(fleets.filter((f) => f.InstanceFleetType === resize.type), resize, "fleet", () => void 0)
|
|
1598
|
+
}))
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
async function applyInstancesResizes(logicalId, clusterId, targets, deadline, mask) {
|
|
1602
|
+
if (targets.groups.length === 0 && targets.fleets.length === 0) return;
|
|
1603
|
+
const options = (resize) => {
|
|
1604
|
+
const remaining = deadline - Date.now();
|
|
1605
|
+
if (remaining <= 0) throw new ProvisioningError(safeMsg`Timed out before applying Instances.${resize.path} to EMR cluster ${clusterId}: the earlier resizes used the whole wait (${String(Math.round(this.maxWaitMs / 6e4))} min)`, "AWS::EMR::Cluster", logicalId, clusterId);
|
|
1606
|
+
return {
|
|
1607
|
+
pollIntervalMs: this.pollIntervalMs,
|
|
1608
|
+
maxWaitMs: remaining
|
|
1609
|
+
};
|
|
1610
|
+
};
|
|
1611
|
+
const context = mask ? { maskSecrets: mask } : void 0;
|
|
1612
|
+
const restated = async (resize, run) => {
|
|
1613
|
+
try {
|
|
1614
|
+
await run();
|
|
1615
|
+
} catch (error) {
|
|
1616
|
+
if (!(error instanceof ProvisioningError)) throw error;
|
|
1617
|
+
throw new ProvisioningError(safeMsg`Failed to apply Instances.${resize.path} to EMR cluster ${clusterId}: ` + error.message, "AWS::EMR::Cluster", logicalId, clusterId, error);
|
|
1618
|
+
}
|
|
1619
|
+
};
|
|
1620
|
+
for (const { resize, id } of targets.groups) {
|
|
1621
|
+
const bag = (side) => ({
|
|
1622
|
+
JobFlowId: clusterId,
|
|
1623
|
+
InstanceCount: side["InstanceCount"],
|
|
1624
|
+
AutoScalingPolicy: side["AutoScalingPolicy"]
|
|
1625
|
+
});
|
|
1626
|
+
const delegateOptions = options(resize);
|
|
1627
|
+
await restated(resize, () => new EMRInstanceGroupConfigProvider(delegateOptions).update(logicalId, id, "AWS::EMR::InstanceGroupConfig", bag(resize.next), bag(resize.prev), context));
|
|
1628
|
+
}
|
|
1629
|
+
for (const { resize, id } of targets.fleets) {
|
|
1630
|
+
const bag = (side) => ({
|
|
1631
|
+
ClusterId: clusterId,
|
|
1632
|
+
InstanceFleetType: resize.type,
|
|
1633
|
+
TargetOnDemandCapacity: side["TargetOnDemandCapacity"],
|
|
1634
|
+
TargetSpotCapacity: side["TargetSpotCapacity"]
|
|
1635
|
+
});
|
|
1636
|
+
const delegateOptions = options(resize);
|
|
1637
|
+
await restated(resize, () => new EMRInstanceFleetConfigProvider(delegateOptions).update(logicalId, id, "AWS::EMR::InstanceFleetConfig", bag(resize.next), bag(resize.prev), context));
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
async function update(logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
1641
|
+
refuseMalformedDesiredTags(properties["Tags"], resourceType, logicalId, physicalId);
|
|
1642
|
+
const resizeDeadline = Date.now() + this.maxWaitMs;
|
|
1643
|
+
const changed = (key) => !jsonEqual$2(properties[key], previousProperties[key]);
|
|
1644
|
+
const nextInstances = properties["Instances"] ?? {};
|
|
1645
|
+
const prevInstances = previousProperties["Instances"] ?? {};
|
|
1646
|
+
const replaceRemedy = () => {
|
|
1647
|
+
const replaceFlags = deployReplaceCommand(true);
|
|
1648
|
+
return toBoolean(prevInstances["TerminationProtected"]) === true ? protectedReplacementAdvice({
|
|
1649
|
+
evidence: "cdkd's recorded properties for this cluster carry Instances.TerminationProtected: true",
|
|
1650
|
+
replaceFlags,
|
|
1651
|
+
disable: {
|
|
1652
|
+
before: "aws emr modify-cluster-attributes --cluster-id",
|
|
1653
|
+
identifier: physicalId,
|
|
1654
|
+
after: "--no-termination-protected"
|
|
1655
|
+
}
|
|
1656
|
+
}) : `Re-deploy with ${replaceFlags}, or destroy + redeploy the stack.`;
|
|
1657
|
+
};
|
|
1658
|
+
let instancesPlan = EMPTY_INSTANCES_PLAN;
|
|
1659
|
+
if (changed("Instances")) {
|
|
1660
|
+
const mask = context?.maskSecrets;
|
|
1661
|
+
const isReplacingMember = (key) => emrClusterInstancesReplaced({ [key]: prevInstances[key] }, { [key]: withRecordedReferences(nextInstances[key], prevInstances[key], mask) });
|
|
1662
|
+
const movedKeys = [.../* @__PURE__ */ new Set([...Object.keys(nextInstances), ...Object.keys(prevInstances)])].filter((key) => !jsonEqual$2(nextInstances[key], prevInstances[key]));
|
|
1663
|
+
const blockIsObject = (value) => value == null || typeof value === "object" && !Array.isArray(value);
|
|
1664
|
+
const blocksAreObjects = blockIsObject(properties["Instances"]) && blockIsObject(previousProperties["Instances"]);
|
|
1665
|
+
if (blocksAreObjects ? movedKeys.some(isReplacingMember) : emrClusterInstancesReplaced(previousProperties["Instances"], properties["Instances"])) {
|
|
1666
|
+
const named = blocksAreObjects ? movedKeys.find(isReplacingMember) : void 0;
|
|
1667
|
+
const subject = named === void 0 ? safeMsg`AWS EMR Cluster's Instances block` : safeMsg`AWS EMR Cluster Instances.${named}`;
|
|
1668
|
+
throw new ResourceUpdateNotSupportedError(resourceType, logicalId, `${subject} cannot be updated in place — CloudFormation replaces the cluster for this change. ` + replaceRemedy());
|
|
1669
|
+
}
|
|
1670
|
+
instancesPlan = planInstancesInPlace(prevInstances, nextInstances);
|
|
1671
|
+
}
|
|
1672
|
+
const terminationProtectedChanged = instancesPlan.terminationProtected;
|
|
1673
|
+
for (const key of Object.keys({
|
|
1674
|
+
...properties,
|
|
1675
|
+
...previousProperties
|
|
1676
|
+
})) {
|
|
1677
|
+
if (key === "Instances") continue;
|
|
1678
|
+
if (!changed(key)) continue;
|
|
1679
|
+
if (!MUTABLE_TOP_LEVEL_PROPS.has(key) && !await unchangedBehindSecretReference({
|
|
1680
|
+
resourceType,
|
|
1681
|
+
key,
|
|
1682
|
+
desired: properties[key],
|
|
1683
|
+
previous: previousProperties[key],
|
|
1684
|
+
maskSecrets: context?.maskSecrets
|
|
1685
|
+
})) throw new ResourceUpdateNotSupportedError(resourceType, logicalId, safeMsg`AWS EMR Cluster ${key} is immutable on AWS — it is fixed at cluster creation. ` + replaceRemedy());
|
|
1686
|
+
}
|
|
1687
|
+
if (instancesPlan.unhealthyNodeReplacement && nextInstances["UnhealthyNodeReplacement"] === void 0) {
|
|
1688
|
+
const removal = safeMsg`${logicalId} (AWS::EMR::Cluster): removing Instances.UnhealthyNodeReplacement fails under CloudFormation too (its update ends in Internal Failure and rolls back). Declare it explicitly instead (true is EMR's default).`;
|
|
1689
|
+
if (!context?.replayingState) throw new ResourceUpdateNotSupportedError(resourceType, logicalId, removal);
|
|
1690
|
+
this.logger.warn(safeMsg`${removal} The rollback leaves the live value in place.`);
|
|
1691
|
+
instancesPlan = {
|
|
1692
|
+
...instancesPlan,
|
|
1693
|
+
unhealthyNodeReplacement: false
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
const unusable = (resize, keys, refuseRemoval) => {
|
|
1697
|
+
for (const key of keys) {
|
|
1698
|
+
if (resize.next[key] !== void 0 && toNumber$2(resize.next[key]) === void 0) return safeMsg`Instances.${resize.path}.${key} is not a number, so cdkd cannot resize to it.`;
|
|
1699
|
+
if (refuseRemoval && resize.next[key] === void 0 && resize.prev[key] !== void 0) return key === "InstanceCount" ? safeMsg`removing Instances.${resize.path}.${key} is refused: CloudFormation requires it, and sending none would scale the group to 0. Declare it explicitly instead.` : safeMsg`removing Instances.${resize.path}.${key} fails under CloudFormation too (ModifyInstanceFleet needs both capacities). Declare it explicitly instead (0 for none).`;
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
const keepNumeric = (resizes, keys, refuseRemoval = false) => resizes.filter((resize) => {
|
|
1703
|
+
const why = unusable(resize, keys, refuseRemoval);
|
|
1704
|
+
if (why === void 0) return true;
|
|
1705
|
+
const message = safeMsg`${logicalId} (AWS::EMR::Cluster): ` + why;
|
|
1706
|
+
if (!context?.replayingState) throw new ResourceUpdateNotSupportedError(resourceType, logicalId, message);
|
|
1707
|
+
this.logger.warn(keys.includes("InstanceCount") && !jsonEqual$2(resize.prev["AutoScalingPolicy"], resize.next["AutoScalingPolicy"]) ? safeMsg`${message} The rollback leaves the live size in place, and the group's AutoScalingPolicy change is not applied either.` : safeMsg`${message} The rollback leaves the live size in place.`);
|
|
1708
|
+
return false;
|
|
1709
|
+
});
|
|
1710
|
+
instancesPlan = {
|
|
1711
|
+
...instancesPlan,
|
|
1712
|
+
groups: keepNumeric(instancesPlan.groups, ["InstanceCount"], true),
|
|
1713
|
+
fleets: keepNumeric(instancesPlan.fleets, FLEET_IN_PLACE_MEMBERS, true)
|
|
1714
|
+
};
|
|
1715
|
+
let instancesTargets = NO_INSTANCES_TARGETS;
|
|
1716
|
+
if (instancesPlan.groups.length > 0 || instancesPlan.fleets.length > 0) try {
|
|
1717
|
+
instancesTargets = await this.resolveInstancesTargets(logicalId, physicalId, instancesPlan);
|
|
1718
|
+
} catch (error) {
|
|
1719
|
+
if (error instanceof ProvisioningError) throw error;
|
|
1720
|
+
const cause = error instanceof Error ? error : void 0;
|
|
1721
|
+
throw this.wrapCaughtError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to update EMR Cluster ${logicalId}: ${text}`, resourceType, logicalId, physicalId, cause));
|
|
1722
|
+
}
|
|
1723
|
+
const removed = context?.removedProperties;
|
|
1724
|
+
const leftInPlaceNames = LEFT_IN_PLACE_ON_REMOVAL$1.filter((key) => removed !== void 0 ? removed.has(key) : properties[key] === void 0 && previousProperties[key] !== void 0);
|
|
1725
|
+
const warnLeftInPlace = () => {
|
|
1726
|
+
if (leftInPlaceNames.length === 0 || context?.desiredFromAwsReadback) return;
|
|
1727
|
+
this.logger.warn(leftInPlaceWarning$1(logicalId, leftInPlaceNames, context?.replayingState ? "rollback" : "deploy"));
|
|
1728
|
+
};
|
|
1729
|
+
const visibleChanged = changed("VisibleToAllUsers");
|
|
1730
|
+
const stepConcurrencyChanged = changed("StepConcurrencyLevel") && properties["StepConcurrencyLevel"] !== void 0;
|
|
1731
|
+
const managedScalingChanged = changed("ManagedScalingPolicy");
|
|
1732
|
+
const autoTerminationChanged = changed("AutoTerminationPolicy");
|
|
1733
|
+
const tagsChanged = changed("Tags");
|
|
1734
|
+
if (!terminationProtectedChanged && !instancesPlan.unhealthyNodeReplacement && instancesPlan.groups.length === 0 && instancesPlan.fleets.length === 0 && !visibleChanged && !stepConcurrencyChanged && !managedScalingChanged && !autoTerminationChanged && !tagsChanged) {
|
|
1735
|
+
this.logger.debug(`No mutable diff for EMR Cluster ${logicalId}, skipping update`);
|
|
1736
|
+
warnLeftInPlace();
|
|
1737
|
+
return {
|
|
1738
|
+
physicalId,
|
|
1739
|
+
wasReplaced: false
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
this.logger.debug(`Updating EMR Cluster ${logicalId}: ${physicalId}`);
|
|
1743
|
+
try {
|
|
1744
|
+
if (terminationProtectedChanged) await this.getClient().send(new SetTerminationProtectionCommand({
|
|
1745
|
+
JobFlowIds: [physicalId],
|
|
1746
|
+
TerminationProtected: toBoolean(nextInstances["TerminationProtected"]) ?? false
|
|
1747
|
+
}));
|
|
1748
|
+
if (instancesPlan.unhealthyNodeReplacement) await this.getClient().send(new SetUnhealthyNodeReplacementCommand({
|
|
1749
|
+
JobFlowIds: [physicalId],
|
|
1750
|
+
UnhealthyNodeReplacement: toBoolean(nextInstances["UnhealthyNodeReplacement"])
|
|
1751
|
+
}));
|
|
1752
|
+
await this.applyInstancesResizes(logicalId, physicalId, instancesTargets, resizeDeadline, context?.maskSecrets);
|
|
1753
|
+
if (visibleChanged) await this.getClient().send(new SetVisibleToAllUsersCommand({
|
|
1754
|
+
JobFlowIds: [physicalId],
|
|
1755
|
+
VisibleToAllUsers: toBoolean(properties["VisibleToAllUsers"]) ?? false
|
|
1756
|
+
}));
|
|
1757
|
+
if (stepConcurrencyChanged) await this.getClient().send(new ModifyClusterCommand({
|
|
1758
|
+
ClusterId: physicalId,
|
|
1759
|
+
StepConcurrencyLevel: toNumber$2(properties["StepConcurrencyLevel"])
|
|
1760
|
+
}));
|
|
1761
|
+
if (managedScalingChanged) {
|
|
1762
|
+
const next = this.toManagedScalingPolicy(properties["ManagedScalingPolicy"]);
|
|
1763
|
+
if (next) await this.getClient().send(new PutManagedScalingPolicyCommand({
|
|
1764
|
+
ClusterId: physicalId,
|
|
1765
|
+
ManagedScalingPolicy: next
|
|
1766
|
+
}));
|
|
1767
|
+
else await this.getClient().send(new RemoveManagedScalingPolicyCommand({ ClusterId: physicalId }));
|
|
1768
|
+
}
|
|
1769
|
+
if (autoTerminationChanged) {
|
|
1770
|
+
const next = this.toAutoTerminationPolicy(properties["AutoTerminationPolicy"]);
|
|
1771
|
+
if (next && next.IdleTimeout !== void 0) await this.getClient().send(new PutAutoTerminationPolicyCommand({
|
|
1772
|
+
ClusterId: physicalId,
|
|
1773
|
+
AutoTerminationPolicy: next
|
|
1774
|
+
}));
|
|
1775
|
+
else await this.getClient().send(new RemoveAutoTerminationPolicyCommand({ ClusterId: physicalId }));
|
|
1776
|
+
}
|
|
1777
|
+
if (tagsChanged) await this.applyTagDiff(physicalId, resourceType, logicalId, previousProperties["Tags"], properties["Tags"]);
|
|
1778
|
+
let cluster;
|
|
1779
|
+
try {
|
|
1780
|
+
cluster = (await this.getClient().send(new DescribeClusterCommand({ ClusterId: physicalId }))).Cluster;
|
|
1781
|
+
} catch (describeError) {
|
|
1782
|
+
this.logger.debug(`Post-update attribute refresh for ${physicalId} failed (returning without attributes): ${describeAwsFailure(describeError).detail}`);
|
|
1783
|
+
}
|
|
1784
|
+
this.logger.debug(`Successfully updated EMR Cluster ${logicalId}`);
|
|
1785
|
+
warnLeftInPlace();
|
|
1786
|
+
return {
|
|
1787
|
+
physicalId,
|
|
1788
|
+
wasReplaced: false,
|
|
1789
|
+
...cluster && { attributes: this.buildAttributes(cluster) }
|
|
1790
|
+
};
|
|
1791
|
+
} catch (error) {
|
|
1792
|
+
if (error instanceof ProvisioningError) throw error;
|
|
1793
|
+
const cause = error instanceof Error ? error : void 0;
|
|
1794
|
+
throw this.wrapCaughtError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to update EMR Cluster ${logicalId}: ${text}`, resourceType, logicalId, physicalId, cause));
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
async function applyTagDiff(physicalId, resourceType, logicalId, prevTagsRaw, nextTagsRaw) {
|
|
1798
|
+
const plan = planTagDiff(prevTagsRaw, nextTagsRaw);
|
|
1799
|
+
const tagWarning = tagPlanWarning(plan, resourceType, logicalId);
|
|
1800
|
+
if (tagWarning !== void 0) this.logger.warn(tagWarning);
|
|
1801
|
+
const toSet = [...plan.set].map(([Key, Value]) => ({
|
|
1802
|
+
Key,
|
|
1803
|
+
Value
|
|
1804
|
+
}));
|
|
1805
|
+
const toRemove = plan.remove;
|
|
1806
|
+
if (toRemove.length > 0) await this.getClient().send(new RemoveTagsCommand({
|
|
1807
|
+
ResourceId: physicalId,
|
|
1808
|
+
TagKeys: toRemove
|
|
1809
|
+
}));
|
|
1810
|
+
if (toSet.length > 0) await this.getClient().send(new AddTagsCommand({
|
|
1811
|
+
ResourceId: physicalId,
|
|
1812
|
+
Tags: toSet
|
|
1813
|
+
}));
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
// src/provisioning/providers/emr-cluster/delete.ts
|
|
1817
|
+
async function deleteImpl(logicalId, physicalId, resourceType, _properties, context) {
|
|
1818
|
+
await deleteWithProtectionCompensation({
|
|
1819
|
+
registry: this.protectionFlips,
|
|
1820
|
+
key: protectionFlipKey(resourceType, physicalId, context?.expectedRegion),
|
|
1821
|
+
run: (flip) => this.deleteOnce(logicalId, physicalId, resourceType, context, flip),
|
|
1822
|
+
compensation: {
|
|
1823
|
+
logicalId,
|
|
1824
|
+
physicalId,
|
|
1825
|
+
logger: this.logger,
|
|
1826
|
+
site: emrClusterProtectionSite(physicalId, context?.expectedRegion),
|
|
1827
|
+
reEnable: async () => {
|
|
1828
|
+
await this.getClient().send(new SetTerminationProtectionCommand({
|
|
1829
|
+
JobFlowIds: [physicalId],
|
|
1830
|
+
TerminationProtected: true
|
|
1831
|
+
}));
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
async function deleteOnce(logicalId, physicalId, resourceType, context, flip) {
|
|
1837
|
+
this.logger.debug(`Deleting EMR Cluster ${logicalId}: ${physicalId}`);
|
|
1838
|
+
let current;
|
|
1839
|
+
try {
|
|
1840
|
+
current = (await this.getClient().send(new DescribeClusterCommand({ ClusterId: physicalId }))).Cluster;
|
|
1841
|
+
} catch (error) {
|
|
1842
|
+
if (error instanceof InvalidRequestException) {
|
|
1843
|
+
const clientRegion = await this.getClient().config.region();
|
|
1844
|
+
assertRegionMatch(clientRegion, context?.expectedRegion, resourceType, logicalId, physicalId);
|
|
1845
|
+
if (context?.failedCreateOrphan === true) this.logger.info(safeMsg` EMR cluster ${physicalId} (${logicalId}), which a failed deploy created, is already gone; nothing to delete`);
|
|
1846
|
+
else this.logger.debug(`EMR Cluster ${physicalId} does not exist, skipping deletion`);
|
|
1847
|
+
return;
|
|
1848
|
+
}
|
|
1849
|
+
const cause = error instanceof Error ? error : void 0;
|
|
1850
|
+
throw this.wrapCaughtError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to describe EMR Cluster ${logicalId} before deletion: ${text}`, resourceType, logicalId, physicalId, cause));
|
|
1851
|
+
}
|
|
1852
|
+
const currentState = current?.Status?.State;
|
|
1853
|
+
if (currentState && TERMINAL_STATES.has(currentState)) {
|
|
1854
|
+
if (context?.failedCreateOrphan === true) this.logger.info(safeMsg` EMR cluster ${physicalId} (${logicalId}), which a failed deploy created, is already ${currentState}; nothing to delete`);
|
|
1855
|
+
else this.logger.debug(`EMR Cluster ${physicalId} already ${currentState}, skipping deletion`);
|
|
1856
|
+
return;
|
|
1857
|
+
}
|
|
1858
|
+
try {
|
|
1859
|
+
if (context?.removeProtection) {
|
|
1860
|
+
await observeThenDisableProtection({
|
|
1861
|
+
flip,
|
|
1862
|
+
logger: this.logger,
|
|
1863
|
+
physicalId,
|
|
1864
|
+
mask: context?.maskSecrets,
|
|
1865
|
+
guardName: "TerminationProtected",
|
|
1866
|
+
observe: () => Promise.resolve(current?.TerminationProtected === true),
|
|
1867
|
+
disable: async () => {
|
|
1868
|
+
await this.getClient().send(new SetTerminationProtectionCommand({
|
|
1869
|
+
JobFlowIds: [physicalId],
|
|
1870
|
+
TerminationProtected: false
|
|
1871
|
+
}));
|
|
1872
|
+
}
|
|
1873
|
+
});
|
|
1874
|
+
this.logger.debug(`Disabled termination protection on EMR Cluster ${physicalId} before deletion`);
|
|
1875
|
+
}
|
|
1876
|
+
await this.getClient().send(new TerminateJobFlowsCommand({ JobFlowIds: [physicalId] }));
|
|
1877
|
+
flip.deleteAccepted = true;
|
|
1878
|
+
} catch (error) {
|
|
1879
|
+
const cause = error instanceof Error ? error : void 0;
|
|
1880
|
+
throw this.wrapCaughtError(context?.maskSecrets, error, (text) => new ProvisioningError(`Failed to terminate EMR Cluster ${logicalId}: ${text}`, resourceType, logicalId, physicalId, cause));
|
|
1881
|
+
}
|
|
1882
|
+
await this.waitForClusterTerminated(physicalId, logicalId, resourceType, context?.maskSecrets);
|
|
1883
|
+
this.logger.debug(`Successfully deleted EMR Cluster ${logicalId}`);
|
|
1884
|
+
}
|
|
1885
|
+
async function describeForPoll(clusterId, transientState, maxConsecutiveTransient = 5) {
|
|
1886
|
+
try {
|
|
1887
|
+
const response = await this.getClient().send(new DescribeClusterCommand({ ClusterId: clusterId }));
|
|
1888
|
+
transientState.count = 0;
|
|
1889
|
+
return response.Cluster;
|
|
1890
|
+
} catch (error) {
|
|
1891
|
+
const name = error instanceof Error ? error.name : "";
|
|
1892
|
+
const msg = describeAwsFailure(error).detail;
|
|
1893
|
+
if ((name === "ThrottlingException" || name === "InternalServerException" || name === "InternalServerError" || name === "TimeoutError" || /rate exceeded|too many requests|throttl|timed? ?out|ECONNRESET|EPIPE|socket hang up/i.test(msg)) && transientState.count < maxConsecutiveTransient) {
|
|
1894
|
+
transientState.count += 1;
|
|
1895
|
+
this.logger.debug(`Transient DescribeCluster error while polling ${clusterId} (${transientState.count}/${maxConsecutiveTransient}): ${msg} — retrying`);
|
|
1896
|
+
return;
|
|
1897
|
+
}
|
|
1898
|
+
throw error;
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
async function waitForClusterReady(clusterId, logicalId, resourceType, mask) {
|
|
1902
|
+
const startTime = Date.now();
|
|
1903
|
+
const transientState = { count: 0 };
|
|
1904
|
+
while (Date.now() - startTime < this.maxWaitMs) {
|
|
1905
|
+
const cluster = await this.describeForPoll(clusterId, transientState);
|
|
1906
|
+
const state = cluster?.Status?.State;
|
|
1907
|
+
if (cluster && state && CREATE_READY_STATES.has(state)) return cluster;
|
|
1908
|
+
if (state && TERMINAL_STATES.has(state)) {
|
|
1909
|
+
const reason = cluster?.Status?.StateChangeReason;
|
|
1910
|
+
throw this.wrapStatusReasonError(mask, {
|
|
1911
|
+
code: reason?.Code,
|
|
1912
|
+
message: reason?.Message
|
|
1913
|
+
}, "no state-change reason reported", (text, cause) => new ProvisioningError(`EMR Cluster ${clusterId} entered terminal state ${state} during creation: ${text}`, resourceType, logicalId, clusterId, cause));
|
|
1914
|
+
}
|
|
1915
|
+
this.logger.debug(`EMR Cluster ${clusterId} state: ${state ?? "unknown"}, waiting...`);
|
|
1916
|
+
await new Promise((resolve) => setTimeout(resolve, this.pollIntervalMs));
|
|
1917
|
+
}
|
|
1918
|
+
throw new ProvisioningError(`Timed out waiting for EMR Cluster ${clusterId} to reach WAITING/RUNNING (${Math.round(this.maxWaitMs / 6e4)} min)`, resourceType, logicalId, clusterId);
|
|
1919
|
+
}
|
|
1920
|
+
async function waitForClusterTerminated(clusterId, logicalId, resourceType, mask) {
|
|
1921
|
+
const startTime = Date.now();
|
|
1922
|
+
const transientState = { count: 0 };
|
|
1923
|
+
while (Date.now() - startTime < this.maxWaitMs) {
|
|
1924
|
+
let cluster;
|
|
1925
|
+
try {
|
|
1926
|
+
cluster = await this.describeForPoll(clusterId, transientState);
|
|
1927
|
+
} catch (error) {
|
|
1928
|
+
if (error instanceof InvalidRequestException) return;
|
|
1929
|
+
const cause = error instanceof Error ? error : void 0;
|
|
1930
|
+
throw this.wrapCaughtError(mask, error, (text) => new ProvisioningError(`Failed to poll EMR Cluster ${clusterId} termination: ${text}`, resourceType, logicalId, clusterId, cause));
|
|
1931
|
+
}
|
|
1932
|
+
const state = cluster?.Status?.State;
|
|
1933
|
+
if (state && TERMINAL_STATES.has(state)) {
|
|
1934
|
+
if (state === "TERMINATED_WITH_ERRORS") {
|
|
1935
|
+
const m = maskerOrIdentity(mask);
|
|
1936
|
+
const head = `EMR Cluster ${clusterId} terminated with errors: `;
|
|
1937
|
+
const stateReason = cluster?.Status?.StateChangeReason;
|
|
1938
|
+
const reason = describeAwsStatusReason({
|
|
1939
|
+
code: stateReason?.Code,
|
|
1940
|
+
message: stateReason?.Message
|
|
1941
|
+
}, "no state-change reason reported");
|
|
1942
|
+
if (reason.redacted) this.logger.debug(m(`${head}${m(reason.detail)}`));
|
|
1943
|
+
this.logger.warn(m(`${head}${m(reason.summary)} (the cluster is gone and no longer bills)`));
|
|
1944
|
+
}
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
this.logger.debug(`EMR Cluster ${clusterId} state: ${state ?? "unknown"}, waiting for termination...`);
|
|
1948
|
+
await new Promise((resolve) => setTimeout(resolve, this.pollIntervalMs));
|
|
1949
|
+
}
|
|
1950
|
+
throw new ProvisioningError(`Timed out waiting for EMR Cluster ${clusterId} termination (${Math.round(this.maxWaitMs / 6e4)} min) — verify and terminate it manually to stop billing`, resourceType, logicalId, clusterId);
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
// src/provisioning/providers/emr-cluster/read-state.ts
|
|
1954
|
+
function buildAttributes(cluster) {
|
|
1955
|
+
const attributes = {};
|
|
1956
|
+
if (cluster?.Id !== void 0) attributes["Id"] = cluster.Id;
|
|
1957
|
+
if (cluster?.MasterPublicDnsName !== void 0) attributes["MasterPublicDNS"] = cluster.MasterPublicDnsName;
|
|
1958
|
+
return attributes;
|
|
1959
|
+
}
|
|
1960
|
+
async function getAttribute(physicalId, _resourceType, attributeName) {
|
|
1961
|
+
if (attributeName === "Id") return physicalId;
|
|
1962
|
+
const cluster = (await this.getClient().send(new DescribeClusterCommand({ ClusterId: physicalId }))).Cluster;
|
|
1963
|
+
if (!cluster) return void 0;
|
|
1964
|
+
switch (attributeName) {
|
|
1965
|
+
case "MasterPublicDNS": return cluster.MasterPublicDnsName;
|
|
1966
|
+
default: return;
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
async function isSameResource(journaledPhysicalId, record, resourceType, context) {
|
|
1970
|
+
if (resourceType !== "AWS::EMR::Cluster") return "unknown";
|
|
1971
|
+
if (!CLUSTER_ID_PATTERN.test(journaledPhysicalId) || !CLUSTER_ID_PATTERN.test(record.physicalId)) return "unknown";
|
|
1972
|
+
if (journaledPhysicalId === record.physicalId) return "same";
|
|
1973
|
+
if (await this.getClient().config.region() !== context.expectedRegion) return "unknown";
|
|
1974
|
+
const recorded = await this.readClusterIdentity(record.physicalId);
|
|
1975
|
+
if (recorded?.id !== record.physicalId) return "unknown";
|
|
1976
|
+
return (await this.readClusterIdentity(journaledPhysicalId))?.id === recorded.id ? "same" : "different";
|
|
1977
|
+
}
|
|
1978
|
+
async function readClusterIdentity(clusterId) {
|
|
1979
|
+
let response;
|
|
1980
|
+
try {
|
|
1981
|
+
response = await this.getClient().send(new DescribeClusterCommand({ ClusterId: clusterId }));
|
|
1982
|
+
} catch (error) {
|
|
1983
|
+
if (error instanceof InvalidRequestException) return void 0;
|
|
1984
|
+
throw error;
|
|
1985
|
+
}
|
|
1986
|
+
const id = response.Cluster?.Id;
|
|
1987
|
+
if (typeof id !== "string") throw new Error("DescribeCluster did not return the cluster asked for");
|
|
1988
|
+
return { id };
|
|
1989
|
+
}
|
|
1990
|
+
async function importImpl(input) {
|
|
1991
|
+
const explicit = resolveExplicitPhysicalId(input, null);
|
|
1992
|
+
if (explicit) {
|
|
1993
|
+
const cluster = await this.describeClusterOrUndefined(explicit);
|
|
1994
|
+
if (!cluster || cluster.Status?.State && TERMINAL_STATES.has(cluster.Status.State)) return null;
|
|
1995
|
+
return {
|
|
1996
|
+
physicalId: explicit,
|
|
1997
|
+
attributes: this.buildAttributes(cluster)
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
2000
|
+
return null;
|
|
2001
|
+
}
|
|
2002
|
+
async function describeClusterOrUndefined(clusterId) {
|
|
2003
|
+
try {
|
|
2004
|
+
return (await this.getClient().send(new DescribeClusterCommand({ ClusterId: clusterId }))).Cluster;
|
|
2005
|
+
} catch (err) {
|
|
2006
|
+
if (err instanceof InvalidRequestException) return void 0;
|
|
2007
|
+
throw err;
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
async function readCurrentState(physicalId, _logicalId, _resourceType, properties) {
|
|
2011
|
+
const cluster = await this.describeClusterOrUndefined(physicalId);
|
|
2012
|
+
if (!cluster) return void 0;
|
|
2013
|
+
if (cluster.Status?.State && TERMINAL_STATES.has(cluster.Status.State)) return RESOURCE_NOT_FOUND;
|
|
2014
|
+
let instanceGroups = [];
|
|
2015
|
+
let instanceFleets = [];
|
|
2016
|
+
const declares = (key) => properties?.[key] != null;
|
|
2017
|
+
let policies;
|
|
2018
|
+
try {
|
|
2019
|
+
[, policies] = await Promise.all([cluster.InstanceCollectionType === "INSTANCE_FLEET" ? this.listInstanceFleets(physicalId).then((fleets) => {
|
|
2020
|
+
instanceFleets = fleets;
|
|
2021
|
+
}) : this.listInstanceGroups(physicalId).then((groups) => {
|
|
2022
|
+
instanceGroups = groups;
|
|
2023
|
+
}), readDeclaredPolicies.call(this, physicalId, {
|
|
2024
|
+
autoTermination: declares("AutoTerminationPolicy"),
|
|
2025
|
+
managedScaling: declares("ManagedScalingPolicy")
|
|
2026
|
+
})]);
|
|
2027
|
+
} catch (err) {
|
|
2028
|
+
if (err instanceof InvalidRequestException) return void 0;
|
|
2029
|
+
throw err;
|
|
2030
|
+
}
|
|
2031
|
+
const out = {
|
|
2032
|
+
Name: cluster.Name ?? "",
|
|
2033
|
+
ReleaseLabel: cluster.ReleaseLabel ?? "",
|
|
2034
|
+
ServiceRole: cluster.ServiceRole ?? "",
|
|
2035
|
+
LogUri: cluster.LogUri ?? "",
|
|
2036
|
+
LogEncryptionKmsKeyId: cluster.LogEncryptionKmsKeyId ?? "",
|
|
2037
|
+
AutoScalingRole: cluster.AutoScalingRole ?? "",
|
|
2038
|
+
ScaleDownBehavior: cluster.ScaleDownBehavior ?? "",
|
|
2039
|
+
CustomAmiId: cluster.CustomAmiId ?? "",
|
|
2040
|
+
OSReleaseLabel: cluster.OSReleaseLabel ?? "",
|
|
2041
|
+
SecurityConfiguration: cluster.SecurityConfiguration ?? "",
|
|
2042
|
+
EbsRootVolumeSize: cluster.EbsRootVolumeSize,
|
|
2043
|
+
EbsRootVolumeIops: cluster.EbsRootVolumeIops,
|
|
2044
|
+
EbsRootVolumeThroughput: cluster.EbsRootVolumeThroughput,
|
|
2045
|
+
StepConcurrencyLevel: cluster.StepConcurrencyLevel,
|
|
2046
|
+
VisibleToAllUsers: cluster.VisibleToAllUsers ?? false,
|
|
2047
|
+
JobFlowRole: cluster.Ec2InstanceAttributes?.IamInstanceProfile ?? "",
|
|
2048
|
+
Applications: cluster.Applications ?? [],
|
|
2049
|
+
Tags: normalizeAwsTagsToCfn(cluster.Tags),
|
|
2050
|
+
Instances: this.reverseInstancesToCfn(cluster, instanceGroups, instanceFleets),
|
|
2051
|
+
...policies
|
|
2052
|
+
};
|
|
2053
|
+
if (typeof cluster.SessionEnabled === "boolean") out["SessionEnabled"] = cluster.SessionEnabled;
|
|
2054
|
+
const cw = cluster.MonitoringConfiguration?.CloudWatchLogConfiguration;
|
|
2055
|
+
if (cw) out["MonitoringConfiguration"] = { CloudWatchLogConfiguration: Object.fromEntries(Object.entries({
|
|
2056
|
+
Enabled: cw.Enabled,
|
|
2057
|
+
LogGroupName: cw.LogGroupName,
|
|
2058
|
+
LogStreamNamePrefix: cw.LogStreamNamePrefix,
|
|
2059
|
+
EncryptionKeyArn: cw.EncryptionKeyArn,
|
|
2060
|
+
LogTypes: cw.LogTypes
|
|
2061
|
+
}).filter(([, v]) => v !== void 0)) };
|
|
2062
|
+
return out;
|
|
2063
|
+
}
|
|
2064
|
+
const POLICY_KEYS = ["AutoTerminationPolicy", "ManagedScalingPolicy"];
|
|
2065
|
+
async function readUnsettled(physicalId, logicalId, resourceType, names, recordedProperties) {
|
|
2066
|
+
const wanted = POLICY_KEYS.filter((key) => names.has(key));
|
|
2067
|
+
const properties = { ...recordedProperties };
|
|
2068
|
+
for (const key of wanted) if (properties[key] == null) properties[key] = {};
|
|
2069
|
+
const live = await this.readCurrentState(physicalId, logicalId, resourceType, properties);
|
|
2070
|
+
if (live === void 0 || live === RESOURCE_NOT_FOUND) return live;
|
|
2071
|
+
const out = { ...live };
|
|
2072
|
+
for (const key of wanted) {
|
|
2073
|
+
if (!Object.hasOwn(out, key)) throw new Error(`the ${key} of EMR cluster ${logicalId} could not be read`);
|
|
2074
|
+
const value = out[key];
|
|
2075
|
+
if (typeof value === "object" && value !== null && Object.keys(value).length === 0) delete out[key];
|
|
2076
|
+
}
|
|
2077
|
+
return out;
|
|
2078
|
+
}
|
|
2079
|
+
async function readDeclaredPolicies(clusterId, wanted) {
|
|
2080
|
+
const readOne = (key, action, send) => send().then((value) => ({ value }), (err) => {
|
|
2081
|
+
if (err instanceof InvalidRequestException) throw err;
|
|
2082
|
+
const name = err?.name;
|
|
2083
|
+
const errorClass = typeof name === "string" && /^[A-Za-z0-9]{1,64}$/.test(name) ? name : "an error";
|
|
2084
|
+
const hint = isPermissionDenial(err) ? `; allow elasticmapreduce:${action}` : "";
|
|
2085
|
+
this.logger.warn(safeMsg`EMR cluster ${clusterId}: ${key} not read (${errorClass}${hint}).`);
|
|
2086
|
+
});
|
|
2087
|
+
const [autoTermination, managedScaling] = await Promise.all([wanted.autoTermination ? readOne("AutoTerminationPolicy", "GetAutoTerminationPolicy", () => this.getClient().send(new GetAutoTerminationPolicyCommand({ ClusterId: clusterId })).then((resp) => resp.AutoTerminationPolicy)) : Promise.resolve(void 0), wanted.managedScaling ? readOne("ManagedScalingPolicy", "GetManagedScalingPolicy", () => this.getClient().send(new GetManagedScalingPolicyCommand({ ClusterId: clusterId })).then((resp) => resp.ManagedScalingPolicy)) : Promise.resolve(void 0)]);
|
|
2088
|
+
const out = {};
|
|
2089
|
+
if (autoTermination !== void 0) out["AutoTerminationPolicy"] = structuredClone(autoTermination.value ?? {});
|
|
2090
|
+
if (managedScaling !== void 0) out["ManagedScalingPolicy"] = structuredClone(managedScaling.value ?? {});
|
|
2091
|
+
return out;
|
|
2092
|
+
}
|
|
2093
|
+
async function listInstanceGroups(clusterId) {
|
|
2094
|
+
const groups = [];
|
|
2095
|
+
let marker;
|
|
2096
|
+
do {
|
|
2097
|
+
const resp = await this.getClient().send(new ListInstanceGroupsCommand({
|
|
2098
|
+
ClusterId: clusterId,
|
|
2099
|
+
...marker && { Marker: marker }
|
|
2100
|
+
}));
|
|
2101
|
+
groups.push(...resp.InstanceGroups ?? []);
|
|
2102
|
+
marker = resp.Marker;
|
|
2103
|
+
} while (marker);
|
|
2104
|
+
return groups;
|
|
2105
|
+
}
|
|
2106
|
+
async function listInstanceFleets(clusterId) {
|
|
2107
|
+
const fleets = [];
|
|
2108
|
+
let marker;
|
|
2109
|
+
do {
|
|
2110
|
+
const resp = await this.getClient().send(new ListInstanceFleetsCommand({
|
|
2111
|
+
ClusterId: clusterId,
|
|
2112
|
+
...marker && { Marker: marker }
|
|
2113
|
+
}));
|
|
2114
|
+
fleets.push(...resp.InstanceFleets ?? []);
|
|
2115
|
+
marker = resp.Marker;
|
|
2116
|
+
} while (marker);
|
|
2117
|
+
return fleets;
|
|
2118
|
+
}
|
|
2119
|
+
function reverseInstancesToCfn(cluster, instanceGroups, instanceFleets) {
|
|
2120
|
+
const ec2 = cluster.Ec2InstanceAttributes;
|
|
2121
|
+
const instances = {};
|
|
2122
|
+
const taskGroups = [];
|
|
2123
|
+
for (const g of instanceGroups) {
|
|
2124
|
+
const cfn = this.reverseInstanceGroup(g);
|
|
2125
|
+
switch (g.InstanceGroupType) {
|
|
2126
|
+
case "MASTER":
|
|
2127
|
+
instances["MasterInstanceGroup"] = cfn;
|
|
2128
|
+
break;
|
|
2129
|
+
case "CORE":
|
|
2130
|
+
instances["CoreInstanceGroup"] = cfn;
|
|
2131
|
+
break;
|
|
2132
|
+
case "TASK": taskGroups.push(cfn);
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
if (taskGroups.length > 0) instances["TaskInstanceGroups"] = taskGroups;
|
|
2136
|
+
const taskFleets = [];
|
|
2137
|
+
for (const f of instanceFleets) {
|
|
2138
|
+
const cfn = this.reverseInstanceFleet(f);
|
|
2139
|
+
switch (f.InstanceFleetType) {
|
|
2140
|
+
case "MASTER":
|
|
2141
|
+
instances["MasterInstanceFleet"] = cfn;
|
|
2142
|
+
break;
|
|
2143
|
+
case "CORE":
|
|
2144
|
+
instances["CoreInstanceFleet"] = cfn;
|
|
2145
|
+
break;
|
|
2146
|
+
case "TASK": taskFleets.push(cfn);
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
if (taskFleets.length > 0) instances["TaskInstanceFleets"] = taskFleets;
|
|
2150
|
+
if (ec2?.Ec2KeyName !== void 0) instances["Ec2KeyName"] = ec2.Ec2KeyName;
|
|
2151
|
+
if (ec2?.Ec2SubnetId !== void 0) instances["Ec2SubnetId"] = ec2.Ec2SubnetId;
|
|
2152
|
+
if (ec2?.RequestedEc2SubnetIds !== void 0) instances["Ec2SubnetIds"] = ec2.RequestedEc2SubnetIds;
|
|
2153
|
+
if (ec2?.EmrManagedMasterSecurityGroup !== void 0) instances["EmrManagedMasterSecurityGroup"] = ec2.EmrManagedMasterSecurityGroup;
|
|
2154
|
+
if (ec2?.EmrManagedSlaveSecurityGroup !== void 0) instances["EmrManagedSlaveSecurityGroup"] = ec2.EmrManagedSlaveSecurityGroup;
|
|
2155
|
+
if (ec2?.ServiceAccessSecurityGroup !== void 0) instances["ServiceAccessSecurityGroup"] = ec2.ServiceAccessSecurityGroup;
|
|
2156
|
+
if (ec2?.AdditionalMasterSecurityGroups !== void 0) instances["AdditionalMasterSecurityGroups"] = ec2.AdditionalMasterSecurityGroups;
|
|
2157
|
+
if (ec2?.AdditionalSlaveSecurityGroups !== void 0) instances["AdditionalSlaveSecurityGroups"] = ec2.AdditionalSlaveSecurityGroups;
|
|
2158
|
+
if (cluster.TerminationProtected !== void 0) instances["TerminationProtected"] = cluster.TerminationProtected;
|
|
2159
|
+
if (cluster.UnhealthyNodeReplacement !== void 0) instances["UnhealthyNodeReplacement"] = cluster.UnhealthyNodeReplacement;
|
|
2160
|
+
return instances;
|
|
2161
|
+
}
|
|
2162
|
+
function reverseInstanceGroup(g) {
|
|
2163
|
+
const out = {
|
|
2164
|
+
InstanceType: g.InstanceType ?? "",
|
|
2165
|
+
InstanceCount: g.RequestedInstanceCount ?? 0
|
|
2166
|
+
};
|
|
2167
|
+
if (g.Name !== void 0) out["Name"] = g.Name;
|
|
2168
|
+
if (g.Market !== void 0) out["Market"] = g.Market;
|
|
2169
|
+
if (g.BidPrice !== void 0) out["BidPrice"] = g.BidPrice;
|
|
2170
|
+
if (g.CustomAmiId !== void 0) out["CustomAmiId"] = g.CustomAmiId;
|
|
2171
|
+
return out;
|
|
2172
|
+
}
|
|
2173
|
+
function reverseInstanceFleet(f) {
|
|
2174
|
+
const out = {};
|
|
2175
|
+
if (f.Name !== void 0) out["Name"] = f.Name;
|
|
2176
|
+
if (f.TargetOnDemandCapacity !== void 0) out["TargetOnDemandCapacity"] = f.TargetOnDemandCapacity;
|
|
2177
|
+
if (f.TargetSpotCapacity !== void 0) out["TargetSpotCapacity"] = f.TargetSpotCapacity;
|
|
2178
|
+
return out;
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
// src/provisioning/providers/emr-cluster-provider.ts
|
|
2182
|
+
const EMR_DECLARED_POLICY_KEYS = ["AutoTerminationPolicy", "ManagedScalingPolicy"];
|
|
2183
|
+
var EMRClusterProvider = class {
|
|
2184
|
+
client;
|
|
2185
|
+
createClient;
|
|
2186
|
+
providerRegion = ambientRegion();
|
|
2187
|
+
logger = getLogger().child("EMRClusterProvider");
|
|
2188
|
+
protectionFlips = new ProtectionFlipRegistry();
|
|
2189
|
+
pollIntervalMs;
|
|
2190
|
+
maxWaitMs;
|
|
2191
|
+
constructor(options) {
|
|
2192
|
+
this.pollIntervalMs = options?.pollIntervalMs ?? 15e3;
|
|
2193
|
+
this.maxWaitMs = options?.maxWaitMs ?? 36e5;
|
|
2194
|
+
}
|
|
2195
|
+
wrapStatusReasonError(mask, reason, fallback, build) {
|
|
2196
|
+
return wrapStatusReasonError.call(this, mask, reason, fallback, build);
|
|
2197
|
+
}
|
|
2198
|
+
wrapCaughtError(mask, error, build) {
|
|
2199
|
+
return wrapCaughtError.call(this, mask, error, build);
|
|
2200
|
+
}
|
|
2201
|
+
cleanupFailureText(head, error, mask) {
|
|
2202
|
+
return cleanupFailureText.call(this, head, error, mask);
|
|
2203
|
+
}
|
|
2204
|
+
handledProperties = /* @__PURE__ */ new Map([["AWS::EMR::Cluster", /* @__PURE__ */ new Set([
|
|
2205
|
+
"AdditionalInfo",
|
|
2206
|
+
"Applications",
|
|
2207
|
+
"AutoScalingRole",
|
|
2208
|
+
"AutoTerminationPolicy",
|
|
2209
|
+
"BootstrapActions",
|
|
2210
|
+
"Configurations",
|
|
2211
|
+
"CustomAmiId",
|
|
2212
|
+
"EbsRootVolumeIops",
|
|
2213
|
+
"EbsRootVolumeSize",
|
|
2214
|
+
"EbsRootVolumeThroughput",
|
|
2215
|
+
"Instances",
|
|
2216
|
+
"JobFlowRole",
|
|
2217
|
+
"KerberosAttributes",
|
|
2218
|
+
"LogEncryptionKmsKeyId",
|
|
2219
|
+
"LogUri",
|
|
2220
|
+
"ManagedScalingPolicy",
|
|
2221
|
+
"MonitoringConfiguration",
|
|
2222
|
+
"Name",
|
|
2223
|
+
"OSReleaseLabel",
|
|
2224
|
+
"PlacementGroupConfigs",
|
|
2225
|
+
"ReleaseLabel",
|
|
2226
|
+
"ScaleDownBehavior",
|
|
2227
|
+
"SecurityConfiguration",
|
|
2228
|
+
"ServiceRole",
|
|
2229
|
+
"SessionEnabled",
|
|
2230
|
+
"StepConcurrencyLevel",
|
|
2231
|
+
"Steps",
|
|
2232
|
+
"Tags",
|
|
2233
|
+
"VisibleToAllUsers"
|
|
2234
|
+
])]]);
|
|
2235
|
+
removalHandledInUpdate = /* @__PURE__ */ new Map([["AWS::EMR::Cluster", /* @__PURE__ */ new Set([
|
|
2236
|
+
...[...this.handledProperties.get("AWS::EMR::Cluster") ?? []].filter((key) => !MUTABLE_TOP_LEVEL_PROPS.has(key)),
|
|
2237
|
+
"Tags",
|
|
2238
|
+
"VisibleToAllUsers",
|
|
2239
|
+
"ManagedScalingPolicy",
|
|
2240
|
+
"AutoTerminationPolicy",
|
|
2241
|
+
...LEFT_IN_PLACE_ON_REMOVAL$1
|
|
2242
|
+
])]]);
|
|
2243
|
+
getClient() {
|
|
2244
|
+
return getClient.call(this);
|
|
2245
|
+
}
|
|
2246
|
+
getCreateClient() {
|
|
2247
|
+
return getCreateClient.call(this);
|
|
2248
|
+
}
|
|
2249
|
+
getMinResourceTimeoutMs() {
|
|
2250
|
+
return this.maxWaitMs + this.pollIntervalMs;
|
|
2251
|
+
}
|
|
2252
|
+
create(logicalId, resourceType, properties, context) {
|
|
2253
|
+
return create$1.call(this, logicalId, resourceType, properties, context);
|
|
2254
|
+
}
|
|
2255
|
+
toJobFlowInstancesConfig(config) {
|
|
2256
|
+
return toJobFlowInstancesConfig.call(this, config);
|
|
2257
|
+
}
|
|
2258
|
+
toInstanceGroupConfig(raw, role) {
|
|
2259
|
+
return toInstanceGroupConfig.call(this, raw, role);
|
|
2260
|
+
}
|
|
2261
|
+
toInstanceFleetConfig(raw, type) {
|
|
2262
|
+
return toInstanceFleetConfig$1.call(this, raw, type);
|
|
2263
|
+
}
|
|
2264
|
+
toManagedScalingPolicy(config) {
|
|
2265
|
+
return toManagedScalingPolicy.call(this, config);
|
|
2266
|
+
}
|
|
2267
|
+
toAutoTerminationPolicy(config) {
|
|
2268
|
+
return toAutoTerminationPolicy.call(this, config);
|
|
2269
|
+
}
|
|
2270
|
+
resolveInstancesTargets(logicalId, clusterId, plan) {
|
|
2271
|
+
return resolveInstancesTargets.call(this, logicalId, clusterId, plan);
|
|
2272
|
+
}
|
|
2273
|
+
applyInstancesResizes(logicalId, clusterId, targets, deadline, mask) {
|
|
2274
|
+
return applyInstancesResizes.call(this, logicalId, clusterId, targets, deadline, mask);
|
|
2275
|
+
}
|
|
2276
|
+
update(logicalId, physicalId, resourceType, properties, previousProperties, context) {
|
|
2277
|
+
return update.call(this, logicalId, physicalId, resourceType, properties, previousProperties, context);
|
|
2278
|
+
}
|
|
2279
|
+
applyTagDiff(physicalId, resourceType, logicalId, prevTagsRaw, nextTagsRaw) {
|
|
2280
|
+
return applyTagDiff.call(this, physicalId, resourceType, logicalId, prevTagsRaw, nextTagsRaw);
|
|
2281
|
+
}
|
|
2282
|
+
delete(logicalId, physicalId, resourceType, _properties, context) {
|
|
2283
|
+
return deleteImpl.call(this, logicalId, physicalId, resourceType, _properties, context);
|
|
2284
|
+
}
|
|
2285
|
+
deleteOnce(logicalId, physicalId, resourceType, context, flip) {
|
|
2286
|
+
return deleteOnce.call(this, logicalId, physicalId, resourceType, context, flip);
|
|
2287
|
+
}
|
|
2288
|
+
describeForPoll(clusterId, transientState, maxConsecutiveTransient = 5) {
|
|
2289
|
+
return describeForPoll.call(this, clusterId, transientState, maxConsecutiveTransient);
|
|
2290
|
+
}
|
|
2291
|
+
waitForClusterReady(clusterId, logicalId, resourceType, mask) {
|
|
2292
|
+
return waitForClusterReady.call(this, clusterId, logicalId, resourceType, mask);
|
|
2293
|
+
}
|
|
2294
|
+
waitForClusterTerminated(clusterId, logicalId, resourceType, mask) {
|
|
2295
|
+
return waitForClusterTerminated.call(this, clusterId, logicalId, resourceType, mask);
|
|
2296
|
+
}
|
|
2297
|
+
buildAttributes(cluster) {
|
|
2298
|
+
return buildAttributes.call(this, cluster);
|
|
2299
|
+
}
|
|
2300
|
+
getAttribute(physicalId, _resourceType, attributeName) {
|
|
2301
|
+
return getAttribute.call(this, physicalId, _resourceType, attributeName);
|
|
2302
|
+
}
|
|
2303
|
+
isSameResource(journaledPhysicalId, record, resourceType, context) {
|
|
2304
|
+
return isSameResource.call(this, journaledPhysicalId, record, resourceType, context);
|
|
2305
|
+
}
|
|
2306
|
+
readClusterIdentity(clusterId) {
|
|
2307
|
+
return readClusterIdentity.call(this, clusterId);
|
|
2308
|
+
}
|
|
2309
|
+
import(input) {
|
|
2310
|
+
return importImpl.call(this, input);
|
|
2311
|
+
}
|
|
2312
|
+
describeClusterOrUndefined(clusterId) {
|
|
2313
|
+
return describeClusterOrUndefined.call(this, clusterId);
|
|
2314
|
+
}
|
|
2315
|
+
readCurrentState(physicalId, _logicalId, _resourceType, properties) {
|
|
2316
|
+
return readCurrentState.call(this, physicalId, _logicalId, _resourceType, properties);
|
|
2317
|
+
}
|
|
2318
|
+
readUnsettled(physicalId, logicalId, resourceType, names, recordedProperties) {
|
|
2319
|
+
return readUnsettled.call(this, physicalId, logicalId, resourceType, names, recordedProperties);
|
|
2320
|
+
}
|
|
2321
|
+
canonicalizeDriftPair(_resourceType, baseline, aws, properties) {
|
|
2322
|
+
return Promise.resolve(projectDeclaredDriftPair(EMR_DECLARED_POLICY_KEYS, baseline, aws, properties, void 0, true));
|
|
2323
|
+
}
|
|
2324
|
+
getDriftUnknownPaths(_resourceType, properties) {
|
|
2325
|
+
return [
|
|
2326
|
+
...undeclaredDriftKeys(EMR_DECLARED_POLICY_KEYS, properties),
|
|
2327
|
+
"AdditionalInfo",
|
|
2328
|
+
"Applications",
|
|
2329
|
+
"BootstrapActions",
|
|
2330
|
+
"Configurations",
|
|
2331
|
+
"Instances.HadoopVersion",
|
|
2332
|
+
"Instances.KeepJobFlowAliveWhenNoSteps",
|
|
2333
|
+
"Instances.Placement",
|
|
2334
|
+
"Instances.CoreInstanceGroup.AutoScalingPolicy",
|
|
2335
|
+
"Instances.CoreInstanceGroup.Configurations",
|
|
2336
|
+
"Instances.CoreInstanceGroup.EbsConfiguration",
|
|
2337
|
+
"Instances.MasterInstanceGroup.AutoScalingPolicy",
|
|
2338
|
+
"Instances.MasterInstanceGroup.Configurations",
|
|
2339
|
+
"Instances.MasterInstanceGroup.EbsConfiguration",
|
|
2340
|
+
"Instances.CoreInstanceFleet.InstanceTypeConfigs",
|
|
2341
|
+
"Instances.CoreInstanceFleet.LaunchSpecifications",
|
|
2342
|
+
"Instances.CoreInstanceFleet.ResizeSpecifications",
|
|
2343
|
+
"Instances.MasterInstanceFleet.InstanceTypeConfigs",
|
|
2344
|
+
"Instances.MasterInstanceFleet.LaunchSpecifications",
|
|
2345
|
+
"Instances.MasterInstanceFleet.ResizeSpecifications",
|
|
2346
|
+
"Instances.TaskInstanceFleets",
|
|
2347
|
+
"Instances.TaskInstanceGroups",
|
|
2348
|
+
"KerberosAttributes",
|
|
2349
|
+
"MonitoringConfiguration",
|
|
2350
|
+
"PlacementGroupConfigs",
|
|
2351
|
+
"SessionEnabled",
|
|
2352
|
+
"Steps"
|
|
2353
|
+
];
|
|
2354
|
+
}
|
|
2355
|
+
listInstanceGroups(clusterId) {
|
|
2356
|
+
return listInstanceGroups.call(this, clusterId);
|
|
2357
|
+
}
|
|
2358
|
+
listInstanceFleets(clusterId) {
|
|
2359
|
+
return listInstanceFleets.call(this, clusterId);
|
|
2360
|
+
}
|
|
2361
|
+
reverseInstancesToCfn(cluster, instanceGroups, instanceFleets) {
|
|
2362
|
+
return reverseInstancesToCfn.call(this, cluster, instanceGroups, instanceFleets);
|
|
2363
|
+
}
|
|
2364
|
+
reverseInstanceGroup(g) {
|
|
2365
|
+
return reverseInstanceGroup.call(this, g);
|
|
2366
|
+
}
|
|
2367
|
+
reverseInstanceFleet(f) {
|
|
2368
|
+
return reverseInstanceFleet.call(this, f);
|
|
2369
|
+
}
|
|
2370
|
+
};
|
|
2371
|
+
|
|
2372
|
+
export { EMRClusterProvider, undeclaredDriftKeys as a, reportPossibleOrphans as c, projectDeclaredDriftPair as i, EMRInstanceGroupConfigProvider as n, collectOrphanIds as o, filledDefaultsFrom as r, orphanCommandRegionArg as s, EMRInstanceFleetConfigProvider as t };
|
|
2373
|
+
//# sourceMappingURL=emr-cluster-provider-CxM25Nws.js.map
|