def get_VAMPS_submission_status_row(self, sess_obj): vamps_session = None session_to_use = None mobedac_logger.debug("vamps_status_record_id " + str(self.vamps_status_record_id)) try: if False: # environment == 'test': session_to_use = sess_obj else: session_to_use = vampsSession() result_row = session_to_use.execute( "SELECT status, status_message FROM vamps_upload_status where id=:id", {"id": self.vamps_status_record_id}, ).first() mobedac_logger.debug( "SELECT status, status_message FROM vamps_upload_status where id=:id" + self.vamps_status_record_id + " and result: " + str(result_row) ) return result_row except: mobedac_logger.exception( "submissionORM error retrieving vamps_upload_status with id: " + self.vamps_status_record_id ) raise finally: # if using the vamps db session then close it...the other one will be closed by the request processing thread or whoever if environment == "test": session_to_use.close()
def get_VAMPS_submission_status_row(self, sess_obj): vamps_session = None session_to_use = None mobedac_logger.debug("vamps_status_record_id " + str(self.vamps_status_record_id)) try: if False: #environment == 'test': session_to_use = sess_obj else: session_to_use = vampsSession() result_row = session_to_use.execute( "SELECT status, status_message FROM vamps_upload_status where id=:id", { 'id': self.vamps_status_record_id }).first() mobedac_logger.debug( "SELECT status, status_message FROM vamps_upload_status where id=:id" + self.vamps_status_record_id + " and result: " + str(result_row)) return result_row except: mobedac_logger.exception( "submissionORM error retrieving vamps_upload_status with id: " + self.vamps_status_record_id) raise finally: # if using the vamps db session then close it...the other one will be closed by the request processing thread or whoever if environment == 'test': session_to_use.close()
def stop_the_server(self): try: mobedac_logger.debug("Telling submission processing thread to shutdown...") self.submission_processor_thread.stop_processing() # wait here for the processor to stop self.submission_processor_thread.join(20.0) # did it stop? do we need to to whack it? if self.submission_processor_thread.is_alive(): self.submission_processor_thread.stop_processing() except: mobedac_logger.exception("Got error trying to stop submission processor thread") cherrypy.engine.exit()
def get_current_status(self): status = {} try: # this is more complicated since there is no message on our side so at this point # this web service does not think there is an error...but perhaps VAMPS has run # into an error? if self.next_action == self.ACTION_DOWNLOAD: # we are telling them that VAMPS is doing the retrieval but it is really # this web service that grabs the data and then passes it off to VAMPS msg = "The VAMPS system is still retrieving the data from MoBEDAC." code = self.PROCESSING_STATUS elif self.next_action == self.ACTION_VAMPS_UPLOAD: msg = "The data has been retrieved from MoBEDAC and will soon be uploaded to the VAMPS processor." code = self.PROCESSING_STATUS elif self.next_action == self.ACTION_GAST: # so at this point this WS successfully passed the data off to VAMPS who # is doing the trimming...we need to check with VAMPS vamps_status_row = self.get_VAMPS_submission_status_row(None) # need to get the status value status = vamps_status_row[0] if status == 'TRIM_ERROR': # for now msg = "There was an error during VAMPS upload processing" code = self.ERROR_STATUS elif status == 'TRIM_PROCESSING': # for now msg = "The data is being uploaded and quality checked by the VAMPS system." code = self.PROCESSING_STATUS else: # for now msg = "The data was successfully uploaded and quality checked by VAMPS and is awaiting GAST processing" code = self.PROCESSING_STATUS elif self.next_action == self.ACTION_POST_RESULTS_TO_MOBEDAC: # at this point the WS started up the GAST on VAMPS and so we need to check # with VAMPS to check the VAMPS Gasting status vamps_status_row = self.get_VAMPS_submission_status_row(None) status = vamps_status_row[0] if status == 'GAST_PROCESSING': msg = "The VAMPS system is performing GAST processing." code = self.PROCESSING_STATUS elif status == 'GAST_SUCCESS': msg = "The VAMPS system has successfully completed the GAST processing. And needs to be returned to MoBEDAC" code = self.PROCESSING_STATUS elif status == 'GAST_ERROR': msg = "There was an error during GAST processing" code = self.ERROR_STATUS else: msg = "The VAMPS system is performing GAST processing." code = self.PROCESSING_STATUS elif self.next_action == self.ACTION_PROCESSING_COMPLETE: msg = "Processing is complete and data has been returned to MoBEDAC." code = self.COMPLETE_SUCCESS_STATUS else: # this is kind of an error state? msg = "The submission is in state: " + self.next_action code = 4 except: mobedac_logger.exception( "submissionORM error generating submission status message") msg = "There was an error retrieving the status of this submission" code = self.ERROR_STATUS mobedac_logger.debug("status_code " + str(code) + " current_status " + str(msg)) return {"status_code": code, "current_status": msg}
def get_current_status(self): status = {} try: # this is more complicated since there is no message on our side so at this point # this web service does not think there is an error...but perhaps VAMPS has run # into an error? if self.next_action == self.ACTION_DOWNLOAD: # we are telling them that VAMPS is doing the retrieval but it is really # this web service that grabs the data and then passes it off to VAMPS msg = "The VAMPS system is still retrieving the data from MoBEDAC." code = self.PROCESSING_STATUS elif self.next_action == self.ACTION_VAMPS_UPLOAD: msg = "The data has been retrieved from MoBEDAC and will soon be uploaded to the VAMPS processor." code = self.PROCESSING_STATUS elif self.next_action == self.ACTION_GAST: # so at this point this WS successfully passed the data off to VAMPS who # is doing the trimming...we need to check with VAMPS vamps_status_row = self.get_VAMPS_submission_status_row(None) # need to get the status value status = vamps_status_row[0] if status == "TRIM_ERROR": # for now msg = "There was an error during VAMPS upload processing" code = self.ERROR_STATUS elif status == "TRIM_PROCESSING": # for now msg = "The data is being uploaded and quality checked by the VAMPS system." code = self.PROCESSING_STATUS else: # for now msg = "The data was successfully uploaded and quality checked by VAMPS and is awaiting GAST processing" code = self.PROCESSING_STATUS elif self.next_action == self.ACTION_POST_RESULTS_TO_MOBEDAC: # at this point the WS started up the GAST on VAMPS and so we need to check # with VAMPS to check the VAMPS Gasting status vamps_status_row = self.get_VAMPS_submission_status_row(None) status = vamps_status_row[0] if status == "GAST_PROCESSING": msg = "The VAMPS system is performing GAST processing." code = self.PROCESSING_STATUS elif status == "GAST_SUCCESS": msg = "The VAMPS system has successfully completed the GAST processing. And needs to be returned to MoBEDAC" code = self.PROCESSING_STATUS elif status == "GAST_ERROR": msg = "There was an error during GAST processing" code = self.ERROR_STATUS else: msg = "The VAMPS system is performing GAST processing." code = self.PROCESSING_STATUS elif self.next_action == self.ACTION_PROCESSING_COMPLETE: msg = "Processing is complete and data has been returned to MoBEDAC." code = self.COMPLETE_SUCCESS_STATUS else: # this is kind of an error state? msg = "The submission is in state: " + self.next_action code = 4 except: mobedac_logger.exception("submissionORM error generating submission status message") msg = "There was an error retrieving the status of this submission" code = self.ERROR_STATUS mobedac_logger.debug("status_code " + str(code) + " current_status " + str(msg)) return {"status_code": code, "current_status": msg}
def default(self, *args): cherrypy.response.status = 404 mobedac_logger.debug("Likely got a bad URL with tuple path: /" + "/".join(list(args))) return "Unknown resource /" + "/".join(list(args))
self.submission_processor_thread.stop_processing() except: mobedac_logger.exception("Got error trying to stop submission processor thread") cherrypy.engine.exit() if __name__ == '__main__': import argparse the_root = None try: from initparms import get_parm port = get_parm('port') logicalpath = get_parm('logicalpath') workingfiledir = get_parm('workingfiledir') mobedac_logger.debug("in main of mobedac_server") submission_processor_thread = Submission_Processor(10, get_parm('vamps_data_post_url'), get_parm('vamps_data_gast_url'), workingfiledir) # do we want to not start listening to requests on startup disable_processor_flag = get_parm("processor_disabled_on_startup") if disable_processor_flag != None and disable_processor_flag.lower() == 'true': submission_processor_thread.disable_processing() submission_processor_thread.start() # force cherrypy to use the port WE want cherrypy.config.update({'server.socket_port': int(port),}) the_root = Root(submission_processor_thread) cherrypy.tree.mount(the_root, logicalpath) cherrypy.engine.start() cherrypy.engine.block() # we don't return from this call...cherrypy takes over and starts handling requests the_root.stop_the_server()