def submit(self, service, args, user=None): """ Parse a SOAP query For each request the application description is parsed and arguments are fill with the request elements value. """ self.job = Job(service=Service(service), user=user) self.job.save() fd = open('%s/%s/%s_raw.pick' % (IBISCUS_DATA, ibiscus['cache_dir'], service)) app_desc = load(fd) fd.close() order = ['' for i in range(0, len(app_desc))] for param in app_desc: if param['class'] == 'argument': # Extended parameters if param.get('extend', False): # Add argument to the command if param['extend'] == 'param': args[param['name']] = param['name'] # Create an aditional file elif param['extend'] == 'swap': if param.get('default', False): args[param['name']] = '%s/%s' % (self.job.job_data_dir, self._parse_var(param['default'])) else: # Generate a name if no default value args[param['name']] = '%s/%s' % (self.job.job_data_dir, random_str()) # Reference to a file on the system elif param['extend'] == 'reference': args[param['name']] = '%s/%s%s' % (param['default'], args[param['name']], param.get('extra', '')) # Add absolute paht from the job data directory to the user value elif param['extend'] == 'file': args[param['name']] = '%s/%s' % (self.job.job_data_dir, args[param['name']]) # endif: Extended parameters # Set default value if not args.get(param['name'], True): if param.get('required', True): return self._abort() if param.get('default', ''): args[param['name']] = param['default'] # Save submited attachement if param['type'] == 'attachment': filename = random_str() self.storage.put_contents(self.job.job_id, filename, args[param['name']].data) args[param['name']] = filename # Manage boolean arguments elif param['type'] == 'boolean': # If we just want to set the option to tell is true/false if param.get('prefix', '') and (param.get('extra', '') and param['extra'] == 'present'): if args[param['name']] is True: args[param['name']] = param['prefix'] else: args[param['name']] = '' del param['prefix'] # Check argument value if param.get('check_fct', ''): c = getattr(checking, param['check_fct']) if not c(args.get(param['name'])): return self._abort() # Order the arguments order[param['position']] = '%s%s' % (param.get('prefix', ''), args.get(param['name'])) # Save the file to retrieve if 'retrieve' in param and param['retrieve'] is True: ret = Retrieval(parent_job=self.job, name=param['name'], key=args.get(basename(param['name']))) ret.save() # At the end len(args) should be zero del args[param['name']] # Additional service information if param['class'] == 'info': if param['type'] == 'executable': order.insert(0, param['value']) # The binary is mandatory to run the job # Need to check it here because app desc check can't do this _bin_set = True elif param['type'] == 'retrieval': ret = Retrieval(parent_job=self.job, name=param['name'], key=args.get(basename(param['name']))) ret.save() # Ensure we have all the parameters if len(args) > 1 and _bin_set is not None: return self._abort() else: self.job.command_args=' '.join(cleanlist(order)) self.job.state = 'waiting' self.job.save() return self.job.job_id
class SoapService: def __init__(self): self.storage_manager() def storage_manager(self): p = __import__('ibiscus.storage.%s' % IBISCUS_STORAGE) m = getattr(p, 'storage') c = getattr(m, IBISCUS_STORAGE) self.storage = getattr(c, 'StorageManager')() def _parse_var(self, str): """parse the substitution varibales""" vars = ( ('{JOB_ID}', self.job.job_id), ) for var, value in vars: str = str.replace(var, value) return str def _abort(self): """abort a job""" self.job.state = 'aborted' self.job.save() return 'aborted' def submit(self, service, args, user=None): """ Parse a SOAP query For each request the application description is parsed and arguments are fill with the request elements value. """ self.job = Job(service=Service(service), user=user) self.job.save() fd = open('%s/%s/%s_raw.pick' % (IBISCUS_DATA, ibiscus['cache_dir'], service)) app_desc = load(fd) fd.close() order = ['' for i in range(0, len(app_desc))] for param in app_desc: if param['class'] == 'argument': # Extended parameters if param.get('extend', False): # Add argument to the command if param['extend'] == 'param': args[param['name']] = param['name'] # Create an aditional file elif param['extend'] == 'swap': if param.get('default', False): args[param['name']] = '%s/%s' % (self.job.job_data_dir, self._parse_var(param['default'])) else: # Generate a name if no default value args[param['name']] = '%s/%s' % (self.job.job_data_dir, random_str()) # Reference to a file on the system elif param['extend'] == 'reference': args[param['name']] = '%s/%s%s' % (param['default'], args[param['name']], param.get('extra', '')) # Add absolute paht from the job data directory to the user value elif param['extend'] == 'file': args[param['name']] = '%s/%s' % (self.job.job_data_dir, args[param['name']]) # endif: Extended parameters # Set default value if not args.get(param['name'], True): if param.get('required', True): return self._abort() if param.get('default', ''): args[param['name']] = param['default'] # Save submited attachement if param['type'] == 'attachment': filename = random_str() self.storage.put_contents(self.job.job_id, filename, args[param['name']].data) args[param['name']] = filename # Manage boolean arguments elif param['type'] == 'boolean': # If we just want to set the option to tell is true/false if param.get('prefix', '') and (param.get('extra', '') and param['extra'] == 'present'): if args[param['name']] is True: args[param['name']] = param['prefix'] else: args[param['name']] = '' del param['prefix'] # Check argument value if param.get('check_fct', ''): c = getattr(checking, param['check_fct']) if not c(args.get(param['name'])): return self._abort() # Order the arguments order[param['position']] = '%s%s' % (param.get('prefix', ''), args.get(param['name'])) # Save the file to retrieve if 'retrieve' in param and param['retrieve'] is True: ret = Retrieval(parent_job=self.job, name=param['name'], key=args.get(basename(param['name']))) ret.save() # At the end len(args) should be zero del args[param['name']] # Additional service information if param['class'] == 'info': if param['type'] == 'executable': order.insert(0, param['value']) # The binary is mandatory to run the job # Need to check it here because app desc check can't do this _bin_set = True elif param['type'] == 'retrieval': ret = Retrieval(parent_job=self.job, name=param['name'], key=args.get(basename(param['name']))) ret.save() # Ensure we have all the parameters if len(args) > 1 and _bin_set is not None: return self._abort() else: self.job.command_args=' '.join(cleanlist(order)) self.job.state = 'waiting' self.job.save() return self.job.job_id def cancel(self, job_id): try: cur_job = Job.objects.get(job_id=job_id) cur_state = cur_job.state cur_job.state = JobState.FAILED cur_job.save() return cur_state except: return JobState.UNDETERMINED def check_status(self, job_id): try: cur_job = Job.objects.get(job_id=job_id) return cur_job.state except: return JobState.FAILED def get_results(self, job_id): cur_job = Job.objects.get(job_id=job_id, state=JobState.DONE) files = Retrieval.objects.filter(parent_job=cur_job) attachment = Attachment() for file in files: try: self.storage.get_contents(self.job_id, file.name) # Hack to avoid error if no data if file_data == '': file_data = ' ' except: file_data = ' ' attachment.__setattr__(file.name, Attachment()) attachement_elem = retrieval.__getattribute__(file.name) attachement_elem.data = file_data return attachment