Exemplo n.º 1
0
def get_batch_list(track_id, tpid, tpe, seq, image_type):
    table = get_table_name()
    #row = '%s-%s_%s_%s_%s' % (track_id, tpid, tpe, seq, image_type)
    row = rowkey.gen(track_id, tpid, tpe, seq, image_type)
    ret = hbase_util.get_col(table, row, 'meta', 'batch_list')
    if ret:
        assert ret.keys() == ['meta:batch_list']
        return ret['meta:batch_list']
    else:
        return None
Exemplo n.º 2
0
def clear_batch(track_id, tpid, tpe, seq, image_type):
    table = get_table_name()
    #row_key = '%s-%s_%s_%s_%s' % (track_id, tpid, tpe, seq, image_type)
    row = rowkey.gen(track_id, tpid, tpe, seq, image_type)
    cols = []
    cols.append(('meta', 'batch_list', ''))
    sys.stdout.flush()
    ret = hbase_util.put_cols(table, row, cols)

    sys.stdout.flush()
    return ret
Exemplo n.º 3
0
def image_exist(track_id, tpid, tpe, seq, image_type, batch=''):
    row_key = rowkey.gen(track_id, tpid, tpe, seq, image_type)
    logger().info('row_key[%s], batch[%s]', row_key, batch)
    if not batch:
        last_batch = batch_manager.get_last_batch(track_id, tpid, tpe, seq,
                                                  image_type)
        return last_batch != None
    else:
        if tpe == '00' and seq == '004':
            return False
        else:
            table = get_table_name()
            ret = hbase_util.get_col(table, row_key, 'content', batch)
            return not not ret
Exemplo n.º 4
0
def image_delete(track_id, tpid, tpe, seq, image_type, batch=''):
    row_key = rowkey.gen(track_id, tpid, tpe, seq, image_type)
    if not batch:
        batch = batch_manager.get_last_batch(track_id, tpid, tpe, seq,
                                             image_type)
        if not batch:
            logger().error('get empty batch for row_key[%s]', row_key)
            return False

    table = get_table_name()
    columns = ['content:' + batch]
    logger().debug('delete row [%s], batch[%s]', row_key, batch)
    hbase_util.delete(table, row_key, columns=columns)
    batch_manager.del_batch(track_id, tpid, tpe, seq, image_type, batch)
    return True
Exemplo n.º 5
0
def image_get(track_id, tpid, tpe, seq, image_type, batch=None):
    #row_key = '%s-%s_%s_%s_%s' % (track_id, tpid, tpe, seq, image_type)
    row_key = rowkey.gen(track_id, tpid, tpe, seq, image_type)
    if not batch:
        batch = batch_manager.get_last_batch(track_id, tpid, tpe, seq,
                                             image_type)
        if not batch:
            logger().error('get empty batch for row_key[%s]', row_key)
            return None

    table = get_table_name()
    logger().debug('row [%s], batch[%s]', row_key, batch)
    ret = hbase_util.get_col(table, row_key, 'content', batch)
    if ret:
        return ret['content:' + batch]
    return None
Exemplo n.º 6
0
def del_batch(track_id, tpid, tpe, seq, image_type, batch):
    batch_list = get_batch_list(track_id, tpid, tpe, seq, image_type)
    logger().debug('old batch_list:%s', batch_list)
    if batch_list:
        batch_list = _batch_del(batch_list, batch)
    else:
        batch_list = ''
    logger().debug('new batch_list:%s', batch_list)

    # write
    table = get_table_name()
    #row_key = '%s-%s_%s_%s_%s' % (track_id, tpid, tpe, seq, image_type)
    row = rowkey.gen(track_id, tpid, tpe, seq, image_type)
    cols = []
    cols.append(('meta', 'batch_list', batch_list))
    return hbase_util.put_cols(table, row, cols)
Exemplo n.º 7
0
def image_write(track_id, tpid, tpe, seq, image_type, content, task_seq,
                batch):
    row_key = rowkey.gen(track_id, tpid, tpe, seq, image_type)

    cols = []
    table = batch_manager.get_table_name()
    cols.append(('meta', 'type', tpe))
    cols.append(('meta', 'seq', seq))
    cols.append(('meta', 'image_type', image_type))
    cols.append(('meta', 'task_seq_' + task_seq, batch))
    if not hbase_util.put_cols(table, row_key, cols):
        return False

    cols = []
    table = get_table_name()
    logger().info('write row_key[%s] to table[%s]', row_key, table)
    cols.append(('content', batch, content))
    if not hbase_util.put_cols(table, row_key, cols):
        return False
    return True
Exemplo n.º 8
0
def rowkey_main():
    print gen('test1', '11', '2', '3', 'jpg')
    print gen_v2('test2', '11', '2', '3', 'jpg')
Exemplo n.º 9
0
def rowkey_test():
    assert_equal('0-test1-11_2_3_jpg', gen('test1', '11', '2', '3', 'jpg'))
    assert_equal('55-test2-11_2_3_jpg', gen_v2('test2', '11', '2', '3', 'jpg'))