Adding OsloRPC server and client

* Using new RPC interface OsloRPCServer and
   OsloRPCClient are created.

TODO (next commits):
 - integrate new RPC interface in Mistral
 - make RPC implementation configurable
 - unit tests

Partially implements blueprint mistral-alternative-rpc

Co-Authored-By: Dawid Deja <dawid.deja@intel.com>
Change-Id: I6c9770a5b84509529abc14dff2b4a9f6e3411951
This commit is contained in:
Nikolay Mahotkin 2015-06-22 16:23:59 +03:00 committed by Dawid Deja
parent 76e8ed75fa
commit 2cdd95aa29
26 changed files with 127 additions and 19 deletions

View File

@ -25,7 +25,7 @@ from mistral.api.controllers import resource
from mistral.api.controllers.v2 import types
from mistral import context
from mistral.db.v2 import api as db_api
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral import exceptions as exc
from mistral.utils import rest_utils
from mistral.workflow import states

View File

@ -25,7 +25,7 @@ from mistral.api.controllers.v2 import task
from mistral.api.controllers.v2 import types
from mistral import context
from mistral.db.v2 import api as db_api
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral import exceptions as exc
from mistral.services import workflows as wf_service
from mistral.utils import rest_utils

View File

@ -27,7 +27,7 @@ from mistral.api.controllers.v2 import action_execution
from mistral.api.controllers.v2 import types
from mistral import context
from mistral.db.v2 import api as db_api
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral import exceptions as exc
from mistral.utils import rest_utils
from mistral.workbook import parser as spec_parser

View File

