@cumulus/message 10.0.0 → 10.1.1-alpha.0

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/PDRs.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Message } from '@cumulus/types';
2
+ import { ApiPdr } from '@cumulus/types/api/pdrs';
2
3
  interface PDR {
3
4
  name: string;
4
5
  PANSent: boolean;
@@ -7,11 +8,6 @@ interface PDR {
7
8
  interface MessageWithOptionalPayloadPdr extends Message.CumulusMessage {
8
9
  payload: {
9
10
  pdr?: PDR;
10
- };
11
- }
12
- interface MessageWithOptionalPdrStats extends Message.CumulusMessage {
13
- payload: {
14
- pdr: PDR;
15
11
  failed?: unknown[];
16
12
  running?: unknown[];
17
13
  completed?: unknown[];
@@ -71,30 +67,30 @@ export declare const getMessagePdrName: (message: MessageWithOptionalPayloadPdr)
71
67
  /**
72
68
  * Get the number of running executions for a PDR, if any.
73
69
  *
74
- * @param {MessageWithOptionalPdrStats} message - A workflow message
70
+ * @param {MessageWithOptionalPayloadPdr} message - A workflow message
75
71
  * @returns {number} Number of running executions
76
72
  *
77
73
  * @alias module:PDRs
78
74
  */
79
- export declare const getMessagePdrRunningExecutions: (message: MessageWithOptionalPdrStats) => number;
75
+ export declare const getMessagePdrRunningExecutions: (message: MessageWithOptionalPayloadPdr) => number;
80
76
  /**
81
77
  * Get the number of completed executions for a PDR, if any.
82
78
  *
83
- * @param {MessageWithOptionalPdrStats} message - A workflow message
79
+ * @param {MessageWithOptionalPayloadPdr} message - A workflow message
84
80
  * @returns {number} Number of completed executions
85
81
  *
86
82
  * @alias module:PDRs
87
83
  */
88
- export declare const getMessagePdrCompletedExecutions: (message: MessageWithOptionalPdrStats) => number;
84
+ export declare const getMessagePdrCompletedExecutions: (message: MessageWithOptionalPayloadPdr) => number;
89
85
  /**
90
86
  * Get the number of failed executions for a PDR, if any.
91
87
  *
92
- * @param {MessageWithOptionalPdrStats} message - A workflow message
88
+ * @param {MessageWithOptionalPayloadPdr} message - A workflow message
93
89
  * @returns {number} Number of failed executions
94
90
  *
95
91
  * @alias module:PDRs
96
92
  */
97
- export declare const getMessagePdrFailedExecutions: (message: MessageWithOptionalPdrStats) => number;
93
+ export declare const getMessagePdrFailedExecutions: (message: MessageWithOptionalPayloadPdr) => number;
98
94
  /**
99
95
  * Get the PDR stats from a workflow message, if any.
100
96
  *
@@ -104,7 +100,7 @@ export declare const getMessagePdrFailedExecutions: (message: MessageWithOptiona
104
100
  *
105
101
  * @alias module:PDRs
106
102
  */
107
- export declare const getMessagePdrStats: (message: MessageWithOptionalPdrStats) => PdrStats;
103
+ export declare const getMessagePdrStats: (message: MessageWithOptionalPayloadPdr) => PdrStats;
108
104
  /**
109
105
  * Get the percent completion of PDR executions
110
106
  *
@@ -114,5 +110,15 @@ export declare const getMessagePdrStats: (message: MessageWithOptionalPdrStats)
114
110
  * @alias module:PDRs
115
111
  */
116
112
  export declare const getPdrPercentCompletion: (stats: PdrStats) => number;
113
+ /**
114
+ * Generate a PDR record for the API from the message.
115
+ *
116
+ * @param {MessageWithOptionalPayloadPdr} message - A workflow message object
117
+ * @param {string} [updatedAt] - Optional updated timestamp to apply to record
118
+ * @returns {ExecutionRecord} An PDR API record
119
+ *
120
+ * @alias module:Executions
121
+ */
122
+ export declare const generatePdrApiRecordFromMessage: (message: MessageWithOptionalPayloadPdr, updatedAt?: number) => ApiPdr | undefined;
117
123
  export {};
118
124
  //# sourceMappingURL=PDRs.d.ts.map
package/PDRs.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"PDRs.d.ts","sourceRoot":"","sources":["src/PDRs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,UAAU,GAAG;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,UAAU,6BAA8B,SAAQ,OAA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gCAAgC,YAClC,6BAA6B,KACrC,MAAkD,CAAC;AAEtD;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,YAC/B,6BAA6B,KACrC,MAA+C,CAAC;AAEnD;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,YACpB,6BAA6B,KACrC,QAWF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,UAC3B,QAAQ,KACd,MAQF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,+BAA+B,YACjC,6BAA6B,yBAErC,MAAM,GAAG,SAyDX,CAAC"}
package/PDRs.js CHANGED
@@ -1,6 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPdrPercentCompletion = exports.getMessagePdrStats = exports.getMessagePdrFailedExecutions = exports.getMessagePdrCompletedExecutions = exports.getMessagePdrRunningExecutions = exports.getMessagePdrName = exports.getMessagePdrPANMessage = exports.getMessagePdrPANSent = exports.messageHasPdr = exports.getMessagePdr = void 0;
6
+ exports.generatePdrApiRecordFromMessage = exports.getPdrPercentCompletion = exports.getMessagePdrStats = exports.getMessagePdrFailedExecutions = exports.getMessagePdrCompletedExecutions = exports.getMessagePdrRunningExecutions = exports.getMessagePdrName = exports.getMessagePdrPANMessage = exports.getMessagePdrPANSent = exports.messageHasPdr = exports.getMessagePdr = void 0;
7
+ const errors_1 = require("@cumulus/errors");
8
+ const logger_1 = __importDefault(require("@cumulus/logger"));
9
+ const Collections_1 = require("./Collections");
10
+ const Executions_1 = require("./Executions");
11
+ const Providers_1 = require("./Providers");
12
+ const workflows_1 = require("./workflows");
13
+ const logger = new logger_1.default({ sender: '@cumulus/message/PDRs' });
4
14
  /**
5
15
  * Get the PDR object from a workflow message, if any.
6
16
  *
@@ -54,7 +64,7 @@ exports.getMessagePdrName = getMessagePdrName;
54
64
  /**
55
65
  * Get the number of running executions for a PDR, if any.
56
66
  *
57
- * @param {MessageWithOptionalPdrStats} message - A workflow message
67
+ * @param {MessageWithOptionalPayloadPdr} message - A workflow message
58
68
  * @returns {number} Number of running executions
59
69
  *
60
70
  * @alias module:PDRs
@@ -64,7 +74,7 @@ exports.getMessagePdrRunningExecutions = getMessagePdrRunningExecutions;
64
74
  /**
65
75
  * Get the number of completed executions for a PDR, if any.
66
76
  *
67
- * @param {MessageWithOptionalPdrStats} message - A workflow message
77
+ * @param {MessageWithOptionalPayloadPdr} message - A workflow message
68
78
  * @returns {number} Number of completed executions
69
79
  *
70
80
  * @alias module:PDRs
@@ -74,7 +84,7 @@ exports.getMessagePdrCompletedExecutions = getMessagePdrCompletedExecutions;
74
84
  /**
75
85
  * Get the number of failed executions for a PDR, if any.
76
86
  *
77
- * @param {MessageWithOptionalPdrStats} message - A workflow message
87
+ * @param {MessageWithOptionalPayloadPdr} message - A workflow message
78
88
  * @returns {number} Number of failed executions
79
89
  *
80
90
  * @alias module:PDRs
@@ -122,4 +132,63 @@ const getPdrPercentCompletion = (stats) => {
122
132
  return progress;
123
133
  };
124
134
  exports.getPdrPercentCompletion = getPdrPercentCompletion;
135
+ /**
136
+ * Generate a PDR record for the API from the message.
137
+ *
138
+ * @param {MessageWithOptionalPayloadPdr} message - A workflow message object
139
+ * @param {string} [updatedAt] - Optional updated timestamp to apply to record
140
+ * @returns {ExecutionRecord} An PDR API record
141
+ *
142
+ * @alias module:Executions
143
+ */
144
+ const generatePdrApiRecordFromMessage = (message, updatedAt = Date.now()) => {
145
+ const pdr = (0, exports.getMessagePdr)(message);
146
+ // We got a message with no PDR (OK)
147
+ if (!pdr) {
148
+ logger.info('No PDRs to process on the message');
149
+ return undefined;
150
+ }
151
+ // We got a message with a PDR but no name to identify it (Not OK)
152
+ if (!pdr.name) {
153
+ throw new errors_1.CumulusMessageError(`Could not find name on PDR object ${JSON.stringify(pdr)}`);
154
+ }
155
+ const collectionId = (0, Collections_1.getCollectionIdFromMessage)(message);
156
+ if (!collectionId) {
157
+ throw new errors_1.CumulusMessageError('meta.collection required to generate a PDR record');
158
+ }
159
+ const providerId = (0, Providers_1.getMessageProviderId)(message);
160
+ if (!providerId) {
161
+ throw new errors_1.CumulusMessageError('meta.provider required to generate a PDR record');
162
+ }
163
+ const status = (0, workflows_1.getMetaStatus)(message);
164
+ if (!status) {
165
+ throw new errors_1.CumulusMessageError('meta.status required to generate a PDR record');
166
+ }
167
+ const arn = (0, Executions_1.getMessageExecutionArn)(message);
168
+ if (!arn) {
169
+ throw new errors_1.CumulusMessageError('cumulus_meta.state_machine and cumulus_meta.execution_name required to generate a PDR record');
170
+ }
171
+ const execution = (0, Executions_1.getExecutionUrlFromArn)(arn);
172
+ const stats = (0, exports.getMessagePdrStats)(message);
173
+ const progress = (0, exports.getPdrPercentCompletion)(stats);
174
+ const now = Date.now();
175
+ const workflowStartTime = (0, workflows_1.getMessageWorkflowStartTime)(message);
176
+ const record = {
177
+ pdrName: pdr.name,
178
+ collectionId,
179
+ status,
180
+ provider: providerId,
181
+ progress,
182
+ execution,
183
+ PANSent: (0, exports.getMessagePdrPANSent)(message),
184
+ PANmessage: (0, exports.getMessagePdrPANMessage)(message),
185
+ stats,
186
+ createdAt: (0, workflows_1.getMessageWorkflowStartTime)(message),
187
+ timestamp: now,
188
+ updatedAt,
189
+ duration: (0, workflows_1.getWorkflowDuration)(workflowStartTime, now),
190
+ };
191
+ return record;
192
+ };
193
+ exports.generatePdrApiRecordFromMessage = generatePdrApiRecordFromMessage;
125
194
  //# sourceMappingURL=PDRs.js.map
package/PDRs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"PDRs.js","sourceRoot":"","sources":["src/PDRs.ts"],"names":[],"mappings":";;;AA8BA;;;;;;;GAOG;AACI,MAAM,aAAa,GAAG,CAC3B,OAAsC,EACrB,EAAE,WAAC,OAAA,MAAA,OAAO,CAAC,OAAO,0CAAE,GAAG,CAAA,EAAA,CAAC;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,IAAA,mCAAsB,EAAC,GAAG,CAAC,CAAC;IAE9C,MAAM,KAAK,GAAG,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,IAAA,+BAAuB,EAAC,KAAK,CAAC,CAAC;IAChD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,iBAAiB,GAAG,IAAA,uCAA2B,EAAC,OAAO,CAAC,CAAC;IAE/D,MAAM,MAAM,GAAG;QACb,OAAO,EAAE,GAAG,CAAC,IAAI;QACjB,YAAY;QACZ,MAAM;QACN,QAAQ,EAAE,UAAU;QACpB,QAAQ;QACR,SAAS;QACT,OAAO,EAAE,IAAA,4BAAoB,EAAC,OAAO,CAAC;QACtC,UAAU,EAAE,IAAA,+BAAuB,EAAC,OAAO,CAAC;QAC5C,KAAK;QACL,SAAS,EAAE,IAAA,uCAA2B,EAAC,OAAO,CAAC;QAC/C,SAAS,EAAE,GAAG;QACd,SAAS;QACT,QAAQ,EAAE,IAAA,+BAAmB,EAAC,iBAAiB,EAAE,GAAG,CAAC;KACtD,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA5DW,QAAA,+BAA+B,mCA4D1C"}
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"StepFunctions.d.ts","sourceRoot":"","sources":["src/StepFunctions.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAMzC;;;;;;;;;;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"}
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
@@ -1 +1 @@
1
- {"version":3,"file":"StepFunctions.js","sourceRoot":"","sources":["src/StepFunctions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AAEb;;;;;;GAMG;AAEH,iDAAyC;AACzC,gEAAkD;AAClD,6DAAqC;AAGrC,MAAM,GAAG,GAAG,IAAI,gBAAM,CAAC;IACrB,MAAM,EAAE,gCAAgC;CACzC,CAAC,CAAC;AAEH;;;;;;;;;;GAUG;AACI,MAAM,qBAAqB,GAAG,KAAK,EACxC,KAEC,EACiB,EAAE;IACpB,IAAI,CAAC,KAAK,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAEjC,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,eAAe,CAC7C,KAAK,CAAC,OAAO,CAAC,MAAM,EACpB,KAAK,CAAC,OAAO,CAAC,GAAG,CAClB,CAAC;IAEF,IAAI,WAAW,GAAG,SAAS,CAAC;IAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE;QAC5B,MAAM,iBAAiB,GAAG,IAAA,wBAAQ,EAAC;YACjC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU;YAC9B,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AAqB,CAAC;KAC9B;AACH,CAAC,CAAC;AA1CW,QAAA,yBAAyB,6BA0CpC;AAEK,MAAM,mCAAmC,GAAG,KAAK,EAAE,cAAqG,EAAE,EAAE;IACjK,IAAI,cAAc,CAAC;IACnB,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE;QAC9C,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;KAC1D;SAAM,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW,EAAE;QACvD,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KAC3D;SAAM;QACL,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,aAAG,EAAC,cAAc,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC;QAC3E,cAAc,GAAG,MAAM,IAAA,iCAAyB,EAAC,YAAY,CAAC,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": "10.0.0",
3
+ "version": "10.1.1-alpha.0",
4
4
  "description": "Utilities for building and parsing Cumulus messages",
5
5
  "keywords": [
6
6
  "GIBS",
@@ -49,6 +49,5 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/uuid": "^8.0.0"
52
- },
53
- "gitHead": "7c6d2d1cd79b57d6943bbc3d898d0cf975b543b1"
52
+ }
54
53
  }
package/src/Build.ts CHANGED
@@ -10,9 +10,9 @@
10
10
  */
11
11
 
12
12
  import merge from 'lodash/merge';
13
+
13
14
  import { Message } from '@cumulus/types';
14
15
  import { v4 as uuidv4 } from 'uuid';
15
-
16
16
  import {
17
17
  WorkflowMessageTemplate,
18
18
  WorkflowMessageTemplateCumulusMeta,
@@ -17,6 +17,8 @@ type CollectionInfo = {
17
17
  version: string
18
18
  };
19
19
 
20
+ export const collectionIdSeparator = '___';
21
+
20
22
  /**
21
23
  * Returns the collection ID.
22
24
  *
@@ -27,7 +29,7 @@ type CollectionInfo = {
27
29
  * @alias module:Collections
28
30
  */
29
31
  export const constructCollectionId = (name: string, version: string) =>
30
- `${name}___${version}`;
32
+ `${name}${collectionIdSeparator}${version}`;
31
33
 
32
34
  /**
33
35
  * Returns the name and version of a collection based on
@@ -35,12 +37,14 @@ export const constructCollectionId = (name: string, version: string) =>
35
37
  *
36
38
  * @param {string} collectionId - collectionId used in elasticsearch index
37
39
  * @returns {Object} name and version as object
40
+ *
41
+ * @alias module:Collections
38
42
  */
39
43
  export const deconstructCollectionId = (collectionId: string) => {
40
44
  let name;
41
45
  let version;
42
46
  try {
43
- [name, version] = collectionId.split('___');
47
+ [name, version] = collectionId.split(collectionIdSeparator);
44
48
  } catch (error) {
45
49
  throw new Error(`invalid collectionId: ${JSON.stringify(collectionId)}`);
46
50
  }
@@ -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
+ };