def get_resource_ref(self): """ Obtain the resource ID that the resource is registered with. """ (content, headers, msg) = yield self.rpc_send('get_resource_ref', '') if content['status'] == 'OK': defer.returnValue(AgentInstance.decode(content['value'])) else: defer.returnValue(None)
def get_resource_instance(self): """ Obtain the resource instance object from the existing registered resource. """ (content, headers, msg) = \ yield self.rpc_send('get_resource_instance', '') if content['status'] == 'OK': content_decode = AgentInstance.decode(content['value']) assert (isinstance(content_decode, AgentInstance)) defer.returnValue(content_decode) else: defer.returnValue(None)
def get_resource_instance(self): """ Obtain the resource instance object from the existing registered resource. """ (content, headers, msg) = \ yield self.rpc_send('get_resource_instance', '') if content['status'] == 'OK': content_decode = AgentInstance.decode(content['value']) assert(isinstance(content_decode, AgentInstance)) defer.returnValue(content_decode) else: defer.returnValue(None)
def op_register_resource(self, content, headers, msg): """ Registers or re-registers self in the agent registry. @param content Must include an encoded AgentInstance subclass that may or may not have been previously filled out. The instance class should be appropriate to the type of resource being registered. Perhaps the client is checking the type? @todo Turn initial parameter asserts into a decode check @note Registering an existing InstrumentAgent with an existing registry @msc hscale = "2"; User, InstrumentAgentClient, InstrumentAgentResourceInstance, InstrumentAgent, ResourceAgent, ResourceAgentClient, AgentRegistryClient, AgentRegistry; User -> InstrumentAgent [label="instantiate and spawn IA subclass"]; User -> InstrumentAgentClient[label="instantiate IAClient subclass"]; AgentRegistryClient -> InstrumentAgent [label="reference stored in IA"]; --- [label="All setup now, registry must already have a client on hand"]; User => InstrumentAgentClient [label="register_resource()"]; InstrumentAgentClient -> InstrumentAgentResourceInstance [label="instantiate"]; InstrumentAgentClient -> InstrumentAgentResourceInstance [label="get driver address"]; InstrumentAgentClient <- InstrumentAgentResourceInstance [label="driver address"]; InstrumentAgentClient => InstrumentAgentClient [label="ResourceAgentClient.register_resource()"]; InstrumentAgentClient =>> InstrumentAgent [label="op_register_resource() via AMQP"]; InstrumentAgent => AgentRegistryClient [label="register_agent_instance(self, custom_descriptor)"]; AgentRegistryClient => AgentRegistryClient [label="describe_instance(agent_instance, custom_descriptor)"]; AgentRegistryClient << AgentRegistryClient [label="return AgentDescription"]; AgentRegistryClient => AgentRegistryClient [label="find_registered_agent_instance_from_description(above)"]; AgentRegistryClient =>> AgentRegistry [label="register_resource() via base class AMQP"]; AgentRegistryClient <<= AgentRegistry [label="return via AMQP"]; InstrumentAgent << AgentRegistryClient [label="Success/failure"]; InstrumentAgentClient <<= ResourceAgent [label="Success/failure via InstrumentAgent via AMQP"]; User << InstrumentAgentClient [label="return"]; @endmsc """ if (content == ""): descriptor = None elif (content != None): descriptor = AgentInstance.decode(content) assert ((descriptor == None) or (isinstance(descriptor, AgentInstance))) assert (descriptor != "") # Register the instance/description returned_instance = \ yield self.reg_client.register_agent_instance(self, descriptor) self.resource_ref = returned_instance.reference(head=True) if (self.resource_ref == None) or (self.resource_ref == False): yield self.reply_err(msg, "Could not register instance!") else: yield self.reply_ok(msg, self.resource_ref.encode())
def op_register_resource(self, content, headers, msg): """ Registers or re-registers self in the agent registry. @param content Must include an encoded AgentInstance subclass that may or may not have been previously filled out. The instance class should be appropriate to the type of resource being registered. Perhaps the client is checking the type? @todo Turn initial parameter asserts into a decode check @note Registering an existing InstrumentAgent with an existing registry @msc hscale = "2"; User, InstrumentAgentClient, InstrumentAgentResourceInstance, InstrumentAgent, ResourceAgent, ResourceAgentClient, AgentRegistryClient, AgentRegistry; User -> InstrumentAgent [label="instantiate and spawn IA subclass"]; User -> InstrumentAgentClient[label="instantiate IAClient subclass"]; AgentRegistryClient -> InstrumentAgent [label="reference stored in IA"]; --- [label="All setup now, registry must already have a client on hand"]; User => InstrumentAgentClient [label="register_resource()"]; InstrumentAgentClient -> InstrumentAgentResourceInstance [label="instantiate"]; InstrumentAgentClient -> InstrumentAgentResourceInstance [label="get driver address"]; InstrumentAgentClient <- InstrumentAgentResourceInstance [label="driver address"]; InstrumentAgentClient => InstrumentAgentClient [label="ResourceAgentClient.register_resource()"]; InstrumentAgentClient =>> InstrumentAgent [label="op_register_resource() via AMQP"]; InstrumentAgent => AgentRegistryClient [label="register_agent_instance(self, custom_descriptor)"]; AgentRegistryClient => AgentRegistryClient [label="describe_instance(agent_instance, custom_descriptor)"]; AgentRegistryClient << AgentRegistryClient [label="return AgentDescription"]; AgentRegistryClient => AgentRegistryClient [label="find_registered_agent_instance_from_description(above)"]; AgentRegistryClient =>> AgentRegistry [label="register_resource() via base class AMQP"]; AgentRegistryClient <<= AgentRegistry [label="return via AMQP"]; InstrumentAgent << AgentRegistryClient [label="Success/failure"]; InstrumentAgentClient <<= ResourceAgent [label="Success/failure via InstrumentAgent via AMQP"]; User << InstrumentAgentClient [label="return"]; @endmsc """ if (content == ""): descriptor = None elif (content != None): descriptor = AgentInstance.decode(content) assert((descriptor == None) or (isinstance(descriptor, AgentInstance))) assert(descriptor != "") # Register the instance/description returned_instance = \ yield self.reg_client.register_agent_instance(self, descriptor) self.resource_ref = returned_instance.reference(head=True) if (self.resource_ref == None) or (self.resource_ref == False): yield self.reply_err(msg, "Could not register instance!") else: yield self.reply_ok(msg, self.resource_ref.encode())
def register_resource(self, agent_instance=None, descriptor=None): """ Have the resource register itself with the agent registry via the client that has been set via set__client() @param resource_desc The ResourceDescription object to register @param resource_inst The instance object to register """ if (agent_instance == None): (content, headers, msg) = yield self.rpc_send('register_resource', '') else: assert(isinstance(agent_instance, (AgentInstance, AgentDescription))) # Add resource agent part of the information agent_instance.proc_id = str(self.target) (content, headers, msg) = \ yield self.rpc_send('register_resource', agent_instance.encode()) if (content['status'] == 'OK'): defer.returnValue(AgentInstance.decode(content['value'])) else: defer.returnValue(None)
def register_resource(self, agent_instance=None, descriptor=None): """ Have the resource register itself with the agent registry via the client that has been set via set__client() @param resource_desc The ResourceDescription object to register @param resource_inst The instance object to register """ if (agent_instance == None): (content, headers, msg) = yield self.rpc_send('register_resource', '') else: assert (isinstance(agent_instance, (AgentInstance, AgentDescription))) # Add resource agent part of the information agent_instance.proc_id = str(self.target) (content, headers, msg) = \ yield self.rpc_send('register_resource', agent_instance.encode()) if (content['status'] == 'OK'): defer.returnValue(AgentInstance.decode(content['value'])) else: defer.returnValue(None)