[822] | 1 | /* |
---|
| 2 | * Author : Gérald FENOY |
---|
| 3 | * |
---|
[839] | 4 | * Copyright (c) 2017 GeoLabs SARL |
---|
[822] | 5 | * |
---|
[839] | 6 | * This work was supported by public funds received in the framework of GEOSUD, |
---|
| 7 | * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed |
---|
| 8 | * by the French National Research Agency |
---|
| 9 | * |
---|
[822] | 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 11 | * of this software and associated documentation files (the "Software"), to deal |
---|
| 12 | * in the Software without restriction, including without limitation the rights |
---|
| 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 14 | * copies of the Software, and to permit persons to whom the Software is |
---|
| 15 | * furnished to do so, subject to the following conditions: |
---|
| 16 | * |
---|
| 17 | * The above copyright notice and this permission notice shall be included in |
---|
| 18 | * all copies or substantial portions of the Software. |
---|
| 19 | * |
---|
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 26 | * THE SOFTWARE. |
---|
| 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #include "service_internal_hpc.h" |
---|
| 31 | #include "response_print.h" |
---|
| 32 | #include "server_internal.h" |
---|
[839] | 33 | #include "service_callback.h" |
---|
| 34 | #include "mimetypes.h" |
---|
[822] | 35 | #include <sys/un.h> |
---|
[899] | 36 | #include "cgic.h" |
---|
[822] | 37 | |
---|
[839] | 38 | typedef struct { |
---|
| 39 | maps* conf; |
---|
| 40 | char* local_file; |
---|
| 41 | char* target_file; |
---|
| 42 | } local_params; |
---|
| 43 | |
---|
[846] | 44 | /** |
---|
| 45 | * Add nested outputs to every outputs that is geographic format |
---|
| 46 | * @see isGeographic |
---|
| 47 | * @param s the service current definition |
---|
| 48 | */ |
---|
[839] | 49 | void addNestedOutputs(service** s){ |
---|
| 50 | if((*s)==NULL){ |
---|
| 51 | return; |
---|
| 52 | } |
---|
[877] | 53 | if(*s==NULL || (*s)->outputs==NULL || (*s)->content==NULL){ |
---|
[839] | 54 | return; |
---|
[822] | 55 | } |
---|
[839] | 56 | elements *out=(*s)->outputs; |
---|
| 57 | elements* cur=out; |
---|
| 58 | map* serviceType=getMap((*s)->content,"ServiceType"); |
---|
| 59 | if(strncmp(serviceType->value,"HPC",3)!=0) |
---|
| 60 | return; |
---|
| 61 | while(cur!=NULL && cur->defaults!=NULL){ |
---|
| 62 | map* mimeType=getMap(cur->defaults->content,"mimeType"); |
---|
[862] | 63 | map* useMS=getMap(cur->defaults->content,"useMapserver"); |
---|
| 64 | if(mimeType!=NULL && useMS!=NULL && strncasecmp(useMS->value,"true",4)==0){ |
---|
[839] | 65 | int geo=isGeographic(mimeType->value); |
---|
| 66 | if(geo>0){ |
---|
| 67 | elements *tmp[3]={ |
---|
| 68 | dupElements(cur), |
---|
| 69 | dupElements(cur), |
---|
| 70 | dupElements(cur) |
---|
| 71 | }; |
---|
| 72 | char *geoLink="wcs_link"; |
---|
| 73 | if(geo==2){ |
---|
| 74 | geoLink="wfs_link"; |
---|
| 75 | } |
---|
| 76 | int i=0; |
---|
| 77 | for(;i<3;i++){ |
---|
| 78 | if(tmp[i]->next!=NULL){ |
---|
| 79 | freeElements(&tmp[i]->next); |
---|
| 80 | free(tmp[i]->next); |
---|
| 81 | tmp[i]->next=NULL; |
---|
| 82 | } |
---|
| 83 | free(tmp[i]->name); |
---|
[850] | 84 | if(tmp[i]->format!=NULL) |
---|
| 85 | free(tmp[i]->format); |
---|
[839] | 86 | tmp[i]->format=zStrdup("ComplexData"); |
---|
| 87 | freeMap(&tmp[i]->content); |
---|
| 88 | free(tmp[i]->content); |
---|
| 89 | tmp[i]->content=NULL; |
---|
| 90 | switch(i){ |
---|
| 91 | case 0: |
---|
| 92 | tmp[i]->name=zStrdup("download_link"); |
---|
| 93 | tmp[i]->content=createMap("Title",_("Download link")); |
---|
| 94 | addToMap(tmp[i]->content,"Abstract",_("The download link")); |
---|
| 95 | addToMap(tmp[i]->defaults->content,"useMapserver","false"); |
---|
| 96 | if(tmp[i]->supported!=NULL){ |
---|
| 97 | freeIOType(&tmp[i]->supported); |
---|
| 98 | free(tmp[i]->supported); |
---|
| 99 | tmp[i]->supported=NULL; |
---|
| 100 | } |
---|
| 101 | break; |
---|
| 102 | case 1: |
---|
| 103 | tmp[i]->name=zStrdup("wms_link"); |
---|
| 104 | tmp[i]->content=createMap("Title",_("WMS link")); |
---|
| 105 | addToMap(tmp[i]->content,"Abstract",_("The WMS link")); |
---|
| 106 | if(tmp[i]->supported!=NULL && tmp[i]->supported->next!=NULL){ |
---|
| 107 | freeIOType(&tmp[i]->supported->next); |
---|
| 108 | free(tmp[i]->supported->next); |
---|
| 109 | tmp[i]->supported->next=NULL; |
---|
| 110 | }else{ |
---|
| 111 | if(tmp[i]->supported!=NULL) |
---|
| 112 | addToMap(tmp[i]->supported->content,"useMapserver","true"); |
---|
| 113 | addToMap(tmp[i]->defaults->content,"useMapserver","true"); |
---|
| 114 | } |
---|
| 115 | break; |
---|
| 116 | case 2: |
---|
| 117 | if(geo==2){ |
---|
| 118 | tmp[i]->name=zStrdup("wfs_link"); |
---|
| 119 | tmp[i]->content=createMap("Title",_("WFS link")); |
---|
| 120 | addToMap(tmp[i]->content,"Abstract",_("The WFS link")); |
---|
| 121 | }else{ |
---|
| 122 | tmp[i]->name=zStrdup("wcs_link"); |
---|
| 123 | tmp[i]->content=createMap("Title",_("WCS link")); |
---|
| 124 | addToMap(tmp[i]->content,"Abstract",_("The WCS link")); |
---|
| 125 | } |
---|
| 126 | if(tmp[i]->supported!=NULL && tmp[i]->supported->next!=NULL && |
---|
| 127 | tmp[i]->supported->next->content!=NULL){ |
---|
| 128 | freeIOType(&tmp[i]->supported); |
---|
| 129 | free(tmp[i]->supported); |
---|
| 130 | tmp[i]->supported=NULL; |
---|
| 131 | tmp[i]->supported=createIoType(); |
---|
| 132 | iotype* cnext=cur->supported->next; |
---|
| 133 | tmp[i]->supported->content=createMap(cnext->content->name,cnext->content->value); |
---|
| 134 | addMapToMap(&tmp[i]->supported->content,cnext->content->next); |
---|
| 135 | addToMap(tmp[i]->supported->content,"useMapserver","true"); |
---|
| 136 | }else |
---|
| 137 | addToMap(tmp[i]->defaults->content,"useMapserver","true"); |
---|
| 138 | break; |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | addToElements(&cur->child,tmp[0]); |
---|
| 142 | addToElements(&cur->child,tmp[1]); |
---|
| 143 | addToElements(&cur->child,tmp[2]); |
---|
| 144 | free(cur->format); |
---|
| 145 | cur->format=NULL; |
---|
| 146 | if(cur->defaults!=NULL){ |
---|
| 147 | freeIOType(&cur->defaults); |
---|
[854] | 148 | free(cur->defaults); |
---|
[839] | 149 | cur->defaults=NULL; |
---|
| 150 | } |
---|
| 151 | if(cur->supported!=NULL){ |
---|
| 152 | freeIOType(&cur->supported); |
---|
[854] | 153 | free(cur->supported); |
---|
[839] | 154 | cur->supported=NULL; |
---|
| 155 | } |
---|
| 156 | freeElements(&tmp[2]); |
---|
| 157 | free(tmp[2]); |
---|
| 158 | freeElements(&tmp[1]); |
---|
| 159 | free(tmp[1]); |
---|
| 160 | freeElements(&tmp[0]); |
---|
| 161 | free(tmp[0]); |
---|
| 162 | //addToMap(cur->content,"internal","true"); |
---|
[862] | 163 | } |
---|
[894] | 164 | }else{ |
---|
| 165 | if(mimeType!=NULL){ |
---|
[895] | 166 | elements *tmp=dupElements(cur); |
---|
| 167 | tmp->name=zStrdup("download_link"); |
---|
| 168 | tmp->content=createMap("Title",_("Download link")); |
---|
| 169 | addToMap(tmp->content,"Abstract",_("The download link")); |
---|
| 170 | addToMap(tmp->defaults->content,"useMapserver","false"); |
---|
| 171 | if(tmp->supported!=NULL){ |
---|
| 172 | freeIOType(&tmp->supported); |
---|
| 173 | free(tmp->supported); |
---|
| 174 | tmp->supported=NULL; |
---|
| 175 | } |
---|
| 176 | addToElements(&cur->child,tmp); |
---|
| 177 | free(cur->format); |
---|
| 178 | cur->format=NULL; |
---|
| 179 | if(cur->defaults!=NULL){ |
---|
| 180 | freeIOType(&cur->defaults); |
---|
| 181 | free(cur->defaults); |
---|
| 182 | cur->defaults=NULL; |
---|
| 183 | } |
---|
| 184 | if(cur->supported!=NULL){ |
---|
| 185 | freeIOType(&cur->supported); |
---|
| 186 | free(cur->supported); |
---|
| 187 | cur->supported=NULL; |
---|
| 188 | } |
---|
| 189 | freeElements(&tmp); |
---|
| 190 | free(tmp); |
---|
[894] | 191 | } |
---|
[839] | 192 | } |
---|
| 193 | cur=cur->next; |
---|
| 194 | } |
---|
[850] | 195 | //dumpElements((*s)->outputs); |
---|
[822] | 196 | } |
---|
| 197 | |
---|
| 198 | /** |
---|
[854] | 199 | * Acquire a read lock on every files used as input for executing a service. |
---|
| 200 | * @param conf the main configuration file map |
---|
| 201 | * @return 0 if every file can be locked, -1 if one lock has failed. |
---|
| 202 | */ |
---|
| 203 | int addReadLocks(maps** conf){ |
---|
| 204 | map* queueLengthMap=getMapFromMaps(*conf,"uploadQueue","length"); |
---|
| 205 | maps* queueMaps=getMaps(*conf,"uploadQueue"); |
---|
| 206 | if(queueLengthMap!=NULL){ |
---|
| 207 | int cnt=atoi(queueLengthMap->value); |
---|
| 208 | int i=0; |
---|
| 209 | for(i=0;i<cnt;i++){ |
---|
| 210 | map* argv[2]={ |
---|
| 211 | getMapArray(queueMaps->content,"input",i), |
---|
| 212 | getMapArray(queueMaps->content,"localPath",i) |
---|
| 213 | }; |
---|
| 214 | zooLock* lck; |
---|
| 215 | if((lck=lockFile(*conf,argv[1]->value,'r'))==NULL){ |
---|
| 216 | char* templateStr=_("Unable to lock the file for %s in read mode."); |
---|
| 217 | char *tmpMessage=(char*)malloc((strlen(templateStr)+strlen(argv[0]->value)+1)*sizeof(char)); |
---|
| 218 | sprintf(tmpMessage,templateStr,argv[0]->value); |
---|
| 219 | setMapInMaps(*conf,"lenv","message",tmpMessage); |
---|
| 220 | free(tmpMessage); |
---|
| 221 | return -1; |
---|
| 222 | }else{ |
---|
| 223 | if(zoo_file_locks_cnt==0){ |
---|
| 224 | zoo_file_locks=(zooLock**)malloc(sizeof(zooLock*)); |
---|
| 225 | } |
---|
| 226 | else{ |
---|
| 227 | zoo_file_locks=(zooLock**)realloc(zoo_file_locks,(zoo_file_locks_cnt+1)*sizeof(zooLock*)); |
---|
| 228 | } |
---|
| 229 | zoo_file_locks[zoo_file_locks_cnt]=lck; |
---|
| 230 | zoo_file_locks_cnt++; |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | } |
---|
| 234 | return 0; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | /** |
---|
| 238 | * Remove all read locks set for files used as input for executing the service. |
---|
| 239 | * @param conf the main configuration maps pointer |
---|
| 240 | * @return 0 in case of success, -1 if any error occured. In case of error, one |
---|
| 241 | * can refer to the message map array from the lenv section. |
---|
| 242 | */ |
---|
| 243 | int removeReadLocks(maps** conf){ |
---|
| 244 | int res=0; |
---|
| 245 | int nberr=0; |
---|
| 246 | map* queueLengthMap=getMapFromMaps(*conf,"uploadQueue","length"); |
---|
| 247 | maps* queueMaps=getMaps(*conf,"uploadQueue"); |
---|
| 248 | if(queueLengthMap!=NULL){ |
---|
| 249 | int cnt=atoi(queueLengthMap->value); |
---|
| 250 | int i=0; |
---|
| 251 | for(i=0;i<cnt;i++){ |
---|
| 252 | if(unlockFile(*conf,zoo_file_locks[i])<1){ |
---|
| 253 | map* argv=getMapArray(queueMaps->content,"input",i); |
---|
| 254 | char* templateStr=_("Unable to unlock the file for %s after execution."); |
---|
| 255 | char *tmpMessage=(char*)malloc((strlen(templateStr)+strlen(argv->value)+1)*sizeof(char)); |
---|
| 256 | sprintf(tmpMessage,templateStr,argv->value); |
---|
| 257 | maps* lenv=getMaps(*conf,"lenv"); |
---|
| 258 | setMapArray(lenv->content,"message",nberr,tmpMessage); |
---|
| 259 | free(tmpMessage); |
---|
| 260 | res=-1; |
---|
| 261 | nberr++; |
---|
| 262 | } |
---|
| 263 | } |
---|
| 264 | } |
---|
| 265 | free(zoo_file_locks); |
---|
| 266 | return res; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | /** |
---|
| 270 | * Get the section name depending on number of features and/or pixels of each |
---|
| 271 | * inputs and the threshold defined in a section. |
---|
| 272 | * It supposes that your inputs has been published using MapServer support, |
---|
| 273 | * implying that the number of features (nb_features), respectively pixels |
---|
| 274 | * (nb_pixels), are defined. The section, identified by confId, should contain |
---|
| 275 | * preview_max_features and preview_max_pixels defining the threshold values. |
---|
| 276 | * @param conf the main configuration file maps pointer |
---|
| 277 | * @param inputs the inputs maps pointer |
---|
| 278 | * @param confId the section identifier |
---|
| 279 | * @return "preview_conf" in case the numbers are lower than the threshold, |
---|
| 280 | * "fullres_conf" in other cases. |
---|
| 281 | */ |
---|
| 282 | char* getConfiguration(maps** conf,maps** inputs,const char* confId){ |
---|
| 283 | maps* input=*inputs; |
---|
| 284 | map* max_pixels=getMapFromMaps(*conf,confId,"preview_max_pixels"); |
---|
| 285 | map* max_features=getMapFromMaps(*conf,confId,"preview_max_features"); |
---|
| 286 | int i_max_pixels=atoi(max_pixels->value); |
---|
| 287 | int i_max_features=atoi(max_features->value); |
---|
| 288 | while(input!=NULL && input->content!=NULL){ |
---|
| 289 | map* tmpMap=getMap(input->content,"geodatatype"); |
---|
| 290 | if(tmpMap!=NULL){ |
---|
| 291 | map* currentNb; |
---|
| 292 | if(strcasecmp(tmpMap->value,"raster")==0 ){ |
---|
| 293 | currentNb=getMap(input->content,"nb_pixels"); |
---|
| 294 | if(atoi(currentNb->value)>i_max_pixels) |
---|
| 295 | return "fullres_conf"; |
---|
| 296 | }else{ |
---|
| 297 | if(strcasecmp(tmpMap->value,"vector")==0 ){ |
---|
| 298 | currentNb=getMap(input->content,"nb_features"); |
---|
| 299 | if(atoi(currentNb->value)>i_max_features) |
---|
| 300 | return "fullres_conf"; |
---|
| 301 | } |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | input=input->next; |
---|
| 305 | } |
---|
| 306 | return "preview_conf"; |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | /** |
---|
[822] | 310 | * Load and run a HPC Application corresponding to the service. |
---|
| 311 | * |
---|
| 312 | * @param main_conf the conf maps containing the main.cfg settings |
---|
| 313 | * @param request the map containing the HTTP request |
---|
| 314 | * @param s the service structure |
---|
| 315 | * @param real_inputs the maps containing the inputs |
---|
| 316 | * @param real_outputs the maps containing the outputs |
---|
[860] | 317 | * @return SERVICE_SUCCEEDED in case of success, -1 or SERVICE_FAILED when failing. |
---|
[822] | 318 | */ |
---|
| 319 | int zoo_hpc_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){ |
---|
| 320 | maps* m=*main_conf; |
---|
| 321 | maps* inputs=*real_inputs; |
---|
| 322 | maps* outputs=*real_outputs; |
---|
| 323 | map* tmp0=getMapFromMaps(*main_conf,"lenv","cwd"); |
---|
| 324 | char *ntmp=tmp0->value; |
---|
| 325 | map* tmp=NULL; |
---|
| 326 | int res=-1; |
---|
[854] | 327 | // Get the configuration id depending on service type and defined thresholds |
---|
| 328 | // then, set the configId key in the lenv section |
---|
[839] | 329 | char *serviceType; |
---|
[886] | 330 | map* mServiceType=getMap(s->content,"confId"); |
---|
[839] | 331 | if(mServiceType!=NULL) |
---|
| 332 | serviceType=mServiceType->value; |
---|
| 333 | else |
---|
| 334 | serviceType="HPC"; |
---|
[822] | 335 | map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath"); |
---|
| 336 | map* uuid=getMapFromMaps(*main_conf,"lenv","usid"); |
---|
[854] | 337 | map* confMap=getMapFromMaps(*main_conf,serviceType,getConfiguration(main_conf,real_inputs,serviceType)); |
---|
| 338 | char * configurationId=confMap->value; |
---|
| 339 | setMapInMaps(*main_conf,"lenv","configId",configurationId); |
---|
| 340 | // Dump lenv maps again after having set the configId ... |
---|
| 341 | char *flenv = |
---|
| 342 | (char *) |
---|
| 343 | malloc ((strlen (tmpPath->value) + |
---|
| 344 | strlen (uuid->value) + 12) * sizeof (char)); |
---|
| 345 | sprintf (flenv, "%s/%s_lenv.cfg", tmpPath->value, uuid->value); |
---|
| 346 | maps* lenvMaps=getMaps(m,"lenv"); |
---|
| 347 | dumpMapsToFile(lenvMaps,flenv,0); |
---|
| 348 | free(flenv); |
---|
| 349 | |
---|
| 350 | map* targetPathMap=getMapFromMaps(*main_conf,configurationId,"remote_data_path"); |
---|
[888] | 351 | map* targetPersistentPathMap=getMapFromMaps(*main_conf,configurationId,"remote_persistent_data_path"); |
---|
[854] | 352 | |
---|
[839] | 353 | pthread_t threads_pool[50]; |
---|
| 354 | // Force the HPC services to be called asynchronously |
---|
| 355 | map* isAsync=getMapFromMaps(*main_conf,"lenv","async"); |
---|
| 356 | if(isAsync==NULL){ |
---|
| 357 | errorException(*main_conf,_("The synchronous mode is not supported by this type of service"),"NoSuchMode",s->name); |
---|
| 358 | return -1; |
---|
| 359 | } |
---|
[822] | 360 | |
---|
| 361 | maps* input=*real_inputs; |
---|
| 362 | char **parameters=NULL; |
---|
| 363 | int parameters_cnt=0; |
---|
[839] | 364 | while(input!=NULL && input->content!=NULL){ |
---|
[862] | 365 | map* isInRequest=getMap(input->content,"inRequest"); |
---|
[886] | 366 | map* minNb=getMap(input->content,"minOccurs"); |
---|
[862] | 367 | if(getMaps(*real_outputs,input->name)==NULL && |
---|
| 368 | ( (isInRequest!=NULL && strncasecmp(isInRequest->value,"true",4)==0) |
---|
| 369 | || (minNb!=NULL && atoi(minNb->value)>0) ) ){ |
---|
[839] | 370 | parameters_cnt+=1; |
---|
| 371 | if(parameters_cnt==1) |
---|
| 372 | parameters=(char**)malloc(parameters_cnt*sizeof(char*)); |
---|
| 373 | else |
---|
| 374 | parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*)); |
---|
| 375 | if(getMap(input->content,"mimeType")!=NULL){ |
---|
| 376 | // Input is ComplexData |
---|
| 377 | if(getMap(input->content,"cache_file")==NULL){ |
---|
| 378 | // Input data has been passed by value |
---|
| 379 | // TODO: publish input through MapServer / use output publication |
---|
| 380 | dumpMapsValuesToFiles(main_conf,&input); |
---|
| 381 | addToMap(input->content,"toPublish","true"); |
---|
[862] | 382 | //addToMap(input->content,"useMapserver","true"); |
---|
[839] | 383 | } |
---|
| 384 | if(getMap(input->content,"cache_file")!=NULL){ |
---|
| 385 | map* length=getMap(input->content,"length"); |
---|
| 386 | if(length==NULL){ |
---|
| 387 | addToMap(input->content,"length","1"); |
---|
| 388 | length=getMap(input->content,"length"); |
---|
| 389 | } |
---|
| 390 | int len=atoi(length->value); |
---|
| 391 | int i=0; |
---|
| 392 | for(i=0;i<len;i++){ |
---|
| 393 | map* tmp=getMapArray(input->content,"cache_file",i); |
---|
[888] | 394 | map* origin=getMapArray(input->content,"origin",i); |
---|
[839] | 395 | char* targetName=strrchr(tmp->value,'/'); |
---|
[888] | 396 | char *targetPath; |
---|
| 397 | if(origin!=NULL && strcasecmp(origin->value,"SHARED")==0 && targetPersistentPathMap!=NULL){ |
---|
| 398 | targetPath=(char*)malloc((strlen(targetPersistentPathMap->value)+strlen(targetName)+2)*sizeof(char)); |
---|
| 399 | sprintf(targetPath,"%s/%s",targetPersistentPathMap->value,targetName); |
---|
| 400 | } |
---|
| 401 | else{ |
---|
| 402 | targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char)); |
---|
| 403 | sprintf(targetPath,"%s/%s",targetPathMap->value,targetName); |
---|
| 404 | } |
---|
[839] | 405 | setMapArray(input->content,"targetPath",i,targetPath); |
---|
| 406 | setMapArray(input->content,"localPath",i,tmp->value); |
---|
[862] | 407 | map* tmp1=getMapArray(input->content,"value",i); |
---|
| 408 | if(tmp1!=NULL){ |
---|
| 409 | free(tmp1->value); |
---|
| 410 | tmp1->value=strdup("empty"); |
---|
| 411 | } |
---|
[839] | 412 | if(i==0){ |
---|
| 413 | parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char)); |
---|
| 414 | sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath); |
---|
| 415 | }else{ |
---|
[862] | 416 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
| 417 | fflush(stderr); |
---|
[839] | 418 | char *tmpStr=zStrdup(parameters[parameters_cnt-1]); |
---|
| 419 | parameters[parameters_cnt-1]=(char*)realloc(parameters[parameters_cnt-1],(strlen(tmpStr)+strlen(targetPath)+2)*sizeof(char)); |
---|
| 420 | sprintf(parameters[parameters_cnt-1],"%s %s",tmpStr,targetPath); |
---|
| 421 | free(tmpStr); |
---|
[862] | 422 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
| 423 | fflush(stderr); |
---|
[839] | 424 | } |
---|
| 425 | free(targetPath); |
---|
| 426 | } |
---|
[862] | 427 | addToUploadQueue(main_conf,input); |
---|
[839] | 428 | }else{ |
---|
| 429 | // ??? |
---|
| 430 | fprintf(stderr,"%s %d\n",__FILE__,__LINE__); |
---|
| 431 | fflush(stderr); |
---|
| 432 | } |
---|
[822] | 433 | }else{ |
---|
[839] | 434 | // LitteralData and BboxData |
---|
| 435 | if(getMap(input->content,"dataType")!=NULL){ |
---|
| 436 | // For LitteralData, simply pass the value |
---|
[886] | 437 | map* length=getMap(input->content,"length"); |
---|
| 438 | if(length!=NULL){ |
---|
| 439 | char* value=NULL; |
---|
| 440 | int len=atoi(length->value); |
---|
| 441 | int i=0; |
---|
| 442 | for(i=0;i<len;i++){ |
---|
| 443 | map* val=getMapArray(input->content,"value",i); |
---|
| 444 | if(val!=NULL){ |
---|
| 445 | if(value==NULL){ |
---|
| 446 | value=(char*)malloc((strlen(val->value)+3)*sizeof(char)); |
---|
| 447 | sprintf(value,"\"%s\"",val->value); |
---|
| 448 | } |
---|
| 449 | else{ |
---|
| 450 | value=(char*)realloc(value,(strlen(value)+strlen(val->value)+4)*sizeof(char)); |
---|
| 451 | sprintf(value,"%s \"%s\"",value,val->value); |
---|
| 452 | } |
---|
| 453 | } |
---|
| 454 | } |
---|
| 455 | if(value!=NULL){ |
---|
| 456 | parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(value)+3)*sizeof(char)); |
---|
| 457 | sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,value); |
---|
| 458 | } |
---|
| 459 | }else{ |
---|
| 460 | map* val=getMap(input->content,"value"); |
---|
| 461 | parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(val->value)+5)*sizeof(char)); |
---|
| 462 | sprintf(parameters[parameters_cnt-1],"-%s \"%s\"",input->name,val->value); |
---|
| 463 | } |
---|
[839] | 464 | } |
---|
[822] | 465 | } |
---|
| 466 | } |
---|
| 467 | input=input->next; |
---|
| 468 | } |
---|
| 469 | |
---|
[860] | 470 | #ifdef HPC_DEBUG |
---|
[839] | 471 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
[860] | 472 | #endif |
---|
[902] | 473 | #ifdef USE_CALLBACK |
---|
[860] | 474 | invokeCallback(m,inputs,NULL,1,1); |
---|
[862] | 475 | invokeCallback(m,inputs,NULL,2,0); |
---|
[902] | 476 | #endif |
---|
[854] | 477 | if(getMapFromMaps(m,"lenv","mapError")!=NULL){ |
---|
[902] | 478 | #ifdef USE_CALLBACK |
---|
[862] | 479 | invokeCallback(*main_conf,inputs,NULL,7,0); |
---|
[902] | 480 | #endif |
---|
[854] | 481 | return -1; |
---|
| 482 | } |
---|
[860] | 483 | #ifdef HPC_DEBUG |
---|
| 484 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 485 | dumpMaps(inputs); |
---|
| 486 | #endif |
---|
[839] | 487 | |
---|
| 488 | // Upload data on HPC |
---|
[854] | 489 | if(runUpload(main_conf)==false){ |
---|
[862] | 490 | errorException (*main_conf, _("Unable to lock the file for upload!"), |
---|
[854] | 491 | "InternalError", NULL); |
---|
[860] | 492 | #ifdef HPC_DEBUG |
---|
[854] | 493 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
[860] | 494 | #endif |
---|
[902] | 495 | #ifdef USE_CALLBACK |
---|
[862] | 496 | invokeCallback(*main_conf,inputs,NULL,7,0); |
---|
[902] | 497 | #endif |
---|
[860] | 498 | #ifdef HPC_DEBUG |
---|
[854] | 499 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
[860] | 500 | #endif |
---|
[854] | 501 | return -1; |
---|
| 502 | } |
---|
[860] | 503 | #ifdef HPC_DEBUG |
---|
[839] | 504 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
[860] | 505 | #endif |
---|
[902] | 506 | #ifdef USE_CALLBACK |
---|
[839] | 507 | invokeCallback(m,inputs,NULL,2,1); |
---|
[902] | 508 | #endif |
---|
[860] | 509 | #ifdef HPC_DEBUG |
---|
[839] | 510 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
[860] | 511 | #endif |
---|
[839] | 512 | |
---|
[854] | 513 | // Add the filename to generate for every output to parameters |
---|
[822] | 514 | input=*real_outputs; |
---|
[860] | 515 | #ifdef HPC_DEBUG |
---|
[854] | 516 | dumpMaps(input); |
---|
[860] | 517 | #endif |
---|
[822] | 518 | while(input!=NULL){ |
---|
[862] | 519 | // Parse all outputs including inner outputs if required. |
---|
[822] | 520 | if(input->child==NULL){ |
---|
| 521 | // Name every files that should be produced by the service execution |
---|
[839] | 522 | map* mime=getMap(input->content,"mimeType"); |
---|
| 523 | char* targetName; |
---|
| 524 | if(mime!=NULL){ |
---|
| 525 | bool hasExt=false; |
---|
| 526 | map* fileExt=getFileExtensionMap(mime->value,&hasExt); |
---|
| 527 | targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+strlen(fileExt->value)+11)*sizeof(char)); |
---|
| 528 | sprintf(targetName,"output_%s_%s_%s.%s",s->name,input->name,uuid->value,fileExt->value); |
---|
| 529 | freeMap(&fileExt); |
---|
| 530 | free(fileExt); |
---|
| 531 | }else{ |
---|
| 532 | targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+14)*sizeof(char)); |
---|
| 533 | sprintf(targetName,"output_%s_%s_%s.tif",s->name,input->name,uuid->value); |
---|
| 534 | } |
---|
[822] | 535 | char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char)); |
---|
| 536 | sprintf(targetPath,"%s/%s",targetPathMap->value,targetName); |
---|
[862] | 537 | map *tmpUrl=getMapFromMaps(*main_conf,"main","tmpUrl"); |
---|
| 538 | char *targetUrl=(char*)malloc((strlen(tmpUrl->value)+strlen(targetName)+2)*sizeof(char)); |
---|
| 539 | sprintf(targetUrl,"%s/%s",tmpUrl->value,targetName); |
---|
[851] | 540 | free(targetName); |
---|
[822] | 541 | setMapInMaps(*real_outputs,input->name,"generated_file",targetPath); |
---|
[862] | 542 | addToMap(input->content,"generated_url",targetUrl); |
---|
| 543 | free(targetUrl); |
---|
| 544 | { |
---|
[854] | 545 | parameters_cnt+=1; |
---|
| 546 | if(parameters_cnt==1) |
---|
| 547 | parameters=(char**)malloc(parameters_cnt*sizeof(char*)); |
---|
| 548 | else |
---|
| 549 | parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*)); |
---|
| 550 | // We should verify if any optional tag for output is required |
---|
| 551 | // (i.e. -out output.tiff *int8*), meaning that we should search |
---|
| 552 | // for a corresponding inputs name. |
---|
| 553 | map* inValue=getMapFromMaps(*real_inputs,input->name,"value"); |
---|
| 554 | if(inValue!=NULL){ |
---|
| 555 | parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+strlen(inValue->value)+4)*sizeof(char)); |
---|
| 556 | sprintf(parameters[parameters_cnt-1],"-%s %s %s",input->name,targetPath,inValue->value); |
---|
| 557 | }else{ |
---|
| 558 | parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char)); |
---|
| 559 | sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath); |
---|
| 560 | } |
---|
[839] | 561 | } |
---|
| 562 | free(targetPath); |
---|
| 563 | }// In other case it means we need to return the cache_file as generated_file |
---|
| 564 | else{ |
---|
| 565 | // Name every files that should be produced by the service execution |
---|
| 566 | map* mime=getMap(input->child->content,"mimeType"); |
---|
| 567 | char* targetName; |
---|
| 568 | if(mime!=NULL){ |
---|
| 569 | bool hasExt=false; |
---|
| 570 | map* fileExt=getFileExtensionMap(mime->value,&hasExt); |
---|
| 571 | targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+strlen(fileExt->value)+11)*sizeof(char)); |
---|
| 572 | sprintf(targetName,"output_%s_%s_%s.%s",s->name,input->name,uuid->value,fileExt->value); |
---|
| 573 | freeMap(&fileExt); |
---|
| 574 | free(fileExt); |
---|
| 575 | }else{ |
---|
| 576 | targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+14)*sizeof(char)); |
---|
| 577 | sprintf(targetName,"output_%s_%s_%s.tif",s->name,input->name,uuid->value); |
---|
| 578 | } |
---|
| 579 | char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char)); |
---|
| 580 | sprintf(targetPath,"%s/%s",targetPathMap->value,targetName); |
---|
[862] | 581 | map *tmpUrl=getMapFromMaps(*main_conf,"main","tmpUrl"); |
---|
| 582 | char *targetUrl=(char*)malloc((strlen(tmpUrl->value)+strlen(targetName)+2)*sizeof(char)); |
---|
| 583 | sprintf(targetUrl,"%s/%s",tmpUrl->value,targetName); |
---|
[851] | 584 | free(targetName); |
---|
[839] | 585 | addToMap(input->content,"generated_file",targetPath); |
---|
[854] | 586 | addToMap(input->content,"storage",targetPath); |
---|
[862] | 587 | addToMap(input->content,"generated_url",targetUrl); |
---|
| 588 | free(targetUrl); |
---|
[854] | 589 | if(strcasecmp(input->name,"wms_link")!=0&& |
---|
| 590 | strcasecmp(input->name,"wcs_link")!=0 && |
---|
| 591 | strcasecmp(input->name,"wfs_link")!=0){ |
---|
| 592 | parameters_cnt+=1; |
---|
| 593 | if(parameters_cnt==1) |
---|
| 594 | parameters=(char**)malloc(parameters_cnt*sizeof(char*)); |
---|
| 595 | else |
---|
| 596 | parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*)); |
---|
| 597 | // We should verify if any optional tag for output is required |
---|
| 598 | // (i.e. -out output.tiff *int8*), meaning that we should search |
---|
| 599 | // for a corresponding inputs name. |
---|
| 600 | map* inValue=getMapFromMaps(*real_inputs,input->name,"value"); |
---|
| 601 | if(inValue!=NULL){ |
---|
| 602 | parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+strlen(inValue->value)+4)*sizeof(char)); |
---|
| 603 | sprintf(parameters[parameters_cnt-1],"-%s %s %s",input->name,targetPath,inValue->value); |
---|
| 604 | }else{ |
---|
| 605 | parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char)); |
---|
| 606 | sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath); |
---|
| 607 | } |
---|
[839] | 608 | } |
---|
| 609 | free(targetPath); |
---|
[822] | 610 | } |
---|
| 611 | input=input->next; |
---|
| 612 | } |
---|
| 613 | // Produce the SBATCH File locally |
---|
[839] | 614 | char *scriptPath=(char*)malloc((strlen(s->name)+strlen(tmpPath->value)+strlen(uuid->value)+10)*sizeof(char)); |
---|
[822] | 615 | sprintf(scriptPath,"%s/zoo_%s_%s.sh",tmpPath->value,s->name,uuid->value); |
---|
[839] | 616 | setMapInMaps(*main_conf,"lenv","local_script",scriptPath); |
---|
[860] | 617 | #ifdef HPC_DEBUG |
---|
[839] | 618 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 619 | fflush(stderr); |
---|
[860] | 620 | #endif |
---|
[902] | 621 | #ifdef USE_CALLBACK |
---|
[839] | 622 | invokeCallback(m,inputs,NULL,3,0); |
---|
[902] | 623 | #endif |
---|
[860] | 624 | #ifdef HPC_DEBUG |
---|
[839] | 625 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 626 | fflush(stderr); |
---|
[860] | 627 | #endif |
---|
[822] | 628 | FILE* scriptFile=fopen(scriptPath,"w+"); |
---|
[854] | 629 | map* headerMap=getMapFromMaps(*main_conf,configurationId,"jobscript_header"); |
---|
[822] | 630 | if(headerMap!=NULL){ |
---|
| 631 | // Use the header file if defined in the HPC section of the main.cfg file |
---|
| 632 | struct stat f_status; |
---|
| 633 | int s=stat(headerMap->value, &f_status); |
---|
| 634 | if(s==0){ |
---|
| 635 | char* fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); |
---|
| 636 | FILE* f=fopen(headerMap->value,"rb"); |
---|
| 637 | fread(fcontent,f_status.st_size,1,f); |
---|
| 638 | int fsize=f_status.st_size; |
---|
| 639 | fcontent[fsize]=0; |
---|
| 640 | fclose(f); |
---|
[839] | 641 | fprintf(scriptFile,"%s\n### --- ZOO-Service HEADER end --- ###\n\n",fcontent); |
---|
[822] | 642 | free(fcontent); |
---|
| 643 | }else |
---|
| 644 | fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service HEADER (no header found) *** ###\n\n"); |
---|
| 645 | }else |
---|
| 646 | fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service HEADER *** ###\n\n"); |
---|
[854] | 647 | maps* hpc_opts=getMaps(*main_conf,configurationId); |
---|
[839] | 648 | if(hpc_opts!=NULL){ |
---|
| 649 | map* hpc_opts_content=hpc_opts->content; |
---|
| 650 | while(hpc_opts_content!=NULL){ |
---|
[854] | 651 | if(strncasecmp(hpc_opts_content->name,"sbatch_options_",15)==0) |
---|
| 652 | fprintf(scriptFile,"#SBATCH --%s=%s\n",strstr(hpc_opts_content->name,"sbatch_options_")+15,hpc_opts_content->value); |
---|
[839] | 653 | hpc_opts_content=hpc_opts_content->next; |
---|
| 654 | } |
---|
[822] | 655 | } |
---|
| 656 | fprintf(scriptFile,"#SBATCH --job-name=ZOO-Project_%s_%s\n\n",uuid->value,s->name); |
---|
| 657 | map* mods=getMap(s->content,"hpcModules"); |
---|
| 658 | if(mods!=NULL) |
---|
| 659 | fprintf(scriptFile,"#SBATCH --export=MODULES=%s\n",mods->value); |
---|
[839] | 660 | |
---|
[854] | 661 | map* bodyMap=getMapFromMaps(*main_conf,configurationId,"jobscript_body"); |
---|
[839] | 662 | if(bodyMap!=NULL){ |
---|
| 663 | // Use the header file if defined in the HPC section of the main.cfg file |
---|
| 664 | struct stat f_status; |
---|
| 665 | int s=stat(bodyMap->value, &f_status); |
---|
| 666 | if(s==0){ |
---|
| 667 | char* fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); |
---|
| 668 | FILE* f=fopen(bodyMap->value,"rb"); |
---|
| 669 | fread(fcontent,f_status.st_size,1,f); |
---|
| 670 | int fsize=f_status.st_size; |
---|
| 671 | fcontent[fsize]=0; |
---|
| 672 | fclose(f); |
---|
| 673 | fprintf(scriptFile,"%s\n### --- ZOO-Service BODY end --- ###\n\n",fcontent); |
---|
| 674 | free(fcontent); |
---|
| 675 | }else |
---|
[860] | 676 | fprintf(scriptFile,"\n### *** Default ZOO-Service BODY (no body found) *** ###\n\n"); |
---|
[839] | 677 | }else |
---|
[860] | 678 | fprintf(scriptFile,"\n### *** Default ZOO-Service BODY *** ###\n\n"); |
---|
[839] | 679 | |
---|
[822] | 680 | map* sp=getMap(s->content,"serviceProvider"); |
---|
[839] | 681 | |
---|
[822] | 682 | // Require to produce the command line to be executed |
---|
| 683 | fprintf(scriptFile,"\n\necho \"Job started at: $(date)\"\n"); |
---|
| 684 | fprintf(scriptFile,"echo \"Running service: [%s]\"\n",sp->value); |
---|
| 685 | fprintf(scriptFile,"%s ",sp->value); |
---|
| 686 | for(int i=0;i<parameters_cnt;i++){ |
---|
| 687 | fprintf(scriptFile," %s",parameters[i]); |
---|
| 688 | } |
---|
[839] | 689 | for(int i=parameters_cnt-1;i>=0;i--){ |
---|
| 690 | free(parameters[i]); |
---|
| 691 | } |
---|
[822] | 692 | free(parameters); |
---|
| 693 | fprintf(scriptFile,"\n"); |
---|
| 694 | fprintf(scriptFile,"echo \"Job finished at: $(date)\"\n"); |
---|
[877] | 695 | map* footerMap=getMapFromMaps(*main_conf,configurationId,"jobscript_footer"); |
---|
| 696 | if(footerMap!=NULL){ |
---|
| 697 | // Use the footer file if defined in the HPC section of the main.cfg file |
---|
| 698 | struct stat f_status; |
---|
| 699 | int s=stat(footerMap->value, &f_status); |
---|
| 700 | if(s==0){ |
---|
| 701 | char* fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); |
---|
| 702 | FILE* f=fopen(footerMap->value,"rb"); |
---|
| 703 | fread(fcontent,f_status.st_size,1,f); |
---|
| 704 | int fsize=f_status.st_size; |
---|
| 705 | fcontent[fsize]=0; |
---|
| 706 | fclose(f); |
---|
| 707 | char* ffcontent=(char*)malloc((strlen(fcontent)+(3*strlen(uuid->value))+1)*sizeof(char)); |
---|
| 708 | sprintf(ffcontent,fcontent,uuid->value,uuid->value,uuid->value); |
---|
| 709 | fprintf(scriptFile,"%s\n### --- ZOO-Service FOOTER end --- ###\n\n",ffcontent); |
---|
| 710 | free(fcontent); |
---|
| 711 | }else |
---|
| 712 | fprintf(scriptFile,"### *** Default ZOO-Service FOOTER (footer file failed to load) *** ###\n\n"); |
---|
| 713 | }else |
---|
| 714 | fprintf(scriptFile,"### *** Default ZOO-Service FOOTER (no footer found) *** ###\n\n"); |
---|
[822] | 715 | fflush(scriptFile); |
---|
| 716 | fclose(scriptFile); |
---|
[860] | 717 | #ifdef HPC_DEBUG |
---|
[839] | 718 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
[860] | 719 | #endif |
---|
[902] | 720 | #ifdef USE_CALLBACK |
---|
[839] | 721 | invokeCallback(m,inputs,NULL,3,1); |
---|
[902] | 722 | #endif |
---|
[860] | 723 | #ifdef HPC_DEBUG |
---|
[839] | 724 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
[860] | 725 | #endif |
---|
[822] | 726 | |
---|
| 727 | // Upload the SBATCH File to the remote host |
---|
[860] | 728 | #ifdef HPC_DEBUG |
---|
[839] | 729 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
[860] | 730 | #endif |
---|
[902] | 731 | #ifdef USE_CALLBACK |
---|
[839] | 732 | invokeCallback(m,inputs,NULL,4,0); |
---|
[902] | 733 | #endif |
---|
[860] | 734 | #ifdef HPC_DEBUG |
---|
[839] | 735 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
[860] | 736 | #endif |
---|
[854] | 737 | targetPathMap=getMapFromMaps(*main_conf,configurationId,"remote_work_path"); |
---|
[822] | 738 | if(targetPathMap==NULL){ |
---|
[854] | 739 | setMapInMaps(*main_conf,"lenv","message",_("There is no remote_work_path defined in your section!")); |
---|
| 740 | setMapInMaps(*main_conf,"lenv","status","failed"); |
---|
[862] | 741 | errorException (*main_conf, _("There is no remote_work_path defined in your section!"), |
---|
[854] | 742 | "InternalError", NULL); |
---|
[860] | 743 | #ifdef HPC_DEBUG |
---|
[854] | 744 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 745 | fflush(stderr); |
---|
[860] | 746 | #endif |
---|
[902] | 747 | #ifdef USE_CALLBACK |
---|
[862] | 748 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 749 | #endif |
---|
[860] | 750 | #ifdef HPC_DEBUG |
---|
[854] | 751 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 752 | fflush(stderr); |
---|
[860] | 753 | #endif |
---|
[822] | 754 | return SERVICE_FAILED; |
---|
| 755 | } |
---|
| 756 | char* targetName=strrchr(scriptPath,'/'); |
---|
| 757 | char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char)); |
---|
| 758 | sprintf(targetPath,"%s/%s",targetPathMap->value,targetName); |
---|
[839] | 759 | setMapInMaps(*main_conf,"lenv","remote_script",targetPath); |
---|
[822] | 760 | SSHCON *test=ssh_connect(*main_conf); |
---|
[860] | 761 | int copy0=ssh_copy(*main_conf,scriptPath,targetPath,ssh_get_cnt(*main_conf)); |
---|
[854] | 762 | unlink(scriptPath); |
---|
| 763 | free(scriptPath); |
---|
[860] | 764 | if(copy0!=true){ |
---|
[862] | 765 | setMapInMaps(*main_conf,"lenv","message",_("Unable to upload the script")); |
---|
[902] | 766 | #ifdef USE_CALLBACK |
---|
[862] | 767 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 768 | #endif |
---|
[862] | 769 | errorException(*main_conf,_("Unable to upload the script"),"NoApplicableCode",NULL); |
---|
[860] | 770 | return -1; |
---|
| 771 | } |
---|
[822] | 772 | // Execute the SBATCH script remotely |
---|
[854] | 773 | addReadLocks(main_conf); |
---|
| 774 | map* subStr=getMapFromMaps(*main_conf,configurationId,"sbatch_substr"); |
---|
[822] | 775 | char *command=(char*)malloc((strlen(targetPath)+strlen(targetPathMap->value)+strlen(subStr->value)+strlen(uuid->value)+137)*sizeof(char)); |
---|
| 776 | sprintf(command,"sbatch %s 2> %s/error_%s.log | sed \"s:%s::g\"",targetPath,targetPathMap->value,uuid->value,subStr->value); |
---|
[860] | 777 | if(ssh_exec(*main_conf,command,ssh_get_cnt(m))<=0){ |
---|
[822] | 778 | // The sbatch command has failed! |
---|
| 779 | // Download the error log file from the HPC server |
---|
| 780 | char tmpS[1024]; |
---|
| 781 | free(command); |
---|
[839] | 782 | command=(char*)malloc((strlen(targetPathMap->value)+strlen(uuid->value)+11)*sizeof(char)); |
---|
[822] | 783 | sprintf(command,"%s/error_%s.log",targetPathMap->value,uuid->value); |
---|
| 784 | targetName=strrchr(command,'/'); |
---|
| 785 | free(targetPath); |
---|
| 786 | targetPath=(char*)malloc((strlen(tmpPath->value)+strlen(targetName)+2)*sizeof(char)); |
---|
| 787 | sprintf(targetPath,"%s/%s",tmpPath->value,targetName); |
---|
[839] | 788 | if(ssh_fetch(*main_conf,targetPath,command,ssh_get_cnt(m))==0){ |
---|
[822] | 789 | struct stat f_status; |
---|
| 790 | int ts=stat(targetPath, &f_status); |
---|
| 791 | if(ts==0) { |
---|
| 792 | char* fcontent = NULL; |
---|
| 793 | fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); |
---|
| 794 | FILE* f=fopen(targetPath,"rb"); |
---|
| 795 | fread(fcontent,f_status.st_size,1,f); |
---|
| 796 | int fsize=f_status.st_size; |
---|
| 797 | fcontent[fsize]=0; |
---|
| 798 | fclose(f); |
---|
| 799 | setMapInMaps(*main_conf,"lenv","message",fcontent); |
---|
| 800 | free(fcontent); |
---|
| 801 | }else |
---|
| 802 | setMapInMaps(*main_conf,"lenv","message",_("No message provided")); |
---|
| 803 | }else |
---|
| 804 | setMapInMaps(*main_conf,"lenv","message",_("Unable to fetch the remote error log file")); |
---|
[860] | 805 | tmpPath=getMapFromMaps(m,"lenv","message"); |
---|
| 806 | #ifdef HPC_DEBUG |
---|
[850] | 807 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 808 | fflush(stderr); |
---|
[860] | 809 | #endif |
---|
[902] | 810 | #ifdef USE_CALLBACK |
---|
[862] | 811 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 812 | #endif |
---|
[860] | 813 | #ifdef HPC_DEBUG |
---|
[850] | 814 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 815 | fflush(stderr); |
---|
[860] | 816 | #endif |
---|
| 817 | sprintf(tmpS, "Cannot execute the HPC ZOO-Service %s using %s: %s", s->name, configurationId, tmpPath->value); |
---|
[862] | 818 | errorException(*main_conf,tmpS,"NoApplicableCode",NULL); |
---|
[822] | 819 | free(command); |
---|
| 820 | free(targetPath); |
---|
| 821 | ssh_close(*main_conf); |
---|
[860] | 822 | removeReadLocks(main_conf); |
---|
[822] | 823 | return -1; |
---|
| 824 | } |
---|
[851] | 825 | free(targetPath); |
---|
[860] | 826 | #ifdef HPC_DEBUG |
---|
[839] | 827 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 828 | fflush(stderr); |
---|
[860] | 829 | #endif |
---|
[902] | 830 | #ifdef USE_CALLBACK |
---|
[839] | 831 | invokeCallback(m,NULL,NULL,4,1); |
---|
[902] | 832 | #endif |
---|
[860] | 833 | #ifdef HPC_DEBUG |
---|
[839] | 834 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 835 | fflush(stderr); |
---|
[860] | 836 | #endif |
---|
[839] | 837 | free(command); |
---|
[860] | 838 | #ifdef HPC_DEBUG |
---|
[854] | 839 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 840 | fflush(stderr); |
---|
[860] | 841 | #endif |
---|
[822] | 842 | |
---|
| 843 | struct sockaddr_un addr; |
---|
| 844 | memset(&addr, 0, sizeof(addr)); |
---|
| 845 | addr.sun_family = AF_UNIX; |
---|
| 846 | int rc, cl, fd = socket(AF_UNIX, SOCK_STREAM, 0); |
---|
[839] | 847 | char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(uuid->value)+20)); |
---|
[822] | 848 | sprintf(sname,"%s/.wait_socket_%s.sock",tmpPath->value,uuid->value); |
---|
| 849 | strncpy(addr.sun_path, sname, sizeof(addr.sun_path)-1); |
---|
[839] | 850 | |
---|
[822] | 851 | if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { |
---|
| 852 | perror("bind error"); |
---|
[862] | 853 | setMapInMaps(*main_conf,"lenv","message",_("Unable to bind socket!")); |
---|
| 854 | errorException (*main_conf, _("Unable to bind socket!"), |
---|
[854] | 855 | "InternalError", NULL); |
---|
[860] | 856 | #ifdef HPC_DEBUG |
---|
[854] | 857 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 858 | fflush(stderr); |
---|
[860] | 859 | #endif |
---|
[902] | 860 | #ifdef USE_CALLBACK |
---|
[862] | 861 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 862 | #endif |
---|
[860] | 863 | removeReadLocks(main_conf); |
---|
| 864 | #ifdef HPC_DEBUG |
---|
[854] | 865 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 866 | fflush(stderr); |
---|
[860] | 867 | #endif |
---|
[822] | 868 | return -1; |
---|
| 869 | } |
---|
[860] | 870 | #ifdef HPC_DEBUG |
---|
[854] | 871 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 872 | fflush(stderr); |
---|
[860] | 873 | #endif |
---|
[822] | 874 | if (listen(fd, 5) == -1) { |
---|
[839] | 875 | setMapInMaps(*main_conf,"lenv","message",_("Listen error")); |
---|
[862] | 876 | errorException (*main_conf, _("Listen error"), |
---|
[854] | 877 | "InternalError", NULL); |
---|
[860] | 878 | #ifdef HPC_DEBUG |
---|
[854] | 879 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 880 | fflush(stderr); |
---|
[860] | 881 | #endif |
---|
[902] | 882 | #ifdef USE_CALLBACK |
---|
[862] | 883 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 884 | #endif |
---|
[860] | 885 | removeReadLocks(main_conf); |
---|
| 886 | #ifdef HPC_DEBUG |
---|
[854] | 887 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 888 | fflush(stderr); |
---|
[860] | 889 | #endif |
---|
[822] | 890 | return -1; |
---|
| 891 | } |
---|
[839] | 892 | if ( (cl = accept(fd, NULL, NULL)) == -1) { |
---|
| 893 | setMapInMaps(*main_conf,"lenv","message",_("Accept error")); |
---|
[862] | 894 | errorException (*main_conf, _("Accept error"), |
---|
[854] | 895 | "InternalError", NULL); |
---|
[860] | 896 | #ifdef HPC_DEBUG |
---|
[854] | 897 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 898 | fflush(stderr); |
---|
[860] | 899 | #endif |
---|
[902] | 900 | #ifdef USE_CALLBACK |
---|
[862] | 901 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 902 | #endif |
---|
[860] | 903 | removeReadLocks(main_conf); |
---|
| 904 | #ifdef HPC_DEBUG |
---|
[854] | 905 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 906 | fflush(stderr); |
---|
[860] | 907 | #endif |
---|
[822] | 908 | return -1; |
---|
[839] | 909 | }else{ |
---|
[860] | 910 | #ifdef HPC_DEBUG |
---|
[854] | 911 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 912 | fflush(stderr); |
---|
[860] | 913 | #endif |
---|
[839] | 914 | int hasPassed=-1; |
---|
| 915 | char buf[11]; |
---|
| 916 | memset(&buf,0,11); |
---|
| 917 | while ( (rc=read(cl,buf,10)) ) { |
---|
| 918 | if(rc==0){ |
---|
| 919 | setMapInMaps(*main_conf,"lenv","message",_("Read closed")); |
---|
[862] | 920 | errorException (*main_conf, _("Read closed"), |
---|
[854] | 921 | "InternalError", NULL); |
---|
[860] | 922 | #ifdef HPC_DEBUG |
---|
[854] | 923 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 924 | fflush(stderr); |
---|
[860] | 925 | #endif |
---|
[902] | 926 | #ifdef USE_CALLBACK |
---|
[862] | 927 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 928 | #endif |
---|
[860] | 929 | removeReadLocks(main_conf); |
---|
| 930 | #ifdef HPC_DEBUG |
---|
[854] | 931 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 932 | fflush(stderr); |
---|
[860] | 933 | #endif |
---|
[822] | 934 | return -1; |
---|
[839] | 935 | }else{ |
---|
| 936 | if(rc<0){ |
---|
| 937 | setMapInMaps(*main_conf,"lenv","message",_("Read error")); |
---|
[862] | 938 | errorException (*main_conf, _("Read error"), |
---|
[854] | 939 | "InternalError", NULL); |
---|
[860] | 940 | #ifdef HPC_DEBUG |
---|
[854] | 941 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 942 | fflush(stderr); |
---|
[860] | 943 | #endif |
---|
[902] | 944 | #ifdef USE_CALLBACK |
---|
[862] | 945 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 946 | #endif |
---|
[860] | 947 | removeReadLocks(main_conf); |
---|
| 948 | #ifdef HPC_DEBUG |
---|
[854] | 949 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 950 | fflush(stderr); |
---|
[860] | 951 | #endif |
---|
[822] | 952 | return -1; |
---|
| 953 | } |
---|
[839] | 954 | } |
---|
| 955 | hasPassed=1; |
---|
| 956 | res=atoi(buf); |
---|
| 957 | unlink(sname); |
---|
[854] | 958 | free(sname); |
---|
| 959 | removeReadLocks(main_conf); |
---|
| 960 | |
---|
[839] | 961 | if(res==3){ |
---|
[860] | 962 | #ifdef HPC_DEBUG |
---|
[839] | 963 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 964 | fflush(stderr); |
---|
[860] | 965 | #endif |
---|
[902] | 966 | #ifdef USE_CALLBACK |
---|
[839] | 967 | invokeCallback(m,NULL,outputs,5,0); |
---|
[902] | 968 | #endif |
---|
[860] | 969 | #ifdef HPC_DEBUG |
---|
[839] | 970 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 971 | fflush(stderr); |
---|
[860] | 972 | #endif |
---|
| 973 | |
---|
| 974 | // Read informations provided by FinalizeHPC as a configuration file |
---|
| 975 | // then, remove the file. |
---|
| 976 | map* jobid=getMapFromMaps(*main_conf,"lenv","usid"); |
---|
| 977 | map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath"); |
---|
| 978 | char *filePath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+15)*sizeof(char)); |
---|
| 979 | sprintf(filePath,"%s/exec_status_%s",tmpPath->value,jobid->value); |
---|
[887] | 980 | maps* lm = (maps *) malloc (MAPS_SIZE); |
---|
| 981 | lm->child=NULL; |
---|
| 982 | lm->next=NULL; |
---|
[860] | 983 | int saved_stdout = dup (fileno (stdout)); |
---|
| 984 | dup2 (fileno (stderr), fileno (stdout)); |
---|
[887] | 985 | conf_read(filePath,lm); |
---|
[886] | 986 | //dumpMaps(m); |
---|
[860] | 987 | fflush(stdout); |
---|
| 988 | dup2 (saved_stdout, fileno (stdout)); |
---|
| 989 | close(saved_stdout); |
---|
| 990 | unlink(filePath); |
---|
| 991 | free(filePath); |
---|
[887] | 992 | addMapsToMaps(main_conf,lm); |
---|
| 993 | freeMaps(&lm); |
---|
| 994 | free(lm); |
---|
[860] | 995 | |
---|
[839] | 996 | input=*real_outputs; |
---|
| 997 | while(input!=NULL){ |
---|
| 998 | if(input->child==NULL){ |
---|
| 999 | map* generatedFile=getMap(input->content,"generated_file"); |
---|
| 1000 | if(generatedFile!=NULL){ |
---|
| 1001 | char* filename=strrchr(generatedFile->value,'/'); |
---|
| 1002 | char* targetPath=(char*)malloc((strlen(tmpPath->value)+strlen(filename)+2)*sizeof(char)); |
---|
| 1003 | sprintf(targetPath,"%s/%s",tmpPath->value,filename); |
---|
| 1004 | test=ssh_connect(*main_conf); |
---|
| 1005 | if(ssh_fetch(*main_conf,targetPath,generatedFile->value,ssh_get_cnt(m))==0){ |
---|
| 1006 | setMapInMaps(*real_outputs,input->name,"generated_file",targetPath); |
---|
| 1007 | free(targetPath); |
---|
| 1008 | }else{ |
---|
[886] | 1009 | map* hpcStdErr=getMapFromMaps(*main_conf,"henv","StdErr"); |
---|
| 1010 | // Added for using sacct in place of scontrol |
---|
| 1011 | char *sourcePath=NULL; |
---|
| 1012 | if(hpcStdErr!=NULL){ |
---|
| 1013 | sourcePath=(char*)malloc((strlen(targetPathMap->value)+strlen(hpcStdErr->value)+2)*sizeof(char)); |
---|
| 1014 | sprintf(sourcePath,"%s/%s",targetPathMap->value,hpcStdErr->value); |
---|
| 1015 | } |
---|
| 1016 | if(hpcStdErr!=NULL && sourcePath!=NULL && ssh_fetch(*main_conf,targetPath,sourcePath,ssh_get_cnt(m))==0){ |
---|
| 1017 | free(sourcePath); |
---|
[862] | 1018 | struct stat f_status; |
---|
| 1019 | int ts=stat(targetPath, &f_status); |
---|
| 1020 | if(ts==0) { |
---|
| 1021 | char* fcontent = NULL; |
---|
| 1022 | fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); |
---|
| 1023 | FILE* f=fopen(targetPath,"rb"); |
---|
| 1024 | fread(fcontent,f_status.st_size,1,f); |
---|
| 1025 | int fsize=f_status.st_size; |
---|
| 1026 | fcontent[fsize]=0; |
---|
| 1027 | fclose(f); |
---|
| 1028 | setMapInMaps(*main_conf,"lenv","message",fcontent); |
---|
| 1029 | free(fcontent); |
---|
| 1030 | }else{ |
---|
[886] | 1031 | char *tmpStr=(char*)malloc((strlen(targetPath)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char)); |
---|
| 1032 | sprintf(tmpStr,_("Unable to fetch the remote file for %s"),targetPath); |
---|
[862] | 1033 | setMapInMaps(*main_conf,"lenv","message",tmpStr); |
---|
| 1034 | free(tmpStr); |
---|
| 1035 | } |
---|
| 1036 | }else{ |
---|
| 1037 | char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char)); |
---|
| 1038 | sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename); |
---|
| 1039 | setMapInMaps(*main_conf,"lenv","message",tmpStr); |
---|
| 1040 | free(tmpStr); |
---|
| 1041 | } |
---|
[902] | 1042 | #ifdef USE_CALLBACK |
---|
[862] | 1043 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 1044 | #endif |
---|
[839] | 1045 | return SERVICE_FAILED; |
---|
[822] | 1046 | } |
---|
[886] | 1047 | } |
---|
[839] | 1048 | }else{ |
---|
| 1049 | map* generatedFile=getMap(input->content,"generated_file"); |
---|
[862] | 1050 | map* generatedUrl=getMap(input->content,"generated_url"); |
---|
[839] | 1051 | if(generatedFile!=NULL){ |
---|
| 1052 | char* filename=strrchr(generatedFile->value,'/'); |
---|
| 1053 | char* targetPath=(char*)malloc((strlen(tmpPath->value)+strlen(filename)+2)*sizeof(char)); |
---|
| 1054 | sprintf(targetPath,"%s/%s",tmpPath->value,filename); |
---|
| 1055 | test=ssh_connect(*main_conf); |
---|
| 1056 | if(ssh_fetch(*main_conf,targetPath,generatedFile->value,ssh_get_cnt(m))==0){ |
---|
| 1057 | maps* tmp=getMaps(*real_outputs,input->name); |
---|
[854] | 1058 | char serviceName[9]; |
---|
[839] | 1059 | freeMap(&tmp->content); |
---|
| 1060 | free(tmp->content); |
---|
| 1061 | tmp->content=NULL; |
---|
| 1062 | maps* output=getMaps(*real_outputs,input->name); |
---|
| 1063 | setMapInMaps(output->child,"download_link","generated_file",targetPath); |
---|
[862] | 1064 | setMapInMaps(output->child,"download_link","generated_url",generatedUrl->value); |
---|
[854] | 1065 | setMapInMaps(output->child,"download_link","storage",targetPath); |
---|
[839] | 1066 | setMapInMaps(output->child,"download_link","useMapserver","false"); |
---|
[854] | 1067 | setMapInMaps(output->child,"download_link","replicateStorageNext","true"); |
---|
| 1068 | setMapInMaps(output->child,"download_link","asReference","true"); |
---|
| 1069 | setMapInMaps(output->child,"download_link","inRequest","true"); |
---|
[851] | 1070 | setMapInMaps(output->child,"wms_link","generated_file",targetPath); |
---|
[854] | 1071 | setMapInMaps(output->child,"wms_link","storage",targetPath); |
---|
[851] | 1072 | setMapInMaps(output->child,"wms_link","useMapserver","true"); |
---|
| 1073 | setMapInMaps(output->child,"wms_link","msOgc","WMS"); |
---|
| 1074 | setMapInMaps(output->child,"wms_link","requestedMimeType","image/png"); |
---|
[854] | 1075 | setMapInMaps(output->child,"wms_link","asReference","true"); |
---|
| 1076 | if(getMaps(output->child,"wcs_link")!=NULL){ |
---|
| 1077 | sprintf(serviceName,"wcs_link"); |
---|
[862] | 1078 | setMapInMaps(output->child,"wcs_link","msOgc","WCS"); |
---|
| 1079 | }else{ |
---|
[854] | 1080 | sprintf(serviceName,"wfs_link"); |
---|
[862] | 1081 | setMapInMaps(output->child,"wfs_link","msOgc","WFS"); |
---|
| 1082 | } |
---|
[854] | 1083 | setMapInMaps(output->child,serviceName,"storage",targetPath); |
---|
| 1084 | setMapInMaps(output->child,serviceName,"generated_file",targetPath); |
---|
| 1085 | setMapInMaps(output->child,serviceName,"useMapserver","true"); |
---|
| 1086 | setMapInMaps(output->child,serviceName,"asReference","true"); |
---|
| 1087 | }else{ |
---|
[860] | 1088 | map* hpcStdErr=getMapFromMaps(*main_conf,"henv","StdErr"); |
---|
[886] | 1089 | char *sourcePath=NULL; |
---|
| 1090 | if(hpcStdErr!=NULL){ |
---|
| 1091 | dumpMap(hpcStdErr); |
---|
| 1092 | sourcePath=(char*)malloc((strlen(targetPathMap->value)+strlen(hpcStdErr->value)+2)*sizeof(char)); |
---|
| 1093 | sprintf(sourcePath,"%s/%s",targetPathMap->value,hpcStdErr->value); |
---|
| 1094 | } |
---|
| 1095 | if(hpcStdErr!=NULL && sourcePath!=NULL && ssh_fetch(*main_conf,targetPath,sourcePath,ssh_get_cnt(m))==0){ |
---|
| 1096 | free(sourcePath); |
---|
[860] | 1097 | struct stat f_status; |
---|
| 1098 | int ts=stat(targetPath, &f_status); |
---|
| 1099 | if(ts==0) { |
---|
| 1100 | char* fcontent = NULL; |
---|
| 1101 | fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); |
---|
| 1102 | FILE* f=fopen(targetPath,"rb"); |
---|
| 1103 | fread(fcontent,f_status.st_size,1,f); |
---|
| 1104 | int fsize=f_status.st_size; |
---|
| 1105 | fcontent[fsize]=0; |
---|
| 1106 | fclose(f); |
---|
| 1107 | setMapInMaps(*main_conf,"lenv","message",fcontent); |
---|
| 1108 | free(fcontent); |
---|
| 1109 | }else{ |
---|
[886] | 1110 | char *tmpStr=(char*)malloc((strlen(targetPath)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char)); |
---|
| 1111 | sprintf(tmpStr,_("Unable to fetch the remote file for %s"),targetPath); |
---|
[860] | 1112 | setMapInMaps(*main_conf,"lenv","message",tmpStr); |
---|
| 1113 | free(tmpStr); |
---|
| 1114 | } |
---|
| 1115 | }else{ |
---|
[886] | 1116 | char *tmpStr=(char*)malloc((strlen(sourcePath)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char)); |
---|
| 1117 | sprintf(tmpStr,_("Unable to fetch the remote file for %s"),sourcePath); |
---|
[860] | 1118 | setMapInMaps(*main_conf,"lenv","message",tmpStr); |
---|
| 1119 | free(tmpStr); |
---|
| 1120 | } |
---|
[902] | 1121 | #ifdef USE_CALLBACK |
---|
[860] | 1122 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 1123 | #endif |
---|
[854] | 1124 | return SERVICE_FAILED; |
---|
[839] | 1125 | } |
---|
[851] | 1126 | free(targetPath); |
---|
[839] | 1127 | } |
---|
[822] | 1128 | } |
---|
[839] | 1129 | input=input->next; |
---|
[822] | 1130 | } |
---|
[854] | 1131 | |
---|
| 1132 | }else{ |
---|
| 1133 | // Try to access remotely to the log file and return a more relevant error message |
---|
[862] | 1134 | setMapInMaps(*main_conf,"lenv","message",_("HPC Execution failed!")); |
---|
| 1135 | errorException (*main_conf, _("HPC Execution failed!"), |
---|
[854] | 1136 | "InternalError", NULL); |
---|
[860] | 1137 | #ifdef HPC_DEBUG |
---|
[854] | 1138 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 1139 | fflush(stderr); |
---|
[860] | 1140 | #endif |
---|
[902] | 1141 | #ifdef USE_CALLBACK |
---|
[862] | 1142 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 1143 | #endif |
---|
[860] | 1144 | #ifdef HPC_DEBUG |
---|
[854] | 1145 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 1146 | fflush(stderr); |
---|
[860] | 1147 | #endif |
---|
[822] | 1148 | } |
---|
| 1149 | } |
---|
[839] | 1150 | if(hasPassed<0){ |
---|
| 1151 | perror("Failed to read"); |
---|
| 1152 | setMapInMaps(*main_conf,"lenv","message",_("Unable to parse the value returned by remote execution")); |
---|
[862] | 1153 | errorException (*main_conf, _("Unable to parse the value returned by remote execution"), |
---|
[854] | 1154 | "InternalError", NULL); |
---|
[860] | 1155 | #ifdef HPC_DEBUG |
---|
[854] | 1156 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 1157 | fflush(stderr); |
---|
[860] | 1158 | #endif |
---|
[902] | 1159 | #ifdef USE_CALLBACK |
---|
[862] | 1160 | invokeCallback(*main_conf,NULL,NULL,7,0); |
---|
[902] | 1161 | #endif |
---|
[860] | 1162 | #ifdef HPC_DEBUG |
---|
[854] | 1163 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 1164 | fflush(stderr); |
---|
[860] | 1165 | #endif |
---|
[839] | 1166 | return SERVICE_FAILED; |
---|
| 1167 | } |
---|
| 1168 | } |
---|
[860] | 1169 | #ifdef HPC_DEBUG |
---|
[850] | 1170 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 1171 | fflush(stderr); |
---|
[860] | 1172 | #endif |
---|
[822] | 1173 | ssh_close(*main_conf); |
---|
[860] | 1174 | #ifdef HPC_DEBUG |
---|
[850] | 1175 | fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); |
---|
| 1176 | fflush(stderr); |
---|
[860] | 1177 | #endif |
---|
[822] | 1178 | return res; |
---|
| 1179 | } |
---|