Example #1
0
File: job.py Project: wehu/pydv
 def agent_checker(cls):
     for agent_id in cls.agent_status:
         if (time() - cls.agent_status[agent_id]) > cls.agent_time_out:
             if agent_id in cls.running_cmds:
                 logger.warning('agent {} time out and terminated'.format(agent_id))
                 GCFEngine.kill_agent(agent_id)
                 cmd_spec = cls.running_cmds[agent_id]
                 v = cls.agent_visitor[agent_id]
                 del cls.visitor_agent[v]
                 del cls.agent_visitor[agent_id]
                 del cls.agent_status[agent_id]
                 del cls.running_cmds[agent_id]
                 cls.push_cmd(v, cmd_spec)
     cls.timer = Timer(cls.time_out, cls.agent_checker, args=(cls,))
     cls.timer.start()
Example #2
0
 def agent_checker(cls):
     for agent_id in cls.agent_status:
         if (time() - cls.agent_status[agent_id]) > cls.agent_time_out:
             if agent_id in cls.running_cmds:
                 logger.warning(
                     'agent {} time out and terminated'.format(agent_id))
                 GCFEngine.kill_agent(agent_id)
                 cmd_spec = cls.running_cmds[agent_id]
                 v = cls.agent_visitor[agent_id]
                 del cls.visitor_agent[v]
                 del cls.agent_visitor[agent_id]
                 del cls.agent_status[agent_id]
                 del cls.running_cmds[agent_id]
                 cls.push_cmd(v, cmd_spec)
     cls.timer = Timer(cls.time_out, cls.agent_checker, args=(cls, ))
     cls.timer.start()
Example #3
0
    def require_cmd(cls, data):
        agent_id = data['agent_id']
        agent_host = data['agent_host']
        agent_port = data['agent_port']
        cmd_spec = {'cmd': 'terminate'}
        if agent_id in cls.pending_cmds:
            cmd_spec = cls.pending_cmds[agent_id]
            cmd_spec['logfile'] = path.join(cls.out_dir, 'cmds', agent_id)
            del cls.pending_cmds[agent_id]
            if agent_id in cls.reused_agents:
                cls.reused_agents.remove(agent_id)
            cls.running_cmds[agent_id] = cmd_spec

        out_data = marshal.dumps(cmd_spec)
        re_try = 10
        while True:
            try:
                s = socket.socket()
                s.connect((agent_host, agent_port))
                try:
                    s.send(out_data)
                finally:
                    s.close()
                break
            except Exception as e:
                re_try -= 1
                logger.warning(str(e))
                if re_try > 0:
                    pass
                else:
                    raise e

        if agent_id not in cls.running_cmds and agent_id not in cls.reused_agents:
            if agent_id in cls.idle_agents:
                cls.idle_agents.remove(agent_id)
            if agent_id in cls.agent_visitor:
                GCFEngine.kill_agent(agent_id)
                v = cls.agent_visitor[agent_id]
                del cls.visitor_agent[v]
                del cls.agent_visitor[agent_id]
                del cls.agent_status[agent_id]
Example #4
0
File: job.py Project: wehu/pydv
    def require_cmd(cls, data):
        agent_id = data['agent_id']
        agent_host = data['agent_host']
        agent_port = data['agent_port']
        cmd_spec = {'cmd' : 'terminate'}
        if agent_id in cls.pending_cmds:
            cmd_spec = cls.pending_cmds[agent_id]
            cmd_spec['logfile'] = path.join(cls.out_dir, 'cmds', agent_id)
            del cls.pending_cmds[agent_id]
            if agent_id in cls.reused_agents:
                cls.reused_agents.remove(agent_id)
            cls.running_cmds[agent_id] = cmd_spec
       
        out_data = marshal.dumps(cmd_spec)
        re_try = 10
        while True:
            try:
                s = socket.socket()
                s.connect((agent_host, agent_port))
                try:
                    s.send(out_data)
                finally:
                    s.close()
                break
            except Exception as e:
                re_try -= 1
                logger.warning(str(e))
                if re_try > 0:
                    pass
                else:
                    raise e

        if agent_id not in cls.running_cmds and agent_id not in cls.reused_agents:
            if agent_id in cls.idle_agents:
                cls.idle_agents.remove(agent_id)
            if agent_id in cls.agent_visitor:
                GCFEngine.kill_agent(agent_id)
                v = cls.agent_visitor[agent_id]
                del cls.visitor_agent[v]
                del cls.agent_visitor[agent_id]
                del cls.agent_status[agent_id]
Example #5
0
 def cleanup(cls):
     if cls.timer:
         cls.timer.cancel()
     for agent_id in cls.agent_visitor:
         GCFEngine.kill_agent(agent_id)
Example #6
0
File: job.py Project: wehu/pydv
 def cleanup(cls):
     if cls.timer:
         cls.timer.cancel()
     for agent_id in cls.agent_visitor:
         GCFEngine.kill_agent(agent_id)