本文整理汇总了Python中interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient.read_platform_agent_instance方法的典型用法代码示例。如果您正苦于以下问题:Python InstrumentManagementServiceClient.read_platform_agent_instance方法的具体用法?Python InstrumentManagementServiceClient.read_platform_agent_instance怎么用?Python InstrumentManagementServiceClient.read_platform_agent_instance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient
的用法示例。
在下文中一共展示了InstrumentManagementServiceClient.read_platform_agent_instance方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestPlatformInstrument
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import read_platform_agent_instance [as 别名]
#.........这里部分代码省略.........
instrument_agent_instance_obj.driver_config['pagent_pid'] = pid
self.imsclient.update_instrument_agent_instance(instrument_agent_instance_obj)
return self.imsclient.read_instrument_agent_instance(instrument_agent_instance_obj._id)
def _start_platform(self):
"""
Starts the given platform waiting for it to transition to the
UNINITIALIZED state (note that the agent starts in the LAUNCHING state).
More in concrete the sequence of steps here are:
- prepares subscriber to receive the UNINITIALIZED state transition
- launches the platform process
- waits for the start of the process
- waits for the transition to the UNINITIALIZED state
"""
##############################################################
# prepare to receive the UNINITIALIZED state transition:
async_res = AsyncResult()
def consume_event(evt, *args, **kwargs):
log.debug("Got ResourceAgentStateEvent %s from origin %r", evt.state, evt.origin)
if evt.state == PlatformAgentState.UNINITIALIZED:
async_res.set(evt)
# start subscriber:
sub = EventSubscriber(event_type="ResourceAgentStateEvent",
origin=self.platform_device_id,
callback=consume_event)
sub.start()
log.info("registered event subscriber to wait for state=%r from origin %r",
PlatformAgentState.UNINITIALIZED, self.platform_device_id)
#self._event_subscribers.append(sub)
sub._ready_event.wait(timeout=EVENT_TIMEOUT)
##############################################################
# now start the platform:
agent_instance_id = self.platform_agent_instance_id
log.debug("about to call start_platform_agent_instance with id=%s", agent_instance_id)
pid = self.imsclient.start_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
log.debug("start_platform_agent_instance returned pid=%s", pid)
#wait for start
agent_instance_obj = self.imsclient.read_platform_agent_instance(agent_instance_id)
gate = AgentProcessStateGate(self.processdispatchclient.read_process,
self.platform_device_id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(90), "The platform agent instance did not spawn in 90 seconds")
# Start a resource agent client to talk with the agent.
self._pa_client = ResourceAgentClient(self.platform_device_id,
name=gate.process_id,
process=FakeProcess())
log.debug("got platform agent client %s", str(self._pa_client))
##############################################################
# wait for the UNINITIALIZED event:
async_res.get(timeout=self._receive_timeout)
def _register_oms_listener(self):
#load the paramaters and the param dicts necesssary for the VEL3D
log.debug( "---------- connect_to_oms ---------- ")
log.debug("oms_uri = %s", OMS_URI)
self.oms = CIOMSClientFactory.create_instance(OMS_URI)
#buddha url
url = "http://10.22.88.168:5000/ion-service/oms_event"
log.info("test_oms_events_receive:setup http url %s", url)
result = self.oms.event.register_event_listener(url)
log.debug("_register_oms_listener register_event_listener result %s", result)
#-------------------------------------------------------------------------------------
# Set up the subscriber to catch the alert event
#-------------------------------------------------------------------------------------
def callback_for_alert(event, *args, **kwargs):
log.debug("caught an OMSDeviceStatusEvent: %s", event)
self.catch_alert.put(event)
self.event_subscriber = EventSubscriber(event_type='OMSDeviceStatusEvent',
callback=callback_for_alert)
self.event_subscriber.start()
self.addCleanup(self.event_subscriber.stop)
result = self.oms.event.generate_test_event({'platform_id': 'fake_platform_id', 'message': "fake event triggered from CI using OMS' generate_test_event", 'severity': '3', 'group ': 'power'})
log.debug("_register_oms_listener generate_test_event result %s", result)
def _stop_platform(self):
try:
self.IMS.stop_platform_agent_instance(self.platform_agent_instance_id)
except Exception:
log.warn(
"platform_id=%r: Exception in IMS.stop_platform_agent_instance with "
"platform_agent_instance_id = %r. Perhaps already dead.",
self.platform_device_id, self.platform_agent_instance_id)
示例2: TestOmsLaunch
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import read_platform_agent_instance [as 别名]
#.........这里部分代码省略.........
self.pubsubcli.delete_subscription(sub.subscription_id)
sub.stop()
finally:
self._event_subscribers = []
def test_oms_create_and_launch(self):
# pick a base platform:
base_platform_id = BASE_PLATFORM_ID
# and trigger the traversal of the branch rooted at that base platform
# to create corresponding ION objects and configuration dictionaries:
base_platform_objs = self._traverse(base_platform_id)
# now that most of the topology information is there, add the
# PlatformAgentInstance elements
self._set_platform_agent_instances()
base_platform_config = self.platform_configs[base_platform_id]
log.info("base_platform_id = %r", base_platform_id)
log.info("topology = %s", str(self.topology))
#-------------------------------
# Launch Base Platform AgentInstance, connect to the resource agent client
#-------------------------------
agent_instance_id = base_platform_objs['agent_instance_id']
pid = self.imsclient.start_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
log.debug("start_platform_agent_instance returned pid=%s", pid)
#wait for start
instance_obj = self.imsclient.read_platform_agent_instance(agent_instance_id)
gate = ProcessStateGate(self.processdispatchclient.read_process,
instance_obj.agent_process_id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(90), "The platform agent instance did not spawn in 90 seconds")
agent_instance_obj= self.imsclient.read_instrument_agent_instance(agent_instance_id)
log.debug('test_oms_create_and_launch: Platform agent instance obj: %s', str(agent_instance_obj))
# Start a resource agent client to talk with the instrument agent.
self._pa_client = ResourceAgentClient('paclient', name=agent_instance_obj.agent_process_id, process=FakeProcess())
log.debug(" test_oms_create_and_launch:: got pa client %s", str(self._pa_client))
log.debug("base_platform_config =\n%s", base_platform_config)
# ping_agent can be issued before INITIALIZE
retval = self._pa_client.ping_agent(timeout=TIMEOUT)
log.debug( 'Base Platform ping_agent = %s', str(retval) )
# issue INITIALIZE command to the base platform, which will launch the
# creation of the whole platform hierarchy rooted at base_platform_config['platform_id']
# cmd = AgentCommand(command=PlatformAgentEvent.INITIALIZE, kwargs=dict(plat_config=base_platform_config))
cmd = AgentCommand(command=PlatformAgentEvent.INITIALIZE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform INITIALIZE = %s', str(retval) )
# GO_ACTIVE
cmd = AgentCommand(command=PlatformAgentEvent.GO_ACTIVE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform GO_ACTIVE = %s', str(retval) )
# RUN: this command includes the launch of the resource monitoring greenlets
示例3: BaseIntTestPlatform
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import read_platform_agent_instance [as 别名]
#.........这里部分代码省略.........
]
# assign one available instrument to a platform;
# the assignments are arbitrary.
num_assigns = min(len(instr_keys), len(plats_to_assign_instrs))
for ii in range(num_assigns):
platform_id = plats_to_assign_instrs[ii]
self.assertIn(platform_id, p_objs)
p_obj = p_objs[platform_id]
i_obj = i_objs[ii]
self._assign_instrument_to_platform(i_obj, p_obj)
log.debug("instrument %r (%s) assigned to platform %r",
i_obj.instrument_agent_instance_id,
instr_keys[ii],
platform_id)
log.info("%d instruments assigned. Took %.3f secs.",
num_assigns, time.time() - start_time)
return p_root
#################################################################
# start / stop platform
#################################################################
def _start_platform(self, p_obj):
agent_instance_id = p_obj.platform_agent_instance_id
log.debug("about to call start_platform_agent_instance with id=%s", agent_instance_id)
p_obj.pid = self.IMS.start_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
log.debug("start_platform_agent_instance returned pid=%s", p_obj.pid)
#wait for start
agent_instance_obj = self.IMS.read_platform_agent_instance(agent_instance_id)
gate = ProcessStateGate(self.PDC.read_process,
agent_instance_obj.agent_process_id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(90), "The platform agent instance did not spawn in 90 seconds")
# Start a resource agent client to talk with the agent.
self._pa_client = ResourceAgentClient('paclient',
name=agent_instance_obj.agent_process_id,
process=FakeProcess())
log.debug("got platform agent client %s", str(self._pa_client))
def _stop_platform(self, p_obj):
try:
self.IMS.stop_platform_agent_instance(p_obj.platform_agent_instance_id)
except:
if log.isEnabledFor(logging.TRACE):
log.exception(
"platform_id=%r: Exception in IMS.stop_platform_agent_instance with "
"platform_agent_instance_id = %r",
p_obj.platform_id, p_obj.platform_agent_instance_id)
else:
log.warn(
"platform_id=%r: Exception in IMS.stop_platform_agent_instance with "
"platform_agent_instance_id = %r. Perhaps already dead.",
p_obj.platform_id, p_obj.platform_agent_instance_id)
#################################################################
# misc convenience methods
#################################################################
def _create_resource_agent_client(self, resource_id):
client = ResourceAgentClient(resource_id, process=FakeProcess())
示例4: TestPlatformLaunch
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import read_platform_agent_instance [as 别名]
#.........这里部分代码省略.........
self.parsed_dataset = dataset_ids[0]
#######################################
full_config['platform_config'] = {
'platform_id': platform_id,
'driver_config': DVR_CONFIG,
'network_definition' : self._network_definition_ser
}
agent_instance_obj = IonObject(RT.PlatformAgentInstance,
name='%s_PlatformAgentInstance' % platform_id,
description="%s_PlatformAgentInstance" % platform_id,
agent_config=full_config)
agent_instance_id = self.IMS.create_platform_agent_instance(
platform_agent_instance = agent_instance_obj,
platform_agent_id = agent_id,
platform_device_id = self.device_id)
stream_id = stream_ids[0]
self._start_data_subscriber(agent_instance_id, stream_id)
log.debug("about to call imsclient.start_platform_agent_instance with id=%s", agent_instance_id)
pid = self.IMS.start_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
log.debug("start_platform_agent_instance returned pid=%s", pid)
#wait for start
instance_obj = self.IMS.read_platform_agent_instance(agent_instance_id)
gate = ProcessStateGate(self.PDC.read_process,
instance_obj.agent_process_id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(90), "The platform agent instance did not spawn in 90 seconds")
agent_instance_obj= self.IMS.read_instrument_agent_instance(agent_instance_id)
log.debug('Platform agent instance obj')
# Start a resource agent client to talk with the instrument agent.
self._pa_client = ResourceAgentClient('paclient',
name=agent_instance_obj.agent_process_id,
process=FakeProcess())
log.debug("got platform agent client %s", str(self._pa_client))
# ping_agent can be issued before INITIALIZE
retval = self._pa_client.ping_agent(timeout=TIMEOUT)
log.debug('Base Platform ping_agent = %s', str(retval) )
cmd = AgentCommand(command=PlatformAgentEvent.INITIALIZE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform INITIALIZE = %s', str(retval) )
# GO_ACTIVE
cmd = AgentCommand(command=PlatformAgentEvent.GO_ACTIVE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform GO_ACTIVE = %s', str(retval) )
# RUN:
示例5: TestPlatformInstrument
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import read_platform_agent_instance [as 别名]
#.........这里部分代码省略.........
def _start_port_agent(self, instrument_agent_instance_obj=None):
"""
Construct and start the port agent, ONLY NEEDED FOR INSTRUMENT AGENTS.
"""
_port_agent_config = instrument_agent_instance_obj.port_agent_config
# It blocks until the port agent starts up or a timeout
_pagent = PortAgentProcess.launch_process(_port_agent_config, test_mode = True)
pid = _pagent.get_pid()
port = _pagent.get_data_port()
cmd_port = _pagent.get_command_port()
log.info("IMS:_start_pagent returned from PortAgentProcess.launch_process pid: %s ", pid)
# Hack to get ready for DEMO. Further though needs to be put int
# how we pass this config info around.
host = 'localhost'
driver_config = instrument_agent_instance_obj.driver_config
comms_config = driver_config.get('comms_config')
if comms_config:
host = comms_config.get('addr')
else:
log.warn("No comms_config specified, using '%s'" % host)
# Configure driver to use port agent port number.
instrument_agent_instance_obj.driver_config['comms_config'] = {
'addr' : host,
'cmd_port' : cmd_port,
'port' : port
}
instrument_agent_instance_obj.driver_config['pagent_pid'] = pid
self.imsclient.update_instrument_agent_instance(instrument_agent_instance_obj)
return self.imsclient.read_instrument_agent_instance(instrument_agent_instance_obj._id)
def _start_platform(self):
"""
Starts the given platform waiting for it to transition to the
UNINITIALIZED state (note that the agent starts in the LAUNCHING state).
More in concrete the sequence of steps here are:
- prepares subscriber to receive the UNINITIALIZED state transition
- launches the platform process
- waits for the start of the process
- waits for the transition to the UNINITIALIZED state
"""
##############################################################
# prepare to receive the UNINITIALIZED state transition:
async_res = AsyncResult()
def consume_event(evt, *args, **kwargs):
log.debug("Got ResourceAgentStateEvent %s from origin %r", evt.state, evt.origin)
if evt.state == PlatformAgentState.UNINITIALIZED:
async_res.set(evt)
# start subscriber:
sub = EventSubscriber(event_type="ResourceAgentStateEvent",
origin=self.platform_device,
callback=consume_event)
sub.start()
log.info("registered event subscriber to wait for state=%r from origin %r",
PlatformAgentState.UNINITIALIZED, self.platform_device)
#self._event_subscribers.append(sub)
sub._ready_event.wait(timeout=EVENT_TIMEOUT)
##############################################################
# now start the platform:
agent_instance_id = self.platform_agent_instance_id
log.debug("about to call start_platform_agent_instance with id=%s", agent_instance_id)
pid = self.imsclient.start_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
log.debug("start_platform_agent_instance returned pid=%s", pid)
#wait for start
agent_instance_obj = self.imsclient.read_platform_agent_instance(agent_instance_id)
gate = AgentProcessStateGate(self.processdispatchclient.read_process,
self.platform_device._id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(90), "The platform agent instance did not spawn in 90 seconds")
# Start a resource agent client to talk with the agent.
self._pa_client = ResourceAgentClient(self.platform_device,
name=gate.process_id,
process=FakeProcess())
log.debug("got platform agent client %s", str(self._pa_client))
##############################################################
# wait for the UNINITIALIZED event:
async_res.get(timeout=self._receive_timeout)
示例6: BaseIntTestPlatform
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import read_platform_agent_instance [as 别名]
#.........这里部分代码省略.........
platform ID 'LJ01D', which is a leaf in the simulated network.
"""
p_root = self._create_platform('LJ01D')
return p_root
def _create_small_hierarchy(self):
"""
Creates a small platform network consisting of 3 platforms as follows:
Node1D -> MJ01C -> LJ01D
where -> goes from parent to child.
"""
p_root = self._create_platform('Node1D')
p_child = self._create_platform('MJ01C', parent_platform_id='Node1D')
p_grandchild = self._create_platform('LJ01D', parent_platform_id='MJ01C')
self._assign_child_to_parent(p_child, p_root)
self._assign_child_to_parent(p_grandchild, p_child)
self._generate_config(p_root.platform_agent_instance_obj, p_root.platform_id, "_final")
return p_root
#################################################################
# start / stop platform
#################################################################
def _start_platform(self, agent_instance_id):
log.debug("about to call start_platform_agent_instance with id=%s", agent_instance_id)
pid = self.IMS.start_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
log.debug("start_platform_agent_instance returned pid=%s", pid)
#wait for start
agent_instance_obj = self.IMS.read_platform_agent_instance(agent_instance_id)
gate = ProcessStateGate(self.PDC.read_process,
agent_instance_obj.agent_process_id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(90), "The platform agent instance did not spawn in 90 seconds")
# Start a resource agent client to talk with the agent.
self._pa_client = ResourceAgentClient('paclient',
name=agent_instance_obj.agent_process_id,
process=FakeProcess())
log.debug("got platform agent client %s", str(self._pa_client))
def _stop_platform(self, agent_instance_id):
self.IMS.stop_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
#################################################################
# start / stop instrument
#################################################################
def _start_instrument(self, agent_instance_id):
log.debug("about to call start_instrument_agent_instance with id=%s", agent_instance_id)
pid = self.IMS.start_instrument_agent_instance(instrument_agent_instance_id=agent_instance_id)
log.debug("start_instrument_agent_instance returned pid=%s", pid)
#wait for start
agent_instance_obj = self.IMS.read_instrument_agent_instance(agent_instance_id)
gate = ProcessStateGate(self.PDC.read_process,
agent_instance_obj.agent_process_id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(90), "The instrument agent instance did not spawn in 90 seconds")
# Start a resource agent client to talk with the agent.
self._ia_client = ResourceAgentClient('paclient',
示例7: TestOmsLaunch
# 需要导入模块: from interface.services.sa.iinstrument_management_service import InstrumentManagementServiceClient [as 别名]
# 或者: from interface.services.sa.iinstrument_management_service.InstrumentManagementServiceClient import read_platform_agent_instance [as 别名]
#.........这里部分代码省略.........
class_name='DemoStreamAlertTransform')
self.platform_dprocdef_id = self.dataprocessclient.create_data_process_definition(dpd_obj)
#THERE SHOULD BE NO STREAMDEF REQUIRED HERE.
platform_streamdef_id = self.pubsubcli.create_stream_definition(name='platform_eng_parsed', parameter_dictionary_id=self.pdict_id)
self.dataprocessclient.assign_stream_definition_to_data_process_definition(platform_streamdef_id, self.platform_dprocdef_id, binding='output' )
config = {
'process':{
'timer_interval': 5,
'queue_name': 'a_queue',
'variable_name': 'input_voltage',
'time_field_name': 'preferred_timestamp',
'valid_values': [-100, 100],
'timer_origin': 'Interval Timer'
}
}
platform_data_process_id = self.dataprocessclient.create_data_process(self.platform_dprocdef_id, [self.data_product_id], {}, config)
self.dataprocessclient.activate_data_process(platform_data_process_id)
self.addCleanup(self.dataprocessclient.delete_data_process, platform_data_process_id)
#-------------------------------
# Launch Base Platform AgentInstance, connect to the resource agent client
#-------------------------------
agent_instance_id = base_platform_objs['agent_instance_id']
log.debug("about to call imsclient.start_platform_agent_instance with id=%s", agent_instance_id)
pid = self.imsclient.start_platform_agent_instance(platform_agent_instance_id=agent_instance_id)
log.debug("start_platform_agent_instance returned pid=%s", pid)
#wait for start
instance_obj = self.imsclient.read_platform_agent_instance(agent_instance_id)
gate = ProcessStateGate(self.processdispatchclient.read_process,
instance_obj.agent_process_id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(90), "The platform agent instance did not spawn in 90 seconds")
agent_instance_obj= self.imsclient.read_instrument_agent_instance(agent_instance_id)
log.debug('test_oms_create_and_launch: Platform agent instance obj: %s', str(agent_instance_obj))
# Start a resource agent client to talk with the instrument agent.
self._pa_client = ResourceAgentClient('paclient', name=agent_instance_obj.agent_process_id, process=FakeProcess())
log.debug(" test_oms_create_and_launch:: got pa client %s", str(self._pa_client))
log.debug("base_platform_config =\n%s", base_platform_config)
# ping_agent can be issued before INITIALIZE
retval = self._pa_client.ping_agent(timeout=TIMEOUT)
log.debug( 'Base Platform ping_agent = %s', str(retval) )
# issue INITIALIZE command to the base platform, which will launch the
# creation of the whole platform hierarchy rooted at base_platform_config['platform_id']
# cmd = AgentCommand(command=PlatformAgentEvent.INITIALIZE, kwargs=dict(plat_config=base_platform_config))
cmd = AgentCommand(command=PlatformAgentEvent.INITIALIZE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform INITIALIZE = %s', str(retval) )
# GO_ACTIVE
cmd = AgentCommand(command=PlatformAgentEvent.GO_ACTIVE)
retval = self._pa_client.execute_agent(cmd, timeout=TIMEOUT)
log.debug( 'Base Platform GO_ACTIVE = %s', str(retval) )
# RUN: