def op_get_instrument_state(self, content, headers, msg): """ Service operation: . """ # Step 1: Extract the arguments from the UI generated message content commandInput = content['commandInput'] if 'instrumentID' in commandInput: inst_id = str(commandInput['instrumentID']) else: raise ValueError("Input for instrumentID not present") agent_pid = yield self.get_agent_pid_for_instrument(inst_id) if not agent_pid: raise StandardError("No agent found for instrument " + str(inst_id)) iaclient = InstrumentAgentClient(proc=self, target=agent_pid) inst_cap = yield iaclient.get_capabilities() if not inst_cap: raise StandardError("No capabilities available for instrument " + str(inst_id)) ci_commands = inst_cap['ci_commands'] instrument_commands = inst_cap['instrument_commands'] instrument_parameters = inst_cap['instrument_parameters'] ci_parameters = inst_cap['ci_parameters'] values = yield iaclient.get_from_instrument(instrument_parameters) resvalues = {} if values: resvalues = values yield self.reply_ok(msg, resvalues)
def main(): """ Initializes container """ logging.info("ION CONTAINER initializing... [Start an Instrument Agent]") processes = [] processes.extend(agent_procs) processes.extend(service_procs) # Start the processes sup = yield bootstrap.bootstrap(None, processes) eval_start_arguments() simulator = Simulator(INSTRUMENT_ID, 9000) simulator.start() ia_procs = [ {'name':'SBE49IA','module':'ion.agents.instrumentagents.SBE49_IA','class':'SBE49InstrumentAgent','spawnargs':{'instrument-id':INSTRUMENT_ID}}, ] yield bootstrap.spawn_processes(ia_procs, sup=sup) ia_pid = sup.get_child_id('SBE49IA') iaclient = InstrumentAgentClient(proc=sup, target=ia_pid) yield iaclient.register_resource(INSTRUMENT_ID)
def op_get_instrument_state(self, content, headers, msg): """ Service operation: . """ # Step 1: Extract the arguments from the UI generated message content commandInput = content['commandInput'] if 'instrumentID' in commandInput: inst_id = str(commandInput['instrumentID']) else: raise ValueError("Input for instrumentID not present") agent_pid = yield self.get_agent_pid_for_instrument(inst_id) if not agent_pid: raise StandardError("No agent found for instrument "+str(inst_id)) iaclient = InstrumentAgentClient(proc=self, target=agent_pid) inst_cap = yield iaclient.get_capabilities() if not inst_cap: raise StandardError("No capabilities available for instrument "+str(inst_id)) ci_commands = inst_cap['ci_commands'] instrument_commands = inst_cap['instrument_commands'] instrument_parameters = inst_cap['instrument_parameters'] ci_parameters = inst_cap['ci_parameters'] values = yield iaclient.get_from_instrument(instrument_parameters) resvalues = {} if values: resvalues = values yield self.reply_ok(msg, resvalues)
def main(): """ Initializes container """ logging.info("ION CONTAINER initializing... [LCA Java Integration Demo]") processes = [] processes.extend(agent_procs) processes.extend(demo_procs) # Start the processes sup = yield bootstrap.bootstrap(None, processes) simulator = Simulator(INSTRUMENT_ID, 9000) simulator.start() irc = InstrumentRegistryClient(proc=sup) ir1 = InstrumentResource.create_new_resource() ir1.name = "Demo_CTD_1" ir1.model = "SBE49" ir1.serial_num = "12345" ir1.fw_version = "1.334" ir1.manufactorer = "SeaBird" ir1 = yield irc.register_instrument_instance(ir1) ir1_ref = ir1.reference(head=True) ir2 = InstrumentResource.create_new_resource() ir2.name = "Demo_CTD_2" ir2.model = "SBE49" ir2.serial_num = "12399" ir2.fw_version = "1.335" ir2.manufactorer = "SeaBird" ir2 = yield irc.register_instrument_instance(ir2) dprc = DataProductRegistryClient(proc=sup) dp1 = DataProductResource.create_new_resource() dp1.instrument_ref = ir1_ref dp1.name = "Demo_Data_Product_1" dp1.dataformat = "binary" dp1 = yield dprc.register_data_product(dp1) ia_procs = [ { 'name': 'SBE49IA', 'module': 'ion.agents.instrumentagents.SBE49_IA', 'class': 'SBE49InstrumentAgent', 'spawnargs': { 'instrument-id': INSTRUMENT_ID } }, ] yield bootstrap.spawn_processes(ia_procs, sup=sup) ia_pid = sup.get_child_id('SBE49IA') iaclient = InstrumentAgentClient(proc=sup, target=ia_pid) yield iaclient.register_resource(INSTRUMENT_ID)
def op_start_instrument_agent(self, content, headers, msg): """ Service operation: Starts an instrument agent for a type of instrument. """ if 'instrumentID' in content: inst_id = str(content['instrumentID']) else: raise ValueError("Input for instrumentID not present") if 'model' in content: model = str(content['model']) else: raise ValueError("Input for model not present") if model != 'SBE49': raise ValueError("Only SBE49 supported!") agent_pid = yield self.get_agent_pid_for_instrument(inst_id) if agent_pid: raise StandardError("Agent already started for instrument " + str(inst_id)) simulator = Simulator(inst_id) simulator.start() topicname = "Inst/RAW/" + inst_id topic = PubSubTopicResource.create(topicname, "") # Use the service to create a queue and register the topic topic = yield self.dpsc.define_topic(topic) iagent_args = {} iagent_args['instrument-id'] = inst_id driver_args = {} driver_args['port'] = simulator.port driver_args['publish-to'] = topic.RegistryIdentity iagent_args['driver-args'] = driver_args iapd = ProcessDesc( **{ 'name': 'SBE49IA', 'module': 'ion.agents.instrumentagents.SBE49_IA', 'class': 'SBE49InstrumentAgent', 'spawnargs': iagent_args }) iagent_id = yield self.spawn_child(iapd) iaclient = InstrumentAgentClient(proc=self, target=iagent_id) yield iaclient.register_resource(inst_id) yield self.reply_ok(msg, "OK")
def main(): """ Initializes container """ logging.info("ION CONTAINER initializing... [LCA Java Integration Demo]") processes = [] processes.extend(agent_procs) processes.extend(demo_procs) # Start the processes sup = yield bootstrap.bootstrap(None, processes) simulator = Simulator(INSTRUMENT_ID, 9000) simulator.start() irc = InstrumentRegistryClient(proc=sup) ir1 = InstrumentResource.create_new_resource() ir1.name = "Demo_CTD_1" ir1.model = "SBE49" ir1.serial_num = "12345" ir1.fw_version = "1.334" ir1.manufactorer = "SeaBird" ir1 = yield irc.register_instrument_instance(ir1) ir1_ref = ir1.reference(head=True) ir2 = InstrumentResource.create_new_resource() ir2.name = "Demo_CTD_2" ir2.model = "SBE49" ir2.serial_num = "12399" ir2.fw_version = "1.335" ir2.manufactorer = "SeaBird" ir2 = yield irc.register_instrument_instance(ir2) dprc = DataProductRegistryClient(proc=sup) dp1 = DataProductResource.create_new_resource() dp1.instrument_ref = ir1_ref dp1.name = "Demo_Data_Product_1" dp1.dataformat = "binary" dp1 = yield dprc.register_data_product(dp1) ia_procs = [ {'name':'SBE49IA','module':'ion.agents.instrumentagents.SBE49_IA','class':'SBE49InstrumentAgent','spawnargs':{'instrument-id':INSTRUMENT_ID}}, ] yield bootstrap.spawn_processes(ia_procs, sup=sup) ia_pid = sup.get_child_id('SBE49IA') iaclient = InstrumentAgentClient(proc=sup,target=ia_pid) yield iaclient.register_resource(INSTRUMENT_ID)
def op_start_instrument_agent(self, content, headers, msg): """ Service operation: Starts an instrument agent for a type of instrument. """ if 'instrumentID' in content: inst_id = str(content['instrumentID']) else: raise ValueError("Input for instrumentID not present") if 'model' in content: model = str(content['model']) else: raise ValueError("Input for model not present") if model != 'SBE49': raise ValueError("Only SBE49 supported!") agent_pid = yield self.get_agent_pid_for_instrument(inst_id) if agent_pid: raise StandardError("Agent already started for instrument "+str(inst_id)) simulator = Simulator(inst_id) simulator.start() topicname = "Inst/RAW/"+inst_id topic = PubSubTopicResource.create(topicname,"") # Use the service to create a queue and register the topic topic = yield self.dpsc.define_topic(topic) iagent_args = {} iagent_args['instrument-id'] = inst_id driver_args = {} driver_args['port'] = simulator.port driver_args['publish-to'] = topic.RegistryIdentity iagent_args['driver-args'] = driver_args iapd = ProcessDesc(**{'name':'SBE49IA', 'module':'ion.agents.instrumentagents.SBE49_IA', 'class':'SBE49InstrumentAgent', 'spawnargs':iagent_args}) iagent_id = yield self.spawn_child(iapd) iaclient = InstrumentAgentClient(proc=self, target=iagent_id) yield iaclient.register_resource(inst_id) yield self.reply_ok(msg, "OK")
def op_execute_command(self, content, headers, msg): """ Service operation: Execute a command on an instrument. """ # Step 1: Extract the arguments from the UI generated message content commandInput = content['commandInput'] if 'instrumentID' in commandInput: inst_id = str(commandInput['instrumentID']) else: raise ValueError("Input for instrumentID not present") command = [] if 'command' in commandInput: command_op = str(commandInput['command']) else: raise ValueError("Input for command not present") command.append(command_op) arg_idx = 0 while True: argname = 'cmdArg' + str(arg_idx) arg_idx += 1 if argname in commandInput: command.append(str(commandInput[argname])) else: break # Step 2: Find the agent id for the given instrument id agent_pid = yield self.get_agent_pid_for_instrument(inst_id) if not agent_pid: yield self.reply_err( msg, "No agent found for instrument " + str(inst_id)) defer.returnValue(None) # Step 3: Interact with the agent to execute the command iaclient = InstrumentAgentClient(proc=self, target=agent_pid) commandlist = [ command, ] logging.info("Sending command to IA: " + str(commandlist)) cmd_result = yield iaclient.execute_instrument(commandlist) yield self.reply_ok(msg, cmd_result)
def op_execute_command(self, content, headers, msg): """ Service operation: Execute a command on an instrument. """ # Step 1: Extract the arguments from the UI generated message content commandInput = content['commandInput'] if 'instrumentID' in commandInput: inst_id = str(commandInput['instrumentID']) else: raise ValueError("Input for instrumentID not present") command = [] if 'command' in commandInput: command_op = str(commandInput['command']) else: raise ValueError("Input for command not present") command.append(command_op) arg_idx = 0 while True: argname = 'cmdArg'+str(arg_idx) arg_idx += 1 if argname in commandInput: command.append(str(commandInput[argname])) else: break # Step 2: Find the agent id for the given instrument id agent_pid = yield self.get_agent_pid_for_instrument(inst_id) if not agent_pid: yield self.reply_err(msg, "No agent found for instrument "+str(inst_id)) defer.returnValue(None) # Step 3: Interact with the agent to execute the command iaclient = InstrumentAgentClient(proc=self, target=agent_pid) commandlist = [command,] logging.info("Sending command to IA: "+str(commandlist)) cmd_result = yield iaclient.execute_instrument(commandlist) yield self.reply_ok(msg, cmd_result)
def setUp(self): yield self._start_container() # Start an instrument agent processes = [ {'name':'testSBE49IA','module':'ion.agents.instrumentagents.SBE49'}, ] sup = yield self._spawn_processes(processes) svc_id = sup.get_child_id('testSBE49IA') # Start a client (for the RPC) self.IAClient = InstrumentAgentClient(proc=sup, target=svc_id)
def plc_init(self): self.instrument_id = self.spawn_args.get('instrument-id', '123') self.instrument_port = self.spawn_args.get('port', 9000) yield self._configure_driver(self.spawn_args) logging.info( "INIT DRIVER for instrument ID=%s, port=%s, publish-to=%s" % (self.instrument_id, self.instrument_port, self.publish_to)) self.iaclient = InstrumentAgentClient(proc=self, target=self.proc_supid) logging.debug("Instrument driver initialized")
def setUp(self): yield self._start_container() services = [ {'name':'instreg','module':'ion.services.coi.agent_registry','class':'AgentRegistryService'}, {'name':'instreg','module':'ion.services.sa.instrument_registry','class':'InstrumentRegistryService'}, {'name':'pubsub_registry','module':'ion.services.dm.distribution.pubsub_registry','class':'DataPubSubRegistryService'}, {'name':'pubsub_service','module':'ion.services.dm.distribution.pubsub_service','class':'DataPubsubService'}, {'name':'dprodreg','module':'ion.services.sa.data_product_registry','class':'DataProductRegistryService'}, {'name':'instmgmt','module':'ion.services.sa.instrument_management','class':'InstrumentManagementService'}, {'name':'SBE49IA','module':'ion.agents.instrumentagents.SBE49_IA','class':'SBE49InstrumentAgent'}, ] sup = yield self._spawn_processes(services) #self.agreg_client = AgentRegistryClient(proc=sup) #yield self.agreg_client.clear_registry() self.ia_pid = sup.get_child_id('SBE49IA') self.iaclient = InstrumentAgentClient(proc=sup, target=self.ia_pid) self.imc = InstrumentManagementClient(proc=sup) self.newInstrument = {'manufacturer' : "SeaBird Electronics", 'model' : "unknown model", 'serial_num' : "1234", 'fw_version' : "1"} instrument = yield self.imc.create_new_instrument(self.newInstrument) self.inst_id = instrument.RegistryIdentity logging.info("*** Instrument created with ID="+str(self.inst_id)) self.simulator = Simulator(self.inst_id, 9000) self.simulator.start() yield self.iaclient.register_resource(self.inst_id)
class TestInstMgmtRT(IonTestCase): """ Testing instrument management service in end-to-end roundtrip mode """ @defer.inlineCallbacks def setUp(self): yield self._start_container() services = [ {'name':'instreg','module':'ion.services.coi.agent_registry','class':'AgentRegistryService'}, {'name':'instreg','module':'ion.services.sa.instrument_registry','class':'InstrumentRegistryService'}, {'name':'pubsub_registry','module':'ion.services.dm.distribution.pubsub_registry','class':'DataPubSubRegistryService'}, {'name':'pubsub_service','module':'ion.services.dm.distribution.pubsub_service','class':'DataPubsubService'}, {'name':'dprodreg','module':'ion.services.sa.data_product_registry','class':'DataProductRegistryService'}, {'name':'instmgmt','module':'ion.services.sa.instrument_management','class':'InstrumentManagementService'}, {'name':'SBE49IA','module':'ion.agents.instrumentagents.SBE49_IA','class':'SBE49InstrumentAgent'}, ] sup = yield self._spawn_processes(services) #self.agreg_client = AgentRegistryClient(proc=sup) #yield self.agreg_client.clear_registry() self.ia_pid = sup.get_child_id('SBE49IA') self.iaclient = InstrumentAgentClient(proc=sup, target=self.ia_pid) self.imc = InstrumentManagementClient(proc=sup) self.newInstrument = {'manufacturer' : "SeaBird Electronics", 'model' : "unknown model", 'serial_num' : "1234", 'fw_version' : "1"} instrument = yield self.imc.create_new_instrument(self.newInstrument) self.inst_id = instrument.RegistryIdentity logging.info("*** Instrument created with ID="+str(self.inst_id)) self.simulator = Simulator(self.inst_id, 9000) self.simulator.start() yield self.iaclient.register_resource(self.inst_id) @defer.inlineCallbacks def tearDown(self): yield self.simulator.stop() yield Simulator.stop_all_simulators() yield self._stop_container() @defer.inlineCallbacks def test_get_status(self): """ Get status back from instrument agent associated with instrument id """ res = yield self.imc.get_instrument_state(self.inst_id) self.assertNotEqual(res, None) logging.info("Instrument status: " +str(res)) @defer.inlineCallbacks def test_execute_command(self): """ Execute command through instrument agent associated with instrument id """ res = yield self.imc.execute_command(self.inst_id, 'start', [1]) logging.info("Command result 1" +str(res)) @defer.inlineCallbacks def test_start_agent(self): """ Start the agent with all """ newInstrument = {'manufacturer' : "SeaBird Electronics", 'model' : "SBE49", 'serial_num' : "99931", 'fw_version' : "1"} instrument = yield self.imc.create_new_instrument(newInstrument) inst_id1 = instrument.RegistryIdentity logging.info("*** Instrument 2 created with ID="+str(inst_id1)) res = yield self.imc.start_instrument_agent(inst_id1, 'SBE49') logging.info("Command result 1" +str(res))
class TestInstMgmtRT(IonTestCase): """ Testing instrument management service in end-to-end roundtrip mode """ @defer.inlineCallbacks def setUp(self): yield self._start_container() services = [ { 'name': 'instreg', 'module': 'ion.services.coi.agent_registry', 'class': 'AgentRegistryService' }, { 'name': 'instreg', 'module': 'ion.services.sa.instrument_registry', 'class': 'InstrumentRegistryService' }, { 'name': 'pubsub_registry', 'module': 'ion.services.dm.distribution.pubsub_registry', 'class': 'DataPubSubRegistryService' }, { 'name': 'pubsub_service', 'module': 'ion.services.dm.distribution.pubsub_service', 'class': 'DataPubsubService' }, { 'name': 'dprodreg', 'module': 'ion.services.sa.data_product_registry', 'class': 'DataProductRegistryService' }, { 'name': 'instmgmt', 'module': 'ion.services.sa.instrument_management', 'class': 'InstrumentManagementService' }, { 'name': 'SBE49IA', 'module': 'ion.agents.instrumentagents.SBE49_IA', 'class': 'SBE49InstrumentAgent' }, ] sup = yield self._spawn_processes(services) #self.agreg_client = AgentRegistryClient(proc=sup) #yield self.agreg_client.clear_registry() self.ia_pid = sup.get_child_id('SBE49IA') self.iaclient = InstrumentAgentClient(proc=sup, target=self.ia_pid) self.imc = InstrumentManagementClient(proc=sup) self.newInstrument = { 'manufacturer': "SeaBird Electronics", 'model': "unknown model", 'serial_num': "1234", 'fw_version': "1" } instrument = yield self.imc.create_new_instrument(self.newInstrument) self.inst_id = instrument.RegistryIdentity logging.info("*** Instrument created with ID=" + str(self.inst_id)) self.simulator = Simulator(self.inst_id, 9000) self.simulator.start() yield self.iaclient.register_resource(self.inst_id) @defer.inlineCallbacks def tearDown(self): yield self.simulator.stop() yield Simulator.stop_all_simulators() yield self._stop_container() @defer.inlineCallbacks def test_get_status(self): """ Get status back from instrument agent associated with instrument id """ res = yield self.imc.get_instrument_state(self.inst_id) self.assertNotEqual(res, None) logging.info("Instrument status: " + str(res)) @defer.inlineCallbacks def test_execute_command(self): """ Execute command through instrument agent associated with instrument id """ res = yield self.imc.execute_command(self.inst_id, 'start', [1]) logging.info("Command result 1" + str(res)) @defer.inlineCallbacks def test_start_agent(self): """ Start the agent with all """ newInstrument = { 'manufacturer': "SeaBird Electronics", 'model': "SBE49", 'serial_num': "99931", 'fw_version': "1" } instrument = yield self.imc.create_new_instrument(newInstrument) inst_id1 = instrument.RegistryIdentity logging.info("*** Instrument 2 created with ID=" + str(inst_id1)) res = yield self.imc.start_instrument_agent(inst_id1, 'SBE49') logging.info("Command result 1" + str(res))
def setUp(self): yield self._start_container() services = [ { 'name': 'instreg', 'module': 'ion.services.coi.agent_registry', 'class': 'AgentRegistryService' }, { 'name': 'instreg', 'module': 'ion.services.sa.instrument_registry', 'class': 'InstrumentRegistryService' }, { 'name': 'pubsub_registry', 'module': 'ion.services.dm.distribution.pubsub_registry', 'class': 'DataPubSubRegistryService' }, { 'name': 'pubsub_service', 'module': 'ion.services.dm.distribution.pubsub_service', 'class': 'DataPubsubService' }, { 'name': 'dprodreg', 'module': 'ion.services.sa.data_product_registry', 'class': 'DataProductRegistryService' }, { 'name': 'instmgmt', 'module': 'ion.services.sa.instrument_management', 'class': 'InstrumentManagementService' }, { 'name': 'SBE49IA', 'module': 'ion.agents.instrumentagents.SBE49_IA', 'class': 'SBE49InstrumentAgent' }, ] sup = yield self._spawn_processes(services) #self.agreg_client = AgentRegistryClient(proc=sup) #yield self.agreg_client.clear_registry() self.ia_pid = sup.get_child_id('SBE49IA') self.iaclient = InstrumentAgentClient(proc=sup, target=self.ia_pid) self.imc = InstrumentManagementClient(proc=sup) self.newInstrument = { 'manufacturer': "SeaBird Electronics", 'model': "unknown model", 'serial_num': "1234", 'fw_version': "1" } instrument = yield self.imc.create_new_instrument(self.newInstrument) self.inst_id = instrument.RegistryIdentity logging.info("*** Instrument created with ID=" + str(self.inst_id)) self.simulator = Simulator(self.inst_id, 9000) self.simulator.start() yield self.iaclient.register_resource(self.inst_id)
class TestInstrumentAgent(IonTestCase): @defer.inlineCallbacks def setUp(self): yield self._start_container() # Start an instrument agent processes = [ {'name':'testSBE49IA','module':'ion.agents.instrumentagents.SBE49'}, ] sup = yield self._spawn_processes(processes) svc_id = sup.get_child_id('testSBE49IA') # Start a client (for the RPC) self.IAClient = InstrumentAgentClient(proc=sup, target=svc_id) @defer.inlineCallbacks def tearDown(self): yield self._stop_container() @defer.inlineCallbacks def testGetSBE49Capabilities(self): """ Test the ability to gather capabilities from the SBE49 instrument capabilities """ (content, headers, message) = \ yield self.IAClient.rpc_send('getCapabilities', ()) self.assert_(set(IAcommands) == set(content['commands'])) self.assert_(set(IAparameters) == set(content['parameters'])) @defer.inlineCallbacks def testGetSetSBE49Params(self): """ Test the ability of the SBE49 driver to send and receive get, set, and other messages. Best called as RPC message pairs. """ (content, headers, message) = \ yield self.IAClient.rpc_send('get', ('baudrate','outputformat')) self.assertEqual(content, {'baudrate' : 9600, 'outputformat' : 0}) (content, headers, message) = \ yield self.IAClient.rpc_send('set', {'baudrate': 19200, 'outputformat': 1}) self.assertEqual(content, {'baudrate' : 19200, 'outputformat' : 1}) (content, headers, message) = \ yield self.IAClient.rpc_send('get', ('baudrate', 'outputformat')) self.assertEqual(content, {'baudrate' : 19200, 'outputformat' : 1}) (content, headers, message) = \ yield self.IAClient.rpc_send('setLifecycleState', 'undeveloped') self.assertEqual(content, 'undeveloped') (content, headers, message) = \ yield self.IAClient.rpc_send('getLifecycleState', '') self.assertEqual(content, 'undeveloped') (content, headers, message) = \ yield self.IAClient.rpc_send('setLifecycleState', 'developed') self.assertEqual(content, 'developed') (content, headers, message) = \ yield self.IAClient.rpc_send('getLifecycleState', '') self.assertEqual(content, 'developed')