From 00a3a8d580b442ecbd7ff80e412ac70d2f28eb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jero=CC=81nimo=20Albi?= Date: Thu, 2 Mar 2017 15:07:39 +0100 Subject: [PATCH 1/6] Fixed README and removed unused module. --- README.md | 1 + katana/api/schema/param.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7214ab9..b244b4b 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Create a new config file for the **Middleware** as the following: name: example version: "0.1" request: true +response: true info: title: Example Middleware engine: diff --git a/katana/api/schema/param.py b/katana/api/schema/param.py index 827c2fb..60f9245 100644 --- a/katana/api/schema/param.py +++ b/katana/api/schema/param.py @@ -9,7 +9,6 @@ file that was distributed with this source code. """ -import json import logging import sys From 961ebc5dc229d9ae10ffd28e92cc54ca10571937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jero=CC=81nimo=20Albi?= Date: Fri, 3 Mar 2017 15:06:04 +0100 Subject: [PATCH 2/6] Added transport merge for return value --- katana/api/action.py | 22 ++++++++++++++++++---- katana/payload.py | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/katana/api/action.py b/katana/api/action.py index d99fbc9..6c7c5c5 100644 --- a/katana/api/action.py +++ b/katana/api/action.py @@ -19,6 +19,7 @@ from ..payload import ErrorPayload from ..payload import get_path from ..payload import Payload +from ..payload import TRANSPORT_MERGEABLE_PATHS from ..utils import ipc from ..utils import nomap from ..serialization import pack @@ -173,8 +174,8 @@ def runtime_call(address, transport, action, callee, **kwargs): :raises: ApiError :raises: RuntimeCallError - :returns: The return value for the call. - :rtype: object + :returns: The transport and the return value for the call. + :rtype: tuple """ @@ -226,7 +227,8 @@ def runtime_call(address, transport, action, callee, **kwargs): if payload.path_exists('error'): raise ApiError(payload.get('error/message')) - return payload.get('command_reply/result/return') + result = payload.get('command_reply/result') + return (get_path(result, 'transport'), get_path(result, 'return')) class Action(Api): @@ -885,7 +887,7 @@ def call(self, service, version, action, **kwargs): ) raise ApiError(msg) - return runtime_call( + transport, result = runtime_call( address, self.__transport, self.get_action_name(), @@ -893,6 +895,18 @@ def call(self, service, version, action, **kwargs): **kwargs ) + # Clear default to succesfully merge dictionaries. Without + # this merge would be done with a default value that is not + # part of the payload. + self.__transport.set_defaults({}) + for path in TRANSPORT_MERGEABLE_PATHS: + value = get_path(transport, path, None) + # Don't merge empty values + if value: + self.__transport.merge(path, value) + + return result + def defer_call(self, service, version, action, params=None, files=None): """Register a deferred call to a service. diff --git a/katana/payload.py b/katana/payload.py index 3efd2a6..a4966e5 100644 --- a/katana/payload.py +++ b/katana/payload.py @@ -156,7 +156,21 @@ 'timeout': 'x', 'max_items': 'xi', 'max_length': 'xl', -} + } + +# Transport path for field that must be merged when service calls are made +TRANSPORT_MERGEABLE_PATHS = ( + 'data', + 'relations', + 'links', + 'calls', + 'transactions', + 'errors', + 'body', + 'files', + 'meta/fallbacks', + 'meta/properties', + ) def get_path(payload, path, default=EMPTY, mappings=None, delimiter=SEP): From 45c7923458a541967c43f74e609f1dc3b7dfcd39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jero=CC=81nimo=20Albi?= Date: Sat, 4 Mar 2017 10:59:28 +0100 Subject: [PATCH 3/6] Updated Action to use a Transport clone for runtime calls --- katana/api/action.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/katana/api/action.py b/katana/api/action.py index 6c7c5c5..1118e6a 100644 --- a/katana/api/action.py +++ b/katana/api/action.py @@ -9,6 +9,7 @@ file that was distributed with this source code. """ +import copy import logging from decimal import Decimal @@ -277,6 +278,11 @@ def __init__(self, action, params, transport, *args, **kwargs): rtype = self.__action_schema.get_return_type() self.__return_value.set('return', DEFAULT_RETURN_VALUES.get(rtype)) + # Make a transport clone to be used for runtime calls. + # This is required to avoid merging back values that are + # already inside current transport. + self.__runtime_transport = copy.deepcopy(self.__transport) + def __files_to_payload(self, files): if self.__schema: has_file_server = self.__schema.has_file_server() @@ -889,7 +895,7 @@ def call(self, service, version, action, **kwargs): transport, result = runtime_call( address, - self.__transport, + self.__runtime_transport, self.get_action_name(), [service, version, action], **kwargs From 8aa9419e1ad202b73bcb8d61d2032119cbe4fba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jero=CC=81nimo=20Albi?= Date: Sat, 4 Mar 2017 11:34:04 +0100 Subject: [PATCH 4/6] Changed defferred and remote calls to send current action name --- katana/api/action.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/katana/api/action.py b/katana/api/action.py index 1118e6a..68c01ee 100644 --- a/katana/api/action.py +++ b/katana/api/action.py @@ -949,7 +949,8 @@ def defer_call(self, service, version, action, params=None, files=None): payload = Payload().set_many({ 'name': service, 'version': version, - 'action': action, + 'callee': action, + 'action': self.get_action_name(), }) if params: payload.set('params', parse_params(params)) @@ -1006,7 +1007,8 @@ def remote_call(self, address, service, version, action, **kwargs): 'gateway': address, 'name': service, 'version': version, - 'action': action, + 'callee': action, + 'action': self.get_action_name(), }) timeout = kwargs.get('timeout') From facab01c6c093659820a767e7df6c9be7947dce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jero=CC=81nimo=20Albi?= Date: Tue, 7 Mar 2017 15:37:43 +0100 Subject: [PATCH 5/6] Changed `callee` in favor of `action` and `caller` properties. Change was done for calls and transactions. --- katana/api/action.py | 20 ++++++++++---------- katana/payload.py | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/katana/api/action.py b/katana/api/action.py index 68c01ee..00264da 100644 --- a/katana/api/action.py +++ b/katana/api/action.py @@ -800,8 +800,8 @@ def commit(self, action, params=None): payload = Payload().set_many({ 'name': self.get_name(), 'version': self.get_version(), - 'action': self.get_action_name(), - 'callee': action, + 'callee': self.get_action_name(), + 'action': action, }) if params: payload.set('params', parse_params(params)) @@ -824,8 +824,8 @@ def rollback(self, action, params=None): payload = Payload().set_many({ 'name': self.get_name(), 'version': self.get_version(), - 'action': self.get_action_name(), - 'callee': action, + 'callee': self.get_action_name(), + 'action': action, }) if params: payload.set('params', parse_params(params)) @@ -851,8 +851,8 @@ def complete(self, action, params=None): payload = Payload().set_many({ 'name': self.get_name(), 'version': self.get_version(), - 'action': self.get_action_name(), - 'callee': action, + 'callee': self.get_action_name(), + 'action': action, }) if params: payload.set('params', parse_params(params)) @@ -949,8 +949,8 @@ def defer_call(self, service, version, action, params=None, files=None): payload = Payload().set_many({ 'name': service, 'version': version, - 'callee': action, - 'action': self.get_action_name(), + 'action': action, + 'caller': self.get_action_name(), }) if params: payload.set('params', parse_params(params)) @@ -1007,8 +1007,8 @@ def remote_call(self, address, service, version, action, **kwargs): 'gateway': address, 'name': service, 'version': version, - 'callee': action, - 'action': self.get_action_name(), + 'action': action, + 'caller': self.get_action_name(), }) timeout = kwargs.get('timeout') diff --git a/katana/payload.py b/katana/payload.py index a4966e5..cacb0ad 100644 --- a/katana/payload.py +++ b/katana/payload.py @@ -49,6 +49,7 @@ 'config': 'c', 'count': 'c', 'cpu': 'c', + 'caller': 'C', 'calls': 'C', 'complete': 'C', 'command_reply': 'cr', From ce00390efbf5ccd1f188a0b741702c007759ab03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jero=CC=81nimo=20Albi?= Date: Tue, 7 Mar 2017 15:57:19 +0100 Subject: [PATCH 6/6] Version update to `1.0.1` --- CHANGELOG.md | 8 ++++++++ katana/__init__.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c6765a..256f11d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,5 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.0.1] - 2017-03-07 +### Added +- Transport merge support for run-time calls. + +### Changed +- Updated payload argument names for "action" and "callee" to be consistent + between transactions and calls in API `Action` class. + ## [1.0.0] - 2017-03-01 - Initial release diff --git a/katana/__init__.py b/katana/__init__.py index 300328b..885549e 100644 --- a/katana/__init__.py +++ b/katana/__init__.py @@ -12,4 +12,4 @@ __license__ = "MIT" __copyright__ = "Copyright (c) 2016-2017 KUSANAGI S.L. (http://kusanagi.io)" -__version__ = '1.0.0' +__version__ = '1.0.1'