Skip to content

Commit

Permalink
Merge pull request #66 from jeronimoalbi/develop
Browse files Browse the repository at this point in the history
Version update to `1.0.1`
  • Loading branch information
jeronimoalbi authored Mar 7, 2017
2 parents 192f38e + ce00390 commit 69f7ae7
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion katana/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
44 changes: 33 additions & 11 deletions katana/api/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
file that was distributed with this source code.
"""
import copy
import logging

from decimal import Decimal
Expand All @@ -19,6 +20,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
Expand Down Expand Up @@ -173,8 +175,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
"""

Expand Down Expand Up @@ -226,7 +228,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):
Expand Down Expand Up @@ -275,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()
Expand Down Expand Up @@ -792,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))
Expand All @@ -816,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))
Expand All @@ -843,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))
Expand Down Expand Up @@ -885,14 +893,26 @@ def call(self, service, version, action, **kwargs):
)
raise ApiError(msg)

return runtime_call(
transport, result = runtime_call(
address,
self.__transport,
self.__runtime_transport,
self.get_action_name(),
[service, version, action],
**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.
Expand Down Expand Up @@ -930,6 +950,7 @@ def defer_call(self, service, version, action, params=None, files=None):
'name': service,
'version': version,
'action': action,
'caller': self.get_action_name(),
})
if params:
payload.set('params', parse_params(params))
Expand Down Expand Up @@ -987,6 +1008,7 @@ def remote_call(self, address, service, version, action, **kwargs):
'name': service,
'version': version,
'action': action,
'caller': self.get_action_name(),
})

timeout = kwargs.get('timeout')
Expand Down
1 change: 0 additions & 1 deletion katana/api/schema/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
file that was distributed with this source code.
"""
import json
import logging
import sys

Expand Down
17 changes: 16 additions & 1 deletion katana/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'config': 'c',
'count': 'c',
'cpu': 'c',
'caller': 'C',
'calls': 'C',
'complete': 'C',
'command_reply': 'cr',
Expand Down Expand Up @@ -156,7 +157,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):
Expand Down

0 comments on commit 69f7ae7

Please sign in to comment.