Skip to content

Commit

Permalink
Merge pull request #54 from nasa/CUMULUS-906
Browse files Browse the repository at this point in the history
CUMULUS-906: add cumulus_context to task event message
  • Loading branch information
jennyhliu authored Nov 8, 2018
2 parents 3a82501 + e309331 commit 431b64d
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 7 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v1.0.13] - 2018-11-08

### Added
- Add `cumulus_context` attribute from `cumulus_meta[cumulus_context]` to property `cumulus_config` of task event message [CUMULUS-906]

## [v1.0.12] - 2018-09-28

### Fixed
Expand Down Expand Up @@ -147,7 +152,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Initial release

[Unreleased]: https://github.com/nasa/cumulus-message-adapter/compare/v1.0.5...HEAD
[Unreleased]: https://github.com/nasa/cumulus-message-adapter/compare/v1.0.13...HEAD
[v1.0.13]: https://github.com/nasa/cumulus-message-adapter/compare/v1.0.12...v1.0.13
[v1.0.5]: https://github.com/nasa/cumulus-message-adapter/compare/v1.0.4...v1.0.5
[v1.0.4]: https://github.com/nasa/cumulus-message-adapter/compare/v1.0.3...v1.0.4
[v1.0.3]: https://github.com/nasa/cumulus-message-adapter/compare/v1.0.2...v1.0.3
Expand Down
24 changes: 24 additions & 0 deletions examples/messages/cumulus_context.input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"workflow_config": {
"Example": {
"inlinestr": "prefix{meta.foo}suffix",
"array": "{[$.meta.foo]}",
"object": "{{$.meta}}"
}
},
"cumulus_meta": {
"message_source": "sfn",
"state_machine": "arn:aws:states:us-east-1:1234:stateMachine:MySfn",
"execution_name": "MyExecution__id-1234",
"id": "id-1234",
"cumulus_context": {
"anycontext": "anycontextvalue"
}
},
"meta": {
"foo": "bar"
},
"payload": {
"anykey": "anyvalue"
}
}
37 changes: 37 additions & 0 deletions examples/messages/cumulus_context.output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"workflow_config": {
"Example": {
"inlinestr": "prefix{meta.foo}suffix",
"array": "{[$.meta.foo]}",
"object": "{{$.meta}}"
}
},
"cumulus_meta": {
"message_source": "sfn",
"state_machine": "arn:aws:states:us-east-1:1234:stateMachine:MySfn",
"execution_name": "MyExecution__id-1234",
"id": "id-1234",
"cumulus_context": {
"anycontext": "anycontextvalue"
}
},
"meta": {
"foo": "bar"
},
"payload": {
"input": { "anykey": "anyvalue" },
"config": {
"inlinestr": "prefixbarsuffix",
"array": ["bar"],
"object": { "foo": "bar" }
},
"cumulus_config": {
"state_machine": "arn:aws:states:us-east-1:1234:stateMachine:MySfn",
"execution_name": "MyExecution__id-1234",
"cumulus_context": {
"anycontext": "anycontextvalue"
}
}
},
"exception": "None"
}
18 changes: 13 additions & 5 deletions message_adapter/message_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,20 @@ def loadNestedEvent(self, event, context):
response['messageConfig'] = config['cumulus_message']

# add cumulus_config property, only selective attributes from event.cumulus_meta are added
attributes = ['state_machine', 'execution_name']
if ('cumulus_meta' in event
and all(attribute in event['cumulus_meta'] for attribute in attributes)):
if 'cumulus_meta' in event:
response['cumulus_config'] = {}
for attribute in attributes:
response['cumulus_config'][attribute] = event['cumulus_meta'][attribute]
# add both attributes or none of them
attributes = ['state_machine', 'execution_name']
if all(attribute in event['cumulus_meta'] for attribute in attributes):
for attribute in attributes:
response['cumulus_config'][attribute] = event['cumulus_meta'][attribute]

# add attribute cumulus_context
if 'cumulus_context' in event['cumulus_meta']:
response['cumulus_config']['cumulus_context'] = event['cumulus_meta']['cumulus_context']

if not response['cumulus_config']:
del response['cumulus_config']

return response

Expand Down
2 changes: 1 addition & 1 deletion message_adapter/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = 'v1.0.12'
__version__ = 'v1.0.13'
14 changes: 14 additions & 0 deletions tests/test-module.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,20 @@ def test_templates(self):
result = self.cumulus_message_adapter.createNextEvent(msg, in_msg, messageConfig)
assert result == out_msg

@patch.object(cumulus_message_adapter, '_message_adapter__getCurrentSfnTask', return_value="Example")
def test_cumulus_context(self, getCurrentSfnTask_function):
""" test storing cumulus_context metadata """
inp = open(os.path.join(self.test_folder, 'cumulus_context.input.json'))
out = open(os.path.join(self.test_folder, 'cumulus_context.output.json'))
in_msg = json.loads(inp.read())
out_msg = json.loads(out.read())

msg = self.cumulus_message_adapter.loadNestedEvent(in_msg, {})
messageConfig = msg.get('messageConfig')
if 'messageConfig' in msg: del msg['messageConfig']
result = self.cumulus_message_adapter.createNextEvent(msg, in_msg, messageConfig)
assert result == out_msg

def test_input_jsonschema(self):
""" test a working input schema """
inp = open(os.path.join(self.test_folder, 'templates.input.json'))
Expand Down

0 comments on commit 431b64d

Please sign in to comment.