2
# Copyright (c) 2006-2008 Mitch Garnaat http://garnaat.org/
4
# Permission is hereby granted, free of charge, to any person obtaining a
5
# copy of this software and associated documentation files (the
6
# "Software"), to deal in the Software without restriction, including
7
# without limitation the rights to use, copy, modify, merge, publish, dis-
8
# tribute, sublicense, and/or sell copies of the Software, and to permit
9
# persons to whom the Software is furnished to do so, subject to the fol-
12
# The above copyright notice and this permission notice shall be included
13
# in all copies or substantial portions of the Software.
15
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
18
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
import queuetools, os, signal, sys
25
from optparse import OptionParser
26
from boto.mapreduce.partitiondb import PartitionDB, Partition, Version
27
from lqs import LQSServer, PersistHandler
28
from boto.exception import SDBPersistenceError
29
from boto.sdb.persist import get_manager
33
%prog [options] [command]
35
Revert to the previous Version in a PartitionDB.
39
def __init__(self, queue_name):
40
self.q = queuetools.get_queue(queue_name)
42
self.manager = get_manager()
48
print 'Deleting: %s' % m['item']
49
p = Partition(id=m['item'], manager=self.manager)
53
print 'client processing complete'
57
def __init__(self, pdb_name, domain_name=None):
58
self.pdb_name = pdb_name
59
self.manager = get_manager(domain_name)
60
self.pdb = PartitionDB.get(name=self.pdb_name)
65
args = {'v_id' : v.id}
67
s = LQSServer('', PersistHandler, rs, args)
72
Commands = {'client' : 'Start a Revert client',
73
'server' : 'Start a Revert server'}
76
self.parser = OptionParser(usage=USAGE)
77
self.parser.add_option("--help-commands", action="store_true", dest="help_commands",
78
help="provides help on the available commands")
79
self.parser.add_option('-d', '--domain-name', action='store', type='string',
80
help='name of the SimpleDB domain where PDB objects are stored')
81
self.parser.add_option('-n', '--num-processes', action='store', type='int', dest='num_processes',
82
help='the number of client processes launched')
83
self.parser.set_defaults(num_processes=5)
84
self.parser.add_option('-p', '--pdb-name', action='store', type='string',
85
help='name of the PDB in which to store files (will create if necessary)')
86
self.options, self.args = self.parser.parse_args()
87
self.prog_name = sys.argv[0]
89
def print_command_help(self):
91
for key in self.Commands.keys():
92
print ' %s\t\t%s' % (key, self.Commands[key])
95
if not self.options.pdb_name:
96
self.parser.error('No PDB name provided')
97
s = Server(self.options.pdb_name, self.options.domain_name)
100
c = Client('localhost')
103
if self.options.help_commands:
104
self.print_command_help()
106
if len(self.args) == 0:
107
if not self.options.pdb_name:
108
self.parser.error('No PDB name provided')
109
server_command = '%s -p %s ' % (self.prog_name, self.options.pdb_name)
110
server_command += ' server'
111
client_command = '%s client' % self.prog_name
112
server = subprocess.Popen(server_command, shell=True)
113
print 'server pid: %s' % server.pid
116
for i in range(0, self.options.num_processes):
117
client = subprocess.Popen(client_command, shell=True)
118
clients.append(client)
119
print 'waiting for clients to finish'
120
for client in clients:
122
os.kill(server.pid, signal.SIGTERM)
123
elif len(self.args) == 1:
124
self.command = self.args[0]
125
if hasattr(self, 'do_%s' % self.command):
126
method = getattr(self, 'do_%s' % self.command)
129
self.parser.error('command (%s) not recognized' % self.command)
131
self.parser.error('unrecognized commands')
133
if __name__ == "__main__":