Bug fix with actor, @TODO: add orchestrator with appropriate design pattern

community
Steve L. Nyemba 8 years ago
parent 29ac48a2eb
commit 45bd19cd66

@ -32,6 +32,8 @@ class Actor(Thread):
def execute(self,cmd): def execute(self,cmd):
stream = None stream = None
try: try:
print self.getIdentifier()
print cmd
handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE) handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
stream = handler.communicate()[0] stream = handler.communicate()[0]
except Exception,e: except Exception,e:
@ -42,7 +44,15 @@ class Actor(Thread):
message = json.loads(stream) message = json.loads(stream)
content = message['content'] content = message['content']
sender = message['from'] sender = message['from']
self.post(to=sender,content=content) if content.lower() == 'quit' :
channel.close()
print " *** ",self.getIdentifier()
elif content.lower() == 'ping':
self.post(to=sender,content="1")
else:
self.process(content)
self.post(to=sender,content=content)
#message = None #message = None
#try: #try:
#message = json.loads(stream) #message = json.loads(stream)
@ -62,10 +72,10 @@ class Actor(Thread):
host = self.config['api'] host = self.config['api']
uid = self.config['key'] uid = self.config['key']
qid = to#self.config['id'] qid = to#self.config['id']
print [host,uid,qid]
qwriter = QueueWriter(host=host,uid=uid,qid=qid) qwriter = QueueWriter(host=host,uid=uid,qid=qid)
qwriter.init(qid) qwriter.init(qid)
qwriter.write(label=qid,row="got it") qwriter.write(label=qid,row=content)
#qwriter.close() #qwriter.close()
pass pass
def run(self): def run(self):
@ -82,7 +92,7 @@ class Kill(Actor):
def __init__(self,config): def __init__(self,config):
Actor.__init__(self,config) Actor.__init__(self,config)
def process(self,item): def process(self,item):
cmd = "".join(["ps -eo pid,command|grep ",item,'|grep -E"^ {0,1}[0-9]+" -o|xargs kill -9']) cmd = "".join(["ps -eo pid,command|grep ",item,'|grep -E "^ {0,1}[0-9]+" -o|xargs kill -9'])
self.execute(cmd) self.execute(cmd)
# #
# We need to make sure we can get assess the process on this server # We need to make sure we can get assess the process on this server
@ -96,9 +106,15 @@ class Start(Actor):
cmd = " ".join([path,args]) cmd = " ".join([path,args])
self.execute(cmd) self.execute(cmd)
"""
This class is designed to send a message to a given AMQP enpoint
The AMQP endpoint is implemented by QueueWriter class
"""
class Alert(Actor): class Alert(Actor):
pass def process(self,item):
pass
config = {"id":"demo","key":"[0v8]-247&7!v3","api":"localhost"} config = {"id":"demo","key":"[0v8]-247&7!v3","api":"localhost"}
actor = Kill(config) actor = Kill(config)
actor.start() actor.start()

Loading…
Cancel
Save