def test_broken_connection(): remote = ddaclient.RemoteDDA("http://127.0.1.1:1", "") with pytest.raises(requests.ConnectionError): product = remote.query( target="ii_spectra_extract", modules=["ddosa", "git://ddosadm"], assume=[ scwsource_module + '.ScWData(input_scwid="035200230010.001")', 'ddosa.ImageBins(use_ebins=[(20,40)],use_version="onebin_20_40")', 'ddosa.ImagingConfig(use_SouFit=0,use_version="soufit0")' ])
def test_has_input_products(self, instrument, logger=None): print('--> start has input_products') RA = instrument.get_par_by_name('RA').value DEC = instrument.get_par_by_name('DEC').value radius = instrument.get_par_by_name('radius').value scw_list = instrument.get_par_by_name('scw_list').value use_max_pointings = instrument.get_par_by_name('max_pointings').value osa_version = instrument.get_par_by_name('osa_version').value query_out = QueryOutput() message = '' debug_message = '' has_input_products_message = '' prod_list = [] if scw_list is not None and scw_list != []: prod_list = scw_list else: T1_iso = instrument.get_par_by_name('T1')._astropy_time.isot T2_iso = instrument.get_par_by_name('T2')._astropy_time.isot print('input', RA, DEC, T1_iso, T2_iso) if self._test_products_with_astroquery: # note that this just might introduce discrepancy, since it is not the exact workflow used by the backend from astroquery.heasarc import Heasarc import astroquery heasarc = Heasarc() with astroquery.heasarc.Conf.server.set_temp( 'https://www.isdc.unige.ch/browse/w3query.pl'): T_i = heasarc.query_region( SkyCoord(RA, DEC, unit="deg"), mission='integral_rev3_scw', resultmax=1000000, # all ppo radius="200 deg", cache=False, time=T1_iso.replace("T", " ") + " .. " + T2_iso.replace("T", " "), fields='All') else: target = "ReportScWList" modules = ['git://rangequery/staging-1-3'] scwlist_assumption = OsaDispatcher.get_scwlist_assumption( None, T1_iso, T2_iso, RA, DEC, radius, use_max_pointings) assume = [ "rangequery.ReportScWList(input_scwlist=%s)" % scwlist_assumption[0], scwlist_assumption[1] ] remote = dc.RemoteDDA(self.data_server_url, self.data_server_cache) try: product = remote.query(target=target, modules=modules, assume=assume, sync=True) #DONE query_out.set_done(message=message, debug_message=str(debug_message)) prod_list = getattr(product, 'scwidlist', None) if prod_list is None: raise RuntimeError(f"product.prod_list is None") if len(prod_list) < 1: run_query_message = 'scwlist empty' debug_message = '' query_out.set_failed('test has input prods', message=run_query_message, logger=logger, job_status='failed', e_message=run_query_message, debug_message='') raise DDAException(message='scwlist empty', debug_message='') except dc.WorkerException as e: run_query_message = 'WorkerException' debug_message = self.get_exceptions_message(e) # FAILED query_out.set_failed('test has input prods', message='has input_products=%s' % run_query_message, logger=logger, excep=e, job_status='failed', e_message=run_query_message, debug_message=debug_message) raise DDAException('WorkerException', debug_message) except dc.AnalysisException as e: run_query_message = 'AnalysisException' debug_message = self.get_exceptions_message(e) query_out.set_failed('test has input prods', message='run query message=%s' % run_query_message, logger=logger, excep=e, job_status='failed', e_message=run_query_message, debug_message=debug_message) raise DDAException(message=run_query_message, debug_message=debug_message) except Exception as e: run_query_message = 'DDAUnknownException in test has input prods: ' + repr( e) query_out.set_failed('test has input prods ', message='run query message=%s' % run_query_message, logger=logger, excep=e, job_status='failed', e_message=run_query_message, debug_message='') raise DDAUnknownException() return query_out, prod_list
def run_query(self, call_back_url, run_asynch=True, logger=None, target=None, modules=None, assume=None): print(self, "run_query", call_back_url, target, modules, assume) if target is None: target = self.target if modules is None: modules = self.modules if assume is None: assume = self.assume res = None #status = 0 message = '' debug_message = '' backend_comment = '' backend_warning = '' query_out = QueryOutput() try: logger.setLevel(logging.ERROR) print('--osa disp--') print('call_back_url', call_back_url) print('*** run_asynch', run_asynch) res = dc.RemoteDDA(self.data_server_url, self.data_server_cache).query( target=target, modules=modules, assume=assume, inject=self.inject, prompt_delegate=run_asynch, callback=call_back_url) backend_comment, backend_warning = self.get_comments(res) print('--> url for call_back', call_back_url) print("--> cached object in", res, res.ddcache_root_local) #DONE query_out.set_done(message=message, debug_message=str(debug_message), job_status='done', comment=backend_comment, warning=backend_warning) #job.set_done() except dc.AnalysisException as e: run_query_message = 'AnalysisException' debug_message = self.get_exceptions_message(e) # we have to add the exception to the message try: my_dict = literal_eval(debug_message) except: my_dict = debug_message if 'exception' in debug_message: print('debug_message', type(debug_message), debug_message) #print(my_dict) if hasattr(my_dict, 'keys'): if 'exception' in my_dict.keys(): run_query_message = run_query_message + ':%s' % my_dict[ 'exception'] elif 'exception' in str(my_dict): run_query_message = run_query_message + ':%s' % str( my_dict) query_out.set_failed('run query ', message='run query message=%s' % run_query_message, logger=logger, excep=e, job_status='failed', e_message=run_query_message, debug_message=debug_message) raise DDAException(message=run_query_message, debug_message=debug_message) except dc.WorkerException as e: run_query_message = 'WorkerException' debug_message = self.get_exceptions_message(e) #FAILED query_out.set_failed('run query ', message='run query message=%s' % run_query_message, logger=logger, excep=e, job_status='failed', e_message=run_query_message, debug_message=debug_message) raise DDAException(message=run_query_message, debug_message=debug_message) except dc.AnalysisDelegatedException as e: # DONE DELEGATION backend_comment, backend_warning = self.get_comments(res) query_out.set_done(message=message, debug_message=str(debug_message), job_status='submitted', comment=backend_comment, warning=backend_warning) except Exception as e: run_query_message = 'DDAUnknownException in run_query: ' + repr(e) query_out.set_failed('run query ', message='run query message=%s' % run_query_message, logger=logger, excep=e, job_status='failed', e_message=run_query_message, debug_message='') raise DDAUnknownException(message=run_query_message) return res, query_out
def test_communication(self, max_trial=120, sleep_s=1, logger=None): print('--> start test connection to', self.data_server_url) remote = dc.RemoteDDA(self.data_server_url, self.data_server_cache) query_out = QueryOutput() message = '' debug_message = '' connection_status_message = '' busy_exception = False time.sleep(sleep_s) for i in range(max_trial): time.sleep(sleep_s) try: r = remote.poke() print('remote poke ok at trial', i) #DONE query_out.set_done(message=message, debug_message=str(debug_message)) busy_exception = False connection_status_message = 'OK' break except dc.WorkerException as e: connection_status_message = self.get_exception_status_message( e) query_out.set_query_exception(e, 'test connection', message='connection_status=%s' % connection_status_message, logger=logger) busy_exception = True print('remote poke not ok, trial', i, connection_status_message) except Exception as e: connection_status_message = self.get_exception_status_message( e) query_out.set_query_exception(e, 'test connection', message='connection_status=%s' % connection_status_message, logger=logger) busy_exception = True print('remote poke not ok, trial', i, connection_status_message) if busy_exception == True: try: r = remote.poke() except Exception as e: connection_status_message = self.get_exception_status_message( e) # FAILED #query_out.set_failed('test connection', # message='connection_status=%s' % connection_status_message, # logger=logger, # excep=e) run_query_message = 'Connection Error' debug_message = self.get_exceptions_message(e) # FAILED query_out.set_failed('test connection', message='connection_status=%s' % connection_status_message, logger=logger, excep=e, e_message=run_query_message, debug_message=debug_message) raise DDAException('Connection Error', debug_message) if connection_status_message == 'busy' or busy_exception == True: print('server is busy') # FAILED #query_out.set_failed('test busy', # message='connection_status=%s'%connection_status_message, # logger=logger, # excep=e) query_out.set_failed('test busy', message='connection_status=%s' % connection_status_message, logger=logger, excep=e, e_message='data server busy', debug_message='data server busy') raise DDAException('Connection Error', debug_message) print('--> end test busy') return query_out