示例#1
0
def image_delete(track_id, tpid, tpe, seq, image_type, batch=''):
    row_key = rowkey.gen_v2(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
示例#2
0
def image_exist(track_id, tpid, tpe, seq, image_type, batch=''):
    row_key = rowkey.gen_v2(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)
        logger().info('v2 last_batch[%s]', last_batch)
        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
示例#3
0
def image_get(track_id, tpid, tpe, seq, image_type, batch=None):
    if tpe == '00' and seq == '004':
        ret = rawdata_api.image_get(track_id, tpid)
        if ret:
            return ret
    #row_key = '%s-%s_%s_%s_%s' % (track_id, tpid, tpe, seq, image_type)
    row_key = rowkey.gen_v2(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
def test():
    assert_true(clear_batch('test', '1', '2', '3', 'jpg'))

    assert_true(set_batch('test', '1', '2', '3', 'jpg', '!!!'))
    assert_equal('!!!', get_last_batch('test', '1', '2', '3', 'jpg'))

    assert_true(set_batch('test', '1', '2', '3', 'jpg', 'batch1'))
    assert_equal('batch1', get_last_batch('test', '1', '2', '3', 'jpg'))

    assert_true(set_batch('test', '1', '2', '3', 'jpg', 'batch3'))
    assert_equal('batch3', get_last_batch('test', '1', '2', '3', 'jpg'))

    assert_true(set_batch('test', '1', '2', '3', 'jpg', 'batch2'))
    assert_equal('batch3', get_last_batch('test', '1', '2', '3', 'jpg'))

    assert_true(del_batch('test', '1', '2', '3', 'jpg', 'batch3'))
    assert_equal('batch2', get_last_batch('test', '1', '2', '3', 'jpg'))

    assert_true(del_batch('test', '1', '2', '3', 'jpg', 'batch2'))
    assert_equal('batch1', get_last_batch('test', '1', '2', '3', 'jpg'))

    assert_true(del_batch('test', '1', '2', '3', 'jpg', 'batch1'))
    assert_equal('!!!', get_last_batch('test', '1', '2', '3', 'jpg'))
def main():
    setUp()

    print 'clear:', clear_batch('test', '1', '2', '3', 'jpg')

    print 'set:', set_batch('test', '1', '2', '3', 'jpg', '!!!')
    print 'last:', get_last_batch('test', '1', '2', '3', 'jpg')

    print 'set', set_batch('test', '1', '2', '3', 'jpg', 'batch1')
    print 'last:', get_last_batch('test', '1', '2', '3', 'jpg')

    print 'set:', set_batch('test', '1', '2', '3', 'jpg', 'batch3')
    print 'last:', get_last_batch('test', '1', '2', '3', 'jpg')

    print 'set:', set_batch('test', '1', '2', '3', 'jpg', 'batch2')
    print 'last:', get_last_batch('test', '1', '2', '3', 'jpg')

    print 'del:', del_batch('test', '1', '2', '3', 'jpg', 'batch2')
    print 'last:', get_last_batch('test', '1', '2', '3', 'jpg')

    print 'del:', del_batch('test', '1', '2', '3', 'jpg', 'batch3')
    print 'last:', get_last_batch('test', '1', '2', '3', 'jpg')