def test_annotate(self): ''' Run pa-annotate on a valid Genome object and verify that the job runs and returns a valid ProbAnno object in the expected time.''' # Run the annotate() function to generate a ProbAnno object. paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token) jobid = paClient.annotate({ "genome": self._config["genomeid"], "genome_workspace": self._config["test_ws"], "probanno": self._config["probannoid"], "probanno_workspace": self._config["test_ws"] }) # Allow time for the command to run. time.sleep(float(self._config["runtime"])) # Make sure the job has completed. ujsClient = UserAndJobState(self._config['ujs_url'], token=self._token) jobList = ujsClient.list_jobs([self._config['test_user']], 'CE') jobCompleted = False for job in jobList: if jobid == job[0]: jobCompleted = True jobInfo = job self.assertTrue( jobCompleted, 'Job did not complete before timeout of %s seconds' % (self._config['runtime'])) # See if the job ended in error. details = '' if jobInfo[11] == 1: details = ujsClient.get_detailed_error(jobInfo[0]) self.assertEqual(jobInfo[11], 0, 'Job ended in error: %s' % (details)) # Look for the ProbAnno object in the test workspace. wsClient = Workspace(self._config["workspace_url"], token=self._token) try: probannoObjectId = { 'workspace': self._config['test_ws'], 'name': self._config['probannoid'] } objectList = wsClient.get_objects([probannoObjectId]) probannoObject = objectList[0] self.assertEqual( probannoObject['info'][1], self._config['probannoid'], 'ProbAnno object id %s is not %s' % (probannoObject['info'][1], self._config['probannoid'])) except WorkspaceServerError as e: traceback.print_exc(file=sys.stderr) self.fail( msg= "The expected object %s did not get created in the workspace %s!\n" % (self._config["probannoid"], self._config["test_ws"]))
def test_annotate(self): ''' Run pa-annotate on a valid Genome object and verify that the job runs and returns a valid ProbAnno object in the expected time.''' # Run the annotate() function to generate a ProbAnno object. paClient = ProbabilisticAnnotation(self._config["probanno_url"], token=self._token) jobid = paClient.annotate( { "genome": self._config["genomeid"], "genome_workspace": self._config["test_ws"], "probanno": self._config["probannoid"], "probanno_workspace": self._config["test_ws"] } ) # Allow time for the command to run. time.sleep(float(self._config["runtime"])) # Make sure the job has completed. ujsClient = UserAndJobState(self._config['ujs_url'], token=self._token) jobList = ujsClient.list_jobs([ self._config['test_user'] ], 'CE') jobCompleted = False for job in jobList: if jobid == job[0]: jobCompleted = True jobInfo = job self.assertTrue(jobCompleted, 'Job did not complete before timeout of %s seconds' %(self._config['runtime'])) # See if the job ended in error. details = '' if jobInfo[11] == 1: details = ujsClient.get_detailed_error(jobInfo[0]) self.assertEqual(jobInfo[11], 0, 'Job ended in error: %s' %(details)) # Look for the ProbAnno object in the test workspace. wsClient = Workspace(self._config["workspace_url"], token=self._token) try: probannoObjectId = { 'workspace': self._config['test_ws'], 'name': self._config['probannoid'] } objectList = wsClient.get_objects( [ probannoObjectId ] ) probannoObject = objectList[0] self.assertEqual(probannoObject['info'][1], self._config['probannoid'], 'ProbAnno object id %s is not %s' %(probannoObject['info'][1], self._config['probannoid'])) except WorkspaceServerError as e: traceback.print_exc(file=sys.stderr) self.fail(msg = "The expected object %s did not get created in the workspace %s!\n" %(self._config["probannoid"], self._config["test_ws"]))
class NarrativeJobProxy: ''' Module Name: NarrativeJobProxy Module Description: Very simple proxy that reauthenticates requests to the user_and_job_state service as the narrative user. DO NOT DEPLOY PUBLICALLY ''' ######## WARNING FOR GEVENT USERS ####### # Since asynchronous IO can lead to methods - even the same method - # interrupting each other, you must be *very* careful when using global # state. A method could easily clobber the state set by another while # the latter method is running. ######################################### #BEGIN_CLASS_HEADER UPDATE_TOKEN_INTERVAL = 24 * 60 * 60 # 1 day in sec # UPDATE_TOKEN_INTERVAL = 10 def _update_token(self): if self._updating: return if (time.time() - self._updated_at < self.UPDATE_TOKEN_INTERVAL): return self._updating = True print('Updating token at ' + str(time.time())) try: self._ujs = UserAndJobState(self._url, user_id=self._user, password=self._pwd) self._updated_at = time.time() finally: # otherwise token will never be updated self._updating = False #END_CLASS_HEADER # config contains contents of config file in a hash or None if it couldn't # be found def __init__(self, config): #BEGIN_CONSTRUCTOR self._user = config.get('narrative_user') self._pwd = config.get('narrative_user_pwd') if not self._user or not self._pwd: raise ValueError( 'narrative user and/or narrative pwd missing from deploy.cfg') self._url = config.get('ujs_url') if not self._url: raise ValueError('UJS url missing from deploy.cfg') self._updated_at = - self.UPDATE_TOKEN_INTERVAL self._updating = False self._update_token() #END_CONSTRUCTOR pass def ver(self, ctx): # ctx is the context object # return variables are: ver #BEGIN ver ver = '0.0.1' #END ver # At some point might do deeper type checking... if not isinstance(ver, basestring): raise ValueError('Method ver return value ' + 'ver is not type basestring as required.') # return the results return [ver] def get_detailed_error(self, ctx, job): # ctx is the context object # return variables are: error #BEGIN get_detailed_error self._update_token() error = self._ujs.get_detailed_error(job) #END get_detailed_error # At some point might do deeper type checking... if not isinstance(error, basestring): raise ValueError('Method get_detailed_error return value ' + 'error is not type basestring as required.') # return the results return [error] def get_job_info(self, ctx, job): # ctx is the context object # return variables are: info #BEGIN get_job_info self._update_token() info = self._ujs.get_job_info(job) #END get_job_info # At some point might do deeper type checking... if not isinstance(info, list): raise ValueError('Method get_job_info return value ' + 'info is not type list as required.') # return the results return [info]
class NarrativeJobProxy: ''' Module Name: NarrativeJobProxy Module Description: Very simple proxy that reauthenticates requests to the user_and_job_state service as the narrative user. DO NOT DEPLOY PUBLICALLY ''' ######## WARNING FOR GEVENT USERS ####### # Since asynchronous IO can lead to methods - even the same method - # interrupting each other, you must be *very* careful when using global # state. A method could easily clobber the state set by another while # the latter method is running. ######################################### #BEGIN_CLASS_HEADER UPDATE_TOKEN_INTERVAL = 24 * 60 * 60 # 1 day in sec # UPDATE_TOKEN_INTERVAL = 10 def _update_token(self): if self._updating: return if (time.time() - self._updated_at < self.UPDATE_TOKEN_INTERVAL): return self._updating = True print('Updating token at ' + str(time.time())) try: self._ujs = UserAndJobState(self._url, user_id=self._user, password=self._pwd) self._updated_at = time.time() finally: # otherwise token will never be updated self._updating = False #END_CLASS_HEADER # config contains contents of config file in a hash or None if it couldn't # be found def __init__(self, config): #BEGIN_CONSTRUCTOR self._user = config.get('narrative_user') self._pwd = config.get('narrative_user_pwd') if not self._user or not self._pwd: raise ValueError( 'narrative user and/or narrative pwd missing from deploy.cfg') self._url = config.get('ujs_url') if not self._url: raise ValueError('UJS url missing from deploy.cfg') self._updated_at = -self.UPDATE_TOKEN_INTERVAL self._updating = False self._update_token() #END_CONSTRUCTOR pass def ver(self, ctx): # ctx is the context object # return variables are: ver #BEGIN ver ver = '0.0.1' #END ver # At some point might do deeper type checking... if not isinstance(ver, basestring): raise ValueError('Method ver return value ' + 'ver is not type basestring as required.') # return the results return [ver] def get_detailed_error(self, ctx, job): # ctx is the context object # return variables are: error #BEGIN get_detailed_error self._update_token() error = self._ujs.get_detailed_error(job) #END get_detailed_error # At some point might do deeper type checking... if not isinstance(error, basestring): raise ValueError('Method get_detailed_error return value ' + 'error is not type basestring as required.') # return the results return [error] def get_job_info(self, ctx, job): # ctx is the context object # return variables are: info #BEGIN get_job_info self._update_token() info = self._ujs.get_job_info(job) #END get_job_info # At some point might do deeper type checking... if not isinstance(info, list): raise ValueError('Method get_job_info return value ' + 'info is not type list as required.') # return the results return [info]
args = parser.parse_args() # Get the status of the specified job. ujsClient = UserAndJobState(args.ujsURL) try: info = job_info_dict(ujsClient.get_job_info(args.jobID)) except JobStateServerError as e: print e.message exit(1) # Check if the job had an error. if info['error']: print "Job '%s' ended with error '%s' and no results are available." % ( args.jobID, info['status']) print 'Error details:' print ujsClient.get_detailed_error(args.jobID) ujsClient.delete_job(args.jobID) exit(1) # Check if the job is complete. if not info['complete']: print "Job '%s' has status '%s' and is working on task %s of %s. Check again later." \ %(args.jobID, info['status'], info['total_progress'], info['max_progress']) exit(1) # Show job info. if args.showTimes: print 'Job started at %s and finished at %s' % (info['started'], info['last_update']) # Create a shock client.
parser.usage = argparse.SUPPRESS args = parser.parse_args() # Get the status of the specified job. ujsClient = UserAndJobState(args.ujsURL) try: info = job_info_dict(ujsClient.get_job_info(args.jobID)) except JobStateServerError as e: print e.message exit(1) # Check if the job had an error. if info['error']: print "Job '%s' ended with error '%s' and no results are available." %(args.jobID, info['status']) print 'Error details:' print ujsClient.get_detailed_error(args.jobID) ujsClient.delete_job(args.jobID) exit(1) # Check if the job is complete. if not info['complete']: print "Job '%s' has status '%s' and is working on task %s of %s. Check again later." \ %(args.jobID, info['status'], info['total_progress'], info['max_progress']) exit(1) # Show job info. if args.showTimes: print 'Job started at %s and finished at %s' %(info['started'], info['last_update']) # Create a shock client. shockClient = ShockClient(info['results']['shockurl'], ujsClient._headers['AUTHORIZATION'])