added job handling... a bit... :)

This commit is contained in:
Rafael.Timmerberg 2013-07-02 23:30:31 +02:00
commit 0616ea4701
5 changed files with 77 additions and 36 deletions

View file

@ -12,7 +12,8 @@ from periods import CronPeriod, DatePeriod, IntervalPeriod
from lib.services.service import Service
from lib.processors.processor import Processor
from lib.parsers.parser import Parser
from lib.tasks.task import Task
from lib.tasks.task import Task
from argparse import Namespace
MOD_SERVICES = "services"
MOD_PROCESSORS = "processors"

View file

@ -2,9 +2,7 @@
This is what job_function needs as parameter for each job to successfully
execute.
"""
from lib.core.command import Command
from datetime import datetime
def generateId():
i = 0
@ -12,16 +10,18 @@ def generateId():
yield i
i += 1
class JobInfo:
class Job:
def __init__(self, service):
self.service = service
self.name = generateId()
self.job = None
self.jobInfos = []
self.hostThreshold = {}
for host in service.get_hostgroup().get_hosts():
self.hostThreshold[host] = service.get_threshold()
def __str__(self):
return "JobInfo " + str(self.name)
return str(self.__dict__)
def set_logger(self, log):
self.log = log
@ -31,8 +31,33 @@ class JobInfo:
def handle_call(self):
self.log.d("handle call")
self.log.d(self.service)
try:
self.service._execute()
except Exception, e:
self.log.d(e)
for host in self.service.get_hostgroup().get_hosts():
try:
jobInfo = JobInfo(host, self.service)
result = self.service._execute(host)
jobInfo.set_result(result)
jobInfo.set_successfull(self.service.was_execution_successful())
jobInfo.set_execution_end()
except Exception, e:
self.log.d(e)
class JobInfo:
def __init__(self, host, service):
self.id = generateId()
self.host = host
self.service = service
self.executionBegin = datetime.now()
def set_result(self, result):
self.result = result
def set_execution_end(self):
self.executionEnd = datetime.now()
def set_execution_successful(self, successful):
self.executionSuccess = successful

View file

@ -105,25 +105,40 @@ class Service(object):
def needs_arguments(self):
return False
def _execute(self):
self.pre_execute()
result = {}
for host in self.get_hostgroup().get_hosts():
result[host] = self.execute(host)
def set_execution_successful(self, successful):
self.executionSuccessful = successful
parseResult = self.parse_result(result)
self.handle_result(parseResult)
def was_execution_successful(self):
return self.executionSuccessful
def _execute(self, host):
try:
self.set_execution_successful(True)
self.pre_execute(host)
result = self.execute(host)
parseResult = self.parse_result(result)
self.post_execute(parseResult)
return parseResult
except Exception, e:
self.set_execution_successful(False)
self._threshold -= 1
raise e
def execute(self, host):
pass
def pre_execute(self):
def pre_execute(self, host):
pass
def parse_result(self, executionResult):
result = []
for parser in self.get_parser():
result.append(parser.parse(executionResult))
def handle_result(self, parseResult):
pass
return result
def post_execute(self, parseResult):
pass