本文整理汇总了Python中pyon.agent.agent.ResourceAgentClient.execute_agent方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceAgentClient.execute_agent方法的具体用法?Python ResourceAgentClient.execute_agent怎么用?Python ResourceAgentClient.execute_agent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.agent.agent.ResourceAgentClient
的用法示例。
在下文中一共展示了ResourceAgentClient.execute_agent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute_agent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
def execute_agent(self, resource_id='', command=None):
"""Execute command on the agent.
"""
res_type = self._get_resource_type(resource_id)
if self._has_agent(res_type):
rac = ResourceAgentClient(resource_id=resource_id)
return rac.execute_agent(resource_id=resource_id, command=command)
raise BadRequest("Not implemented for resource type %s" % res_type)
示例2: _process_cmd_agent_execute
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
def _process_cmd_agent_execute(resource_id, res_obj=None):
agent_cmd = get_arg('agentcmd')
from pyon.agent.agent import ResourceAgentClient
from interface.objects import AgentCommand
rac = ResourceAgentClient(process=containerui_instance, resource_id=resource_id)
ac = AgentCommand(command=agent_cmd)
res = rac.execute_agent(ac)
res_dict = get_value_dict(res)
res_str = get_formatted_value(res_dict, fieldtype="dict")
return res_str
示例3: start_agent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
def start_agent(self, agent_instance_id, resource_id):
if not agent_instance_id or not resource_id:
log.warn("Could not %s agent %s for device %s", self.op, agent_instance_id, resource_id)
return
res_obj = self.rr.read(resource_id)
log.info('Starting agent...')
if res_obj.type_ == RT.ExternalDatasetAgentInstance or res_obj == RT.ExternalDataset:
dams = DataAcquisitionManagementServiceProcessClient(process=self)
dams.start_external_dataset_agent_instance(agent_instance_id)
elif res_obj.type_ == RT.InstrumentDevice:
ims = InstrumentManagementServiceClient()
ims.start_instrument_agent_instance(agent_instance_id)
elif res_obj.type_ == RT.PlatformDevice:
ims = InstrumentManagementServiceClient()
ims.start_platform_agent_instance(agent_instance_id)
else:
BadRequest("Attempt to start unsupported agent type: %s", res_obj.type_)
log.info('Agent started!')
activate = self.CFG.get("activate", True)
if activate:
log.info('Activating agent...')
client = ResourceAgentClient(resource_id, process=self)
client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN))
client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE))
log.info('Agent active!')
示例4: start_agent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
def start_agent(self, agent_instance_id, resource_id):
if not agent_instance_id or not resource_id:
log.warn("Could not op=%s agent %s for device %s", self.op, agent_instance_id, resource_id)
return
res_obj = self.rr.read(resource_id)
ai_obj = self.rr.read(agent_instance_id)
try:
client = ResourceAgentClient(resource_id, process=self)
if self.force:
log.warn("Agent for resource %s seems running - continuing", resource_id)
if self.autoclean:
self.cleanup_agent(agent_instance_id, resource_id)
else:
log.warn("Agent for resource %s seems running", resource_id)
return
except NotFound:
pass # This is expected
log.info('Starting agent...')
if ai_obj.type_ == RT.ExternalDatasetAgentInstance:
dams = DataAcquisitionManagementServiceProcessClient(process=self)
dams.start_external_dataset_agent_instance(agent_instance_id, headers=self._get_system_actor_headers(),
timeout=self.timeout)
elif ai_obj.type_ == RT.InstrumentAgentInstance:
ims = InstrumentManagementServiceProcessClient(process=self)
ims.start_instrument_agent_instance(agent_instance_id, headers=self._get_system_actor_headers(),
timeout=self.timeout)
elif ai_obj.type_ == RT.PlatformAgentInstance:
ims = InstrumentManagementServiceProcessClient(process=self)
ims.start_platform_agent_instance(agent_instance_id, headers=self._get_system_actor_headers(),
timeout=self.timeout)
else:
BadRequest("Attempt to start unsupported agent type: %s", ai_obj.type_)
log.info('Agent started!')
activate = self.CFG.get("activate", True)
if activate:
log.info('Activating agent...')
client = ResourceAgentClient(resource_id, process=self)
client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE),
headers=self._get_system_actor_headers(), timeout=self.timeout)
client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE),
headers=self._get_system_actor_headers(), timeout=self.timeout)
client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN),
headers=self._get_system_actor_headers(), timeout=self.timeout)
client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE),
headers=self._get_system_actor_headers(), timeout=self.timeout)
log.info('Agent in auto-sample mode!')
示例5: execute_agent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
def execute_agent(self, resource_id='', command=None):
"""Execute command on the agent.
@param resource_id The id of the resource agennt.
@param command An AgentCommand containing the command.
@retval result An AgentCommandResult containing the result.
@throws BadRequest if the command was malformed.
@throws NotFound if the command is not available in current state.
@param resource_id str
@param command AgentCommand
@retval result AgentCommandResult
@throws BadRequest if the command was malformed.
@throws NotFound if the command is not implemented in the agent.
"""
res_type = self._get_resource_type(resource_id)
if self._has_agent(res_type):
rac = ResourceAgentClient(resource_id=resource_id)
return rac.execute_agent(resource_id=resource_id, command=command)
raise BadRequest("Not implemented for resource type %s" % res_type)
示例6: _start_agent
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
def _start_agent(self, eda_instance_id, resource_id):
log.info('Starting agent...')
dams = DataAcquisitionManagementServiceProcessClient(process=self)
dams.start_external_dataset_agent_instance(eda_instance_id)
log.info('Agent started!')
activate = self.CFG.get("activate", True)
if activate:
log.info('Activating agent...')
client = ResourceAgentClient(resource_id, process=self)
client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN))
client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE))
log.info('Agent active!')
示例7: on_start
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
def on_start(self):
rr = self.container.resource_registry
name = self.CFG.get("dataset")
if name: # We are looking for an external dataset!
log.trace("Looking for an external dataset with name %s", name)
objects,_ = rr.find_resources(RT.ExternalDataset)
filtered_objs = [obj for obj in objects if obj.name == name]
if (filtered_objs) == []:
raise ConfigNotFound("No appropriate ExternalDataset objects loaded")
external_dataset = filtered_objs[0]
instance_id = rr.read_object(subject=external_dataset._id,
predicate=PRED.hasAgentInstance,
object_type=RT.ExternalDatasetAgentInstance,
id_only=True)
dams = get_service_registry().services['data_acquisition_management'].client(process=self)
dams.start_external_dataset_agent_instance(instance_id)
client = ResourceAgentClient(external_dataset._id, process=FakeProcess())
else:
name = self.CFG.get("instrument")
if name: # We are looking for an instrument device!
log.trace("Looking for an instrument device with name %s", name)
objects,_ = rr.find_resources(RT.InstrumentDevice)
filtered_objs = [obj for obj in objects if obj.name == name]
if (filtered_objs) == []:
raise ConfigNotFound("No appropriate InstrumentDevice objects loaded")
instrument_device = filtered_objs[0]
log.trace("Found instrument device: %s", instrument_device)
instance_id = rr.read_object(subject=instrument_device._id,
predicate=PRED.hasAgentInstance,
object_type=RT.ExternalDatasetAgentInstance,
id_only=True)
dams = get_service_registry().services['data_acquisition_management'].client(process=self)
proc_id = dams.start_external_dataset_agent_instance(instance_id)
client = ResourceAgentClient(instrument_device._id, process=FakeProcess())
else:
raise ConfigNotFound("Could not find dataset or instrument_device value name")
log.info('Activating agent...')
client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN))
client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE))
log.info('Now reading: %s', name)
示例8: on_start
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
def on_start(self):
name = self.CFG.get("dataset")
rr = self.container.resource_registry
objects,_ = rr.find_resources(RT.ExternalDataset)
filtered_objs = [obj for obj in objects if obj.name == name]
external_dataset = filtered_objs[0]
instance_id = rr.read_object(subject=external_dataset._id, predicate=PRED.hasAgentInstance, object_type=RT.ExternalDatasetAgentInstance, id_only=True)
dams = get_service_registry().services['data_acquisition_management'].client(process=self)
dams.start_external_dataset_agent_instance(instance_id)
# OLD METHOD of starting agent, now this code has been implemented and tested in DAMS
#obj,_ = rr.find_objects(subject=external_dataset._id, predicate=PRED.hasAgentInstance, object_type=RT.ExternalDatasetAgentInstance)
#agent_instance = obj[0]
#obj,_ = rr.find_objects(object_type=RT.ExternalDatasetAgent, predicate=PRED.hasAgentDefinition, subject=agent_instance._id)
#agent = obj[0]
#stream_definition_id = agent_instance.dataset_driver_config['dh_cfg']['stream_def']
#stream_definition = rr.read(stream_definition_id)
#data_producer_id = agent_instance.dataset_driver_config['dh_cfg']['data_producer_id']
#data_producer = rr.read(data_producer_id) #subject="", predicate="", object_type="", assoc="", id_only=False)
#data_product = rr.read_object(object_type=RT.DataProduct, predicate=PRED.hasOutputProduct, subject=external_dataset._id)
#ids,_ = rr.find_objects(data_product._id, PRED.hasStream, RT.Stream, id_only=True)
#stream_id = ids[0]
#route = pubsub.read_stream_route(stream_id)
#agent_instance.dataset_agent_config['driver_config']['dh_cfg']['stream_id'] = stream_id
#agent_instance.dataset_agent_config['driver_config']['stream_id'] = stream_id
#agent_instance.dataset_agent_config['driver_config']['dh_cfg']['stream_route'] = route
#
#log.info('launching agent process: %s.%s', agent.handler_module, agent.handler_class)
#self.container.spawn_process(name=agent_instance.name,
# module=agent.handler_module, cls=agent.handler_class,
# config=agent_instance.dataset_agent_config)
#
# should i wait for process (above) to start
# before launching client (below)?
#
log.info('activating agent...')
client = ResourceAgentClient(external_dataset._id, process=FakeProcess())
client.execute_agent(AgentCommand(command=ResourceAgentEvent.INITIALIZE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.GO_ACTIVE))
client.execute_agent(AgentCommand(command=ResourceAgentEvent.RUN))
client.execute_resource(command=AgentCommand(command=DriverEvent.START_AUTOSAMPLE))
log.info('now reading external dataset: %s', name)
示例9: TestAgentPersistence
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
#.........这里部分代码省略.........
self._ia_pid = container_client.spawn_process(name=IA_NAME,
module=IA_MOD,
cls=IA_CLS,
config=agent_config,
process_id=self._ia_pid)
# Start a resource agent client to talk with the instrument agent.
self._ia_client = None
self._ia_client = ResourceAgentClient(IA_RESOURCE_ID, process=FakeProcess())
log.info('Got instrument agent client %s.', str(self._ia_client))
def _stop_agent(self):
"""
"""
if self._ia_pid:
container_client = ContainerAgentClient(node=self.container.node,
name=self.container.name)
container_client.terminate_process(self._ia_pid)
if self._ia_client:
self._ia_client = None
def _verify_agent_reset(self):
"""
Check agent state and reset if necessary.
This called if a test fails and reset hasn't occurred.
"""
if self._ia_client is None:
return
state = self._ia_client.get_agent_state()
if state != ResourceAgentState.UNINITIALIZED:
cmd = AgentCommand(command=ResourceAgentEvent.RESET)
retval = self._ia_client.execute_agent(cmd)
self._ia_client = None
###############################################################################
# Tests.
###############################################################################
def test_agent_config_persistence(self):
"""
test_agent_config_persistence
Test that agent parameter configuration is persisted between running
instances.
"""
# Start the agent.
self._start_agent()
# We start in uninitialized state.
# In this state there is no driver process.
state = self._ia_client.get_agent_state()
self.assertEqual(state, ResourceAgentState.UNINITIALIZED)
# Ping the agent.
retval = self._ia_client.ping_agent()
log.info(retval)
# Confirm the default agent parameters.
#{'streams': {'raw': ['quality_flag', 'ingestion_timestamp', 'port_timestamp', 'raw', 'lat', 'driver_timestamp', 'preferred_timestamp', 'lon', 'internal_timestamp', 'time'], 'parsed': ['quality_flag', 'ingestion_timestamp', 'port_timestamp', 'pressure', 'lat', 'driver_timestamp', 'conductivity', 'preferred_timestamp', 'temp', 'density', 'salinity', 'lon', 'internal_timestamp', 'time']}}
retval = self._ia_client.get_agent(['streams'])['streams']
self.assertIn('raw', retval.keys())
self.assertIn('parsed', retval.keys())
#{'pubrate': {'raw': 0, 'parsed': 0}}
示例10: TestActivateInstrumentIntegration
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
#.........这里部分代码省略.........
raw_stream_def = SBE37_RAW_stream_definition()
raw_stream_def_id = self.pubsubcli.create_stream_definition(container=raw_stream_def)
dp_obj = IonObject(
RT.DataProduct,
name="the raw data",
description="raw stream test",
temporal_domain=tdom,
spatial_domain=sdom,
)
data_product_id2 = self.dpclient.create_data_product(dp_obj, raw_stream_def_id, parameter_dictionary)
log.debug("new dp_id = %s", str(data_product_id2))
self.damsclient.assign_data_product(input_resource_id=instDevice_id, data_product_id=data_product_id2)
self.dpclient.activate_data_product_persistence(data_product_id=data_product_id2)
# Retrieve the id of the OUTPUT stream from the out Data Product
stream_ids, _ = self.rrclient.find_objects(data_product_id2, PRED.hasStream, None, True)
log.debug("Data product streams2 = %s", str(stream_ids))
self.imsclient.start_instrument_agent_instance(instrument_agent_instance_id=instAgentInstance_id)
inst_agent_instance_obj = self.imsclient.read_instrument_agent_instance(instAgentInstance_id)
log.debug("Instrument agent instance obj: = %s", str(inst_agent_instance_obj))
# Start a resource agent client to talk with the instrument agent.
# self._ia_client = ResourceAgentClient('123xyz', name=inst_agent_instance_obj.agent_process_id, process=FakeProcess())
self._ia_client = ResourceAgentClient(instDevice_id, process=FakeProcess())
log.debug("test_activateInstrumentSample: got ia client %s", str(self._ia_client))
cmd = AgentCommand(command="initialize")
retval = self._ia_client.execute_agent(cmd)
log.debug("test_activateInstrumentSample: initialize %s", str(retval))
time.sleep(1)
log.debug("test_activateInstrumentSample: Sending go_active command (L4-CI-SA-RQ-334)")
cmd = AgentCommand(command="go_active")
reply = self._ia_client.execute_agent(cmd)
log.debug("test_activateInstrument: return value from go_active %s", str(reply))
time.sleep(1)
cmd = AgentCommand(command="get_current_state")
retval = self._ia_client.execute_agent(cmd)
state = retval.result
log.debug(
"test_activateInstrumentSample: current state after sending go_active command %s (L4-CI-SA-RQ-334)",
str(state),
)
cmd = AgentCommand(command="run")
reply = self._ia_client.execute_agent(cmd)
log.debug("test_activateInstrumentSample: run %s", str(reply))
time.sleep(1)
log.debug("test_activateInstrumentSample: calling acquire_sample ")
cmd = AgentCommand(command="acquire_sample")
reply = self._ia_client.execute(cmd)
log.debug("test_activateInstrumentSample: return from acquire_sample %s", str(reply))
time.sleep(1)
log.debug("test_activateInstrumentSample: calling acquire_sample 2")
cmd = AgentCommand(command="acquire_sample")
reply = self._ia_client.execute(cmd)
log.debug("test_activateInstrumentSample: return from acquire_sample 2 %s", str(reply))
示例11: TestIMSDeployAsPrimaryDevice
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
#.........这里部分代码省略.........
# -------------------------------
# Launch InstrumentAgentInstance Sim2, connect to the resource agent client
# -------------------------------
self.imsclient.start_instrument_agent_instance(instrument_agent_instance_id=newInstAgentInstance_id)
self.addCleanup(
self.imsclient.stop_instrument_agent_instance, instrument_agent_instance_id=newInstAgentInstance_id
)
# wait for start
instance_obj = self.imsclient.read_instrument_agent_instance(newInstAgentInstance_id)
gate = ProcessStateGate(
self.processdispatchclient.read_process, instance_obj.agent_process_id, ProcessStateEnum.RUNNING
)
self.assertTrue(
gate.await(30),
"The instrument agent instance (%s) did not spawn in 30 seconds" % instance_obj.agent_process_id,
)
inst_agent2_instance_obj = self.imsclient.read_instrument_agent_instance(newInstAgentInstance_id)
print "test_deployAsPrimaryDevice: Instrument agent instance obj: = ", inst_agent2_instance_obj
# Start a resource agent client to talk with the instrument agent.
self._ia_client_sim2 = ResourceAgentClient(
"iaclient Sim2", name=inst_agent2_instance_obj.agent_process_id, process=FakeProcess()
)
print "activate_instrument: got _ia_client_sim2 %s", self._ia_client_sim2
log.debug(" test_deployAsPrimaryDevice:: got _ia_client_sim2 %s", str(self._ia_client_sim2))
# -------------------------------
# Streaming Sim1 (old instrument)
# -------------------------------
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
retval = self._ia_client_sim1.execute_agent(cmd)
log.debug("test_deployAsPrimaryDevice: initialize %s", str(retval))
log.debug("(L4-CI-SA-RQ-334): Sending go_active command ")
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
reply = self._ia_client_sim1.execute_agent(cmd)
log.debug("test_deployAsPrimaryDevice: return value from go_active %s", str(reply))
self.assertTrue(reply)
cmd = AgentCommand(command=ResourceAgentEvent.GET_RESOURCE_STATE)
retval = self._ia_client_sim1.execute_agent(cmd)
state = retval.result
log.debug("(L4-CI-SA-RQ-334): current state after sending go_active command %s", str(state))
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
reply = self._ia_client_sim1.execute_agent(cmd)
log.debug("test_deployAsPrimaryDevice: run %s", str(reply))
gevent.sleep(2)
cmd = AgentCommand(command=SBE37ProtocolEvent.START_AUTOSAMPLE)
retval = self._ia_client_sim1.execute_resource(cmd)
log.debug("test_activateInstrumentSample: return from START_AUTOSAMPLE: %s", str(retval))
# -------------------------------
# Streaming Sim 2 (new instrument)
# -------------------------------
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
retval = self._ia_client_sim2.execute_agent(cmd)
log.debug("test_deployAsPrimaryDevice: initialize_sim2 %s", str(retval))
log.debug("(L4-CI-SA-RQ-334): Sending go_active command ")
示例12: TestExternalDatasetAgentMgmt
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
#.........这里部分代码省略.........
# Start a resource agent client to talk with the instrument agent.
self._dsa_client = ResourceAgentClient(extDataset_id, process=FakeProcess())
print "TestExternalDatasetAgentMgmt: got ia client %s", self._dsa_client
log.debug("TestExternalDatasetAgentMgmt: got dataset client %s", str(self._dsa_client))
# cmd=AgentCommand(command='initialize')
# _ = self._dsa_client.execute_agent(cmd)
#
# cmd = AgentCommand(command='go_active')
# _ = self._dsa_client.execute_agent(cmd)
#
# cmd = AgentCommand(command='run')
# _ = self._dsa_client.execute_agent(cmd)
#
# log.info('Send an unconstrained request for data (\'new data\')')
# cmd = AgentCommand(command='acquire_data')
# self._dsa_client.execute(cmd)
#
# log.info('Send a second unconstrained request for data (\'new data\'), should be rejected')
# cmd = AgentCommand(command='acquire_data')
# self._dsa_client.execute(cmd)
#
# cmd = AgentCommand(command='reset')
# _ = self._dsa_client.execute_agent(cmd)
# cmd = AgentCommand(command='get_current_state')
# retval = self._dsa_client.execute_agent(cmd)
# state = retval.result
# TODO: Think about what we really should be testing at this point
# The following is taken from ion.agents.data.test.test_external_dataset_agent.ExternalDatasetAgentTestBase.test_states()
# TODO: Do we also need to show data retrieval?
cmd = AgentCommand(command="get_current_state")
retval = self._dsa_client.execute_agent(cmd)
state = retval.result
self.assertEqual(state, InstrumentAgentState.UNINITIALIZED)
cmd = AgentCommand(command="initialize")
retval = self._dsa_client.execute_agent(cmd)
cmd = AgentCommand(command="get_current_state")
retval = self._dsa_client.execute_agent(cmd)
state = retval.result
self.assertEqual(state, InstrumentAgentState.INACTIVE)
cmd = AgentCommand(command="go_active")
retval = self._dsa_client.execute_agent(cmd)
cmd = AgentCommand(command="get_current_state")
retval = self._dsa_client.execute_agent(cmd)
state = retval.result
self.assertEqual(state, InstrumentAgentState.IDLE)
cmd = AgentCommand(command="run")
retval = self._dsa_client.execute_agent(cmd)
cmd = AgentCommand(command="get_current_state")
retval = self._dsa_client.execute_agent(cmd)
state = retval.result
self.assertEqual(state, InstrumentAgentState.OBSERVATORY)
cmd = AgentCommand(command="pause")
retval = self._dsa_client.execute_agent(cmd)
cmd = AgentCommand(command="get_current_state")
retval = self._dsa_client.execute_agent(cmd)
state = retval.result
self.assertEqual(state, InstrumentAgentState.STOPPED)
cmd = AgentCommand(command="resume")
示例13: TestInstrumentAgentWithTrhph
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
#.........这里部分代码省略.........
for sub in self._data_subscribers:
sub.stop()
for gl in self._data_greenlets:
gl.kill()
def _start_event_subscribers(self):
"""
Create subscribers for agent and driver events.
"""
def consume_event(*args, **kwargs):
log.info('Test recieved ION event: args=%s, kwargs=%s, event=%s.',
str(args), str(kwargs), str(args[0]))
self._events_received.append(args[0])
if self._no_events and self._no_events == len(self._event_received):
self._async_event_result.set()
event_sub = EventSubscriber(event_type="DeviceEvent", callback=consume_event)
event_sub.start()
self._event_subscribers.append(event_sub)
def _stop_event_subscribers(self):
"""
Stop event subscribers on cleanup.
"""
log.info('cleanup: _stop_event_subscribers called.')
for sub in self._event_subscribers:
sub.stop()
def _initialize_and_run(self):
"""
Called explicitly by the tests that do regular operations.
"""
cmd = AgentCommand(command='get_agent_state')
retval = self._ia_client.execute_agent(cmd)
state = retval.result
self.assertEqual(state, InstrumentAgentState.UNINITIALIZED)
cmd = AgentCommand(command='initialize')
retval = self._ia_client.execute_agent(cmd)
cmd = AgentCommand(command='get_agent_state')
retval = self._ia_client.execute_agent(cmd)
state = retval.result
self.assertEqual(state, InstrumentAgentState.INACTIVE)
cmd = AgentCommand(command='go_active')
retval = self._ia_client.execute_agent(cmd)
cmd = AgentCommand(command='get_agent_state')
retval = self._ia_client.execute_agent(cmd)
state = retval.result
self.assertEqual(state, InstrumentAgentState.IDLE)
cmd = AgentCommand(command='run')
retval = self._ia_client.execute_agent(cmd)
cmd = AgentCommand(command='get_agent_state')
retval = self._ia_client.execute_agent(cmd)
state = retval.result
self.assertEqual(state, InstrumentAgentState.OBSERVATORY)
def _reset(self):
"""
Set as a clean-up to make sure the agent is reset after each test,
so the driver is stopped.
"""
log.info("_reset called: sending 'reset' command to agent")
cmd = AgentCommand(command='reset')
示例14: TestCTDTransformsIntegration
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
#.........这里部分代码省略.........
# L2 Density: Create the data process
#-------------------------------------------------------------------------------------
l2_density_all_data_process_id = self.dataprocessclient.create_data_process(self.ctd_L2_density_dprocdef_id, [ctd_parsed_data_product], [self.ctd_l2_density_output_dp_id])
self.dataprocessclient.activate_data_process(l2_density_all_data_process_id)
data_process = self.rrclient.read(l2_density_all_data_process_id)
process_ids, _ = self.rrclient.find_objects(subject=l2_density_all_data_process_id, predicate=PRED.hasProcess, id_only=True)
self.addCleanup(self.processdispatchclient.cancel_process, process_ids[0])
#-------------------------------------------------------------------------------------
# Launch InstrumentAgentInstance, connect to the resource agent client
#-------------------------------------------------------------------------------------
self.imsclient.start_instrument_agent_instance(instrument_agent_instance_id=instAgentInstance_id)
self.addCleanup(self.imsclient.stop_instrument_agent_instance,
instrument_agent_instance_id=instAgentInstance_id)
inst_agent_instance_obj= self.imsclient.read_instrument_agent_instance(instAgentInstance_id)
# Wait for instrument agent to spawn
gate = AgentProcessStateGate(self.processdispatchclient.read_process,
instDevice_id,
ProcessStateEnum.RUNNING)
self.assertTrue(gate.await(15), "The instrument agent instance did not spawn in 15 seconds")
# Start a resource agent client to talk with the instrument agent.
self._ia_client = ResourceAgentClient(instDevice_id, to_name=gate.process_id, process=FakeProcess())
#-------------------------------------------------------------------------------------
# Streaming
#-------------------------------------------------------------------------------------
cmd = AgentCommand(command=ResourceAgentEvent.INITIALIZE)
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
cmd = AgentCommand(command=ResourceAgentEvent.GO_ACTIVE)
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
cmd = AgentCommand(command=ResourceAgentEvent.GET_RESOURCE_STATE)
retval = self._ia_client.execute_agent(cmd)
state = retval.result
log.debug("(L4-CI-SA-RQ-334): current state after sending go_active command %s", str(state))
self.assertTrue(state, 'DRIVER_STATE_COMMAND')
cmd = AgentCommand(command=ResourceAgentEvent.RUN)
reply = self._ia_client.execute_agent(cmd)
self.assertTrue(reply.status == 0)
#todo ResourceAgentClient no longer has method set_param
# # Make sure the sampling rate and transmission are sane.
# params = {
# SBE37Parameter.NAVG : 1,
# SBE37Parameter.INTERVAL : 5,
# SBE37Parameter.TXREALTIME : True
# }
# self._ia_client.set_param(params)
#todo There is no ResourceAgentEvent attribute for go_streaming... so what should be the command for it?
cmd = AgentCommand(command=SBE37ProtocolEvent.START_AUTOSAMPLE)
retval = self._ia_client.execute_resource(cmd)
# This gevent sleep is there to test the autosample time, which will show something different from default
# only if the instrument runs for over a minute
示例15: BaseIntTestPlatform
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import execute_agent [as 别名]
#.........这里部分代码省略.........
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())
return client
def _get_state(self):
state = self._pa_client.get_agent_state()
return state
def _assert_state(self, state):
self.assertEquals(self._get_state(), state)
def _execute_agent(self, cmd):
log.info("_execute_agent: cmd=%r kwargs=%r ...", cmd.command, cmd.kwargs)
time_start = time.time()
#retval = self._pa_client.execute_agent(cmd, timeout=timeout)
retval = self._pa_client.execute_agent(cmd)
elapsed_time = time.time() - time_start
log.info("_execute_agent: cmd=%r elapsed_time=%s, retval = %s",
cmd.command, elapsed_time, str(retval))
return retval
#################################################################
# commands that concrete tests can call
#################################################################
def _ping_agent(self):
retval = self._pa_client.ping_agent()
self.assertIsInstance(retval, str)
def _ping_resource(self):
cmd = AgentCommand(command=PlatformAgentEvent.PING_RESOURCE)
if self._get_state() == PlatformAgentState.UNINITIALIZED:
# should get ServerError: "Command not handled in current state"
with self.assertRaises(ServerError):
self._pa_client.execute_agent(cmd)
else:
# In all other states the command should be accepted:
retval = self._execute_agent(cmd)
self.assertEquals("PONG", retval.result)
def _get_metadata(self):
cmd = AgentCommand(command=PlatformAgentEvent.GET_METADATA)
retval = self._execute_agent(cmd)
md = retval.result