Example #1
0
def demo_client(host, port, is_framed_transport):

    # Make socket
    socket = TSocket.TSocket(host, port)

    # Make transport
    if is_framed_transport:
        transport = TTransport.TFramedTransport(socket)
    else:
        transport = TTransport.TBufferedTransport(socket)

    # Wrap in a protocol
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    # Create a client to use the protocol encoder
    client = Client(protocol)

    # Connect!
    transport.open()

    # Check Thrift Server Type
    serverType = client.getThriftServerType()
    if serverType != TThriftServerType.ONE:
        raise Exception(
            "Mismatch between client and server, server type is %s" %
            serverType)

    t = "demo_table"

    #
    # Scan all tables, look for the demo table and delete it.
    #
    print "scanning tables..."
    for table in client.getTableNames():
        print "  found: %s" % (table)
        if table == t:
            if client.isTableEnabled(table):
                print "    disabling table: %s" % (t)
                client.disableTable(table)
            print "    deleting table: %s" % (t)
            client.deleteTable(table)

    columns = []
    col = ColumnDescriptor()
    col.name = 'entry:'
    col.maxVersions = 10
    columns.append(col)
    col = ColumnDescriptor()
    col.name = 'unused:'
    columns.append(col)

    try:
        print "creating table: %s" % (t)
        client.createTable(t, columns)
    except AlreadyExists, ae:
        print "WARN: " + ae.message
Example #2
0
def demo_client(host, port, is_framed_transport):

  # Make socket
  socket = TSocket.TSocket(host, port)

  # Make transport
  if is_framed_transport:
    transport = TTransport.TFramedTransport(socket)
  else:
    transport = TTransport.TBufferedTransport(socket)

  # Wrap in a protocol
  protocol = TBinaryProtocol.TBinaryProtocol(transport)

  # Create a client to use the protocol encoder
  client = Client(protocol)

  # Connect!
  transport.open()

  t = "demo_table"

  #
  # Scan all tables, look for the demo table and delete it.
  #
  print "scanning tables..."
  for table in client.getTableNames():
    print "  found: %s" %(table)
    if table == t:
      if client.isTableEnabled(table):
        print "    disabling table: %s"  %(t)
        client.disableTable(table)
      print "    deleting table: %s"  %(t)
      client.deleteTable(table)

  columns = []
  col = ColumnDescriptor()
  col.name = 'entry:'
  col.maxVersions = 10
  columns.append(col)
  col = ColumnDescriptor()
  col.name = 'unused:'
  columns.append(col)

  try:
    print "creating table: %s" %(t)
    client.createTable(t, columns)
  except AlreadyExists, ae:
    print "WARN: " + ae.message
Example #3
0
 def __init__(self, tableName, host='localhost', port=9090):
     self.tableName = tableName
     transport = TSocket.TSocket(host, port)
     self.transport = TTransport.TBufferedTransport(transport)
     protocol = TBinaryProtocol.TBinaryProtocol(transport)
     self.client = Client(protocol)
     self.transport.open()
     if tableName not in self.client.getTableNames():
         print 'creating table %s' % tableName
         columns = []
         col = ColumnDescriptor()
         col.name = 'page:title'
         col.maxVersions = 10
         columns.append(col)
         col = ColumnDescriptor()
         col.name = 'page:article'
         columns.append(col)
         self.client.createTable(tableName, columns)
Example #4
0
# Scan all tables, look for the demo table and delete it.
#
print "scanning tables..."
for table in client.getTableNames():
    print "  found: %s" % (table)
    if table == t:
        if client.isTableEnabled(table):
            print "    disabling table: %s" % (t)
            client.disableTable(table)
        print "    deleting table: %s" % (t)
        client.deleteTable(table)

columns = []
col = ColumnDescriptor()
col.name = 'entry:'
col.maxVersions = 10
columns.append(col)
col = ColumnDescriptor()
col.name = 'unused:'
columns.append(col)

try:
    print "creating table: %s" % (t)
    client.createTable(t, columns)
except AlreadyExists, ae:
    print "WARN: " + ae.message

cols = client.getColumnDescriptors(t)
print "column families in %s" % (t)
for col_name in cols.keys():
    col = cols[col_name]
Example #5
0
# Scan all tables, look for the demo table and delete it.
#
print "scanning tables..."
for table in client.getTableNames():
    print "  found: %s" % (table)
    if table == t:
        if client.isTableEnabled(table):
            print "    disabling table: %s" % (t)
            client.disableTable(table)
        print "    deleting table: %s" % (t)
        client.deleteTable(table)

columns = []
col = ColumnDescriptor()
col.name = "entry:"
col.maxVersions = 10
columns.append(col)
col = ColumnDescriptor()
col.name = "unused:"
columns.append(col)

try:
    print "creating table: %s" % (t)
    client.createTable(t, columns)
except AlreadyExists, ae:
    print "WARN: " + ae.message

cols = client.getColumnDescriptors(t)
print "column families in %s" % (t)
for col_name in cols.keys():
    col = cols[col_name]