1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#!/usr/bin/env python
# Copyright 2004 Canonical Ltd. All rights reserved.
# Author: Daniel Silverstone <daniel.silverstone@canonical.com>
# Celso Providelo <celso.providelo@canonical.com>
#
# Builder Slave Scanner and result collector
__metaclass__ = type
import sys
import logging
import os
from optparse import OptionParser
from zope.component import getUtility
from canonical.lp import initZopeless
from canonical.launchpad.interfaces import IDistroArchReleaseSet
from canonical.launchpad.scripts.builddmaster import BuilddMaster
from canonical.launchpad.scripts.lockfile import LockFile
from canonical.launchpad.scripts import (
execute_zcml_for_scripts, logger_options, logger
)
_default_lockfile = '/var/lock/buildd-master.lock'
def doSlaveScan(logger):
"""Proceed the Slave Scanning Process."""
# XXX cprov 20051019
# retrive the user infromation from the config file
# setup a transaction manager
tm = initZopeless(dbuser='fiera')
buildMaster = BuilddMaster(logger, tm)
logger.info("Setting Builders.")
# For every distroarchrelease we can find;
# put it into the build master
for archrelease in getUtility(IDistroArchReleaseSet):
buildMaster.addDistroArchRelease(archrelease)
try:
buildMaster.setupBuilders(archrelease)
except KeyError, key:
info = ("Unable to setup builder for %s/%s/%s."
% (archrelease.distrorelease.distribution.name,
archrelease.distrorelease.name,
archrelease.architecturetag))
# less is more, noisely verbose
#logger.warn(info, exc_info=1)
logger.warn(info)
logger.info("Scanning Builders.")
# Scan all the pending builds; update logtails; retrieve
# builds where they are compled
buildMaster.scanActiveBuilders()
# Now that the slaves are free, ask the buildmaster to calculate
# the set of build candiates
buildCandidatesSortedByProcessor = buildMaster.sortAndSplitByProcessor()
logger.info("Dispatching Jobs.")
# Now that we've gathered in all the builds;
# dispatch the pending ones
for processor, buildCandidates in \
buildCandidatesSortedByProcessor.iteritems():
buildMaster.dispatchByProcessor(processor, buildCandidates)
if __name__ == '__main__':
parser = OptionParser()
logger_options(parser)
(options, arguments) = parser.parse_args()
if arguments:
parser.error("Unhandled arguments %s" % repr(arguments))
execute_zcml_for_scripts()
log = logger(options, 'slavescanner')
log.info("Slave Scan Process Initiated.")
locker = LockFile(_default_lockfile, logger=log)
try:
locker.acquire()
except OSError:
logger.info("Cannot acquire lock.")
sys.exit(1)
try:
doSlaveScan(log)
finally:
# release process lock file if the procedure finished properly
locker.release()
log.info("Slave Scan Process Finished.")
|