@cumulus/message 9.8.0 → 9.9.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/Build.d.ts.map +1 -1
- package/Build.js.map +1 -1
- package/DeadLetterMessage.d.ts +16 -0
- package/DeadLetterMessage.d.ts.map +1 -0
- package/DeadLetterMessage.js +42 -0
- package/DeadLetterMessage.js.map +1 -0
- package/README.md +75 -36
- package/StepFunctions.d.ts +56 -0
- package/StepFunctions.d.ts.map +1 -1
- package/StepFunctions.js +127 -8
- package/StepFunctions.js.map +1 -1
- package/package.json +7 -7
- package/src/Build.ts +1 -1
- package/src/DeadLetterMessage.ts +54 -0
- package/src/StepFunctions.ts +158 -1
- package/tsconfig.tsbuildinfo +1 -1
package/Build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Build.d.ts","sourceRoot":"","sources":["src/Build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Build.d.ts","sourceRoot":"","sources":["src/Build.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EACL,uBAAuB,EACvB,kCAAkC,EAClC,QAAQ,EACT,MAAM,SAAS,CAAC;AAYjB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB;kBAOb,MAAM;;;yBAGC,kCAAkC;;MAErD,QAAQ,WASX,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,6BAA6B;wBAUpB,MAAM;qBACT,uBAAuB;aAC/B,MAAM;cACL,QAAQ;;;;;MAKhB,QAAQ,cAmBX,CAAC"}
|
package/Build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Build.js","sourceRoot":"","sources":["src/Build.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AAEb;;;;;;;GAOG;AAEH,yDAAiC;
|
|
1
|
+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AG;QACd,GAAG,eAAe;QAClB,IAAI,EAAE,IAAA,eAAK,EAAC,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE;YAC5C,aAAa,EAAE,QAAQ,CAAC,IAAI;SAC7B,CAAC;QACF,YAAY,EAAE,IAAA,eAAK,EAAC,iBAAiB,EAAE,WAAW,CAAC;QACnD,OAAO;KACR,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AArCW,QAAA,6BAA6B,iCAqCxC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SQSRecord, EventBridgeEvent } from 'aws-lambda';
|
|
2
|
+
import { CumulusMessage } from '@cumulus/types/message';
|
|
3
|
+
declare type StepFunctionEventBridgeEvent = EventBridgeEvent<'Step Functions Execution Status Change', {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
}>;
|
|
6
|
+
declare type UnwrapDeadLetterCumulusMessageReturnType = (StepFunctionEventBridgeEvent | AWS.SQS.Message | SQSRecord | CumulusMessage);
|
|
7
|
+
/**
|
|
8
|
+
* Unwrap dead letter Cumulus message, which may be wrapped in a
|
|
9
|
+
* States cloudwatch event, which is wrapped in an SQS message.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} messageBody - received SQS message
|
|
12
|
+
* @returns {Object} the cumulus message or nearest available object
|
|
13
|
+
*/
|
|
14
|
+
export declare const unwrapDeadLetterCumulusMessage: (messageBody: UnwrapDeadLetterCumulusMessageReturnType) => Promise<UnwrapDeadLetterCumulusMessageReturnType>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=DeadLetterMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeadLetterMessage.d.ts","sourceRoot":"","sources":["src/DeadLetterMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAOxD,aAAK,4BAA4B,GAAG,gBAAgB,CAAC,wCAAwC,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC,CAAC;AAC1H,aAAK,wCAAwC,GAAG,CAC9C,4BAA4B,GAC1B,GAAG,CAAC,GAAG,CAAC,OAAO,GACf,SAAS,GACT,cAAc,CACjB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,gBAC5B,wCAAwC,KACpD,QAAQ,wCAAwC,CA0BlD,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.unwrapDeadLetterCumulusMessage = void 0;
|
|
7
|
+
const SQS_1 = require("@cumulus/aws-client/SQS");
|
|
8
|
+
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
9
|
+
const StepFunctions_1 = require("./StepFunctions");
|
|
10
|
+
const log = new logger_1.default({ sender: '@cumulus/DeadLetterMessage' });
|
|
11
|
+
/**
|
|
12
|
+
* Unwrap dead letter Cumulus message, which may be wrapped in a
|
|
13
|
+
* States cloudwatch event, which is wrapped in an SQS message.
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} messageBody - received SQS message
|
|
16
|
+
* @returns {Object} the cumulus message or nearest available object
|
|
17
|
+
*/
|
|
18
|
+
const unwrapDeadLetterCumulusMessage = async (messageBody) => {
|
|
19
|
+
try {
|
|
20
|
+
if ('cumulus_meta' in messageBody) {
|
|
21
|
+
return messageBody;
|
|
22
|
+
}
|
|
23
|
+
if ('Body' in messageBody || 'body' in messageBody) {
|
|
24
|
+
// AWS.SQS.Message/SQS.Record case
|
|
25
|
+
const unwrappedMessageBody = (0, SQS_1.parseSQSMessageBody)(messageBody);
|
|
26
|
+
return await (0, exports.unwrapDeadLetterCumulusMessage)(unwrappedMessageBody);
|
|
27
|
+
}
|
|
28
|
+
if (!('detail' in messageBody)) {
|
|
29
|
+
// Non-typed catchall
|
|
30
|
+
return messageBody;
|
|
31
|
+
}
|
|
32
|
+
// StepFunctionEventBridgeEvent case
|
|
33
|
+
const unwrappedMessageBody = await (0, StepFunctions_1.getCumulusMessageFromExecutionEvent)(messageBody);
|
|
34
|
+
return await (0, exports.unwrapDeadLetterCumulusMessage)(unwrappedMessageBody);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
log.error('Falling back to storing wrapped message after encountering unwrap error', error);
|
|
38
|
+
return messageBody;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.unwrapDeadLetterCumulusMessage = unwrapDeadLetterCumulusMessage;
|
|
42
|
+
//# sourceMappingURL=DeadLetterMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeadLetterMessage.js","sourceRoot":"","sources":["src/DeadLetterMessage.ts"],"names":[],"mappings":";;;;;;AAEA,iDAA8D;AAE9D,6DAAqC;AAErC,mDAAsE;AAEtE,MAAM,GAAG,GAAG,IAAI,gBAAM,CAAC,EAAE,MAAM,EAAE,4BAA4B,EAAE,CAAC,CAAC;AAUjE;;;;;;GAMG;AACI,MAAM,8BAA8B,GAAG,KAAK,EACjD,WAAqD,EACF,EAAE;IACrD,IAAI;QACF,IAAI,cAAc,IAAI,WAAW,EAAE;YACjC,OAAO,WAAW,CAAC;SACpB;QACD,IAAI,MAAM,IAAI,WAAW,IAAI,MAAM,IAAI,WAAW,EAAE;YAClD,kCAAkC;YAClC,MAAM,oBAAoB,GAAG,IAAA,yBAAmB,EAC9C,WAAW,CACM,CAAC;YACpB,OAAO,MAAM,IAAA,sCAA8B,EAAC,oBAAoB,CAAC,CAAC;SACnE;QACD,IAAI,CAAC,CAAC,QAAQ,IAAI,WAAW,CAAC,EAAE;YAC9B,qBAAqB;YACrB,OAAO,WAAW,CAAC;SACpB;QACD,oCAAoC;QACpC,MAAM,oBAAoB,GAAG,MAAM,IAAA,mDAAmC,EAAC,WAAW,CAAC,CAAC;QACpF,OAAO,MAAM,IAAA,sCAA8B,EAAC,oBAAoB,CAAC,CAAC;KACnE;IAAC,OAAO,KAAK,EAAE;QACd,GAAG,CAAC,KAAK,CACP,yEAAyE,EACzE,KAAK,CACN,CAAC;QACF,OAAO,WAAW,CAAC;KACpB;AACH,CAAC,CAAC;AA5BW,QAAA,8BAA8B,kCA4BzC"}
|
package/README.md
CHANGED
|
@@ -23,9 +23,6 @@ from a Cumulus message</p>
|
|
|
23
23
|
<dt><a href="#module_Queue">Queue</a></dt>
|
|
24
24
|
<dd><p>Utility functions for parsing queue information from a Cumulus message</p>
|
|
25
25
|
</dd>
|
|
26
|
-
<dt><a href="#module_StepFunctions">StepFunctions</a></dt>
|
|
27
|
-
<dd><p>Utility functions for working with AWS Step Function events/messages</p>
|
|
28
|
-
</dd>
|
|
29
26
|
</dl>
|
|
30
27
|
|
|
31
28
|
### Functions
|
|
@@ -47,6 +44,10 @@ the collectionId used in elasticsearch indexing</p>
|
|
|
47
44
|
<dt><a href="#exp_module_Collections--getCollectionIdFromMessage">getCollectionIdFromMessage(message)</a> ⇒ <code>string</code> | <code>undefined</code> ⏏</dt>
|
|
48
45
|
<dd><p>Get collection ID from execution message.</p>
|
|
49
46
|
</dd>
|
|
47
|
+
<dt><a href="#unwrapDeadLetterCumulusMessage">unwrapDeadLetterCumulusMessage(messageBody)</a> ⇒ <code>Object</code></dt>
|
|
48
|
+
<dd><p>Unwrap dead letter Cumulus message, which may be wrapped in a
|
|
49
|
+
States cloudwatch event, which is wrapped in an SQS message.</p>
|
|
50
|
+
</dd>
|
|
50
51
|
<dt><a href="#exp_module_Granules--getMessageGranules">getMessageGranules(message)</a> ⇒ <code>Array.<Object></code> | <code>undefined</code> ⏏</dt>
|
|
51
52
|
<dd><p>Get granules from payload?.granules of a workflow message.</p>
|
|
52
53
|
</dd>
|
|
@@ -95,6 +96,29 @@ the collectionId used in elasticsearch indexing</p>
|
|
|
95
96
|
<dt><a href="#exp_module_Providers--getMessageProviderId">getMessageProviderId(message)</a> ⇒ <code>undefined</code> | <code>string</code> ⏏</dt>
|
|
96
97
|
<dd><p>Get the provider ID from a workflow message, if any.</p>
|
|
97
98
|
</dd>
|
|
99
|
+
<dt><a href="#exp_module_StepFunctions--pullStepFunctionEvent">pullStepFunctionEvent(event)</a> ⇒ <code>Promise.<Object></code> ⏏</dt>
|
|
100
|
+
<dd><p>Given a Step Function event, replace specified key in event with contents
|
|
101
|
+
of S3 remote message</p>
|
|
102
|
+
</dd>
|
|
103
|
+
<dt><a href="#exp_module_StepFunctions--parseStepMessage">parseStepMessage(stepMessage, stepName)</a> ⇒ <code>Promise.<Object></code> ⏏</dt>
|
|
104
|
+
<dd><p>Parse step message with CMA keys and replace specified key in event with contents
|
|
105
|
+
of S3 remote message</p>
|
|
106
|
+
</dd>
|
|
107
|
+
<dt><a href="#getFailedStepName">getFailedStepName(events, failedStepEvent)</a> ⇒ <code>string</code></dt>
|
|
108
|
+
<dd><p>Searches the Execution step History for the TaskStateEntered pertaining to
|
|
109
|
+
the failed task Id. HistoryEvent ids are numbered sequentially, starting at
|
|
110
|
+
one.</p>
|
|
111
|
+
</dd>
|
|
112
|
+
<dt><a href="#lastFailedEventStep">lastFailedEventStep(events)</a> ⇒ <code>Array.<HistoryEvent></code></dt>
|
|
113
|
+
<dd><p>Finds all failed execution events and returns the last one in the list.</p>
|
|
114
|
+
</dd>
|
|
115
|
+
<dt><a href="#getFailedExecutionMessage">getFailedExecutionMessage(inputCumulusMessage, getExecutionHistoryFunction)</a> ⇒ <code>Object</code></dt>
|
|
116
|
+
<dd><p>Get message to use for publishing failed execution notifications.</p>
|
|
117
|
+
<p>Try to get the input to the last failed step in the execution so we can
|
|
118
|
+
update the status of any granules/PDRs that don't exist in the initial execution
|
|
119
|
+
input.</p>
|
|
120
|
+
<p>Falls back to overall execution input.</p>
|
|
121
|
+
</dd>
|
|
98
122
|
<dt><a href="#exp_module_workflows--getMetaStatus">getMetaStatus(message)</a> ⇒ <code>Message.WorkflowStatus</code> | <code>undefined</code> ⏏</dt>
|
|
99
123
|
<dd><p>Get the status of a workflow message, if any.</p>
|
|
100
124
|
</dd>
|
|
@@ -354,63 +378,78 @@ Determine if there is a queue and queue execution limit in the message.
|
|
|
354
378
|
| --- | --- | --- |
|
|
355
379
|
| message | <code>MessageWithQueueInfo</code> | A workflow message object |
|
|
356
380
|
|
|
357
|
-
<a name="
|
|
381
|
+
<a name="deconstructCollectionId"></a>
|
|
358
382
|
|
|
359
|
-
###
|
|
360
|
-
|
|
383
|
+
### deconstructCollectionId(collectionId) ⇒ <code>Object</code>
|
|
384
|
+
Returns the name and version of a collection based on
|
|
385
|
+
the collectionId used in elasticsearch indexing
|
|
361
386
|
|
|
362
|
-
**
|
|
363
|
-
|
|
364
|
-
const StepFunctions = require('@cumulus/message/StepFunctions');
|
|
365
|
-
```
|
|
387
|
+
**Kind**: global function
|
|
388
|
+
**Returns**: <code>Object</code> - name and version as object
|
|
366
389
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
390
|
+
| Param | Type | Description |
|
|
391
|
+
| --- | --- | --- |
|
|
392
|
+
| collectionId | <code>string</code> | collectionId used in elasticsearch index |
|
|
370
393
|
|
|
371
|
-
<a name="
|
|
394
|
+
<a name="unwrapDeadLetterCumulusMessage"></a>
|
|
372
395
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
396
|
+
### unwrapDeadLetterCumulusMessage(messageBody) ⇒ <code>Object</code>
|
|
397
|
+
Unwrap dead letter Cumulus message, which may be wrapped in a
|
|
398
|
+
States cloudwatch event, which is wrapped in an SQS message.
|
|
376
399
|
|
|
377
|
-
**Kind**:
|
|
378
|
-
**Returns**: <code>
|
|
379
|
-
**Throws**:
|
|
400
|
+
**Kind**: global function
|
|
401
|
+
**Returns**: <code>Object</code> - the cumulus message or nearest available object
|
|
380
402
|
|
|
381
|
-
|
|
403
|
+
| Param | Type | Description |
|
|
404
|
+
| --- | --- | --- |
|
|
405
|
+
| messageBody | <code>Object</code> | received SQS message |
|
|
382
406
|
|
|
407
|
+
<a name="getFailedStepName"></a>
|
|
408
|
+
|
|
409
|
+
### getFailedStepName(events, failedStepEvent) ⇒ <code>string</code>
|
|
410
|
+
Searches the Execution step History for the TaskStateEntered pertaining to
|
|
411
|
+
the failed task Id. HistoryEvent ids are numbered sequentially, starting at
|
|
412
|
+
one.
|
|
413
|
+
|
|
414
|
+
**Kind**: global function
|
|
415
|
+
**Returns**: <code>string</code> - name of the current stepfunction task or 'UnknownFailedStepName'.
|
|
383
416
|
|
|
384
417
|
| Param | Type | Description |
|
|
385
418
|
| --- | --- | --- |
|
|
386
|
-
|
|
|
419
|
+
| events | <code>Array.<HistoryEvent></code> | Step Function events array |
|
|
420
|
+
| failedStepEvent | <code>HistoryEvent</code> | Step Function's failed event. |
|
|
387
421
|
|
|
388
|
-
<a name="
|
|
422
|
+
<a name="lastFailedEventStep"></a>
|
|
389
423
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
of S3 remote message
|
|
424
|
+
### lastFailedEventStep(events) ⇒ <code>Array.<HistoryEvent></code>
|
|
425
|
+
Finds all failed execution events and returns the last one in the list.
|
|
393
426
|
|
|
394
|
-
**Kind**:
|
|
395
|
-
**Returns**: <code>
|
|
427
|
+
**Kind**: global function
|
|
428
|
+
**Returns**: <code>Array.<HistoryEvent></code> - - the last lambda or activity that failed in the
|
|
429
|
+
event array, or an empty array.
|
|
396
430
|
|
|
397
431
|
| Param | Type | Description |
|
|
398
432
|
| --- | --- | --- |
|
|
399
|
-
|
|
|
400
|
-
| stepName | <code>string</code> | Name of the step |
|
|
433
|
+
| events | <code>Array.<HistoryEventList></code> | array of AWS Stepfunction execution HistoryEvents |
|
|
401
434
|
|
|
402
|
-
<a name="
|
|
435
|
+
<a name="getFailedExecutionMessage"></a>
|
|
403
436
|
|
|
404
|
-
###
|
|
405
|
-
|
|
406
|
-
|
|
437
|
+
### getFailedExecutionMessage(inputCumulusMessage, getExecutionHistoryFunction) ⇒ <code>Object</code>
|
|
438
|
+
Get message to use for publishing failed execution notifications.
|
|
439
|
+
|
|
440
|
+
Try to get the input to the last failed step in the execution so we can
|
|
441
|
+
update the status of any granules/PDRs that don't exist in the initial execution
|
|
442
|
+
input.
|
|
443
|
+
|
|
444
|
+
Falls back to overall execution input.
|
|
407
445
|
|
|
408
446
|
**Kind**: global function
|
|
409
|
-
**Returns**: <code>Object</code> -
|
|
447
|
+
**Returns**: <code>Object</code> - - CumulusMessage Execution step message or execution input message
|
|
410
448
|
|
|
411
449
|
| Param | Type | Description |
|
|
412
450
|
| --- | --- | --- |
|
|
413
|
-
|
|
|
451
|
+
| inputCumulusMessage | <code>Object</code> | Workflow execution input message |
|
|
452
|
+
| getExecutionHistoryFunction | <code>function</code> | Testing override for mock/etc of StepFunctions.getExecutionHistory |
|
|
414
453
|
|
|
415
454
|
|
|
416
455
|
## About Cumulus
|
package/StepFunctions.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for working with AWS Step Function events/messages
|
|
3
|
+
* @module StepFunctions
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* const StepFunctions = require('@cumulus/message/StepFunctions');
|
|
7
|
+
*/
|
|
8
|
+
import { EventBridgeEvent } from 'aws-lambda';
|
|
9
|
+
import { getExecutionHistory } from '@cumulus/aws-client/StepFunctions';
|
|
1
10
|
import { Message } from '@cumulus/types';
|
|
2
11
|
/**
|
|
3
12
|
* Given a Step Function event, replace specified key in event with contents
|
|
@@ -25,4 +34,51 @@ export declare const pullStepFunctionEvent: (event: {
|
|
|
25
34
|
* @alias module:StepFunctions
|
|
26
35
|
*/
|
|
27
36
|
export declare const parseStepMessage: (stepMessage: Message.CMAMessage, stepName: string) => Promise<Message.CumulusMessage>;
|
|
37
|
+
/**
|
|
38
|
+
* Searches the Execution step History for the TaskStateEntered pertaining to
|
|
39
|
+
* the failed task Id. HistoryEvent ids are numbered sequentially, starting at
|
|
40
|
+
* one.
|
|
41
|
+
*
|
|
42
|
+
* @param {HistoryEvent[]} events - Step Function events array
|
|
43
|
+
* @param {HistoryEvent} failedStepEvent - Step Function's failed event.
|
|
44
|
+
* @returns {string} name of the current stepfunction task or 'UnknownFailedStepName'.
|
|
45
|
+
*/
|
|
46
|
+
export declare const getFailedStepName: (events: AWS.StepFunctions.HistoryEvent[], failedStepEvent: {
|
|
47
|
+
id: number;
|
|
48
|
+
}) => string;
|
|
49
|
+
/**
|
|
50
|
+
* Finds all failed execution events and returns the last one in the list.
|
|
51
|
+
*
|
|
52
|
+
* @param {Array<HistoryEventList>} events - array of AWS Stepfunction execution HistoryEvents
|
|
53
|
+
* @returns {HistoryEvent[]} - the last lambda or activity that failed in the
|
|
54
|
+
* event array, or an empty array.
|
|
55
|
+
*/
|
|
56
|
+
export declare const lastFailedEventStep: (events: AWS.StepFunctions.HistoryEvent[]) => AWS.StepFunctions.HistoryEvent | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Get message to use for publishing failed execution notifications.
|
|
59
|
+
*
|
|
60
|
+
* Try to get the input to the last failed step in the execution so we can
|
|
61
|
+
* update the status of any granules/PDRs that don't exist in the initial execution
|
|
62
|
+
* input.
|
|
63
|
+
*
|
|
64
|
+
* Falls back to overall execution input.
|
|
65
|
+
*
|
|
66
|
+
* @param {Object} inputCumulusMessage - Workflow execution input message
|
|
67
|
+
* @param {Function} getExecutionHistoryFunction - Testing override for mock/etc of
|
|
68
|
+
* StepFunctions.getExecutionHistory
|
|
69
|
+
* @returns {Object} - CumulusMessage Execution step message or execution input message
|
|
70
|
+
*/
|
|
71
|
+
export declare const getFailedExecutionMessage: (inputCumulusMessage: Message.CumulusMessage, getExecutionHistoryFunction?: typeof getExecutionHistory) => Promise<Message.CumulusMessage | {
|
|
72
|
+
exception: {
|
|
73
|
+
failedExecutionStepName: string;
|
|
74
|
+
error?: string | undefined;
|
|
75
|
+
cause?: string | undefined;
|
|
76
|
+
};
|
|
77
|
+
cumulus_meta: Message.CumulusMeta;
|
|
78
|
+
meta: Message.Meta;
|
|
79
|
+
payload: unknown;
|
|
80
|
+
}>;
|
|
81
|
+
export declare const getCumulusMessageFromExecutionEvent: (executionEvent: EventBridgeEvent<"Step Functions Execution Status Change", {
|
|
82
|
+
[key: string]: string;
|
|
83
|
+
}>) => Promise<Message.CumulusMessage>;
|
|
28
84
|
//# sourceMappingURL=StepFunctions.d.ts.map
|
package/StepFunctions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepFunctions.d.ts","sourceRoot":"","sources":["src/StepFunctions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StepFunctions.d.ts","sourceRoot":"","sources":["src/StepFunctions.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAK9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA6BzC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,qBAAqB,UACzB;IACL,OAAO,CAAC,EAAE,QAAQ,aAAa,CAAA;CAChC,KACA,QAAQ,OAAO,CAyBjB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,gBACd,QAAQ,UAAU,YACrB,MAAM,oCAkBjB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,WACpB,IAAI,aAAa,CAAC,YAAY,EAAE,mBACvB;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,WAehC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,WACtB,IAAI,aAAa,CAAC,YAAY,EAAE,KACvC,IAAI,aAAa,CAAC,YAAY,GAAG,SAInC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,wBACf,QAAQ,cAAc,gCACd,0BAA0B;;;;;;;;;EAwCxD,CAAC;AAEF,eAAO,MAAM,mCAAmC;;sCA2B/C,CAAC"}
|
package/StepFunctions.js
CHANGED
|
@@ -22,20 +22,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.parseStepMessage = exports.pullStepFunctionEvent = void 0;
|
|
26
|
-
/**
|
|
27
|
-
* Utility functions for working with AWS Step Function events/messages
|
|
28
|
-
* @module StepFunctions
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* const StepFunctions = require('@cumulus/message/StepFunctions');
|
|
32
|
-
*/
|
|
25
|
+
exports.getCumulusMessageFromExecutionEvent = exports.getFailedExecutionMessage = exports.lastFailedEventStep = exports.getFailedStepName = exports.parseStepMessage = exports.pullStepFunctionEvent = void 0;
|
|
33
26
|
const jsonpath_plus_1 = require("jsonpath-plus");
|
|
27
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
28
|
+
const set_1 = __importDefault(require("lodash/set"));
|
|
29
|
+
const StepFunctions_1 = require("@cumulus/aws-client/StepFunctions");
|
|
30
|
+
const execution_history_1 = require("@cumulus/common/execution-history");
|
|
34
31
|
const s3Utils = __importStar(require("@cumulus/aws-client/S3"));
|
|
35
32
|
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
33
|
+
const Executions_1 = require("./Executions");
|
|
36
34
|
const log = new logger_1.default({
|
|
37
35
|
sender: '@cumulus/message/StepFunctions',
|
|
38
36
|
});
|
|
37
|
+
const executionStatusToWorkflowStatus = (executionStatus) => {
|
|
38
|
+
const statusMap = {
|
|
39
|
+
ABORTED: 'failed',
|
|
40
|
+
FAILED: 'failed',
|
|
41
|
+
RUNNING: 'running',
|
|
42
|
+
SUCCEEDED: 'completed',
|
|
43
|
+
TIMED_OUT: 'failed',
|
|
44
|
+
};
|
|
45
|
+
return statusMap[executionStatus];
|
|
46
|
+
};
|
|
39
47
|
/**
|
|
40
48
|
* Given a Step Function event, replace specified key in event with contents
|
|
41
49
|
* of S3 remote message
|
|
@@ -100,4 +108,115 @@ const parseStepMessage = async (stepMessage, stepName) => {
|
|
|
100
108
|
return parsedMessage;
|
|
101
109
|
};
|
|
102
110
|
exports.parseStepMessage = parseStepMessage;
|
|
111
|
+
/**
|
|
112
|
+
* Searches the Execution step History for the TaskStateEntered pertaining to
|
|
113
|
+
* the failed task Id. HistoryEvent ids are numbered sequentially, starting at
|
|
114
|
+
* one.
|
|
115
|
+
*
|
|
116
|
+
* @param {HistoryEvent[]} events - Step Function events array
|
|
117
|
+
* @param {HistoryEvent} failedStepEvent - Step Function's failed event.
|
|
118
|
+
* @returns {string} name of the current stepfunction task or 'UnknownFailedStepName'.
|
|
119
|
+
*/
|
|
120
|
+
const getFailedStepName = (events, failedStepEvent) => {
|
|
121
|
+
var _a, _b;
|
|
122
|
+
try {
|
|
123
|
+
const previousEvents = events.slice(0, failedStepEvent.id - 1);
|
|
124
|
+
const startEvents = previousEvents.filter((e) => e.type === 'TaskStateEntered');
|
|
125
|
+
const stateName = (_b = (_a = startEvents.pop()) === null || _a === void 0 ? void 0 : _a.stateEnteredEventDetails) === null || _b === void 0 ? void 0 : _b.name;
|
|
126
|
+
if (!stateName)
|
|
127
|
+
throw new Error('TaskStateEntered Event Object did not have `stateEnteredEventDetails.name`');
|
|
128
|
+
return stateName;
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
log.info('Failed to determine a failed stepName from execution events.');
|
|
132
|
+
log.error(error);
|
|
133
|
+
}
|
|
134
|
+
return 'UnknownFailedStepName';
|
|
135
|
+
};
|
|
136
|
+
exports.getFailedStepName = getFailedStepName;
|
|
137
|
+
/**
|
|
138
|
+
* Finds all failed execution events and returns the last one in the list.
|
|
139
|
+
*
|
|
140
|
+
* @param {Array<HistoryEventList>} events - array of AWS Stepfunction execution HistoryEvents
|
|
141
|
+
* @returns {HistoryEvent[]} - the last lambda or activity that failed in the
|
|
142
|
+
* event array, or an empty array.
|
|
143
|
+
*/
|
|
144
|
+
const lastFailedEventStep = (events) => {
|
|
145
|
+
const failures = events.filter((event) => ['LambdaFunctionFailed', 'ActivityFailed'].includes(event.type));
|
|
146
|
+
return failures.pop();
|
|
147
|
+
};
|
|
148
|
+
exports.lastFailedEventStep = lastFailedEventStep;
|
|
149
|
+
/**
|
|
150
|
+
* Get message to use for publishing failed execution notifications.
|
|
151
|
+
*
|
|
152
|
+
* Try to get the input to the last failed step in the execution so we can
|
|
153
|
+
* update the status of any granules/PDRs that don't exist in the initial execution
|
|
154
|
+
* input.
|
|
155
|
+
*
|
|
156
|
+
* Falls back to overall execution input.
|
|
157
|
+
*
|
|
158
|
+
* @param {Object} inputCumulusMessage - Workflow execution input message
|
|
159
|
+
* @param {Function} getExecutionHistoryFunction - Testing override for mock/etc of
|
|
160
|
+
* StepFunctions.getExecutionHistory
|
|
161
|
+
* @returns {Object} - CumulusMessage Execution step message or execution input message
|
|
162
|
+
*/
|
|
163
|
+
const getFailedExecutionMessage = async (inputCumulusMessage, getExecutionHistoryFunction = StepFunctions_1.getExecutionHistory) => {
|
|
164
|
+
const amendedCumulusMessage = { ...inputCumulusMessage };
|
|
165
|
+
try {
|
|
166
|
+
const executionArn = (0, Executions_1.getMessageExecutionArn)(amendedCumulusMessage);
|
|
167
|
+
if (!executionArn) {
|
|
168
|
+
throw new Error('No execution arn found');
|
|
169
|
+
}
|
|
170
|
+
const { events } = await getExecutionHistoryFunction({ executionArn });
|
|
171
|
+
const lastFailedEvent = (0, exports.lastFailedEventStep)(events);
|
|
172
|
+
if (!lastFailedEvent) {
|
|
173
|
+
log.warn(`No failed step events found in execution ${executionArn}`);
|
|
174
|
+
return amendedCumulusMessage;
|
|
175
|
+
}
|
|
176
|
+
const failedExecutionStepName = (0, exports.getFailedStepName)(events, lastFailedEvent);
|
|
177
|
+
const failedStepExitedEvent = (0, execution_history_1.getStepExitedEvent)(events, lastFailedEvent);
|
|
178
|
+
if (!failedStepExitedEvent) {
|
|
179
|
+
log.info(`Could not retrieve output from last failed step in execution ${executionArn}, falling back to execution input`);
|
|
180
|
+
log.info(`Could not find TaskStateExited event after step ID ${lastFailedEvent.id} for execution ${executionArn}`);
|
|
181
|
+
return {
|
|
182
|
+
...amendedCumulusMessage,
|
|
183
|
+
exception: {
|
|
184
|
+
...lastFailedEvent.activityFailedEventDetails,
|
|
185
|
+
...lastFailedEvent.lambdaFunctionFailedEventDetails,
|
|
186
|
+
failedExecutionStepName,
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const taskExitedEventOutput = JSON.parse((0, execution_history_1.getTaskExitedEventOutput)(failedStepExitedEvent) || '{}');
|
|
191
|
+
taskExitedEventOutput.exception = {
|
|
192
|
+
...taskExitedEventOutput.exception,
|
|
193
|
+
failedExecutionStepName,
|
|
194
|
+
};
|
|
195
|
+
return await (0, exports.parseStepMessage)(taskExitedEventOutput, failedExecutionStepName);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
log.error('getFailedExecution failed to retrieve failure:', error);
|
|
199
|
+
return amendedCumulusMessage;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
exports.getFailedExecutionMessage = getFailedExecutionMessage;
|
|
203
|
+
const getCumulusMessageFromExecutionEvent = async (executionEvent) => {
|
|
204
|
+
let cumulusMessage;
|
|
205
|
+
if (executionEvent.detail.status === 'RUNNING') {
|
|
206
|
+
cumulusMessage = JSON.parse(executionEvent.detail.input);
|
|
207
|
+
}
|
|
208
|
+
else if (executionEvent.detail.status === 'SUCCEEDED') {
|
|
209
|
+
cumulusMessage = JSON.parse(executionEvent.detail.output);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
const inputMessage = JSON.parse((0, get_1.default)(executionEvent, 'detail.input', '{}'));
|
|
213
|
+
cumulusMessage = await (0, exports.getFailedExecutionMessage)(inputMessage);
|
|
214
|
+
}
|
|
215
|
+
const fullCumulusMessage = (await (0, exports.pullStepFunctionEvent)(cumulusMessage));
|
|
216
|
+
const workflowStatus = executionStatusToWorkflowStatus(executionEvent.detail.status);
|
|
217
|
+
(0, set_1.default)(fullCumulusMessage, 'meta.status', workflowStatus);
|
|
218
|
+
(0, set_1.default)(fullCumulusMessage, 'cumulus_meta.workflow_stop_time', executionEvent.detail.stopDate);
|
|
219
|
+
return fullCumulusMessage;
|
|
220
|
+
};
|
|
221
|
+
exports.getCumulusMessageFromExecutionEvent = getCumulusMessageFromExecutionEvent;
|
|
103
222
|
//# sourceMappingURL=StepFunctions.js.map
|
package/StepFunctions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StepFunctions.js","sourceRoot":"","sources":["src/StepFunctions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"StepFunctions.js","sourceRoot":"","sources":["src/StepFunctions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AAWb,iDAAyC;AACzC,qDAA6B;AAC7B,qDAA6B;AAE7B,qEAAwE;AACxE,yEAAiG;AAEjG,gEAAkD;AAClD,6DAAqC;AAErC,6CAAsD;AAEtD,MAAM,GAAG,GAAG,IAAI,gBAAM,CAAC;IACrB,MAAM,EAAE,gCAAgC;CACzC,CAAC,CAAC;AAOH,MAAM,+BAA+B,GAAG,CACtC,eAAgC,EACR,EAAE;IAC1B,MAAM,SAAS,GAAuC;QACpD,OAAO,EAAE,QAAQ;QACjB,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE,SAAS;QAClB,SAAS,EAAE,WAAW;QACtB,SAAS,EAAE,QAAQ;KACpB,CAAC;IAEF,OAAO,SAAS,CAAC,eAAe,CAAC,CAA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AC,CAAC;KAChE;IAED,MAAM,kBAAkB,GAAG,CAAC,MAAM,IAAA,6BAAqB,EACrD,cAAc,CACf,CAA2B,CAAC;IAE7B,MAAM,cAAc,GAAG,+BAA+B,CACpD,cAAc,CAAC,MAAM,CAAC,MAAyB,CAChD,CAAC;IACF,IAAA,aAAG,EAAC,kBAAkB,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC;IAEvD,IAAA,aAAG,EACD,kBAAkB,EAClB,iCAAiC,EACjC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAC/B,CAAC;IAEF,OAAO,kBAAkB,CAAC;AAC5B,CAAC,CAAC;AA3BW,QAAA,mCAAmC,uCA2B9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulus/message",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.9.3",
|
|
4
4
|
"description": "Utilities for building and parsing Cumulus messages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"GIBS",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"author": "Cumulus Authors",
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@cumulus/aws-client": "9.
|
|
42
|
-
"@cumulus/common": "9.
|
|
43
|
-
"@cumulus/errors": "9.
|
|
44
|
-
"@cumulus/logger": "9.
|
|
45
|
-
"@cumulus/types": "9.
|
|
41
|
+
"@cumulus/aws-client": "9.9.3",
|
|
42
|
+
"@cumulus/common": "9.9.3",
|
|
43
|
+
"@cumulus/errors": "9.9.3",
|
|
44
|
+
"@cumulus/logger": "9.9.3",
|
|
45
|
+
"@cumulus/types": "9.9.3",
|
|
46
46
|
"jsonpath-plus": "^3.0.0",
|
|
47
47
|
"lodash": "^4.17.20",
|
|
48
48
|
"uuid": "^8.2.0"
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/uuid": "^8.0.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "3cba9ad17e8251719df6710c57ca1e992babdc22"
|
|
54
54
|
}
|
package/src/Build.ts
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SQSRecord, EventBridgeEvent } from 'aws-lambda';
|
|
2
|
+
|
|
3
|
+
import { parseSQSMessageBody } from '@cumulus/aws-client/SQS';
|
|
4
|
+
import { CumulusMessage } from '@cumulus/types/message';
|
|
5
|
+
import Logger from '@cumulus/logger';
|
|
6
|
+
|
|
7
|
+
import { getCumulusMessageFromExecutionEvent } from './StepFunctions';
|
|
8
|
+
|
|
9
|
+
const log = new Logger({ sender: '@cumulus/DeadLetterMessage' });
|
|
10
|
+
|
|
11
|
+
type StepFunctionEventBridgeEvent = EventBridgeEvent<'Step Functions Execution Status Change', { [key: string]: string }>;
|
|
12
|
+
type UnwrapDeadLetterCumulusMessageReturnType = (
|
|
13
|
+
StepFunctionEventBridgeEvent
|
|
14
|
+
| AWS.SQS.Message
|
|
15
|
+
| SQSRecord
|
|
16
|
+
| CumulusMessage
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Unwrap dead letter Cumulus message, which may be wrapped in a
|
|
21
|
+
* States cloudwatch event, which is wrapped in an SQS message.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} messageBody - received SQS message
|
|
24
|
+
* @returns {Object} the cumulus message or nearest available object
|
|
25
|
+
*/
|
|
26
|
+
export const unwrapDeadLetterCumulusMessage = async (
|
|
27
|
+
messageBody: UnwrapDeadLetterCumulusMessageReturnType
|
|
28
|
+
): Promise<UnwrapDeadLetterCumulusMessageReturnType> => {
|
|
29
|
+
try {
|
|
30
|
+
if ('cumulus_meta' in messageBody) {
|
|
31
|
+
return messageBody;
|
|
32
|
+
}
|
|
33
|
+
if ('Body' in messageBody || 'body' in messageBody) {
|
|
34
|
+
// AWS.SQS.Message/SQS.Record case
|
|
35
|
+
const unwrappedMessageBody = parseSQSMessageBody(
|
|
36
|
+
messageBody
|
|
37
|
+
) as CumulusMessage;
|
|
38
|
+
return await unwrapDeadLetterCumulusMessage(unwrappedMessageBody);
|
|
39
|
+
}
|
|
40
|
+
if (!('detail' in messageBody)) {
|
|
41
|
+
// Non-typed catchall
|
|
42
|
+
return messageBody;
|
|
43
|
+
}
|
|
44
|
+
// StepFunctionEventBridgeEvent case
|
|
45
|
+
const unwrappedMessageBody = await getCumulusMessageFromExecutionEvent(messageBody);
|
|
46
|
+
return await unwrapDeadLetterCumulusMessage(unwrappedMessageBody);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
log.error(
|
|
49
|
+
'Falling back to storing wrapped message after encountering unwrap error',
|
|
50
|
+
error
|
|
51
|
+
);
|
|
52
|
+
return messageBody;
|
|
53
|
+
}
|
|
54
|
+
};
|