Coverage for ion/core/cc/cc_agent : 80.46%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#!/usr/bin/env python
@file ion/core/cc/cc_agent.py @author Michael Meisinger @brief capability container control process (agent) """
#from ion.agents.resource_agent import ResourceAgent
#class CCAgent(ResourceAgent):
""" Capability Container agent process interface """ # Init self and container
def plc_activate(self): # Declare CC announcement name
# Attach to CC announcement name label=annName+'.'+self.receiver.label, scope=FanoutReceiver.SCOPE_SYSTEM, group=self.receiver.group, handler=self.receive, error_handler=self.receive_error)
# Start with an identify request. Will lead to an announce by myself #@todo - Can not send a message to a base process which is not initialized!
# self.exchange_management_client = ExchangeManagementClient(ioninit.container_instance)
def plc_terminate(self):
def _send_announcement(self, event): """ Send announce message to CC broadcast name """ 'container-id':str(ioninit.container_instance.id), 'agent':str(self.id.full), 'version':ionconst.VERSION, 'start-time':self.start_time, 'current-time':pu.currenttime_ms(), 'event':event}
def set_announce(announce): global CF_announce
""" Service operation: announce a capability container """
def op_identify(self, content, headers, msg): """ Service operation: ask for identification; respond with announcement """ log.info("op_identify(). Sending announcement") self._check_alive()
# Set the new reference. All alive containers will respond afterwards self.last_identify = int(pu.currenttime_ms())
reactor.callLater(3, self._check_alive) yield self._send_announcement('identify')
""" Check through all containers if we have a potential down one. A container is deemed down if it has not responded since the preceding identify message. """ for cid,cal in self.contalive.copy().iteritems(): if cal<self.last_identify: log.info("Container %s missing. Deemed down, remove." % (cid)) del self.containers[cid] del self.contalive[cid]
def op_spawn(self, content, headers, msg): """ Service operation: spawns a local module """ procMod = str(content['module']) child = ProcessDesc(name=procMod.rpartition('.')[2], module=procMod) pid = yield self.spawn_child(child) yield self.reply_ok(msg, {'process-id':str(pid)})
pass
pass
def op_ping(self, content, headers, msg): """ Service operation: ping reply """ yield self.reply_ok(msg, {'pong':'pong'}, {'quiet':True})
def op_get_info(self, content, headers, msg): """ Service operation: replies with all kinds of local information """ #procsnew = processes.copy() #for pn,p in procsnew.iteritems(): # cls = p.pop('class') # p['classname'] = cls.__name__ # p['module'] = cls.__module__ #res = {'services':procsnew} #procs = {} #for rec in receivers: # recinfo = {} # recinfo['classname'] = rec.process.__class__.__name__ # recinfo['module'] = rec.process.__class__.__module__ # recinfo['label'] = rec.label # procs[rec.name] = recinfo #res['processes'] = procs res = {} yield self.reply_ok(msg, res)
# Spawn of the process using the module name
# --- CC Application interface
# Functions required def start(container, starttype, app_definition, *args, **kwargs): {'name':'ccagent','module':__name__}, ]
module=app_supervisor.__name__, spawnargs={'spawn-procs':agent_proc})
def stop(container, state):
#print "state", state
twistd -n --pidfile t1.pid cc -h amoeba.ucsd.edu -a sysname=mm res/scripts/newcc.py twistd -n --pidfile t2.pid cc -h amoeba.ucsd.edu -a sysname=mm res/scripts/newcc.py
send (2, {'op':'identify','content':''}) send (2, {'op':'spawn','content':{'module':'ion.play.hello_service'}}) """ |