def test_create_codes(bid='test_codes', quantity=10, bits=10, ctype=2, mark=''): bid = 'test_codes' client = ThriftClient(REDEEM_SERVER, RedeemCode) ret = client.call('create_codes', bid, quantity, bits, ctype, mark) print ret
def get(table, key, column, type_): """ Handle our incoming REST requests to interface with Bigtable. For POST or DELETE, we dispatch to other private methods. For GET, we handle right in this method. :param table: The table name we would like to interface with :param key: The row key of the row we are getting or mutating :param column: The fully qualified column name, including the column family prefix in the standard cf:column_name format :param type_: 'str' to store the byte string directly, or 'int' to parse the string as an integer and store it as an integer :return: A string indicating the result of the call. """ if request.method == 'POST': _put(table, key, column, request.get_data(), type_) return "Updated." if request.method == 'DELETE': _delete_column(table, key, column) return "Deleted." with ThriftClient() as client: value = client.get_row(table, key) if not value: return "Not found" value = value[0].columns[column].value if type_ == 'int': value = _decode_int(value) return str(value)
def _delete_column(table, row_key, column): """ Deletes a column from a row, and the whole row if it's the only column :param table: The name of the table :param row_key: The key of the row we want to put a value in :param column: The column name including the column family with the colon format, such as 'cf:count' :return: None """ with ThriftClient() as client: client.delete_column(table, row_key, column)
def _put(table, row_key, column, value, type_): """ Puts a cell in an Hbase row :param table: The name of the table :param row_key: The key of the row we want to put a value in :param column: The column name including the column family with the colon format, such as 'cf:count' :param value: The array of bytes (using Python's string type) to insert as the value for this cell :param type_: 'str' or 'int'. If int, it will be serialized a 4 byte stream. :return: None """ with ThriftClient() as client: if type_ == 'int': value = _encode_int(int(value)) client.put_row(table, row_key, column, value)
def test_redeem_code(bid='test_codes', code=''): bid = 'test_codes' client = ThriftClient(REDEEM_SERVER, RedeemCode) ret = client.call('code_redeem', bid, code) print ret
def test_get_codes(quantity=10, gtype=1): bid = 'test_codes' client = ThriftClient(REDEEM_SERVER, RedeemCode) ret = client.call('get_codes', bid, quantity, gtype) print len(ret), ret
def test_get_code(gtype=1): bid = 'test_codes' client = ThriftClient(REDEEM_SERVER, RedeemCode) ret = client.call('get_code', bid, gtype) print ret
def thrift_client(host, port): return ThriftClient(app.config["THRIFT_HOST"], app.config["THRIFT_PORT"])