def test_create_and_check_for_transform_collection_content_orm(self): """ Transform/Collection/Content (ORM): Test the creation, query, and cancel of a Transform/Collection/Content """ trans_properties = get_transform_properties() coll_properties = get_collection_properties() content_properties = get_content_properties() trans_id = add_transform(**trans_properties) coll_properties['transform_id'] = trans_id coll_id = add_collection(**coll_properties) coll_id_1 = get_collection_id( transform_id=trans_id, relation_type=coll_properties['relation_type']) assert_equal(coll_id, coll_id_1) coll = get_collection(coll_id=coll_id) for key in coll_properties: assert_equal(coll[key], coll_properties[key]) update_collection(coll_id, {'status': CollectionStatus.Closed}) coll = get_collection(coll_id=coll_id) assert_equal(coll['status'], CollectionStatus.Closed) content_properties['coll_id'] = coll_id content_id = add_content(**content_properties) content_1 = get_content(coll_id=coll_id, scope=content_properties['scope'], name=content_properties['name'], content_type=ContentType.File) content_id_1 = content_1['content_id'] assert_equal(content_id, content_id_1) content = get_content(content_id=content_id) update_content(content_id=content_id, parameters={'status': ContentStatus.Lost}) content = get_content(content_id=content_id) assert_equal(content['status'], ContentStatus.Lost) delete_content(content_id=content_id) c = get_content(content_id=content_id) assert_equal(c, None) delete_collection(coll_id=coll_id) coll = get_collection(coll_id=coll_id) assert_equal(coll, None) delete_transform(transform_id=trans_id) t = get_transform(transform_id=trans_id) assert_equal(t, None)
def register_output_contents(coll_scope, coll_name, contents, request_id=None, workload_id=None, relation_type=CollectionRelationType.Output, session=None): """ register contents with collection scope, collection name, request id, workload id and contents. :param coll_scope: scope of the collection. :param coll_name: name the the collection. :param request_id: the request id. :param workload_id: The workload_id of the request. :param contents: list of contents [{'scope': <scope>, 'name': <name>, 'min_id': min_id, 'max_id': max_id, 'status': <status>, 'path': <path>}]. :param session: The database session in use. """ transform_ids = orm_transforms.get_transform_ids(request_id=request_id, workload_id=workload_id, session=session) if transform_ids: collections = orm_collections.get_collections(scope=coll_scope, name=coll_name, transform_id=transform_ids, relation_type=relation_type, session=session) else: collections = [] coll_def = "request_id=%s, workload_id=%s, coll_scope=%s" % (request_id, workload_id, coll_scope) coll_def += ", coll_name=%s, relation_type: %s" % (coll_name, relation_type) if len(collections) != 1: msg = "There should be only one collection matched. However there are %s collections" % len(collections) msg += coll_def raise exceptions.WrongParameterException(msg) coll_id = collections[0]['coll_id'] keys = ['scope', 'name', 'min_id', 'max_id'] for content in contents: ex_content = orm_contents.get_content(coll_id=coll_id, scope=content['scope'], name=content['name'], min_id=content['min_id'], max_id=content['max_id'], session=session) content_def = "scope: %s, name: %s, min_id: %s, max_id: %s" % (content['scope'], content['name'], content['min_id'], content['max_id']) if not ex_content: msg = "No matched content in collection(%s) with content(%s)" % (coll_def, content_def) raise exceptions.WrongParameterException(msg) for key in keys: if key in content: del content[key] content['content_id'] = ex_content['content_id'] orm_contents.update_contents(contents, session=session)
def get_output_content_by_request_id_content_name(request_id, content_scope, content_name, transform_id=None, content_type=None, min_id=None, max_id=None, to_json=False, session=None): """ Get output content by request_id and content name :param request_id: requestn id. :param content_name: The name of the content. :param to_json: return json format. :param session: The database session in use. :returns: content of the output collection. """ transform_ids = orm_transforms.get_transform_ids(request_id, session=session) found_transform_id = None if transform_ids: if len(transform_ids) == 1: found_transform_id = transform_ids[0] elif len(transform_ids) > 1 and transform_id is None: raise "Number of the transforms(%s) is bigger than 1 and transform id is not provided" % len( transform_ids) else: for tf_id in transform_ids: if tf_id == transform_id: found_transform_id = tf_id break coll_id = None if found_transform_id: coll_id = orm_collections.get_collection_id( transform_id=found_transform_id, relation_type=CollectionRelationType.Output, session=session) content = None if coll_id: content = orm_contents.get_content(coll_id=coll_id, scope=content_scope, name=content_name, content_type=content_type, min_id=min_id, max_id=max_id, to_json=to_json, session=session) return content
def test_contents_orm(self): """ Contents (ORM): Test contents """ req_properties = get_request_properties() trans_properties = get_transform_properties() coll_properties = get_collection_properties() content_properties = get_content_properties() request_id = add_request(**req_properties) trans_properties['request_id'] = request_id trans_id = add_transform(**trans_properties) coll_properties['transform_id'] = trans_id coll_id = add_collection(**coll_properties) content_properties['coll_id'] = coll_id origin_content_id = add_content(**content_properties) content_properties1 = copy.deepcopy(content_properties) content_properties1['min_id'] = 101 content_properties1['max_id'] = 200 origin_content_id1 = add_content(**content_properties1) content_properties2 = copy.deepcopy(content_properties) content_properties2['min_id'] = 0 content_properties2['max_id'] = 200 origin_content_id2 = add_content(**content_properties2) content_properties3 = copy.deepcopy(content_properties) content_properties3['name'] = content_properties3['name'] + '_1' origin_content_id3 = add_content(**content_properties3) origin_content_ids = [ origin_content_id, origin_content_id1, origin_content_id2, origin_content_id3 ] contents = get_contents(coll_id=coll_id) assert_equal(len(contents), 4) for content in contents: assert_in(content['content_id'], origin_content_ids) contents = get_contents(scope=content_properties['scope'], name=content_properties['name'], coll_id=coll_id) assert_equal(len(contents), 3) for content in contents: assert_in(content['content_id'], origin_content_ids) contents = get_contents(scope=content_properties3['scope'], name=content_properties3['name'], coll_id=coll_id) assert_equal(len(contents), 1) assert_equal(contents[0]['content_id'], origin_content_id3) contents = get_match_contents(coll_id=content_properties['coll_id'], scope=content_properties['scope'], name=content_properties['name'], min_id=content_properties['min_id'], max_id=content_properties['max_id']) assert_equal(len(contents), 2) for content in contents: assert_in(content['content_id'], [origin_content_id, origin_content_id2]) to_updates = [{ 'path': 'test_path1', 'status': ContentStatus.Processing, 'content_id': origin_content_id }, { 'path': 'test_path2', 'status': ContentStatus.Processing, 'content_id': origin_content_id1 }] update_contents(to_updates) content = get_content(content_id=origin_content_id) assert_equal(content['status'], ContentStatus.Processing) assert_equal(content['path'], 'test_path1') content = get_content(content_id=origin_content_id1) assert_equal(content['status'], ContentStatus.Processing) assert_equal(content['path'], 'test_path2')
def test_catalog_rest(self): """ Catalog (Rest): Test catalog rest functions """ host = get_rest_host() client = Client(host=host) req_properties = get_request_properties() origin_request_id = add_request(**req_properties) trans_properties = get_transform_properties() trans_properties['request_id'] = origin_request_id origin_trans_id = add_transform(**trans_properties) coll_properties = get_collection_properties() coll_properties['transform_id'] = origin_trans_id coll_properties['request_id'] = origin_request_id coll_properties['relation_type'] = CollectionRelationType.Output origin_coll_id = add_collection(**coll_properties) req_trans_colls = client.get_collections(request_id=origin_request_id, workload_id=None) assert_equal(len(req_trans_colls.keys()), 1) req_id = list(req_trans_colls.keys())[0] assert_equal(origin_request_id, req_id) assert_equal(len(req_trans_colls[req_id].keys()), 1) trans_id = list(req_trans_colls[req_id].keys())[0] assert_equal(trans_id, origin_trans_id) colls = req_trans_colls[req_id][trans_id] assert_equal(len(colls), 1) assert_equal(colls[0]['coll_id'], origin_coll_id) req_trans_colls1 = client.get_collections(request_id=None, workload_id=req_properties['request_metadata']['workload_id']) assert_equal(is_same_req_trans_colls(req_trans_colls, req_trans_colls1), True) req_trans_colls1 = client.get_collections(scope=coll_properties['scope'], name=coll_properties['name'], request_id=None, workload_id=None) assert_equal(is_same_req_trans_colls(req_trans_colls, req_trans_colls1), True) content_output_properties = get_content_properties() content_output_properties['content_type'] = ContentType.File content_output_properties['min_id'] = 0 content_output_properties['max_id'] = 1000 content_output_properties['coll_id'] = origin_coll_id origin_content_output_id_0_1000 = add_content(returning_id=True, **content_output_properties) content_output_properties_0_100 = copy.deepcopy(content_output_properties) content_output_properties_0_100['min_id'] = 0 content_output_properties_0_100['max_id'] = 100 content_output_properties['content_type'] = ContentType.Event origin_content_output_id_0_100 = add_content(returning_id=True, **content_output_properties_0_100) content_output_properties_100_200 = copy.deepcopy(content_output_properties) content_output_properties_100_200['min_id'] = 100 content_output_properties_100_200['max_id'] = 200 content_output_properties['content_type'] = ContentType.Event origin_content_output_id_100_200 = add_content(returning_id=True, **content_output_properties_100_200) content_output_properties_name1 = copy.deepcopy(content_output_properties) content_output_properties_name1['name'] = content_output_properties_name1['name'] + '_1' content_output_properties_name1_id = add_content(returning_id=True, **content_output_properties_name1) req_trans_coll_contents = client.get_contents(coll_scope=coll_properties['scope'], coll_name=coll_properties['name'], request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id']) coll_contents = req_trans_coll_contents[origin_request_id][origin_trans_id] coll_scope_name = '%s:%s' % (coll_properties['scope'], coll_properties['name']) coll_scope_names = [scope_name for scope_name in coll_contents] assert_equal(coll_scope_names, [coll_scope_name]) contents = coll_contents[coll_scope_name]['contents'] assert_equal(len(contents), 4) output_content_ids = [output_content['content_id'] for output_content in contents] assert_equal(output_content_ids, [origin_content_output_id_0_1000, origin_content_output_id_0_100, origin_content_output_id_100_200, content_output_properties_name1_id]) req_trans_coll_contents1 = client.get_contents(coll_scope=coll_properties['scope'], coll_name=coll_properties['name'], request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id'], relation_type=CollectionRelationType.Output) assert_equal(is_same_req_trans_coll_contents(req_trans_coll_contents, req_trans_coll_contents1), True) contents = client.get_match_contents(coll_scope=coll_properties['scope'], coll_name=coll_properties['name'], scope=content_output_properties['scope'], name=content_output_properties['name'], min_id=None, max_id=None, request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id'], only_return_best_match=False) assert_equal(len(contents), 3) content_ids = [content['content_id'] for content in contents] content_ids.sort() content_ids1 = [origin_content_output_id_0_1000, origin_content_output_id_0_100, origin_content_output_id_100_200] content_ids1.sort() assert_equal(content_ids, content_ids1) contents = client.get_match_contents(coll_scope=coll_properties['scope'], coll_name=coll_properties['name'], scope=content_output_properties['scope'], name=content_output_properties['name'], min_id=0, max_id=50, request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id'], only_return_best_match=False) assert_equal(len(contents), 2) content_ids = [content['content_id'] for content in contents] content_ids.sort() content_ids1 = [origin_content_output_id_0_1000, origin_content_output_id_0_100] content_ids1.sort() assert_equal(content_ids, content_ids1) contents = client.get_match_contents(coll_scope=coll_properties['scope'], coll_name=coll_properties['name'], scope=content_output_properties['scope'], name=content_output_properties['name'], min_id=0, max_id=50, request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id'], only_return_best_match=True) assert_equal(len(contents), 1) content_ids = [content['content_id'] for content in contents] assert_equal(content_ids, [origin_content_output_id_0_100]) contents = [{'scope': content_output_properties['scope'], 'name': content_output_properties['name'], 'min_id': content_output_properties['min_id'], 'max_id': content_output_properties['max_id'], 'status': ContentStatus.Available, 'path': '/abc/test_path'}, {'scope': content_output_properties_name1['scope'], 'name': content_output_properties_name1['name'], 'min_id': content_output_properties_name1['min_id'], 'max_id': content_output_properties_name1['max_id'], 'status': ContentStatus.Failed}] client.register_contents(coll_scope=coll_properties['scope'], coll_name=coll_properties['name'], contents=contents, request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id']) content = get_content(content_id=origin_content_output_id_0_1000) assert_equal(content['status'], ContentStatus.Available) assert_equal(content['path'], '/abc/test_path') content = get_content(content_id=content_output_properties_name1_id) assert_equal(content['status'], ContentStatus.Failed)
def test_catalog_core(self): """ Catalog (Core): Test catalog core functions """ req_properties = get_request_properties() origin_request_id = add_request(**req_properties) trans_properties = get_transform_properties() trans_properties['request_id'] = origin_request_id origin_trans_id = add_transform(**trans_properties) coll_properties = get_collection_properties() coll_properties['transform_id'] = origin_trans_id coll_properties['request_id'] = origin_request_id coll_input_properties = copy.deepcopy(coll_properties) coll_input_properties['name'] = coll_input_properties['name'] + '_input' coll_output_properties = copy.deepcopy(coll_properties) coll_output_properties['relation_type'] = CollectionRelationType.Output coll_output_properties['name'] = coll_output_properties['name'] + '_output' coll_log_properties = copy.deepcopy(coll_properties) coll_log_properties['relation_type'] = CollectionRelationType.Log coll_log_properties['name'] = coll_log_properties['name'] + '_log' origin_coll_input_id = add_collection(**coll_input_properties) origin_coll_output_id = add_collection(**coll_output_properties) origin_coll_log_id = add_collection(**coll_log_properties) origin_coll_id_list = [origin_coll_input_id, origin_coll_output_id, origin_coll_log_id] req_trans_colls = get_collections_by_request(request_id=origin_request_id, workload_id=None) assert_equal(len(req_trans_colls.keys()), 1) req_id = list(req_trans_colls.keys())[0] assert_equal(origin_request_id, req_id) assert_equal(len(req_trans_colls[req_id].keys()), 1) trans_id = list(req_trans_colls[req_id].keys())[0] assert_equal(trans_id, origin_trans_id) colls = req_trans_colls[req_id][trans_id] assert_equal(len(colls), 3) for coll in colls: assert_in(coll['coll_id'], origin_coll_id_list) for key in coll_input_properties: if key == 'relation_type': if coll['coll_id'] == origin_coll_input_id: assert_equal(coll[key], CollectionRelationType.Input) elif coll['coll_id'] == origin_coll_output_id: assert_equal(coll[key], CollectionRelationType.Output) else: assert_equal(coll['coll_id'], origin_coll_log_id) assert_equal(coll[key], CollectionRelationType.Log) if key == 'name': if coll['coll_id'] == origin_coll_input_id: assert_equal(coll[key], coll_input_properties[key]) elif coll['coll_id'] == origin_coll_output_id: assert_equal(coll[key], coll_output_properties[key]) else: assert_equal(coll[key], coll_log_properties[key]) req_trans_colls1 = get_collections_by_request(request_id=None, workload_id=req_properties['request_metadata']['workload_id']) assert_equal(is_same_req_trans_colls(req_trans_colls, req_trans_colls1), True) req_trans_colls1 = get_collections_by_request(request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id']) assert_equal(is_same_req_trans_colls(req_trans_colls, req_trans_colls1), True) req_trans_colls = get_collections(scope=coll_properties['scope'], name=coll_properties['name'], request_id=None, workload_id=None) assert_equal(len(req_trans_colls.keys()), 1) req_id = list(req_trans_colls.keys())[0] assert_equal(origin_request_id, req_id) assert_equal(len(req_trans_colls[req_id].keys()), 1) trans_id = list(req_trans_colls[req_id].keys())[0] assert_equal(trans_id, origin_trans_id) colls = req_trans_colls[req_id][trans_id] assert_equal(len(colls), 3) for coll in colls: assert_in(coll['coll_id'], origin_coll_id_list) for key in coll_input_properties: if key == 'relation_type': if coll['coll_id'] == origin_coll_input_id: assert_equal(coll[key], CollectionRelationType.Input) elif coll['coll_id'] == origin_coll_output_id: assert_equal(coll[key], CollectionRelationType.Output) else: assert_equal(coll['coll_id'], origin_coll_log_id) assert_equal(coll[key], CollectionRelationType.Log) if key == 'name': if coll['coll_id'] == origin_coll_input_id: assert_equal(coll[key], coll_input_properties[key]) elif coll['coll_id'] == origin_coll_output_id: assert_equal(coll[key], coll_output_properties[key]) else: assert_equal(coll[key], coll_log_properties[key]) req_trans_colls = get_collections(scope=coll_properties['scope'], name=coll_input_properties['name'], request_id=origin_request_id, workload_id=None) assert_equal(len(req_trans_colls.keys()), 1) req_id = list(req_trans_colls.keys())[0] assert_equal(origin_request_id, req_id) assert_equal(len(req_trans_colls[req_id].keys()), 1) trans_id = list(req_trans_colls[req_id].keys())[0] assert_equal(trans_id, origin_trans_id) colls = req_trans_colls[req_id][trans_id] assert_equal(len(colls), 1) coll = colls[0] for key in coll_properties: if key == 'relation_type': assert_equal(coll[key], CollectionRelationType.Input) if key == 'name': assert_equal(coll[key], coll_input_properties[key]) req_trans_colls = get_collections(scope=coll_properties['scope'], name=coll_output_properties['name'], request_id=None, workload_id=req_properties['request_metadata']['workload_id']) assert_equal(len(req_trans_colls.keys()), 1) req_id = list(req_trans_colls.keys())[0] assert_equal(origin_request_id, req_id) assert_equal(len(req_trans_colls[req_id].keys()), 1) trans_id = list(req_trans_colls[req_id].keys())[0] assert_equal(trans_id, origin_trans_id) colls = req_trans_colls[req_id][trans_id] assert_equal(len(colls), 1) coll = colls[0] for key in coll_properties: if key == 'relation_type': assert_equal(coll[key], CollectionRelationType.Output) if key == 'name': assert_equal(coll[key], coll_output_properties[key]) req_trans_colls = get_collections(scope=coll_properties['scope'], name=coll_log_properties['name'], request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id']) assert_equal(len(req_trans_colls.keys()), 1) req_id = list(req_trans_colls.keys())[0] assert_equal(origin_request_id, req_id) assert_equal(len(req_trans_colls[req_id].keys()), 1) trans_id = list(req_trans_colls[req_id].keys())[0] assert_equal(trans_id, origin_trans_id) colls = req_trans_colls[req_id][trans_id] assert_equal(len(colls), 1) coll = colls[0] for key in coll_properties: if key == 'relation_type': assert_equal(coll[key], CollectionRelationType.Log) if key == 'name': assert_equal(coll[key], coll_log_properties[key]) trans_properties1 = copy.deepcopy(trans_properties) origin_trans_id1 = add_transform(**trans_properties1) coll_properties1 = copy.deepcopy(coll_properties) coll_properties1['name'] = coll_properties1['name'] + '_1' coll_properties1['transform_id'] = origin_trans_id1 coll_input_properties1 = copy.deepcopy(coll_properties1) coll_input_properties1['name'] = coll_input_properties1['name'] + '_input' coll_output_properties1 = copy.deepcopy(coll_properties1) coll_output_properties1['relation_type'] = CollectionRelationType.Output coll_output_properties1['name'] = coll_output_properties1['name'] + '_output' coll_log_properties1 = copy.deepcopy(coll_properties1) coll_log_properties1['relation_type'] = CollectionRelationType.Log coll_log_properties1['name'] = coll_log_properties1['name'] + '_log' origin_coll_input_id1 = add_collection(**coll_input_properties1) origin_coll_output_id1 = add_collection(**coll_output_properties1) origin_coll_log_id1 = add_collection(**coll_log_properties1) origin_coll_id_list1 = [origin_coll_input_id1, origin_coll_output_id1, origin_coll_log_id1] req_trans_colls = get_collections_by_request(request_id=origin_request_id, workload_id=None) assert_equal(len(req_trans_colls.keys()), 1) req_id = list(req_trans_colls.keys())[0] assert_equal(origin_request_id, req_id) assert_equal(len(req_trans_colls[req_id].keys()), 2) for trans_id in req_trans_colls[req_id]: if trans_id == origin_trans_id: colls = req_trans_colls[req_id][trans_id] assert_equal(len(colls), 3) for coll in colls: assert_in(coll['coll_id'], origin_coll_id_list) for key in coll_properties: if key == 'relation_type': if coll['coll_id'] == origin_coll_input_id: assert_equal(coll[key], CollectionRelationType.Input) elif coll['coll_id'] == origin_coll_output_id: assert_equal(coll[key], CollectionRelationType.Output) else: assert_equal(coll['coll_id'], origin_coll_log_id) assert_equal(coll[key], CollectionRelationType.Log) if key == 'name': if coll['coll_id'] == origin_coll_input_id: assert_equal(coll[key], coll_input_properties[key]) elif coll['coll_id'] == origin_coll_output_id: assert_equal(coll[key], coll_output_properties[key]) else: assert_equal(coll[key], coll_log_properties[key]) if trans_id == origin_trans_id1: colls = req_trans_colls[req_id][trans_id] assert_equal(len(colls), 3) for coll in colls: assert_in(coll['coll_id'], origin_coll_id_list1) for key in coll_properties: if key == 'relation_type': if coll['coll_id'] == origin_coll_input_id1: assert_equal(coll[key], CollectionRelationType.Input) elif coll['coll_id'] == origin_coll_output_id1: assert_equal(coll[key], CollectionRelationType.Output) else: assert_equal(coll['coll_id'], origin_coll_log_id1) assert_equal(coll[key], CollectionRelationType.Log) if key == 'name': if coll['coll_id'] == origin_coll_input_id1: assert_equal(coll[key], coll_input_properties1[key]) elif coll['coll_id'] == origin_coll_output_id1: assert_equal(coll[key], coll_output_properties1[key]) else: assert_equal(coll[key], coll_log_properties1[key]) req_trans_colls1 = get_collections_by_request(request_id=None, workload_id=req_properties['request_metadata']['workload_id']) assert_equal(is_same_req_trans_colls(req_trans_colls, req_trans_colls1), True) req_trans_colls1 = get_collections_by_request(request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id']) assert_equal(is_same_req_trans_colls(req_trans_colls, req_trans_colls1), True) req_trans_colls = get_collections(scope=coll_properties['scope'], name=coll_properties['name'], request_id=None, workload_id=None) assert_equal(len(req_trans_colls.keys()), 1) req_id = list(req_trans_colls.keys())[0] assert_equal(origin_request_id, req_id) assert_equal(len(req_trans_colls[req_id].keys()), 2) for trans_id in req_trans_colls[req_id]: if trans_id == origin_trans_id: colls = req_trans_colls[req_id][trans_id] assert_equal(len(colls), 3) for coll in colls: assert_in(coll['coll_id'], origin_coll_id_list) for key in coll_properties: if key == 'relation_type': if coll['coll_id'] == origin_coll_input_id: assert_equal(coll[key], CollectionRelationType.Input) elif coll['coll_id'] == origin_coll_output_id: assert_equal(coll[key], CollectionRelationType.Output) else: assert_equal(coll['coll_id'], origin_coll_log_id) assert_equal(coll[key], CollectionRelationType.Log) if key == 'name': if coll['coll_id'] == origin_coll_input_id: assert_equal(coll[key], coll_input_properties[key]) elif coll['coll_id'] == origin_coll_output_id: assert_equal(coll[key], coll_output_properties[key]) else: assert_equal(coll[key], coll_log_properties[key]) if trans_id == origin_trans_id1: colls = req_trans_colls[req_id][trans_id] assert_equal(len(colls), 3) for coll in colls: assert_in(coll['coll_id'], origin_coll_id_list1) for key in coll_properties: if key == 'relation_type': if coll['coll_id'] == origin_coll_input_id1: assert_equal(coll[key], CollectionRelationType.Input) elif coll['coll_id'] == origin_coll_output_id1: assert_equal(coll[key], CollectionRelationType.Output) else: assert_equal(coll['coll_id'], origin_coll_log_id1) assert_equal(coll[key], CollectionRelationType.Log) if key == 'name': if coll['coll_id'] == origin_coll_input_id1: assert_equal(coll[key], coll_input_properties1[key]) elif coll['coll_id'] == origin_coll_output_id1: assert_equal(coll[key], coll_output_properties1[key]) else: assert_equal(coll[key], coll_log_properties1[key]) req_properties = get_request_properties() origin_request_id = add_request(**req_properties) trans_properties = get_transform_properties() trans_properties['request_id'] = origin_request_id origin_trans_id = add_transform(**trans_properties) coll_properties = get_collection_properties() coll_properties['transform_id'] = origin_trans_id coll_properties['request_id'] = origin_request_id coll_input_properties = copy.deepcopy(coll_properties) coll_input_properties['name'] = coll_input_properties['name'] + '_input' coll_output_properties = copy.deepcopy(coll_properties) coll_output_properties['relation_type'] = CollectionRelationType.Output coll_output_properties['name'] = coll_output_properties['name'] + '_output' origin_coll_input_id = add_collection(**coll_input_properties) origin_coll_output_id = add_collection(**coll_output_properties) content_input_properties = get_content_properties() content_input_properties['coll_id'] = origin_coll_input_id origin_content_input_id_0_100 = add_content(returning_id=True, **content_input_properties) content_input_properties_100_200 = copy.deepcopy(content_input_properties) content_input_properties_100_200['min_id'] = 100 content_input_properties_100_200['max_id'] = 200 origin_content_input_id_100_200 = add_content(returning_id=True, **content_input_properties_100_200) content_input_properties_name1 = copy.deepcopy(content_input_properties) content_input_properties_name1['name'] = content_input_properties_name1['name'] + '_1' content_input_properties_name1_id = add_content(returning_id=True, **content_input_properties_name1) content_output_properties = get_content_properties() content_output_properties['content_type'] = ContentType.File content_output_properties['min_id'] = 0 content_output_properties['max_id'] = 1000 content_output_properties['coll_id'] = origin_coll_output_id origin_content_output_id_0_1000 = add_content(returning_id=True, **content_output_properties) content_output_properties_0_100 = copy.deepcopy(content_output_properties) content_output_properties_0_100['min_id'] = 0 content_output_properties_0_100['max_id'] = 100 content_output_properties['content_type'] = ContentType.Event origin_content_output_id_0_100 = add_content(returning_id=True, **content_output_properties_0_100) content_output_properties_100_200 = copy.deepcopy(content_output_properties) content_output_properties_100_200['min_id'] = 100 content_output_properties_100_200['max_id'] = 200 content_output_properties['content_type'] = ContentType.Event origin_content_output_id_100_200 = add_content(returning_id=True, **content_output_properties_100_200) content_output_properties_name1 = copy.deepcopy(content_output_properties) content_output_properties_name1['name'] = content_output_properties_name1['name'] + '_1' content_output_properties_name1_id = add_content(returning_id=True, **content_output_properties_name1) with assert_raises(exceptions.WrongParameterException): get_contents(coll_scope=None, coll_name=None, request_id=None, workload_id=None, relation_type=None) req_trans_coll_contents = get_contents(coll_scope=coll_properties['scope'], coll_name=coll_properties['name'], request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id']) coll_contents = req_trans_coll_contents[origin_request_id][origin_trans_id] coll_input_scope_name = '%s:%s' % (coll_input_properties['scope'], coll_input_properties['name']) coll_output_scope_name = '%s:%s' % (coll_output_properties['scope'], coll_output_properties['name']) coll_scope_names = [scope_name for scope_name in coll_contents] assert_equal(coll_scope_names, [coll_input_scope_name, coll_output_scope_name]) input_contents = coll_contents[coll_input_scope_name]['contents'] output_contents = coll_contents[coll_output_scope_name]['contents'] assert_equal(len(input_contents), 3) assert_equal(len(output_contents), 4) input_content_ids = [input_content['content_id'] for input_content in input_contents] assert_equal(input_content_ids, [origin_content_input_id_0_100, origin_content_input_id_100_200, content_input_properties_name1_id]) output_content_ids = [output_content['content_id'] for output_content in output_contents] assert_equal(output_content_ids, [origin_content_output_id_0_1000, origin_content_output_id_0_100, origin_content_output_id_100_200, content_output_properties_name1_id]) req_trans_coll_contents = get_contents(coll_scope=coll_properties['scope'], coll_name=coll_properties['name'], request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id'], relation_type=CollectionRelationType.Input) coll_contents = req_trans_coll_contents[origin_request_id][origin_trans_id] coll_input_scope_name = '%s:%s' % (coll_input_properties['scope'], coll_input_properties['name']) coll_scope_names = list(coll_contents.keys()) assert_equal(coll_scope_names, [coll_input_scope_name]) req_trans_coll_contents = get_contents(coll_scope=coll_properties['scope'], coll_name=coll_properties['name'], request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id'], relation_type=CollectionRelationType.Output) coll_contents = req_trans_coll_contents[origin_request_id][origin_trans_id] coll_output_scope_name = '%s:%s' % (coll_output_properties['scope'], coll_output_properties['name']) coll_scope_names = list(coll_contents.keys()) assert_equal(coll_scope_names, [coll_output_scope_name]) contents = [{'scope': content_output_properties['scope'], 'name': content_output_properties['name'], 'min_id': content_output_properties['min_id'], 'max_id': content_output_properties['max_id'], 'status': ContentStatus.Available, 'path': '/abc/test_path'}, {'scope': content_output_properties_name1['scope'], 'name': content_output_properties_name1['name'], 'min_id': content_output_properties_name1['min_id'], 'max_id': content_output_properties_name1['max_id'], 'status': ContentStatus.Failed}] register_output_contents(coll_scope=coll_output_properties['scope'], coll_name=coll_output_properties['name'], contents=contents, request_id=origin_request_id, workload_id=None) content = get_content(content_id=origin_content_output_id_0_1000) assert_equal(content['status'], ContentStatus.Available) assert_equal(content['path'], '/abc/test_path') content = get_content(content_id=content_output_properties_name1_id) assert_equal(content['status'], ContentStatus.Failed) contents = get_match_contents(coll_scope=coll_output_properties['scope'], coll_name=coll_output_properties['name'], scope=content_output_properties['scope'], name=content_output_properties['name'], min_id=None, max_id=None, request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id'], only_return_best_match=False) assert_equal(len(contents), 3) content_ids = [content['content_id'] for content in contents] content_ids.sort() content_ids1 = [origin_content_output_id_0_1000, origin_content_output_id_0_100, origin_content_output_id_100_200] content_ids1.sort() assert_equal(content_ids, content_ids1) contents = get_match_contents(coll_scope=coll_output_properties['scope'], coll_name=coll_output_properties['name'], scope=content_output_properties['scope'], name=content_output_properties['name'], min_id=0, max_id=50, request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id'], only_return_best_match=False) assert_equal(len(contents), 2) content_ids = [content['content_id'] for content in contents] content_ids.sort() content_ids1 = [origin_content_output_id_0_1000, origin_content_output_id_0_100] content_ids1.sort() assert_equal(content_ids, content_ids1) contents = get_match_contents(coll_scope=coll_output_properties['scope'], coll_name=coll_output_properties['name'], scope=content_output_properties['scope'], name=content_output_properties['name'], min_id=0, max_id=50, request_id=origin_request_id, workload_id=req_properties['request_metadata']['workload_id'], only_return_best_match=True) assert_equal(len(contents), 1) content_ids = [content['content_id'] for content in contents] assert_equal(content_ids, [origin_content_output_id_0_100])