Esempio n. 1
0
def create_keyspaces(replication):
    """ 
  Creates keyspace which AppScale uses for storing application 
  and user data

  Args:
    replication: Replication factor for Cassandra
  Raises:
    AppScaleBadArg: When args are bad
  """
    if int(replication) <= 0:
        raise dbconstants.AppScaleBadArg(
            "Replication must be greater than zero")

    print "Creating Cassandra Key Spaces"

    # Set this to False to keep data from a previous deployment. Setting it
    # it to True will remove previous tables.
    _DROP_TABLES = True

    # TODO use shared library to get constants
    host = helper_functions.read_file('/etc/appscale/my_private_ip')

    sysman = system_manager.SystemManager(host + ":" +\
                str(cassandra_interface.CASS_DEFAULT_PORT))

    if _DROP_TABLES:
        try:
            sysman.drop_keyspace(cassandra_interface.KEYSPACE)
        except pycassa.cassandra.ttypes.InvalidRequestException, e:
            pass
Esempio n. 2
0
 def create_keyspaces(cls):
     sysm = sm.SystemManager()
     if TWITTER_KEYSPACE not in sysm.list_keyspaces():
         sysm.create_keyspace(TWITTER_KEYSPACE, sm.SIMPLE_STRATEGY,
                              {'replication_factor': '1'})
     for name, m in cls.models.items():
         m.create(sysm, TWITTER_KEYSPACE)
def create_keyspaces(replication):
  """ 
  Creates keyspace which AppScale uses for storing application 
  and user data

  Args:
    replication: Replication factor for Cassandra
  Raises:
    AppScaleBadArg: When args are bad
  """
  if int(replication) <= 0: 
    raise dbconstants.AppScaleBadArg("Replication must be greater than zero")

  print "Creating Cassandra Key Spaces" 

  # TODO use shared library to get constants
  host = file_io.read('/etc/appscale/my_private_ip')

  sysman = system_manager.SystemManager(host + ":" +\
              str(cassandra_interface.CASS_DEFAULT_PORT))

  try:
    sysman.create_keyspace(cassandra_interface.KEYSPACE, 
                      pycassa.SIMPLE_STRATEGY, 
                      {'replication_factor':str(replication)})

    # This column family is for testing for functional testing
    sysman.create_column_family(cassandra_interface.KEYSPACE, 
                           cassandra_interface.STANDARD_COL_FAM, 
                           comparator_type=system_manager.UTF8_TYPE)

    for table_name in dbconstants.INITIAL_TABLES:
      sysman.create_column_family(cassandra_interface.KEYSPACE, 
                               table_name,
                               comparator_type=system_manager.UTF8_TYPE)
  
    sysman.close()
  # TODO: Figure out the exact exceptions we're trying to catch in the 
  # case where we are doing data persistance
  except Exception, e:
    sysman.close()
    # TODO: Figure out the exact exceptions we're trying to catch in the 
    print "Received an exception of type " + str(e.__class__) +\
          " with message: " + str(e)
 def __init__(self, host='localhost:9160'):
     self.host = host
     self.sm = system_manager.SystemManager(self.host)
Esempio n. 5
0
    if keyspace in sysm.list_keyspaces():
        sysm.drop_keyspace(keyspace)
    sysm.create_keyspace(keyspace, system_manager.SIMPLE_STRATEGY,
                         {'replication_factor': '1'})
    sysm.create_column_family(keyspace, columnfamily)
    sysm.alter_column(keyspace, columnfamily, 'strcol', system_manager.ASCII_TYPE)
    sysm.alter_column(keyspace, columnfamily, 'intcol', system_manager.INT_TYPE)
    sysm.alter_column(keyspace, columnfamily, 'longcol', system_manager.LONG_TYPE)
    sysm.alter_column(keyspace, columnfamily, 'floatcol', system_manager.FLOAT_TYPE)
    sysm.alter_column(keyspace, columnfamily, 'doublecol', system_manager.DOUBLE_TYPE)
    sysm.alter_column(keyspace, columnfamily, 'datecol', system_manager.DATE_TYPE)


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "Error.  Pass the name of the YAML configuration file as parameter."
        sys.exit(-1)
    conffile = sys.argv[1]

    sysm = system_manager.SystemManager()
    setup_keyspace(sysm)
    pool = ConnectionPool(keyspace)
    cf = ColumnFamily(pool, columnfamily)

    # Write and read keys
    write(cf)
    clist = read_cl(cf)
    #print "First rows of clist ->", clist[:10]
    sarray = read_np(cf, conffile)
    print "First rows of sarray->", repr(sarray[:10])
Esempio n. 6
0
 def drop_keyspaces(cls):
     sysm = sm.SystemManager()
     sysm.drop_keyspace(TWITTER_KEYSPACE)