From 995f584468ce1c620ce0196f88f21327bf908997 Mon Sep 17 00:00:00 2001 From: znek Date: Wed, 30 Jun 2004 23:29:35 +0000 Subject: [PATCH] load balancing testing scripts git-svn-id: http://svn.opengroupware.org/SOGo/trunk@131 d1b88da0-ebda-0310-925b-ed51d893ca5b --- db/scripts/create_user_tables.py | 152 +++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 db/scripts/create_user_tables.py diff --git a/db/scripts/create_user_tables.py b/db/scripts/create_user_tables.py new file mode 100644 index 00000000..6049e435 --- /dev/null +++ b/db/scripts/create_user_tables.py @@ -0,0 +1,152 @@ +#!/usr/bin/env python + +import pg +import sys +import random + + +# the default database. this is where folder_info lives +DEFAULT_DB="test" +USER="OGo" +PASSWORD="OGo" +HOST="agenor-db" +PORT="5432" + +DEFAULT_CONNECTION = "%s:%s@%s:%s" % (USER, PASSWORD, HOST, PORT) + +# insert more names if you want to test with multiple db's! +dbConnectionMap = { DEFAULT_DB : DEFAULT_CONNECTION } + + +# lookup table for db connections +connectionPool = {} + + +# +# TEMPLATES +# + +CREATE_QUICK="""CREATE TABLE %(user)s_quick ( + c_name VARCHAR(256) NOT NULL PRIMARY KEY, -- the filename + uid VARCHAR(256) NOT NULL, + startdate INT NOT NULL, + enddate INT NOT NULL, + title VARCHAR(1000) NOT NULL, + participants VARCHAR(100000) NOT NULL +);""" + +CREATE_BLOB="""CREATE TABLE %(user)s_blob ( + c_name VARCHAR(256) NOT NULL PRIMARY KEY, -- the filename + c_content VARCHAR(100000) NOT NULL, -- the BLOB + c_creationdate INT NOT NULL, -- creation date + c_lastmodified INT NOT NULL, -- last modification (UPDATE) + c_version INT NOT NULL, -- version counter +);""" + +INSERT_FOLDERINFO_USER="""INSERT INTO SOGo_folder_info + ( c_path, c_path1, c_path2, c_path3, c_path4, c_foldername, + c_location, c_quick_location, c_folder_type ) +VALUES + ( '/Users/%(user)s', + 'Users', + '%(user)s', + NULL, + NULL, + '%(user)s', + 'http://%(connection)/%(db)/SOGo_user_folder', + 'http://%(connection)s/%(db)/SOGo_user_folder_quick', + 'Container' );""" + +INSERT_FOLDERINFO_USER_PRIVCAL="""INSERT INTO SOGo_folder_info + ( c_path, c_path1, c_path2, c_path3, c_path4, c_foldername, + c_location, c_quick_location, c_folder_type ) +VALUES + ( '/Users/%(user)s/Calendar', + 'Users', + '%(user)s', + 'Calendar', + NULL, + 'Calendar', + 'http://%(connection)s/%(db)/SOGo_%(user)s_privcal', + 'http://%(connection)s/%(db)/SOGo_%(user)s_privcal_quick', + 'Appointment' );""" + + +# +# HELPERS +# + +def usage(): + sys.stderr.write("""create_user_tables.py + + filename is plain text, platform encoding. Each line has a username. Simple. + """) + sys.exit(1) + +def splitConnectionString(connectionString): + res = [] + for t in connectionString.split("@"): + for r in t.split(":"): + res.append(r) + return res + +# +# MAIN +# + +def run(): + global dbConnectionMap, connectionPool + + # check arguments + try: + filename = sys.argv[1] + except IndexError: + usage() + + # check filename + try: + f = open (filename, "r"); + except IOError: + sys.stderr.write("%s\n" % (sys.exc_value)) + sys.exit(1) + + # setup connection pools + dbs = dbConnectionMap.keys() + dbsCount = len(dbs) + for db in dbs: + conString = dbConnectionMap[db] + c = splitConnectionString(conString) + #pg.DB(dbname, host, port, opt, tty, user, passwd) + con = pg.DB(db, c[2], int(c[3]), None, None, c[0], c[1]) + connectionPool[db] = con + + # get the default connection + db = DEFAULT_DB + defcon = connectionPool[db] + con = defcon + + # read list of users + users = f.readlines() + for user in users: + user = user.strip() + + # pick a random database if dbsCount > 1 + if dbsCount > 1: + idx = random.randrange(0, dbsCount) + db = dbs[idx] + con = connectionPool[db] + + map = { "user" : user, + "db" : db, + "connection" : dbConnectionMap[db], + } + + con.query(CREATE_QUICK % map) + con.query(CREATE_BLOB % map) + defcon.query(INSERT_FOLDERINFO_USER % map) + defcon.query(INSERT_FOLDERINFO_USER_PRIVCAL % map) + + +# let the games begin ... +if __name__ == "__main__": + run() -- 2.39.5