#********************************************************************
#
# Copyright (C) 2005-2006 Hari Krishna Dara
#
# This file is part of p4admin.
#
# p4admin is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# p4admin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#*******************************************************************
import logging
import time
import string
import config
import runSync
import notify
import verify
import scheduler
import utils
log = logging.getLogger(__name__)
def runSched():
sched = scheduler.Scheduler()
for job in ('quickSync', 'fullSync', 'checkpoint', 'verify'):
registerJob(sched, job)
sched.start()
try:
sched.wait()
finally:
if sched.isAlive():
log.warn('Error in protocol detected... '
'Scheduler.wait() returned while it is still alive')
else:
log.debug('Scheduler finished execution')
def registerJob(sched, job):
if eval('config.'+job+'Enabled'):
initialTime = utils.computeFirstRunTime(eval('config.'+job+'FirstRun'))
log.debug("Initial %s happens at: %s", job, time.ctime(initialTime))
actHandCls = eval(string.capitalize(job[0])+job[1:]+'ActionHandler')
actHand = actHandCls(initialTime,
eval('config.'+job+'RunInterval'), eval('config.'+job+'Heartbeat'))
actHand.setNotifyCompletion(eval('config.'+job+'NotifyRun'))
actHand.setExpectedRunDuration(eval('config.'+job+'ExpectedRunDuration'))
sched.registerAction(actHand)
else:
log.debug("%s job disabled", job)
class FullSyncActionHandler(scheduler.ActionHandlerBase):
def __init__(self, firstRunTime, interval, heartbeat):
super(FullSyncActionHandler, self).__init__("FullSyncAction",
firstRunTime, interval, True, heartbeat, 1)
def executeImpl(self):
return runSync.runSync(False)
class QuickSyncActionHandler(scheduler.ActionHandlerBase):
def __init__(self, firstRunTime, interval, heartbeat):
super(QuickSyncActionHandler, self).__init__("QuickSyncAction",
firstRunTime, interval, True, heartbeat, 2)
def executeImpl(self):
return runSync.runSync(True)
class CheckpointActionHandler(scheduler.ActionHandlerBase):
def __init__(self, firstRunTime, interval, heartbeat):
super(CheckpointActionHandler, self).__init__("CheckpointAction",
firstRunTime, interval, True, heartbeat, 1)
def executeImpl(self):
import checkpt
return checkpt.takeCheckpoint()
class VerifyActionHandler(scheduler.ActionHandlerBase):
def __init__(self, firstRunTime, interval, heartbeat):
super(VerifyActionHandler, self).__init__("VerifyAction", firstRunTime,
interval, True, heartbeat, 1)
def executeImpl(self):
return verify.verifyLocalP4Server()
if __name__ == "__main__":
runSched()