From 172d83b94e6196933cce72282e1918fc0b862487 Mon Sep 17 00:00:00 2001 From: zagganas Date: Tue, 3 May 2022 09:25:24 +0000 Subject: [PATCH] Fixed upload when inputs is a list --- models/SoftwareUpload.php | 7 +- scheduler_files/imageUploader.py | 8 +- scheduler_files/uploadFunctions.py | 145 ++++++++++++++++++++++++++++- 3 files changed, 157 insertions(+), 3 deletions(-) diff --git a/models/SoftwareUpload.php b/models/SoftwareUpload.php index 79e8ca8..dc07c75 100644 --- a/models/SoftwareUpload.php +++ b/models/SoftwareUpload.php @@ -191,7 +191,7 @@ public function upload() $command=Software::sudoWrap(Yii::$app->params['scriptsFolder'] . "imageUploader.py "); $command.= implode(" ", $arguments) . " "; $command.= "2>&1"; - + Software::exec_log($command,$out,$ret); $errors=''; @@ -325,6 +325,11 @@ public function upload() $errors.="One of the inputs does has an unknown type."; $errors.="
Please correct the file syntax and try again or contact an administrator."; break; + case 100: + $errors.="Error: code $ret. "; + $errors.="Your CWL definition has a format not recognized by the system"; + $errors.="
Please contact an administrator to fix the issue."; + break; default: $errors.="Error: code $ret. "; $errors.="
An unexpected error occurred."; diff --git a/scheduler_files/imageUploader.py b/scheduler_files/imageUploader.py index cb027be..402ed6d 100755 --- a/scheduler_files/imageUploader.py +++ b/scheduler_files/imageUploader.py @@ -166,6 +166,12 @@ def quoteEnclose(string): if 'inputs' not in cwlContent: cwlContent['inputs']=[]; -exit_value=uf.inputStore(softName,softVersion, cwlContent['inputs']) +if isinstance(cwlContent['inputs'],dict): + exit_value=uf.inputStoreDict(softName,softVersion, cwlContent['inputs']) +elif isinstance(cwlContent['inputs'],list): + exit_value=uf.inputStoreList(softName,softVersion, cwlContent['inputs']) +else: + exit_value=100 + exit(exit_value) diff --git a/scheduler_files/uploadFunctions.py b/scheduler_files/uploadFunctions.py index be2899a..d2984cb 100755 --- a/scheduler_files/uploadFunctions.py +++ b/scheduler_files/uploadFunctions.py @@ -139,7 +139,7 @@ def cwlReturnDockerImage(content): else: exit(23) -def inputStore(softName,softVersion, inputs): +def inputStoreDict(softName,softVersion, inputs): types=set(['string', 'int', 'long', 'float', 'double', 'null', 'File', 'Directory', 'Any','boolean']) #open db connection and get image id @@ -278,6 +278,149 @@ def inputStore(softName,softVersion, inputs): return 0 +def inputStoreList(softName,softVersion, inputs): + types=set(['string', 'int', 'long', 'float', 'double', 'null', 'File', 'Directory', 'Any','boolean']) + + #open db connection and get image id + conn=psg.connect(host=host, user=dbuser, password=passwd, dbname=dbname) + cur=conn.cursor() + + query="SELECT id FROM software WHERE name='" + softName + "' AND version='" + softVersion + "'" + cur.execute(query) + result=cur.fetchall() + softId=str(result[0][0]) + + #save script in database and get its id + # print(inputs) + if len(inputs)==0: + exit(30) + + #create queries for input insertion + query='INSERT INTO software_inputs(name, position, softwareid, field_type, prefix, separate, optional, default_value, is_array, array_separator, nested_array_binding) VALUES ' + + bindingFlag=False + positionFlag=False + separateInner=False + prefixInner=False + + + for inpt in inputs: + try: + inpt_name=inpt['id'] + except: + deleteSavedSoftware(softName,softVersion) + return 100 + is_array='f' + array_separator='' + nested_array_binding='f' + prefix='' + separate='t' + if 'type' not in inpt.keys(): + #stop execution and return because this is serious + deleteSavedSoftware(softName,softVersion) + return 34 + fieldType=inpt['type'] + #field type is array + if isinstance(fieldType,dict): + if fieldType['type']!='array': + deleteSavedSoftware(softName,softVersion) + return 36 + is_array='t' + if 'inputBinding' in fieldType: + nested_array_binding='t' + innerBinding=fieldType['inputBinding'] + if 'separate' in binding: + separateInner=True + if innerBinding['separate']==False: + separate='f' + if 'prefix' in binding: + prefixInner=True + prefix=innerBinding['prefix'] + if 'items' not in fieldType: + deleteSavedSoftware(softName,softVersion) + return 37 + + fieldType=fieldType['items'] + + else: + fieldType=inpt['type'].strip() + + + if 'inputBinding' not in inpt.keys(): + bindingFlag=True + continue + #exit(32) + + + outerBinding=inpt['inputBinding'] + # Get position, separate and prefix from inputBinding. + # If it does not exist, ignore input + if 'position' not in outerBinding: + positionFlat=True + continue + position=outerBinding['position'] + + if ('separate' in outerBinding) and (separateInner==False): + if outerBinding['separate']=='false': + separate='f' + else: + separate='t' + + if ('prefix' in outerBinding) and (prefixInner==False): + prefix=outerBinding['prefix'] + if ('itemSeparator' in outerBinding): + array_separator=outerBinding['itemSeparator'] + + # print(separate) + + optional='f' + if fieldType[-1]=='?': + optional='t' + fieldType=fieldType[:-1] + + if '[]' in fieldType: + is_array='t' + fieldType=fieldType[:-2] + + if fieldType not in types: + #stop execution and return because this is serious + deleteSavedSoftware(softName,softVersion) + print("Field type: %s not in Types %s" % (fieldType,types)) + return 35 + + + #get default value + defaultValue='' + if (fieldType!='File') and (fieldType!='Directory') and (fieldType!='null'): + if 'default' in inpt.keys(): + defaultValue=str(inpt['default']) + + name=quoteEnclose(inpt_name) + fieldType=quoteEnclose(fieldType) + prefix=quoteEnclose(prefix) + defaultValue=quoteEnclose(defaultValue) + optional=quoteEnclose(optional) + separate=quoteEnclose(separate) + is_array=quoteEnclose(is_array) + array_separator=quoteEnclose(array_separator) + nested_array_binding=quoteEnclose(nested_array_binding) + + query+='(' + name + ',' + str(position) + ',' + str(softId) + ',' + fieldType + ',' + prefix + ',' + separate + ',' + optional + ',' + defaultValue + ',' + is_array+ ',' + array_separator + ',' + nested_array_binding + '),' + + query=query[:-1] + # print(query) + cur.execute(query) + conn.commit() + + conn.close() + + if bindingFlag: + return 32 + if positionFlag: + return 33 + + return 0 + def imageStore(name,version,image,script,user,visibility, workingDir,imountPoint,omountPoint, description,cwlPath,biotools,doiFile,mpi,original,docker_or_local,covid19,instructions,gpu):