-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CUMULUS-436: Add activities support to @cumulus/integration-tests #277
Merged
abarciauskas-bgse
merged 16 commits into
master
from
abarciauskas-bgse_integration-tests-activities
Mar 29, 2018
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
54889cd
Update lambda.js for activities
abarciauskas-bgse 903c78c
Rename lambda module to sfnStep
abarciauskas-bgse 7825445
Add item to changelog
abarciauskas-bgse 990055e
Minor formatting
abarciauskas-bgse 8908084
Fix eslint errors
abarciauskas-bgse 4284251
Add name to root package.json
abarciauskas-bgse b4ca277
Use valid name
abarciauskas-bgse 0d48e2c
Revert chage to package.json
abarciauskas-bgse 1d984a0
Update .eslint-ratchet-high-water-mark
abarciauskas-bgse 4819f66
Merge branch 'master' into abarciauskas-bgse_integration-tests-activi…
abarciauskas-bgse 1d9f3ef
Return succeeded details without unnecessary const
abarciauskas-bgse 0764060
Add getLambdaOutput map to sfnStep.LambdaStep.getStepOutput
abarciauskas-bgse 5bd08d7
Refactor executionArn
abarciauskas-bgse d0c90e1
simplify conditional for scheduleEvent presence
abarciauskas-bgse c099a12
Update eslint-ratchet-high-water-mark
abarciauskas-bgse 002aa07
Merge branch 'master' into abarciauskas-bgse_integration-tests-activi…
abarciauskas-bgse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1348 | ||
1344 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
'use strict'; | ||
|
||
const { sfn } = require('@cumulus/common/aws'); | ||
|
||
/** | ||
* `SfnStep` provides methods for getting the output of a step within an AWS | ||
* Step Function for a specific execution. | ||
*/ | ||
class SfnStep { | ||
/** | ||
* `getStartEvent` gets the "start" event for a step, given its schedule event | ||
* | ||
* @param {Object} executionHistory - AWS Step Function execution history | ||
* @param {Object} scheduleEvent - AWS Step Function schedule-type event | ||
* @returns {Object} - AWS Step Function start-type event | ||
*/ | ||
getStartEvent(executionHistory, scheduleEvent) { | ||
return executionHistory.events.find((event) => { | ||
const isStartEvent = this.startEvents.includes(event.type); | ||
const previousEventIsScheduleEvent = event.previousEventId === scheduleEvent.id; | ||
return isStartEvent && previousEventIsScheduleEvent; | ||
}); | ||
} | ||
|
||
/** | ||
* `getCompletionEvent` gets the "completion" event for a step, given its start event | ||
* | ||
* @param {Object} executionHistory - AWS Step Function execution history | ||
* @param {Object} startEvent - AWS Step Function start-type event | ||
* @returns {Object} - AWS Step Function completion-type event | ||
*/ | ||
getCompletionEvent(executionHistory, startEvent) { | ||
return executionHistory.events.find((event) => { | ||
const isCompletionEvent = this.completionEvents.includes(event.type); | ||
const previousEventIsStartEvent = event.previousEventId === startEvent.id; | ||
return isCompletionEvent && previousEventIsStartEvent; | ||
}); | ||
} | ||
|
||
/** | ||
* Get the events for the step execution for the given workflow execution. | ||
* This function currently assumes one execution of the given step (by step name) per workflow. | ||
* | ||
* @param {string} workflowExecutionArn - Arn of the workflow execution | ||
* @param {string} stepName - name of the step | ||
* @returns {Object} an object containing a schedule event, start event, and complete | ||
* event if exist, null if cannot find the step | ||
*/ | ||
async getStepExecution(workflowExecutionArn, stepName) { | ||
const executionHistory = ( | ||
await sfn().getExecutionHistory({ executionArn: workflowExecutionArn }).promise() | ||
); | ||
|
||
// Get the event where the step was scheduled | ||
const scheduleEvent = executionHistory.events.find((event) => { | ||
const eventScheduled = this.scheduleEvents.includes(event.type); | ||
const eventDetails = event[this.eventDetailsKeys.scheduled]; | ||
const isStepEvent = eventDetails && eventDetails.resource.includes(stepName); | ||
return eventScheduled && isStepEvent; | ||
}); | ||
|
||
if (!scheduleEvent) { | ||
console.log(`Could not find step ${stepName} in execution.`); | ||
return null; | ||
} | ||
|
||
let startEvent = null; | ||
let completeEvent = null; | ||
|
||
if (scheduleEvent.type !== this.startFailedEvent) { | ||
startEvent = this.getStartEvent(executionHistory, scheduleEvent, this); | ||
|
||
if (startEvent !== null && startEvent.type !== this.startFailedEvent) { | ||
completeEvent = this.getCompletionEvent(executionHistory, startEvent, this); | ||
} | ||
} | ||
|
||
return { scheduleEvent, startEvent, completeEvent }; | ||
} | ||
|
||
/** | ||
* Get the output payload from the step, if the step succeeds | ||
* | ||
* @param {string} workflowExecutionArn - Arn of the workflow execution | ||
* @param {string} stepName - name of the step | ||
* @returns {Object} object containing the payload, null if error | ||
*/ | ||
async getStepOutput(workflowExecutionArn, stepName) { | ||
const stepExecution = await this.getStepExecution(workflowExecutionArn, stepName, this); | ||
|
||
if (stepExecution === null) { | ||
console.log(`Could not find step ${stepName} in execution.`); | ||
return null; | ||
} | ||
|
||
if (stepExecution.completeEvent === null || | ||
stepExecution.completeEvent.type !== this.successEvent) { | ||
console.log(`Step ${stepName} was not successful.`); | ||
return null; | ||
} | ||
|
||
return JSON.parse(stepExecution.completeEvent[this.eventDetailsKeys.succeeded].output.toString()); | ||
} | ||
} | ||
|
||
/** | ||
* `LambdaStep` is a step inside a step function that runs an AWS Lambda function. | ||
*/ | ||
class LambdaStep extends SfnStep { | ||
//eslint-disable-next-line require-jsdoc | ||
constructor() { | ||
super(); | ||
this.scheduleFailedEvent = 'LambdaFunctionScheduleFailed'; | ||
this.scheduleEvents = [ | ||
this.scheduleFailedEvent, | ||
'LambdaFunctionScheduled' | ||
]; | ||
this.startFailedEvent = 'LambdaFunctionStartFailed'; | ||
this.startEvents = [ | ||
this.startFailedEvent, | ||
'LambdaFunctionStarted' | ||
]; | ||
this.successEvent = 'LambdaFunctionSucceeded'; | ||
this.completionEvents = [ | ||
this.successEvent, | ||
'LambdaFunctionFailed', | ||
'LambdaFunctionTimedOut' | ||
]; | ||
this.eventDetailsKeys = { | ||
scheduled: 'lambdaFunctionScheduledEventDetails', | ||
succeeded: 'lambdaFunctionSucceededEventDetails' | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* `ActivityStep` is a step inside a step function that runs an AWS ECS activity. | ||
*/ | ||
class ActivityStep extends SfnStep { | ||
//eslint-disable-next-line require-jsdoc | ||
constructor() { | ||
super(); | ||
this.scheduleFailedEvent = 'ActivityScheduleFailed'; | ||
this.scheduleEvents = [ | ||
'ActivityScheduled', | ||
this.scheduleFailedEvent | ||
]; | ||
this.startEvents = ['ActivityStarted']; | ||
this.startFailedEvent = undefined; // there is no 'ActivityStartFailed' | ||
this.successEvent = 'ActivitySucceeded'; | ||
this.completionEvents = [ | ||
this.successEvent, | ||
'ActivityFailed', | ||
'ActivityTimedOut' | ||
]; | ||
this.eventDetailsKeys = { | ||
scheduled: 'activityScheduledEventDetails', | ||
succeeded: 'activitySucceededEventDetails' | ||
}; | ||
} | ||
} | ||
|
||
module.exports = { | ||
ActivityStep, | ||
LambdaStep | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I usually prefer to add the eslint-disable comment on the same line that is causing the error. So, something like this:
await timeout(waitPeriodMs); // eslint-disable-line no-await-in-loop