@ -17,6 +17,7 @@ import sys
import eventlet
eventlet.monkey_patch(
os=True,
select=True,
@ -54,7 +55,7 @@ from mistral import context as ctx
from mistral.db.v2 import api as db_api
from mistral.engine import default_engine as def_eng
from mistral.engine import default_executor as def_executor
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral.services import expiration_policy
from mistral.services import scheduler
from mistral.utils import profiler

View File

@ -20,7 +20,7 @@ from osprofiler import profiler
import six
from mistral.db.v2 import api as db_api
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral.engine import utils as e_utils
from mistral.engine import workflow_handler as wf_handler
from mistral import exceptions as exc

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.engine.rpc_direct.kombu import kombu_client
from mistral.engine.rpc.kombu import kombu_client
# Example of using Kombu based RPC client.

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral.engine.rpc_direct.kombu import kombu_server
from mistral.engine.rpc.kombu import kombu_server
# Simple example of endpoint of RPC server, which just

View File

@ -18,8 +18,8 @@ import time
import kombu
from oslo_log import log as logging
from mistral.engine.rpc_direct import base as rpc_base
from mistral.engine.rpc_direct.kombu import base as kombu_base
from mistral.engine.rpc import base as rpc_base
from mistral.engine.rpc.kombu import base as kombu_base
from mistral import exceptions as exc
from mistral import utils

View File

@ -19,8 +19,8 @@ import kombu
from oslo_log import log as logging
from mistral import context as auth_context
from mistral.engine.rpc_direct import base as rpc_base
from mistral.engine.rpc_direct.kombu import base as kombu_base
from mistral.engine.rpc import base as rpc_base
from mistral.engine.rpc.kombu import base as kombu_base
from mistral import exceptions as exc

View File

View File

@ -0,0 +1,48 @@
# Copyright 2015 - Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import oslo_messaging as messaging
from mistral import context as auth_ctx
from mistral.engine.rpc import base as rpc_base
from mistral.engine.rpc import rpc
class OsloRPCClient(rpc_base.RPCClient):
def __init__(self, conf):
super(OsloRPCClient, self).__init__(conf)
self.topic = conf.get('topic', '')
serializer = auth_ctx.RpcContextSerializer(
auth_ctx.JsonPayloadSerializer())
self._client = messaging.RPCClient(
rpc.get_transport(),
messaging.Target(topic=self.topic),
serializer=serializer
)
def sync_call(self, ctx, method, target=None, **kwargs):
return self._client.prepare(topic=self.topic, server=target).call(
ctx,
method,
**kwargs
)
def async_call(self, ctx, method, target=None, **kwargs):
return self._client.prepare(topic=self.topic, server=target).cast(
ctx,
method,
**kwargs
)

View File

@ -0,0 +1,56 @@
# Copyright 2015 - Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo_log import log as logging
import oslo_messaging as messaging
from mistral import context as ctx
from mistral.engine.rpc import base as rpc_base
from mistral.engine.rpc import rpc
LOG = logging.getLogger(__name__)
class OsloRPCServer(rpc_base.RPCServer):
def __init__(self, conf):
super(OsloRPCServer, self).__init__(conf)
self.topic = conf.get('topic', '')
self.server_id = conf.get('server_id', '')
self.queue = self.topic
self.routing_key = self.topic
self.channel = None
self.connection = None
self.endpoints = []
def register_endpoint(self, endpoint):
self.endpoints.append(endpoint)
def run(self):
target = messaging.Target(
topic=self.topic,
server=self.server_id
)
server = messaging.get_rpc_server(
rpc.get_transport(),
target,
self.endpoints,
executor='eventlet',
serializer=ctx.RpcContextSerializer(ctx.JsonPayloadSerializer())
)
server.start()
server.wait()

View File

@ -23,7 +23,7 @@ import six
from mistral.db.v2 import api as db_api
from mistral.db.v2.sqlalchemy import models as db_models
from mistral.engine import dispatcher
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral.engine import utils as eng_utils
from mistral import exceptions as exc
from mistral.services import scheduler

View File

@ -21,7 +21,7 @@ from oslo_service import threadgroup
from mistral import context as auth_ctx
from mistral.db.v2 import api as db_api_v2
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral import exceptions as exc
from mistral.services import security
from mistral.services import triggers

View File

@ -23,7 +23,7 @@ from oslo_config import cfg
from mistral.db.v2 import api as db_api
from mistral.db.v2.sqlalchemy import models
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral import exceptions as exc
from mistral.tests.unit.api import base
from mistral.workflow import states

View File

@ -17,6 +17,7 @@
import copy
import datetime
import json
import mock
import uuid
from webtest import app as webtest_app
@ -24,12 +25,13 @@ from webtest import app as webtest_app
from mistral.db.v2 import api as db_api
from mistral.db.v2.sqlalchemy import api as sql_db_api
from mistral.db.v2.sqlalchemy import models
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral import exceptions as exc
from mistral.tests.unit.api import base
from mistral import utils
from mistral.workflow import states
WF_EX = models.WorkflowExecution(
id='123e4567-e89b-12d3-a456-426655440000',
workflow_name='some',

View File

@ -20,7 +20,7 @@ import mock
from mistral.db.v2 import api as db_api
from mistral.db.v2.sqlalchemy import models
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral import exceptions as exc
from mistral.tests.unit.api import base
from mistral.workflow import data_flow

View File

@ -22,11 +22,12 @@ from mistral import context as ctx
from mistral.db.v2 import api as db_api
from mistral.engine import default_engine as def_eng
from mistral.engine import default_executor as def_exec
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral.services import scheduler
from mistral.tests.unit import base
from mistral.workflow import states
LOG = logging.getLogger(__name__)
# Default delay and timeout in seconds for await_xxx() functions.

View File

@ -17,7 +17,7 @@ from oslo_config import cfg
from mistral.db.v2 import api as db_api
from mistral.engine import default_executor
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral.services import workbooks as wb_service
from mistral.tests.unit.engine import base

View File

@ -17,7 +17,7 @@ import eventlet
import mock
from oslo_config import cfg
from mistral.engine import rpc
from mistral.engine.rpc import rpc
from mistral import exceptions as exc
from mistral.services import periodic
from mistral.services import security