Example #1
0
class ProcedureCaller:
    '''Creates a client and has methods to call procedures and check responses.'''
    status_codes = {
        -1: "User Abort",
        -2: "Graceful Failure",
        -3: "Unexpected Failure",
        -4: "Connection Lost",
        -5: "Server Unavailable",
        -6: "Connection Timeout",
        -7: "Response Unkonwn",
        -8: "Transaction Restart",
        -9: "Operational Failure"
    }

    def __init__(self, args):
        try:
            self.client = voltdbclient.FastSerializer(args.server, args.port,
                                                      False, args.username,
                                                      args.password)
        except socket.error, e:
            print "Can't connect to " + args.server + ":" + str(args.port)
            print str(e)
            exit(-1)

        self.stats_caller = voltdbclient.VoltProcedure(
            self.client, "@Statistics", [
                voltdbclient.FastSerializer.VOLTTYPE_STRING,
                voltdbclient.FastSerializer.VOLTTYPE_INTEGER
            ])
        print "Connected to VoltDB server: " + args.server + ":" + str(
            args.port)
Example #2
0
 def call_proc(self, sysproc_name, types, args, check_status = True):
     utility.verbose_info('Call procedure: %s%s' % (sysproc_name, tuple(args)))
     proc = voltdbclient.VoltProcedure(self.client, sysproc_name, types)
     response = proc.call(params = args)
     if check_status and response.status != 1:
         utility.abort('"%s" procedure call failed.' % sysproc_name, (response,))
     utility.verbose_info(response)
     return utility.VoltResponseWrapper(response)
Example #3
0
 def call_proc(self, sysproc_name, types, args, check_status=True, timeout=None):
     if self.client is None:
         utility.abort('Command is not set up as a client.',
                       'Add an appropriate admin or client bundle to @VOLT.Command().')
     utility.verbose_info('Call procedure: %s%s' % (sysproc_name, tuple(args)))
     proc = voltdbclient.VoltProcedure(self.client, sysproc_name, types)
     response = proc.call(params=args, timeout=timeout)
     if check_status and response.status != 1:
         utility.abort('"%s" procedure call failed.' % sysproc_name, (response,))
     utility.verbose_info(response)
     return utility.VoltResponseWrapper(response)
Example #4
0
            -3: "Unexpected Failure",
            -4: "Connection Lost",
            -5: "Server Unavailable",
            -6: "Connection Timeout",
            -7: "Response Unkonwn",
            -8: "Transaction Restart",
            -9: "Operational Failure"
        }
        print status_codes.get(status, "No Status code was returned") + ": " + response.statusString
        ex = response.exception
        if ex is not None:
            print ex.typestr + ": " + ex.message
        exit(-1)

# define procedure calls
proc_stats = voltdbclient.VoltProcedure( client, "@Statistics", [voltdbclient.FastSerializer.VOLTTYPE_STRING,voltdbclient.FastSerializer.VOLTTYPE_INTEGER] )
proc_catalog = voltdbclient.VoltProcedure( client, "@SystemCatalog", [voltdbclient.FastSerializer.VOLTTYPE_STRING] )

# function to get short name of procedure
def get_proc_name(procname):
    if '.' in procname:
        shortname = procname[procname.rindex('.')+1:] # everything after the right-most '.'
        if shortname not in ['delete','insert','select','update','upsert']:
            procname = shortname
    return procname

def get_partition_count():
    response = proc_stats.call(["PARTITIONCOUNT",0])
    check_response(response)
    table = response.tables[0]
    return table.tuples[0][3]