Ejemplo n.º 1
0
def create_db():
    logging.info('creating dynamodb table')

    try:
        table = Table.create(table_name, schema=[
            HashKey('id')
        ], throughput = { 'read' : 64, 'write' : 64 })

    except JSONResponseError as e:
        logging.error('exception: {}'.format(e.error_message))
        return -1

    # allow time for table creation
    #
    tries = 16
    for x in range(tries):
        time.sleep(1)
        t = table.describe()
        tstat = t['Table']['TableStatus']
        logging.info('{}/{}: table status: {}'.format(1+x, tries, tstat))
        if tstat == 'ACTIVE':
            logging.info('table created')
            return 1

    logging.error('create table failed')
    return -1
Ejemplo n.º 2
0
def create_db():
    logging.info('creating dynamodb table')

    try:
        table = Table.create(table_name,
                             schema=[HashKey('id')],
                             throughput={
                                 'read': 64,
                                 'write': 64
                             })

    except JSONResponseError as e:
        logging.error('exception: {}'.format(e.error_message))
        return -1

    # allow time for table creation
    #
    tries = 16
    for x in range(tries):
        time.sleep(1)
        t = table.describe()
        tstat = t['Table']['TableStatus']
        logging.info('{}/{}: table status: {}'.format(1 + x, tries, tstat))
        if tstat == 'ACTIVE':
            logging.info('table created')
            return 1

    logging.error('create table failed')
    return -1
Ejemplo n.º 3
0
    def do_refresh(self, line):
        "refresh {table_name}"
        table = self.get_table(line)

        while True:
            desc = table.describe()
            status = desc['Table']['TableStatus']
            if status == 'ACTIVE':
                break
            else:
                print status, "..."
                time.sleep(5)

        print ""
        self.pprint(desc)
Ejemplo n.º 4
0
 def get_connection(cls, table_object_name):
     if table_object_name not in cls._connection_dict:
         if cls._region_conn is None:
             cls._region_conn = get_dynamodb_connection()
         table_properties = cls._TABLE_NAME_TO_PROPERTIES[table_object_name]
         avro_schema = get_avro_schema(table_properties['avro_schema'])
         table_name = read_string(table_properties['physical_id_key'])
         table = Table(table_name, connection=cls._region_conn)
         try:
             results = table.describe()
             raw_indexes = results['Table'].get('GlobalSecondaryIndexes',
                                                [])
             table.global_indexes = introspect_global_indexes(raw_indexes)
         except Exception:
             log_exception("Table Connection Failed")
         cls._connection_dict[table_object_name] = table_properties[
             'class'](table, avro_schema)
     return cls._connection_dict[table_object_name]
Ejemplo n.º 5
0
    def do_capacity(self, line):
        "capacity [tablename] {read_units} {write_units}"
        table, line = self.get_table_params(line)
        args = self.getargs(line)

        read_units = int(args[0])
        write_units = int(args[1])

        desc = table.describe()
        prov = desc['Table']['ProvisionedThroughput']

        current_read, current_write = prov['ReadCapacityUnits'], prov['WriteCapacityUnits']
        if read_units < current_read or write_units < current_write:
            print "%s: updating capacity to %d read units, %d write units" % (table.table_name, read_units, write_units)
            print ""
            if not table.update(throughput={'read': read_units, 'write': write_units}):
                print "update failed"
            else:
                self.do_refresh(table.table_name)

        else:
            print "%s: current capacity is %d read units, %d write units" % (table.table_name, current_read, current_write)
            # we can only double the current value at each call
            while current_read < read_units or current_write < write_units:
                if (read_units - current_read) > current_read:
                    current_read *= 2
                else:
                    current_read = read_units

                if (write_units - current_write) > current_write:
                    current_write *= 2
                else:
                    current_write = write_units

                print "%s: updating capacity to %d read units, %d write units" % (table.table_name, current_read, current_write)
                if not table.update({'read': current_read, 'write': current_write}):
                    print ""
                    print "update failed"
                    print ""
                    break
                else:
                    print ""
                    self.do_refresh(table.table_name)
                    print ""
Ejemplo n.º 6
0
 def get_connection(cls, table_object_name):
     if table_object_name not in cls._connection_dict:
         if cls._region_conn is None:
             cls._region_conn = get_dynamodb_connection()
         table_properties = cls._TABLE_NAME_TO_PROPERTIES[table_object_name]
         avro_schema = get_avro_schema(table_properties['avro_schema'])
         table_name = read_string(table_properties['physical_id_key'])
         table = Table(
             table_name,
             connection=cls._region_conn
         )
         try:
             results = table.describe()
             raw_indexes = results['Table'].get('GlobalSecondaryIndexes', [])
             table.global_indexes = introspect_global_indexes(raw_indexes)
         except Exception:
             log_exception("Table Connection Failed")
         cls._connection_dict[table_object_name] = table_properties['class'](
             table,
             avro_schema
         )
     return cls._connection_dict[table_object_name]