diff --git a/CHANGELOG.md b/CHANGELOG.md index 4859097..ec269ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/examples/messages/cumulus_context.input.json b/examples/messages/cumulus_context.input.json new file mode 100644 index 0000000..f0b0537 --- /dev/null +++ b/examples/messages/cumulus_context.input.json @@ -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" + } +} diff --git a/examples/messages/cumulus_context.output.json b/examples/messages/cumulus_context.output.json new file mode 100644 index 0000000..37a124e --- /dev/null +++ b/examples/messages/cumulus_context.output.json @@ -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" +} diff --git a/message_adapter/message_adapter.py b/message_adapter/message_adapter.py index d0650f1..9bc1b98 100644 --- a/message_adapter/message_adapter.py +++ b/message_adapter/message_adapter.py @@ -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 diff --git a/message_adapter/version.py b/message_adapter/version.py index 1fb88d0..efb1fc0 100644 --- a/message_adapter/version.py +++ b/message_adapter/version.py @@ -1 +1 @@ -__version__ = 'v1.0.12' +__version__ = 'v1.0.13' diff --git a/tests/test-module.py b/tests/test-module.py index 1ba7d79..cef5b50 100644 --- a/tests/test-module.py +++ b/tests/test-module.py @@ -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'))