本文整理汇总了Python中pyon.net.endpoint.BaseEndpoint类的典型用法代码示例。如果您正苦于以下问题:Python BaseEndpoint类的具体用法?Python BaseEndpoint怎么用?Python BaseEndpoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseEndpoint类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test__ensure_node
def test__ensure_node(self, gcimock):
bep = BaseEndpoint()
self.assertIsNone(bep.node)
bep._ensure_node()
self.assertEquals(bep.node, gcimock().node)
开发者ID:daf,项目名称:pyon,代码行数:7,代码来源:test_endpoint.py
示例2: _build_header
def _build_header(self, raw_msg, raw_headers):
"""
Builds the header for this Process-level RPC conversation.
"""
header = EndpointUnit._build_header(self, raw_msg, raw_headers)
# Add our process identity to the headers (as sender)
header.update({'sender-name': self._process.name or 'unnamed-process', # @TODO
'sender': self._process.id})
if hasattr(self._process, 'process_type'):
header.update({'sender-type': self._process.process_type or 'unknown-process-type'})
if self._process.process_type == 'service' and hasattr(self.channel, '_send_name'):
header.update({'sender-service': "%s,%s" % (self.channel._send_name.exchange, self._process.name)})
# Use received message headers context to set security attributes forward
context = self.get_context()
if isinstance(context, dict):
new_header = self.build_security_headers(context)
header.update(new_header)
else:
# no context? we're the originator of the message then
container_id = BaseEndpoint._get_container_instance().id
header['origin-container-id'] = container_id
# This is the originating conversation
if 'conv-id' in raw_headers:
header['original-conv-id'] = raw_headers['conv-id']
return header
开发者ID:edwardhunter,项目名称:scioncc,代码行数:30,代码来源:endpoint.py
示例3: _build_header
def _build_header(self, raw_msg, raw_headers):
"""
Builds the header for this Process-level RPC conversation.
https://confluence.oceanobservatories.org/display/syseng/CIAD+COI+OV+Common+Message+Format
"""
header = EndpointUnit._build_header(self, raw_msg, raw_headers)
# add our process identity to the headers
header.update({'sender-name': self._process.name or 'unnamed-process', # @TODO
'sender': self._process.id})
if hasattr(self._process, 'process_type'):
header.update({'sender-type': self._process.process_type or 'unknown-process-type'})
if self._process.process_type == 'service' and hasattr(self.channel, '_send_name'):
header.update({'sender-service': "%s,%s" % (self.channel._send_name.exchange, self._process.name)})
context = self.get_context()
#log.debug('ProcessEndpointUnitMixin._build_header has context of: %s', context)
# use context to set security attributes forward
if isinstance(context, dict):
new_header = self.build_security_headers(context)
header.update(new_header)
else:
# no context? we're the originator of the message then
container_id = BaseEndpoint._get_container_instance().id
header['origin-container-id'] = container_id
#This is the originating conversation
if 'conv-id' in raw_headers:
header['original-conv-id'] = raw_headers['conv-id']
return header
开发者ID:j2project,项目名称:pyon,代码行数:35,代码来源:endpoint.py
示例4: _build_header
def _build_header(self, raw_msg):
"""
Builds the header for this Process-level RPC conversation.
https://confluence.oceanobservatories.org/display/syseng/CIAD+COI+OV+Common+Message+Format
"""
header = EndpointUnit._build_header(self, raw_msg)
# add our process identity to the headers
header.update({'sender-name' : self._process.name or 'unnamed-process', # @TODO
'sender' : self._process.id })
if hasattr(self._process,'process_type' ):
header.update({'sender-type' : self._process.process_type or 'unknown-process-type' })
if self._process.process_type == 'service':
header.update({ 'sender-service' : "%s,%s" % ( self.channel._send_name.exchange,self._process.name) })
context = self._process.get_context()
log.debug('ProcessEndpointUnitMixin._build_header has context of: %s', context)
# use context to set security attributes forward
if isinstance(context, dict):
# fwd on actor specific information, according to common message format spec
actor_id = context.get('ion-actor-id', None)
actor_roles = context.get('ion-actor-roles', None)
actor_tokens = context.get('ion-actor-tokens', None)
expiry = context.get('expiry', None)
container_id = context.get('origin-container-id', None)
#If an actor-id is specified then there may be other associated data that needs to be passed on
if actor_id:
header['ion-actor-id'] = actor_id
if actor_roles: header['ion-actor-roles'] = actor_roles
if actor_tokens: header['ion-actor-tokens'] = actor_tokens
if expiry: header['expiry'] = expiry
if container_id: header['origin-container-id'] = container_id
else:
# no context? we're the originator of the message then
container_id = BaseEndpoint._get_container_instance().id
header['origin-container-id'] = container_id
return header
开发者ID:oldpatricka,项目名称:pyon,代码行数:43,代码来源:endpoint.py
示例5: test_close
def test_close(self):
bep = BaseEndpoint()
bep.close()
开发者ID:daf,项目名称:pyon,代码行数:3,代码来源:test_endpoint.py
示例6: test__get_container_instance
def test__get_container_instance(self):
c = Container() # ensure we've got an instance in Container.instance
self.assertEquals(BaseEndpoint._get_container_instance(), c)
开发者ID:daf,项目名称:pyon,代码行数:3,代码来源:test_endpoint.py
示例7: setUp
def setUp(self):
self._node = Mock(spec=NodeB)
self._ef = BaseEndpoint(node=self._node)
self._ch = Mock(spec=SendChannel)
self._node.channel.return_value = self._ch
开发者ID:daf,项目名称:pyon,代码行数:5,代码来源:test_endpoint.py
示例8: TestBaseEndpoint
class TestBaseEndpoint(PyonTestCase):
def setUp(self):
self._node = Mock(spec=NodeB)
self._ef = BaseEndpoint(node=self._node)
self._ch = Mock(spec=SendChannel)
self._node.channel.return_value = self._ch
def test_create_endpoint(self):
e = self._ef.create_endpoint()
# check attrs
self.assertTrue(hasattr(e, 'channel'))
# make sure we can shut it down
e.close()
self._ch.close.assert_any_call()
def test_create_endpoint_existing_channel(self):
ch = Mock(spec=SendChannel)
e = self._ef.create_endpoint(existing_channel=ch)
self.assertEquals(e.channel, ch)
self.assertEquals(ch.connect.call_count, 0)
ch.connect("exist")
ch.connect.assert_called_once_with('exist')
e.close()
def test_create_endpoint_kwarg(self):
"""
Make sure our kwarg gets set.
"""
class OptEndpointUnit(EndpointUnit):
def __init__(self, opt=None, **kwargs):
self._opt = opt
EndpointUnit.__init__(self, **kwargs)
self._ef.endpoint_unit_type = OptEndpointUnit
e = self._ef.create_endpoint(opt="stringer")
self.assertTrue(hasattr(e, "_opt"))
self.assertEquals(e._opt, "stringer")
def test__ensure_node_errors(self):
bep = BaseEndpoint()
gcimock = Mock()
gcimock.return_value = None
with patch('pyon.net.endpoint.BaseEndpoint._get_container_instance', gcimock):
self.assertRaises(EndpointError, bep._ensure_node)
@patch('pyon.net.endpoint.BaseEndpoint._get_container_instance')
def test__ensure_node_existing_node(self, gcimock):
self._ef._ensure_node()
self.assertFalse(gcimock.called)
@patch('pyon.net.endpoint.BaseEndpoint._get_container_instance')
def test__ensure_node(self, gcimock):
bep = BaseEndpoint()
self.assertIsNone(bep.node)
bep._ensure_node()
self.assertEquals(bep.node, gcimock().node)
def test__get_container_instance(self):
c = Container() # ensure we've got an instance in Container.instance
self.assertEquals(BaseEndpoint._get_container_instance(), c)
def test_close(self):
bep = BaseEndpoint()
bep.close()
开发者ID:daf,项目名称:pyon,代码行数:72,代码来源:test_endpoint.py
示例9: publish_event_object
def publish_event_object(self, event_object):
"""
Publishes an event of given type for the given origin. Event_type defaults to an
event_type set when initializing the EventPublisher. Other kwargs fill out the fields
of the event. This operation will fail with an exception.
@param event_object the event object to be published
@retval event_object the event object which was published
"""
if not event_object:
raise BadRequest("Must provide event_object")
event_object.base_types = event_object._get_extends()
topic = self._topic(event_object) # Routing key generated using type_, base_types, origin, origin_type, sub_type
container = (hasattr(self, '_process') and hasattr(self._process, 'container') and self._process.container) or BaseEndpoint._get_container_instance()
if container and container.has_capability(container.CCAP.EXCHANGE_MANAGER):
# make sure we are an xp, if not, upgrade
if not isinstance(self._send_name, XOTransport):
default_nt = NameTrio(self.get_events_exchange_point())
if isinstance(self._send_name, NameTrio) \
and self._send_name.exchange == default_nt.exchange \
and self._send_name.queue == default_nt.queue \
and self._send_name.binding == default_nt.binding:
self._send_name = container.create_xp(self._events_xp)
else:
self._send_name = container.create_xp(self._send_name)
xp = self._send_name
to_name = xp.create_route(topic)
else:
to_name = (self._send_name.exchange, topic)
current_time = get_ion_ts_millis()
# Ensure valid created timestamp if supplied
if event_object.ts_created:
if not is_valid_ts(event_object.ts_created):
raise BadRequest("The ts_created value is not a valid timestamp: '%s'" % (event_object.ts_created))
# Reject events that are older than specified time
if int(event_object.ts_created) > ( current_time + VALID_EVENT_TIME_PERIOD ):
raise BadRequest("This ts_created value is too far in the future:'%s'" % (event_object.ts_created))
# Reject events that are older than specified time
if int(event_object.ts_created) < (current_time - VALID_EVENT_TIME_PERIOD) :
raise BadRequest("This ts_created value is too old:'%s'" % (event_object.ts_created))
else:
event_object.ts_created = str(current_time)
# Set the actor id based on
if not event_object.actor_id:
event_object.actor_id = self._get_actor_id()
#Validate this object - ideally the validator should pass on problems, but for now just log
#any errors and keep going, since seeing invalid situations are better than skipping validation.
try:
event_object._validate()
except Exception as e:
log.exception(e)
#Ensure the event object has a unique id
if '_id' in event_object:
raise BadRequest("The event object cannot contain a _id field '%s'" % (event_object))
#Generate a unique ID for this event
event_object._id = create_unique_event_id()
try:
self.publish(event_object, to_name=to_name)
except Exception as ex:
log.exception("Failed to publish event (%s): '%s'" % (ex.message, event_object))
raise
return event_object
开发者ID:mkl-,项目名称:scioncc,代码行数:78,代码来源:event.py
示例10: __init__
def __init__(self, event_type=None, xp=None, process=None, **kwargs):
"""
Constructs a publisher of events for a specific type.
@param event_type The name of the event type object
@param xp Exchange (AMQP) name, can be none, will use events default.
"""
self.event_type = event_type
self.process = process
self._events_xp = CFG.get_safe("exchange.core.events", DEFAULT_EVENTS_XP)
if bootstrap.container_instance and getattr(bootstrap.container_instance, 'event_repository', None):
self.event_repo = bootstrap.container_instance.event_repository
else:
self.event_repo = None
# generate an exchange name to publish events to
container = (hasattr(self, '_process') and hasattr(self._process, 'container') and self._process.container) or BaseEndpoint._get_container_instance()
if container and container.has_capability(container.CCAP.EXCHANGE_MANAGER): # might be too early in chain
xp = xp or container.create_xp(self._events_xp)
to_name = xp
else:
xp = xp or self.get_events_exchange_point()
to_name = (xp, None)
Publisher.__init__(self, to_name=to_name, **kwargs)
开发者ID:mkl-,项目名称:scioncc,代码行数:27,代码来源:event.py
示例11: __init__
def __init__(self, xp_name=None, event_type=None, origin=None, queue_name=None,
sub_type=None, origin_type=None, pattern=None, auto_delete=None):
self._events_xp = CFG.get_safe("exchange.core.events", DEFAULT_EVENTS_XP)
self.event_type = event_type
self.sub_type = sub_type
self.origin_type = origin_type
self.origin = origin
# Default for auto_delete is True for events, unless otherwise specified
if auto_delete is None:
auto_delete = True
self._auto_delete = auto_delete
xp_name = xp_name or self._events_xp
if pattern:
binding = pattern
else:
binding = self._topic(event_type, origin, sub_type, origin_type)
# create queue_name if none passed in
if queue_name is None:
queue_name = "subsc_" + create_simple_unique_id()
# prepend proc name to queue name if we have one
if hasattr(self, "_process") and self._process:
queue_name = "%s_%s" % (self._process._proc_name, queue_name)
# do we have a container/ex_manager?
container = (hasattr(self, '_process') and hasattr(self._process, 'container') and self._process.container) or BaseEndpoint._get_container_instance()
if container:
xp = container.create_xp(xp_name)
xne = container.create_event_xn(queue_name,
pattern=binding,
xp=xp,
auto_delete=auto_delete)
self._ev_recv_name = xne
self.binding = None
else:
# Remove this case. No container??
self.binding = binding
# prefix the queue_name, if specified, with the sysname
queue_name = "%s.system.%s" % (bootstrap.get_sys_name(), queue_name)
# set this name to be picked up by inherited folks
self._ev_recv_name = (xp_name, queue_name)
local_event_queues.append(queue_name)
开发者ID:edwardhunter,项目名称:scioncc,代码行数:50,代码来源:event.py
示例12: TestBaseEndpoint
class TestBaseEndpoint(PyonTestCase):
def setUp(self):
self._node = Mock(spec=NodeB)
self._ef = BaseEndpoint(node=self._node, name="EFTest")
self._ch = Mock(spec=SendChannel)
self._node.channel.return_value = self._ch
def test_create_endpoint(self):
e = self._ef.create_endpoint()
# check attrs
self.assertTrue(hasattr(e, "channel"))
self.assertEquals(self._ch.connect.call_count, 1)
self.assertTrue(self._ef.name in self._ch.connect.call_args[0])
# make sure we can shut it down
e.close()
self._ch.close.assert_any_call()
def test_create_endpoint_new_name(self):
e = self._ef.create_endpoint(to_name="reroute")
self.assertEquals(self._ch.connect.call_count, 1)
self.assertTrue("reroute" in self._ch.connect.call_args[0][0]) # @TODO: this is obtuse
e.close()
def test_create_endpoint_existing_channel(self):
ch = Mock(spec=SendChannel)
e = self._ef.create_endpoint(existing_channel=ch)
self.assertEquals(e.channel, ch)
self.assertEquals(ch.connect.call_count, 0)
ch.connect("exist")
ch.connect.assert_called_once_with("exist")
e.close()
def test_create_endpoint_kwarg(self):
"""
Make sure our kwarg gets set.
"""
class OptEndpointUnit(EndpointUnit):
def __init__(self, opt=None, **kwargs):
self._opt = opt
EndpointUnit.__init__(self, **kwargs)
self._ef.endpoint_unit_type = OptEndpointUnit
e = self._ef.create_endpoint(opt="stringer")
self.assertTrue(hasattr(e, "_opt"))
self.assertEquals(e._opt, "stringer")
def test__ensure_node_errors(self):
bep = BaseEndpoint(name=sentinel.name)
gcimock = Mock()
gcimock.return_value = None
with patch("pyon.net.endpoint.BaseEndpoint._get_container_instance", gcimock):
self.assertRaises(EndpointError, bep._ensure_node)
@patch("pyon.net.endpoint.BaseEndpoint._get_container_instance")
def test__ensure_node_existing_node(self, gcimock):
self._ef._ensure_node()
self.assertFalse(gcimock.called)
@patch("pyon.net.endpoint.BaseEndpoint._get_container_instance")
def test__ensure_node(self, gcimock):
bep = BaseEndpoint(name=sentinel.name)
self.assertIsNone(bep.node)
bep._ensure_node()
self.assertEquals(bep.node, gcimock().node)
开发者ID:dstuebe,项目名称:pyon,代码行数:72,代码来源:test_endpoint.py
注:本文中的pyon.net.endpoint.BaseEndpoint类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论