2011-05-27 06:31:45 +00:00
|
|
|
import os,sys,logging
|
2015-05-04 11:35:35 +00:00
|
|
|
import signal, time
|
2016-05-12 07:30:35 +00:00
|
|
|
from xmlrpc.server import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
|
2013-08-31 22:44:42 +00:00
|
|
|
import threading
|
2016-05-12 07:30:35 +00:00
|
|
|
import queue
|
2015-09-15 14:59:38 +00:00
|
|
|
import socket
|
2016-05-12 07:30:35 +00:00
|
|
|
import io
|
2012-01-15 21:03:53 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
import sqlite3
|
|
|
|
except ImportError:
|
|
|
|
from pysqlite2 import dbapi2 as sqlite3
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
import bb.server.xmlrpc
|
|
|
|
import prserv
|
|
|
|
import prserv.db
|
2013-11-15 20:51:47 +00:00
|
|
|
import errno
|
2011-05-27 06:31:45 +00:00
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
logger = logging.getLogger("BitBake.PRserv")
|
|
|
|
|
2011-05-27 06:31:45 +00:00
|
|
|
if sys.hexversion < 0x020600F0:
|
|
|
|
print("Sorry, python 2.6 or later is required.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
class Handler(SimpleXMLRPCRequestHandler):
|
|
|
|
def _dispatch(self,method,params):
|
|
|
|
try:
|
|
|
|
value=self.server.funcs[method](*params)
|
|
|
|
except:
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
raise
|
|
|
|
return value
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
PIDPREFIX = "/tmp/PRServer_%s_%s.pid"
|
2012-01-10 06:13:50 +00:00
|
|
|
singleton = None
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
|
2013-08-28 16:10:09 +00:00
|
|
|
|
2013-08-31 22:44:42 +00:00
|
|
|
class PRServer(SimpleXMLRPCServer):
|
2011-05-27 06:31:45 +00:00
|
|
|
def __init__(self, dbfile, logfile, interface, daemon=True):
|
|
|
|
''' constructor '''
|
2014-09-24 13:06:42 +00:00
|
|
|
try:
|
|
|
|
SimpleXMLRPCServer.__init__(self, interface,
|
|
|
|
logRequests=False, allow_none=True)
|
|
|
|
except socket.error:
|
|
|
|
ip=socket.gethostbyname(interface[0])
|
|
|
|
port=interface[1]
|
|
|
|
msg="PR Server unable to bind to %s:%s\n" % (ip, port)
|
|
|
|
sys.stderr.write(msg)
|
|
|
|
raise PRServiceConfigError
|
|
|
|
|
2011-05-27 06:31:45 +00:00
|
|
|
self.dbfile=dbfile
|
|
|
|
self.daemon=daemon
|
|
|
|
self.logfile=logfile
|
2012-01-10 06:13:50 +00:00
|
|
|
self.working_thread=None
|
2011-05-27 06:31:45 +00:00
|
|
|
self.host, self.port = self.socket.getsockname()
|
2012-01-10 06:13:50 +00:00
|
|
|
self.pidfile=PIDPREFIX % (self.host, self.port)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
self.register_function(self.getPR, "getPR")
|
|
|
|
self.register_function(self.quit, "quit")
|
|
|
|
self.register_function(self.ping, "ping")
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
self.register_function(self.export, "export")
|
2016-02-23 17:36:33 +00:00
|
|
|
self.register_function(self.dump_db, "dump_db")
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
self.register_function(self.importone, "importone")
|
2011-05-27 06:31:45 +00:00
|
|
|
self.register_introspection_functions()
|
2012-01-10 06:13:50 +00:00
|
|
|
|
2016-05-12 07:30:35 +00:00
|
|
|
self.requestqueue = queue.Queue()
|
2013-08-31 22:44:42 +00:00
|
|
|
self.handlerthread = threading.Thread(target = self.process_request_thread)
|
|
|
|
self.handlerthread.daemon = False
|
|
|
|
|
|
|
|
def process_request_thread(self):
|
|
|
|
"""Same as in BaseServer but as a thread.
|
|
|
|
|
|
|
|
In addition, exception handling is done here.
|
|
|
|
|
|
|
|
"""
|
2014-11-04 14:02:32 +00:00
|
|
|
iter_count = 1
|
2015-01-21 13:53:59 +00:00
|
|
|
# 60 iterations between syncs or sync if dirty every ~30 seconds
|
2014-11-04 14:02:32 +00:00
|
|
|
iterations_between_sync = 60
|
|
|
|
|
2016-01-29 11:08:50 +00:00
|
|
|
bb.utils.set_process_name("PRServ Handler")
|
|
|
|
|
2015-01-21 13:53:59 +00:00
|
|
|
while not self.quit:
|
|
|
|
try:
|
|
|
|
(request, client_address) = self.requestqueue.get(True, 30)
|
2016-05-12 07:30:35 +00:00
|
|
|
except queue.Empty:
|
2015-01-21 13:53:59 +00:00
|
|
|
self.table.sync_if_dirty()
|
|
|
|
continue
|
2013-08-31 22:44:42 +00:00
|
|
|
try:
|
|
|
|
self.finish_request(request, client_address)
|
|
|
|
self.shutdown_request(request)
|
2014-11-04 14:02:32 +00:00
|
|
|
iter_count = (iter_count + 1) % iterations_between_sync
|
|
|
|
if iter_count == 0:
|
|
|
|
self.table.sync_if_dirty()
|
2013-08-31 22:44:42 +00:00
|
|
|
except:
|
|
|
|
self.handle_error(request, client_address)
|
|
|
|
self.shutdown_request(request)
|
2013-09-08 09:45:54 +00:00
|
|
|
self.table.sync()
|
2015-01-21 13:53:59 +00:00
|
|
|
self.table.sync_if_dirty()
|
2013-08-31 22:44:42 +00:00
|
|
|
|
2015-09-08 22:32:07 +00:00
|
|
|
def sigint_handler(self, signum, stack):
|
2016-02-02 12:04:20 +00:00
|
|
|
if self.table:
|
|
|
|
self.table.sync()
|
2015-09-08 22:32:07 +00:00
|
|
|
|
|
|
|
def sigterm_handler(self, signum, stack):
|
2016-02-02 12:04:20 +00:00
|
|
|
if self.table:
|
|
|
|
self.table.sync()
|
2016-02-02 12:05:50 +00:00
|
|
|
self.quit=True
|
2015-09-08 22:32:07 +00:00
|
|
|
|
2013-08-31 22:44:42 +00:00
|
|
|
def process_request(self, request, client_address):
|
|
|
|
self.requestqueue.put((request, client_address))
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def export(self, version=None, pkgarch=None, checksum=None, colinfo=True):
|
|
|
|
try:
|
2013-08-31 22:44:42 +00:00
|
|
|
return self.table.export(version, pkgarch, checksum, colinfo)
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
except sqlite3.Error as exc:
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.error(str(exc))
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
return None
|
|
|
|
|
2016-02-23 17:36:33 +00:00
|
|
|
def dump_db(self):
|
|
|
|
"""
|
|
|
|
Returns a script (string) that reconstructs the state of the
|
|
|
|
entire database at the time this function is called. The script
|
|
|
|
language is defined by the backing database engine, which is a
|
|
|
|
function of server configuration.
|
|
|
|
Returns None if the database engine does not support dumping to
|
|
|
|
script or if some other error is encountered in processing.
|
|
|
|
"""
|
2016-05-12 07:30:35 +00:00
|
|
|
buff = io.StringIO()
|
2016-02-23 17:36:33 +00:00
|
|
|
try:
|
|
|
|
self.table.sync()
|
|
|
|
self.table.dump_db(buff)
|
|
|
|
return buff.getvalue()
|
|
|
|
except Exception as exc:
|
|
|
|
logger.error(str(exc))
|
|
|
|
return None
|
|
|
|
finally:
|
|
|
|
buff.close()
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def importone(self, version, pkgarch, checksum, value):
|
2013-08-31 22:44:42 +00:00
|
|
|
return self.table.importone(version, pkgarch, checksum, value)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
def ping(self):
|
|
|
|
return not self.quit
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
def getinfo(self):
|
|
|
|
return (self.host, self.port)
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def getPR(self, version, pkgarch, checksum):
|
2011-05-27 06:31:45 +00:00
|
|
|
try:
|
2013-08-31 22:44:42 +00:00
|
|
|
return self.table.getValue(version, pkgarch, checksum)
|
2011-05-27 06:31:45 +00:00
|
|
|
except prserv.NotFoundError:
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.error("can not find value for (%s, %s)",version, checksum)
|
2011-05-27 06:31:45 +00:00
|
|
|
return None
|
|
|
|
except sqlite3.Error as exc:
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.error(str(exc))
|
2011-05-27 06:31:45 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
def quit(self):
|
|
|
|
self.quit=True
|
|
|
|
return
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
def work_forever(self,):
|
2011-05-27 06:31:45 +00:00
|
|
|
self.quit = False
|
|
|
|
self.timeout = 0.5
|
2013-02-06 23:18:19 +00:00
|
|
|
|
2016-01-29 11:08:50 +00:00
|
|
|
bb.utils.set_process_name("PRServ")
|
|
|
|
|
2016-02-02 12:04:20 +00:00
|
|
|
# DB connection must be created after all forks
|
|
|
|
self.db = prserv.db.PRData(self.dbfile)
|
|
|
|
self.table = self.db["PRMAIN"]
|
|
|
|
|
2013-02-06 23:18:19 +00:00
|
|
|
logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" %
|
2012-01-10 06:13:50 +00:00
|
|
|
(self.dbfile, self.host, self.port, str(os.getpid())))
|
|
|
|
|
2013-08-31 22:44:42 +00:00
|
|
|
self.handlerthread.start()
|
2011-05-27 06:31:45 +00:00
|
|
|
while not self.quit:
|
|
|
|
self.handle_request()
|
2015-01-21 13:53:59 +00:00
|
|
|
self.handlerthread.join()
|
2015-09-23 13:39:27 +00:00
|
|
|
self.db.disconnect()
|
2012-01-10 06:13:50 +00:00
|
|
|
logger.info("PRServer: stopping...")
|
2011-05-27 06:31:45 +00:00
|
|
|
self.server_close()
|
|
|
|
return
|
|
|
|
|
|
|
|
def start(self):
|
2015-09-08 22:32:07 +00:00
|
|
|
if self.daemon:
|
|
|
|
pid = self.daemonize()
|
|
|
|
else:
|
|
|
|
pid = self.fork()
|
|
|
|
|
2013-02-06 23:18:19 +00:00
|
|
|
# Ensure both the parent sees this and the child from the work_forever log entry above
|
|
|
|
logger.info("Started PRServer with DBfile: %s, IP: %s, PORT: %s, PID: %s" %
|
|
|
|
(self.dbfile, self.host, self.port, str(pid)))
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
def delpid(self):
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
os.remove(self.pidfile)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
def daemonize(self):
|
|
|
|
"""
|
|
|
|
See Advanced Programming in the UNIX, Sec 13.3
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
pid = os.fork()
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
if pid > 0:
|
2013-02-06 15:59:07 +00:00
|
|
|
os.waitpid(pid, 0)
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
#parent return instead of exit to give control
|
2013-02-06 23:18:19 +00:00
|
|
|
return pid
|
2011-06-14 23:44:58 +00:00
|
|
|
except OSError as e:
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
raise Exception("%s [%d]" % (e.strerror, e.errno))
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
os.setsid()
|
|
|
|
"""
|
|
|
|
fork again to make sure the daemon is not session leader,
|
|
|
|
which prevents it from acquiring controlling terminal
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
pid = os.fork()
|
|
|
|
if pid > 0: #parent
|
2013-02-06 15:59:07 +00:00
|
|
|
os._exit(0)
|
2011-06-14 23:44:58 +00:00
|
|
|
except OSError as e:
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
raise Exception("%s [%d]" % (e.strerror, e.errno))
|
2011-05-27 06:31:45 +00:00
|
|
|
|
2015-09-08 22:32:07 +00:00
|
|
|
self.cleanup_handles()
|
|
|
|
os._exit(0)
|
|
|
|
|
|
|
|
def fork(self):
|
|
|
|
try:
|
|
|
|
pid = os.fork()
|
|
|
|
if pid > 0:
|
|
|
|
return pid
|
|
|
|
except OSError as e:
|
|
|
|
raise Exception("%s [%d]" % (e.strerror, e.errno))
|
|
|
|
|
|
|
|
bb.utils.signal_on_parent_exit("SIGTERM")
|
|
|
|
self.cleanup_handles()
|
|
|
|
os._exit(0)
|
|
|
|
|
|
|
|
def cleanup_handles(self):
|
|
|
|
signal.signal(signal.SIGINT, self.sigint_handler)
|
|
|
|
signal.signal(signal.SIGTERM, self.sigterm_handler)
|
2011-05-27 06:31:45 +00:00
|
|
|
os.chdir("/")
|
|
|
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
2016-05-11 21:54:22 +00:00
|
|
|
si = open('/dev/null', 'r')
|
|
|
|
so = open(self.logfile, 'a+')
|
2011-05-27 06:31:45 +00:00
|
|
|
se = so
|
|
|
|
os.dup2(si.fileno(),sys.stdin.fileno())
|
|
|
|
os.dup2(so.fileno(),sys.stdout.fileno())
|
|
|
|
os.dup2(se.fileno(),sys.stderr.fileno())
|
|
|
|
|
bitbake: serv.py: Fix hang when spawned dynamically with bitbake
The PRServer has the possibility to hang indefinitely blocking on a
semaphore processing a xmlrpc request to send an event back to the
main bitbake instance. This was observed during a "bitbake -e" on a
heavily loaded machine and the main bitbake instance and cooker exited
before the PRServer emitted its first log.
The stack trace is provided below as to show what happens every time a
logger.info() is executed in the PRServer. Not only does it write to
the stream handler but it also tries to send the event to the main
event processor.
self._notempty.acquire()
self.queue.put(event)
_ui_handlers[h].event.send(event)
fire_ui_handlers(event, d)
fire(record, None)
self.emit(record)
hdlr.handle(record)
self.callHandlers(record)
self.handle(record)
self._log(INFO, msg, args, **kwargs)
(self.dbfile, self.host, self.port, str(os.getpid())))
self.work_forever()
pid = self.daemonize()
self.prserv.start()
singleton.start()
self.prhost = prserv.serv.auto_start(self.data)
cooker.pre_serve()
bb.cooker.server_main(self.cooker, self.main)
self.run()
code = process_obj._bootstrap()
self._popen = Popen(self)
self.serverImpl.start()
server.detach()
server = start_server(servermodule, configParams, configuration)
ret = main()
It was never intended for the PRServer to send its logs anywhere but
its own log file. The event processing is an artifact of how the
PRServer was forked and it inherits the event log handlers. The
simple fix is to clean up and purge all the log handlers after the
fork() but before doing any of the typical PRServer work or logging.
(Bitbake rev: 972bc43e6d5b1207b944b3baa8f9805adb35dda7)
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-08-27 20:12:55 +00:00
|
|
|
# Clear out all log handlers prior to the fork() to avoid calling
|
|
|
|
# event handlers not part of the PRserver
|
|
|
|
for logger_iter in logging.Logger.manager.loggerDict.keys():
|
2013-08-28 02:20:55 +00:00
|
|
|
logging.getLogger(logger_iter).handlers = []
|
bitbake: serv.py: Fix hang when spawned dynamically with bitbake
The PRServer has the possibility to hang indefinitely blocking on a
semaphore processing a xmlrpc request to send an event back to the
main bitbake instance. This was observed during a "bitbake -e" on a
heavily loaded machine and the main bitbake instance and cooker exited
before the PRServer emitted its first log.
The stack trace is provided below as to show what happens every time a
logger.info() is executed in the PRServer. Not only does it write to
the stream handler but it also tries to send the event to the main
event processor.
self._notempty.acquire()
self.queue.put(event)
_ui_handlers[h].event.send(event)
fire_ui_handlers(event, d)
fire(record, None)
self.emit(record)
hdlr.handle(record)
self.callHandlers(record)
self.handle(record)
self._log(INFO, msg, args, **kwargs)
(self.dbfile, self.host, self.port, str(os.getpid())))
self.work_forever()
pid = self.daemonize()
self.prserv.start()
singleton.start()
self.prhost = prserv.serv.auto_start(self.data)
cooker.pre_serve()
bb.cooker.server_main(self.cooker, self.main)
self.run()
code = process_obj._bootstrap()
self._popen = Popen(self)
self.serverImpl.start()
server.detach()
server = start_server(servermodule, configParams, configuration)
ret = main()
It was never intended for the PRServer to send its logs anywhere but
its own log file. The event processing is an artifact of how the
PRServer was forked and it inherits the event log handlers. The
simple fix is to clean up and purge all the log handlers after the
fork() but before doing any of the typical PRServer work or logging.
(Bitbake rev: 972bc43e6d5b1207b944b3baa8f9805adb35dda7)
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-08-27 20:12:55 +00:00
|
|
|
|
2013-02-06 23:18:19 +00:00
|
|
|
# Ensure logging makes it to the logfile
|
|
|
|
streamhandler = logging.StreamHandler()
|
|
|
|
streamhandler.setLevel(logging.DEBUG)
|
|
|
|
formatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
|
|
|
|
streamhandler.setFormatter(formatter)
|
|
|
|
logger.addHandler(streamhandler)
|
|
|
|
|
2011-05-27 06:31:45 +00:00
|
|
|
# write pidfile
|
|
|
|
pid = str(os.getpid())
|
2016-05-11 21:54:22 +00:00
|
|
|
pf = open(self.pidfile, 'w')
|
2011-05-27 06:31:45 +00:00
|
|
|
pf.write("%s\n" % pid)
|
|
|
|
pf.close()
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
self.work_forever()
|
2013-08-23 16:41:53 +00:00
|
|
|
self.delpid()
|
2012-01-10 06:13:50 +00:00
|
|
|
|
2013-08-28 16:06:10 +00:00
|
|
|
class PRServSingleton(object):
|
2012-01-10 06:13:50 +00:00
|
|
|
def __init__(self, dbfile, logfile, interface):
|
|
|
|
self.dbfile = dbfile
|
|
|
|
self.logfile = logfile
|
|
|
|
self.interface = interface
|
|
|
|
self.host = None
|
|
|
|
self.port = None
|
|
|
|
|
2013-02-06 15:59:07 +00:00
|
|
|
def start(self):
|
2015-09-08 22:32:07 +00:00
|
|
|
self.prserv = PRServer(self.dbfile, self.logfile, self.interface, daemon=False)
|
2013-02-06 15:59:07 +00:00
|
|
|
self.prserv.start()
|
2012-01-10 06:13:50 +00:00
|
|
|
self.host, self.port = self.prserv.getinfo()
|
|
|
|
|
|
|
|
def getinfo(self):
|
|
|
|
return (self.host, self.port)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
2013-08-28 16:06:10 +00:00
|
|
|
class PRServerConnection(object):
|
2011-05-27 06:31:45 +00:00
|
|
|
def __init__(self, host, port):
|
2012-01-10 06:13:50 +00:00
|
|
|
if is_local_special(host, port):
|
|
|
|
host, port = singleton.getinfo()
|
2011-05-27 06:31:45 +00:00
|
|
|
self.host = host
|
|
|
|
self.port = port
|
2013-05-30 17:05:14 +00:00
|
|
|
self.connection, self.transport = bb.server.xmlrpc._create_server(self.host, self.port)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
def terminate(self):
|
|
|
|
try:
|
2013-02-06 23:18:19 +00:00
|
|
|
logger.info("Terminating PRServer...")
|
2011-05-27 06:31:45 +00:00
|
|
|
self.connection.quit()
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
except Exception as exc:
|
|
|
|
sys.stderr.write("%s\n" % str(exc))
|
2011-05-27 06:31:45 +00:00
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def getPR(self, version, pkgarch, checksum):
|
|
|
|
return self.connection.getPR(version, pkgarch, checksum)
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
def ping(self):
|
|
|
|
return self.connection.ping()
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def export(self,version=None, pkgarch=None, checksum=None, colinfo=True):
|
|
|
|
return self.connection.export(version, pkgarch, checksum, colinfo)
|
2012-01-10 06:13:50 +00:00
|
|
|
|
2016-02-23 17:36:33 +00:00
|
|
|
def dump_db(self):
|
|
|
|
return self.connection.dump_db()
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def importone(self, version, pkgarch, checksum, value):
|
|
|
|
return self.connection.importone(version, pkgarch, checksum, value)
|
|
|
|
|
2013-06-07 17:13:04 +00:00
|
|
|
def getinfo(self):
|
|
|
|
return self.host, self.port
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
def start_daemon(dbfile, host, port, logfile):
|
2015-09-15 14:59:38 +00:00
|
|
|
ip = socket.gethostbyname(host)
|
|
|
|
pidfile = PIDPREFIX % (ip, port)
|
2011-05-27 06:31:45 +00:00
|
|
|
try:
|
2016-05-11 21:54:22 +00:00
|
|
|
pf = open(pidfile,'r')
|
2011-05-27 06:31:45 +00:00
|
|
|
pid = int(pf.readline().strip())
|
|
|
|
pf.close()
|
|
|
|
except IOError:
|
|
|
|
pid = None
|
|
|
|
|
|
|
|
if pid:
|
|
|
|
sys.stderr.write("pidfile %s already exist. Daemon already running?\n"
|
2012-01-10 06:13:50 +00:00
|
|
|
% pidfile)
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
return 1
|
2011-05-27 06:31:45 +00:00
|
|
|
|
2015-09-15 14:59:38 +00:00
|
|
|
server = PRServer(os.path.abspath(dbfile), os.path.abspath(logfile), (ip,port))
|
2011-05-27 06:31:45 +00:00
|
|
|
server.start()
|
2015-09-15 14:59:38 +00:00
|
|
|
|
2015-09-10 11:59:45 +00:00
|
|
|
# Sometimes, the port (i.e. localhost:0) indicated by the user does not match with
|
|
|
|
# the one the server actually is listening, so at least warn the user about it
|
|
|
|
_,rport = server.getinfo()
|
|
|
|
if port != rport:
|
|
|
|
sys.stdout.write("Server is listening at port %s instead of %s\n"
|
|
|
|
% (rport,port))
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
return 0
|
2011-05-27 06:31:45 +00:00
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def stop_daemon(host, port):
|
2015-09-10 11:59:45 +00:00
|
|
|
import glob
|
2015-09-15 14:59:38 +00:00
|
|
|
ip = socket.gethostbyname(host)
|
|
|
|
pidfile = PIDPREFIX % (ip, port)
|
2011-05-27 06:31:45 +00:00
|
|
|
try:
|
2016-05-11 21:54:22 +00:00
|
|
|
pf = open(pidfile,'r')
|
2011-05-27 06:31:45 +00:00
|
|
|
pid = int(pf.readline().strip())
|
|
|
|
pf.close()
|
|
|
|
except IOError:
|
|
|
|
pid = None
|
|
|
|
|
|
|
|
if not pid:
|
2015-09-10 11:59:45 +00:00
|
|
|
# when server starts at port=0 (i.e. localhost:0), server actually takes another port,
|
|
|
|
# so at least advise the user which ports the corresponding server is listening
|
|
|
|
ports = []
|
|
|
|
portstr = ""
|
|
|
|
for pf in glob.glob(PIDPREFIX % (ip,'*')):
|
|
|
|
bn = os.path.basename(pf)
|
|
|
|
root, _ = os.path.splitext(bn)
|
|
|
|
ports.append(root.split('_')[-1])
|
|
|
|
if len(ports):
|
|
|
|
portstr = "Wrong port? Other ports listening at %s: %s" % (host, ' '.join(ports))
|
|
|
|
|
|
|
|
sys.stderr.write("pidfile %s does not exist. Daemon not running? %s\n"
|
|
|
|
% (pidfile,portstr))
|
|
|
|
return 1
|
2011-05-27 06:31:45 +00:00
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
try:
|
2015-09-15 14:59:38 +00:00
|
|
|
PRServerConnection(ip, port).terminate()
|
2012-01-10 06:13:50 +00:00
|
|
|
except:
|
|
|
|
logger.critical("Stop PRService %s:%d failed" % (host,port))
|
2011-05-27 06:31:45 +00:00
|
|
|
|
|
|
|
try:
|
2012-01-10 06:13:50 +00:00
|
|
|
if pid:
|
2013-11-15 20:51:47 +00:00
|
|
|
wait_timeout = 0
|
2014-03-28 12:10:54 +00:00
|
|
|
print("Waiting for pr-server to exit.")
|
|
|
|
while is_running(pid) and wait_timeout < 50:
|
|
|
|
time.sleep(0.1)
|
2013-11-15 20:51:47 +00:00
|
|
|
wait_timeout += 1
|
|
|
|
|
|
|
|
if is_running(pid):
|
|
|
|
print("Sending SIGTERM to pr-server.")
|
|
|
|
os.kill(pid,signal.SIGTERM)
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
2014-03-28 12:10:54 +00:00
|
|
|
if os.path.exists(pidfile):
|
|
|
|
os.remove(pidfile)
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
except OSError as e:
|
|
|
|
err = str(e)
|
2012-01-10 06:13:50 +00:00
|
|
|
if err.find("No such process") <= 0:
|
|
|
|
raise e
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
|
|
|
|
return 0
|
2011-05-27 06:31:45 +00:00
|
|
|
|
2013-11-15 20:51:47 +00:00
|
|
|
def is_running(pid):
|
|
|
|
try:
|
|
|
|
os.kill(pid, 0)
|
|
|
|
except OSError as err:
|
|
|
|
if err.errno == errno.ESRCH:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
def is_local_special(host, port):
|
|
|
|
if host.strip().upper() == 'localhost'.upper() and (not port):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2013-05-02 14:46:11 +00:00
|
|
|
class PRServiceConfigError(Exception):
|
|
|
|
pass
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
def auto_start(d):
|
|
|
|
global singleton
|
2013-01-23 14:54:03 +00:00
|
|
|
|
2016-05-12 07:30:35 +00:00
|
|
|
host_params = list(filter(None, (d.getVar('PRSERV_HOST', True) or '').split(':')))
|
2013-01-23 14:54:03 +00:00
|
|
|
if not host_params:
|
2013-06-07 17:13:04 +00:00
|
|
|
return None
|
2013-01-23 14:54:03 +00:00
|
|
|
|
|
|
|
if len(host_params) != 2:
|
|
|
|
logger.critical('\n'.join(['PRSERV_HOST: incorrect format',
|
|
|
|
'Usage: PRSERV_HOST = "<hostname>:<port>"']))
|
2013-05-02 14:46:11 +00:00
|
|
|
raise PRServiceConfigError
|
2012-01-10 06:13:50 +00:00
|
|
|
|
2013-01-23 14:54:03 +00:00
|
|
|
if is_local_special(host_params[0], int(host_params[1])) and not singleton:
|
2012-01-10 06:13:50 +00:00
|
|
|
import bb.utils
|
|
|
|
cachedir = (d.getVar("PERSISTENT_DIR", True) or d.getVar("CACHE", True))
|
|
|
|
if not cachedir:
|
|
|
|
logger.critical("Please set the 'PERSISTENT_DIR' or 'CACHE' variable")
|
2013-05-02 14:46:11 +00:00
|
|
|
raise PRServiceConfigError
|
2012-01-10 06:13:50 +00:00
|
|
|
bb.utils.mkdirhier(cachedir)
|
|
|
|
dbfile = os.path.join(cachedir, "prserv.sqlite3")
|
|
|
|
logfile = os.path.join(cachedir, "prserv.log")
|
|
|
|
singleton = PRServSingleton(os.path.abspath(dbfile), os.path.abspath(logfile), ("localhost",0))
|
|
|
|
singleton.start()
|
|
|
|
if singleton:
|
|
|
|
host, port = singleton.getinfo()
|
|
|
|
else:
|
2013-01-23 14:54:03 +00:00
|
|
|
host = host_params[0]
|
|
|
|
port = int(host_params[1])
|
2012-01-10 06:13:50 +00:00
|
|
|
|
|
|
|
try:
|
2013-06-07 17:13:04 +00:00
|
|
|
connection = PRServerConnection(host,port)
|
|
|
|
connection.ping()
|
|
|
|
realhost, realport = connection.getinfo()
|
|
|
|
return str(realhost) + ":" + str(realport)
|
|
|
|
|
2012-01-10 06:13:50 +00:00
|
|
|
except Exception:
|
|
|
|
logger.critical("PRservice %s:%d not available" % (host, port))
|
2013-05-02 14:46:11 +00:00
|
|
|
raise PRServiceConfigError
|
2012-01-10 06:13:50 +00:00
|
|
|
|
|
|
|
def auto_shutdown(d=None):
|
|
|
|
global singleton
|
|
|
|
if singleton:
|
|
|
|
host, port = singleton.getinfo()
|
|
|
|
try:
|
|
|
|
PRServerConnection(host, port).terminate()
|
|
|
|
except:
|
|
|
|
logger.critical("Stop PRService %s:%d failed" % (host,port))
|
|
|
|
singleton = None
|
|
|
|
|
bitbake/PRservice: Added no_hist mode and export/import.
[YOCTO #1556]
1. Added the package_arch into the index to the DB table. Because the
change in PACKAGE_ARCH will results in different checksum, and it is
better to have seperate PR value domains for differnt PACKAGE_ARCH of
the same pakcage.
2. Changed the PR service to operate in no history mode. In this mode,
the for a given query tuple (version, pkgarch, checksum), the returned
value will be the largest among all the values of the same (version,
pkgarch). This means the PR value returned can NOT be decremented.
3. Added export function. For each (version, pkgarch) tuple, only the
record with the maximum value will be exported.
4. Added import function. The record will only be imported if the
imported value is larger than the value stored in the DB with the same
(version, pkgarch, checksum) tuple.
(Bitbake rev: 379567ee879dcdc09a51f7f1212bde1076147a6f)
Signed-off-by: Lianhao Lu <lianhao.lu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2012-01-10 06:13:49 +00:00
|
|
|
def ping(host, port):
|
2012-01-10 06:13:50 +00:00
|
|
|
conn=PRServerConnection(host, port)
|
|
|
|
return conn.ping()
|