<s> import logging <EOL> import saga <EOL> import json <EOL> import pdb <EOL> from pilot import * <EOL> from bigjob import logger <EOL> class AdvertCoordinationAdaptor : <EOL> """<STR_LIT>""" <EOL> BASE_URL = "<STR_LIT>" <EOL> BASE_URL_QUERY_STRING = "<STR_LIT>" <EOL> PILOT_PATH = "<STR_LIT>" <EOL> PILOT_DATA_PATH = PILOT_PATH <EOL> PILOT_DATA_SERVICE_PATH = PILOT_DATA_PATH + "<STR_LIT>" <EOL> DATA_UNIT_SERVICE_PATH = PILOT_DATA_PATH + "<STR_LIT>" <EOL> COMPUTE_DATA_SERVICE_PATH = PILOT_DATA_PATH + "<STR_LIT>" <EOL> @ classmethod <EOL> def get_base_url ( cls , application_id ) : <EOL> surl = saga . url ( cls . BASE_URL ) <EOL> base_url = surl . scheme + "<STR_LIT>" + surl . host + "<STR_LIT:/>" + application_id + "<STR_LIT:/>" <EOL> logging . debug ( base_url ) <EOL> return base_url <EOL> @ classmethod <EOL> def add_pds ( cls , application_url , pds ) : <EOL> pds_url_no_dbtype = cls . get_pds_url ( application_url , pds . id ) <EOL> pds_url = cls . __get_url ( pds_url_no_dbtype ) <EOL> logger . debug ( "<STR_LIT>" % pds_url ) <EOL> saga . advert . directory ( pds_url , saga . advert . Create | <EOL> saga . advert . CreateParents | <EOL> saga . advert . ReadWrite ) <EOL> return pds_url_no_dbtype <EOL> @ classmethod <EOL> def delete_pds ( cls , pds_url ) : <EOL> pds_url = cls . __get_url ( pds_url ) <EOL> pds_dir = saga . advert . directory ( saga . url ( pds_url ) , <EOL> saga . advert . Create | <EOL> saga . advert . CreateParents | <EOL> saga . advert . ReadWrite ) <EOL> pds_dir . remove ( pds_url , saga . name_space . Recursive ) <EOL> @ classmethod <EOL> def add_pd ( cls , pds_url , pd ) : <EOL> pds_url = cls . __remove_dbtype ( pds_url ) <EOL> pd_url = pds_url + "<STR_LIT:/>" + pd . id <EOL> pd_description_url = cls . __get_url ( pd_url + "<STR_LIT>" ) <EOL> logger . debug ( "<STR_LIT>" % ( pds_url , pd_description_url ) ) <EOL> pd_desc_entry = saga . advert . entry ( saga . url ( pd_description_url ) , <EOL> saga . advert . Create | saga . advert . CreateParents | saga . advert . ReadWrite ) <EOL> logger . debug ( "<STR_LIT>" + pd_description_url ) <EOL> pd_desc_entry . store_string ( json . dumps ( pd . data_unit_description ) ) <EOL> return pd_url <EOL> @ classmethod <EOL> def update_pd ( cls , pd ) : <EOL> if len ( pd . data_units ) > <NUM_LIT:0> : <EOL> du_urls = [ i . url for i in pd . data_units . values ( ) ] <EOL> cls . __store_entry ( cls . __remove_dbtype ( pd . url ) + "<STR_LIT>" , du_urls ) <EOL> cls . __store_entry ( cls . __remove_dbtype ( pd . url ) + "<STR_LIT>" , pd . to_dict ( ) ) <EOL> @ classmethod <EOL> def get_pd ( cls , pds_url ) : <EOL> logger . debug ( "<STR_LIT>" + pds_url ) <EOL> pd_dict = { } <EOL> pd_dict [ "<STR_LIT>" ] = cls . __retrieve_entry ( cls . __remove_dbtype ( pds_url ) + "<STR_LIT>" ) <EOL> return pd_dict <EOL> @ classmethod <EOL> def list_pd ( cls , pds_url ) : <EOL> """<STR_LIT>""" <EOL> pds_url = cls . __get_url ( pds_url ) <EOL> logger . debug ( "<STR_LIT>" % pds_url ) <EOL> pds_dir = saga . advert . directory ( pds_url , saga . advert . Create | <EOL> saga . advert . CreateParents | <EOL> saga . advert . ReadWrite ) <EOL> pd_list = pds_dir . list ( ) <EOL> pd_full_urls = [ ] <EOL> for i in pd_list : <EOL> pd_full_urls . append ( pds_url + "<STR_LIT:/>" + i ) <EOL> return pd_full_urls <EOL> @ classmethod <EOL> def delete_pd ( cls , pds_url ) : <EOL> pds_url = cls . __get_url ( pds_url ) <EOL> pd_dir = saga . advert . directory ( saga . url ( pds_url ) , <EOL> saga . advert . Create | <EOL> saga . advert . CreateParents | <EOL> saga . advert . ReadWrite ) <EOL> pd_dir . remove ( pds_url , saga . name_space . Recursive ) <EOL> @ classmethod <EOL> def add_cds ( cls , application_url , cds ) : <EOL> cds_url_no_dbtype = cls . get_cds_url ( application_url , cds . id ) <EOL> cds_url = cls . __get_url ( cds_url_no_dbtype ) <EOL> logger . debug ( "<STR_LIT>" % cds_url ) <EOL> saga . advert . directory ( cds_url , saga . advert . Create | <EOL> saga . advert . CreateParents | <EOL> saga . advert . ReadWrite ) <EOL> return cds_url_no_dbtype <EOL> @ classmethod <EOL> def update_cds ( cls , cds_url , cds ) : <EOL> pds_urls = [ cls . __remove_dbtype ( i . url ) for i in cds . pilot_data_services ] <EOL> cls . __store_entry ( cls . __remove_dbtype ( cds_url ) + "<STR_LIT>" , pds_urls ) <EOL> pjs_urls = [ i . url for i in cds . pilot_job_services ] <EOL> cls . __store_entry ( cls . __remove_dbtype ( cds_url ) + "<STR_LIT>" , pjs_urls ) <EOL> pd_urls = [ i . url for i in cds . data_units . values ( ) ] <EOL> cls . __store_entry ( cls . __remove_dbtype ( cds_url ) + "<STR_LIT>" , pd_urls ) <EOL> wu_urls = [ i . url for i in cds . compute_units . values ( ) ] <EOL> cls . __store_entry ( cls . __remove_dbtype ( cds_url ) + "<STR_LIT>" , wu_urls ) <EOL> @ classmethod <EOL> def delete_cds ( cls , cds_url ) : <EOL> cds_url = cls . __get_url ( cls . __remove_dbtype ( cds_url ) ) <EOL> cds_dir = saga . advert . directory ( saga . url ( cds_url ) , <EOL> saga . advert . Create | <EOL> saga . advert . CreateParents | <EOL> saga . advert . ReadWrite ) <EOL> @ classmethod <EOL> def add_du ( cls , dus_url , du ) : <EOL> du_url = cls . __remove_dbtype ( dus_url ) + "<STR_LIT:/>" + du . id <EOL> du_url = cls . __get_url ( du_url ) <EOL> return du_url <EOL> @ classmethod <EOL> def get_du ( cls , du_url ) : <EOL> logger . debug ( "<STR_LIT>" + du_url ) <EOL> du_dict = { } <EOL> du_dict [ "<STR_LIT>" ] = cls . __retrieve_entry ( cls . __remove_dbtype ( du_url ) + "<STR_LIT>" ) <EOL> du_dict [ "<STR_LIT:state>" ] = cls . __retrieve_entry ( cls . __remove_dbtype ( du_url ) + "<STR_LIT>" ) <EOL> du_dict [ "<STR_LIT>" ] = cls . __retrieve_entry ( cls . __remove_dbtype ( du_url ) + "<STR_LIT>" ) <EOL> du_dict [ "<STR_LIT>" ] = cls . __retrieve_entry ( cls . __remove_dbtype ( du_url ) + "<STR_LIT>" ) <EOL> logger . debug ( "<STR_LIT>" + du_url + "<STR_LIT>" + str ( du_dict ) ) <EOL> return du_dict <EOL> @ classmethod <EOL> def update_du ( cls , du ) : <EOL> logger . debug ( "<STR_LIT>" + du . url ) <EOL> cls . __store_entry ( cls . __remove_dbtype ( du . url ) + "<STR_LIT>" , du . data_unit_description ) <EOL> cls . __store_entry ( cls . __remove_dbtype ( du . url ) + "<STR_LIT>" , du . state ) <EOL> du_urls = [ i . url for i in du . pilot_data ] <EOL> cls . __store_entry ( cls . __remove_dbtype ( du . url ) + "<STR_LIT>" , du_urls ) <EOL> du_dict_list = [ i . to_dict ( ) for i in du . data_unit_items ] <EOL> cls . __store_entry ( cls . __remove_dbtype ( du . url ) + "<STR_LIT>" , du_dict_list ) <EOL> @ classmethod <EOL> def list_du ( cls , dus_url ) : <EOL> """<STR_LIT>""" <EOL> dus_url = cls . __get_url ( dus_url ) <EOL> logger . debug ( "<STR_LIT>" % dus_url ) <EOL> dus_dir = saga . advert . directory ( dus_url , saga . advert . Create | <EOL> saga . advert . CreateParents | <EOL> saga . advert . ReadWrite ) <EOL> du_list = dus_dir . list ( ) <EOL> du_full_urls = [ ] <EOL> for i in du_list : <EOL> du_full_urls . append ( dus_url + "<STR_LIT:/>" + i ) <EOL> return du_full_urls <EOL> @ classmethod <EOL> def delete_du ( cls , du_url ) : <EOL> du_url = cls . __get_url ( du_url ) <EOL> du_dir = saga . advert . directory ( saga . url ( du_url ) , <EOL> saga . advert . Create | <EOL> saga . advert . CreateParents | <EOL> saga . advert . ReadWrite ) <EOL> du_dir . remove ( du_url , saga . name_space . Recursive ) <EOL> @ classmethod <EOL> def get_pds_url ( cls , application_url , pds_id ) : <EOL> pds_url = application_url + AdvertCoordinationAdaptor . PILOT_DATA_SERVICE_PATH + "<STR_LIT:/>" + pds_id <EOL> logger . debug ( "<STR_LIT>" % ( pds_url ) ) <EOL> return pds_url <EOL> @ classmethod <EOL> def get_cds_url ( cls , application_url , cds_id ) : <EOL> cds_url = application_url + AdvertCoordinationAdaptor . COMPUTE_DATA_SERVICE_PATH + "<STR_LIT:/>" + cds_id <EOL> logger . debug ( "<STR_LIT>" % ( cds_url ) ) <EOL> return cds_url <EOL> @ classmethod <EOL> def __get_url ( cls , url ) : <EOL> """<STR_LIT>""" <EOL> url = url + AdvertCoordinationAdaptor . BASE_URL_QUERY_STRING <EOL> return url <EOL> @ classmethod <EOL> def __remove_dbtype ( cls , url ) : <EOL> surl = saga . url ( url ) <EOL> surl . query = "<STR_LIT>" <EOL> return surl . get_string ( ) <EOL> @ classmethod <EOL> def __store_entry ( cls , entry_url , content ) : <EOL> entry_url = cls . __get_url ( entry_url ) <EOL> entry = saga . advert . entry ( saga . url ( entry_url ) , <EOL> saga . advert . Create | <EOL> saga . advert . CreateParents | saga . advert . ReadWrite ) <EOL> entry . store_string ( json . dumps ( content ) ) <EOL> @ classmethod <EOL> def __retrieve_entry ( cls , entry_url ) : <EOL> entry_url = cls . __get_url ( entry_url ) <EOL> entry = saga . advert . entry ( saga . url ( entry_url ) , <EOL> saga . advert . Create | <EOL> saga . advert . CreateParents | saga . advert . ReadWrite ) <EOL> content = json . loads ( entry . retrieve_string ( ) ) <EOL> return content </s>
