removed the jobInfo object and let the job execute and store all data; looks better to me now
This commit is contained in:
parent
1466ec35dc
commit
fdacf38062
4 changed files with 73 additions and 79 deletions
|
|
@ -88,8 +88,8 @@ def parse_args():
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def handle_job(jobInfo):
|
def handle_job(job):
|
||||||
jobInfo.handle_call()
|
job.handle_call()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
||||||
|
|
@ -28,21 +28,29 @@ logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Job:
|
class Job:
|
||||||
def __init__(self, service, host, members, processors, core, taskList, hostgroup):
|
def __init__(self, service, host, members, processors, core, task_list, hostgroup):
|
||||||
self.service = service
|
self.service = service
|
||||||
self.host = host
|
self.host = host
|
||||||
self.members = members
|
self.members = members
|
||||||
self.processors = processors
|
self.processors = processors
|
||||||
self.core = core
|
self.core = core
|
||||||
self.taskList = taskList
|
self.task_list = task_list
|
||||||
self.hostgroup = hostgroup
|
self.hostgroup = hostgroup
|
||||||
self.jobInfos = []
|
self.job_infos = []
|
||||||
self.jobIndex = -1
|
self.job_index = -1
|
||||||
self.jobInfoSize = 10
|
self.job_info_size = 10
|
||||||
self.jobThreshold = 0
|
self.job_threshold = 0
|
||||||
self.job_fails = 0
|
self.job_fails = 0
|
||||||
self.job_wins = 0
|
self.job_wins = 0
|
||||||
self._enabled = True
|
self.enabled = True
|
||||||
|
self.result = None
|
||||||
|
self.scheduler_job = None
|
||||||
|
self.execution_begin = datetime.now()
|
||||||
|
self.execution_end = None
|
||||||
|
self.errorcode = -1
|
||||||
|
self.message = None
|
||||||
|
self.execution_success = False
|
||||||
|
self.jobHex = self.hex_string()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.__dict__)
|
return str(self.__dict__)
|
||||||
|
|
@ -60,72 +68,60 @@ class Job:
|
||||||
ret = "0" + ret
|
ret = "0" + ret
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def set_job(self, job):
|
def set_job(self, scheduler_job):
|
||||||
self.job = job
|
self.scheduler_job = scheduler_job
|
||||||
|
|
||||||
def set_enabled(self, enabled=True):
|
def set_enabled(self, enabled=True):
|
||||||
self._enabled = enabled
|
self.enabled = enabled
|
||||||
|
|
||||||
def add_job_Info(self, jobInfo):
|
def add_job_info(self, job_info):
|
||||||
self.jobIndex += 1
|
self.job_index += 1
|
||||||
if self.jobIndex > self.jobInfoSize:
|
if self.job_index > self.job_info_size:
|
||||||
self.jobIndex = 0
|
self.job_index = 0
|
||||||
self.jobInfos[self.jobIndex] = jobInfo
|
self.job_infos[self.job_index] = job_info
|
||||||
|
|
||||||
def handle_threshold(self, jobInfo, serviceThreshold, executionSucessful):
|
def handle_threshold(self, service_threshold, execution_sucessful):
|
||||||
if executionSucessful:
|
if execution_sucessful:
|
||||||
if self.jobThreshold > 0:
|
if self.job_threshold > 0:
|
||||||
#TODO: maybe set threshold_handling for each service optionally; will override core setting!
|
#TODO: maybe set threshold_handling for each service optionally; will override core setting!
|
||||||
if self.core["threshold_handling"] == "reset":
|
if self.core["threshold_handling"] == "reset":
|
||||||
# Reset counter to 0
|
|
||||||
logger.debug("Threshold Reset")
|
logger.debug("Threshold Reset")
|
||||||
self.jobThreshold = 0
|
self.job_threshold = 0
|
||||||
else:
|
else:
|
||||||
# Decrement the counter (default)
|
|
||||||
logger.debug("Threshold Decrement")
|
logger.debug("Threshold Decrement")
|
||||||
self.jobThreshold -= 1
|
self.job_threshold -= 1
|
||||||
self.job_wins += 1
|
self.job_wins += 1
|
||||||
else:
|
else:
|
||||||
self.job_fails += 1
|
self.job_fails += 1
|
||||||
self.jobThreshold += 1
|
self.job_threshold += 1
|
||||||
|
|
||||||
if self.jobThreshold >= serviceThreshold:
|
if self.job_threshold >= service_threshold:
|
||||||
logger.debug("Threshold reached!")
|
logger.debug("Threshold reached!")
|
||||||
self.handle_alarm(jobInfo, self.jobThreshold - serviceThreshold)
|
self.handle_alarm()
|
||||||
|
|
||||||
def handle_alarm(self, jobInfo, thresholdOffset):
|
def handle_alarm(self):
|
||||||
for member in self.members:
|
for member in self.members:
|
||||||
self.taskList.execute_task_infos(jobInfo.get_message(), member.get_tasks())
|
self.task_list.execute_task_infos(self.get_message(), member.get_tasks())
|
||||||
|
|
||||||
def handle_call(self):
|
def handle_call(self):
|
||||||
logger.debug("handle call")
|
logger.debug("handle call")
|
||||||
logger.debug(self.service)
|
logger.debug(self.service)
|
||||||
if self._enabled:
|
if self.enabled:
|
||||||
try:
|
try:
|
||||||
jobInfo = JobInfo(self.hex_string(), self.host, self.service)
|
self.service.execute(self)
|
||||||
self.service._execute(jobInfo)
|
self.set_execution_end()
|
||||||
jobInfo.set_execution_end()
|
self.handle_threshold(self.service.get_threshold(), self.was_execution_successful())
|
||||||
|
logger.info("Code: " + str(self.get_errorcode()) + ", Message: " + str(self.get_message()))
|
||||||
self.handle_threshold(jobInfo, self.service.get_threshold(), jobInfo.was_execution_successful())
|
|
||||||
|
|
||||||
logger.info("Code: " + str(jobInfo.get_errorcode()) + ", Message: " + str(jobInfo.get_message()))
|
|
||||||
self.add_job_Info(jobInfo)
|
|
||||||
|
|
||||||
|
self.reset_errorcode(-1)
|
||||||
|
self.set_execution_successful(False)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.debug(e)
|
logger.debug(e)
|
||||||
else:
|
else:
|
||||||
logger.debug("Job " + self.hex_string() + " disabled")
|
logger.debug("Job " + self.hex_string() + " disabled")
|
||||||
|
|
||||||
|
def reset_errorcode(self, errorcode):
|
||||||
class JobInfo(object):
|
self.errorcode = errorcode
|
||||||
def __init__(self, jobHex, host, service):
|
|
||||||
self.jobHex = jobHex
|
|
||||||
self.host = host
|
|
||||||
self.service = service
|
|
||||||
self.executionBegin = datetime.now()
|
|
||||||
self._errorcode = -1
|
|
||||||
self._message = None
|
|
||||||
self._executionSuccess = False
|
|
||||||
|
|
||||||
def get_host(self):
|
def get_host(self):
|
||||||
return self.host
|
return self.host
|
||||||
|
|
@ -134,22 +130,22 @@ class JobInfo(object):
|
||||||
self.result = result
|
self.result = result
|
||||||
|
|
||||||
def set_execution_end(self):
|
def set_execution_end(self):
|
||||||
self.executionEnd = datetime.now()
|
self.execution_end = datetime.now()
|
||||||
|
|
||||||
def set_execution_successful(self, successful):
|
def set_execution_successful(self, successful):
|
||||||
self._executionSuccess = successful
|
self.execution_success = successful
|
||||||
|
|
||||||
def was_execution_successful(self):
|
def was_execution_successful(self):
|
||||||
return self._executionSuccess
|
return self.execution_success
|
||||||
|
|
||||||
def set_message(self, msg):
|
def set_message(self, msg):
|
||||||
self._message = msg
|
self.message = msg
|
||||||
|
|
||||||
def get_message(self):
|
def get_message(self):
|
||||||
return self._message
|
return self.message
|
||||||
|
|
||||||
def set_errorcode(self, errcode):
|
def set_errorcode(self, errcode):
|
||||||
self._errorcode = errcode
|
self.errorcode = errcode
|
||||||
|
|
||||||
def get_errorcode(self):
|
def get_errorcode(self):
|
||||||
return self._errorcode
|
return self.errorcode
|
||||||
|
|
@ -66,20 +66,20 @@ class DummyService(Service):
|
||||||
def needs_arguments(self):
|
def needs_arguments(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def execute(self, jobInfo):
|
def execute(self, job):
|
||||||
|
|
||||||
time.sleep(self.sleep)
|
time.sleep(self.sleep)
|
||||||
|
|
||||||
if self.fail > 0:
|
if self.fail > 0:
|
||||||
jobInfo.set_errorcode(1)
|
job.set_errorcode(1)
|
||||||
jobInfo.set_message("[dummy: " + jobInfo.jobHex + "] Failed on host: " + jobInfo.get_host() +
|
job.set_message("[dummy: " + job.jobHex + "] Failed on host: " + job.get_host() +
|
||||||
" Sleep: " + str(self.sleep) + " Fail: " + str(self.fail))
|
" Sleep: " + str(self.sleep) + " Fail: " + str(self.fail))
|
||||||
|
|
||||||
if jobInfo.get_errorcode() == -1:
|
if job.get_errorcode() == -1:
|
||||||
jobInfo.set_execution_successful(True)
|
job.set_execution_successful(True)
|
||||||
jobInfo.set_errorcode(0)
|
job.set_errorcode(0)
|
||||||
jobInfo.set_message("[dummy: " + jobInfo.jobHex + "] Success on host: " + jobInfo.get_host() +
|
job.set_message("[dummy: " + job.jobHex + "] Success on host: " + job.get_host() +
|
||||||
" Sleep: " + str(self.sleep) + " Fail: " + str(self.fail))
|
" Sleep: " + str(self.sleep) + " Fail: " + str(self.fail))
|
||||||
|
|
||||||
|
|
||||||
def create(kwargs):
|
def create(kwargs):
|
||||||
|
|
|
||||||
|
|
@ -125,31 +125,29 @@ class Service(object):
|
||||||
def needs_arguments(self):
|
def needs_arguments(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _execute(self, jobInfo):
|
def execute(self, job):
|
||||||
try:
|
try:
|
||||||
self.pre_execute(jobInfo)
|
self.pre_execute(job)
|
||||||
|
self.execute(job)
|
||||||
self.execute(jobInfo)
|
#self.parse_result(job)
|
||||||
self.parse_result(jobInfo)
|
self.post_execute(job)
|
||||||
self.post_execute(jobInfo)
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.set_execution_successful(False)
|
job.set_execution_successful(False)
|
||||||
self._threshold -= 1
|
self._threshold -= 1
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def execute(self, jobInfo):
|
##def execute(self):
|
||||||
|
# pass
|
||||||
|
|
||||||
|
def pre_execute(self, job):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def pre_execute(self, jobInfo):
|
def parse_result(self, job):
|
||||||
pass
|
|
||||||
|
|
||||||
def parse_result(self, jobInfo):
|
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for parser in self.get_parser():
|
for parser in self.get_parser():
|
||||||
result.append(parser.parse(jobInfo))
|
result.append(parser.parse(job))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def post_execute(self, jobInfo):
|
def post_execute(self, job):
|
||||||
pass
|
pass
|
||||||
Loading…
Add table
Add a link
Reference in a new issue