Changeset 985 for trunk/zoo-project/zoo-kernel
- Timestamp:
- Mar 9, 2021, 10:00:04 AM (4 years ago)
- Location:
- trunk/zoo-project/zoo-kernel
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/server_internal.c
r982 r985 1143 1143 if(dirp!=NULL){ 1144 1144 while ((dp = readdir(dirp)) != NULL){ 1145 #ifdef DEBUG1146 fprintf(stderr,"File : %s searched : %s\n",dp->d_name,tmp);1147 #endif1148 1145 if(strstr(dp->d_name,pid)!=0){ 1149 1146 sprintf(fileName,"%s/%s",r_inputs->value,dp->d_name); … … 1164 1161 } 1165 1162 } 1166 map* pmStatusFile=getMapFromMaps(conf,"lenv","file.statusFile");1167 if(pmStatusFile!=NULL && zUnlink(pmStatusFile->value)!=0){1168 if(e_type==NULL || strncasecmp(e_type->value,"json",4)!=0)1169 errorException (conf,1170 _("The job cannot be removed, a file cannot be removed"),1171 "NoApplicableCode", NULL);1172 else{1173 setMapInMaps(conf,"lenv","error","true");1174 setMapInMaps(conf,"lenv","code","NoApplicableCode");1175 setMapInMaps(conf,"lenv","message",_("The job cannot be removed, a file cannot be removed"));1176 }1177 return;1178 }1179 1163 #ifdef RELY_ON_DB 1180 1164 removeService(conf,pid); 1181 1165 #endif 1182 1166 if(e_type==NULL || strncasecmp(e_type->value,"json",4)!=0){ 1183 /* No need to call 7_1 when an execution is dismissed.1184 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);1185 invokeCallback(conf,NULL,NULL,7,1);1186 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);1187 */1188 1167 map* statusInfo=createMap("JobID",pid); 1189 1168 addToMap(statusInfo,"Status","Dismissed"); -
trunk/zoo-project/zoo-kernel/service_json.c
r975 r985 287 287 json_object* prop1=json_object_new_object(); 288 288 json_object_object_add(prop1,"default",json_object_new_boolean(isDefault)); 289 json_object_object_add(prop1,"m imeType",json_object_new_string(tmpMap1->value));289 json_object_object_add(prop1,"mediaType",json_object_new_string(tmpMap1->value)); 290 290 tmpMap1=getMap(iot->content,"encoding"); 291 291 if(tmpMap1!=NULL) … … 1046 1046 json_object* res=json_object_new_array(); 1047 1047 map* tmpPath=getMapFromMaps(conf,"main","tmpPath"); 1048 map* oIdentifier=getMapFromMaps(conf,"lenv","oIdentifier");1049 char* cpath=(char*)malloc((strlen(tmpPath->value)+strlen(oIdentifier->value)+14)*sizeof(char));1050 sprintf(cpath,"%s/statusInfos/%s",tmpPath->value,oIdentifier->value);1051 1048 struct dirent *dp; 1052 DIR *dirp = opendir ( cpath);1049 DIR *dirp = opendir (tmpPath->value); 1053 1050 if(dirp!=NULL){ 1054 1051 while ((dp = readdir (dirp)) != NULL){ 1055 char* extn = strstr(dp->d_name, " .json");1052 char* extn = strstr(dp->d_name, "_status.json"); 1056 1053 if(extn!=NULL){ 1057 1054 char* tmpStr=zStrdup(dp->d_name); 1058 tmpStr[strlen(dp->d_name)-5]=0; 1059 json_object* cjob=json_object_new_object(); 1060 json_object_object_add(cjob,"id",json_object_new_string(tmpStr)); 1061 json_object *jobj=printJobStatus(conf,tmpStr); 1062 if(jobj!=NULL) 1063 json_object_object_add(cjob,"infos",jobj); 1064 free(tmpStr); 1055 tmpStr[strlen(dp->d_name)-12]=0; 1056 json_object* cjob=printJobStatus(conf,tmpStr); 1065 1057 json_object_array_add(res,cjob); 1066 1058 } … … 1121 1113 json_object* res3=json_object_new_object(); 1122 1114 if(tmpMap!=NULL) 1123 json_object_object_add(res3,"m imeType",json_object_new_string(tmpMap->value));1115 json_object_object_add(res3,"mediaType",json_object_new_string(tmpMap->value)); 1124 1116 else{ 1125 json_object_object_add(res3,"m imeType",json_object_new_string("text/plain"));1117 json_object_object_add(res3,"mediaType",json_object_new_string("text/plain")); 1126 1118 map* pmDataType=getMap(resu->content,"dataType"); 1127 1119 if(pmDataType!=NULL){ … … 1248 1240 json_object* res=json_object_new_array(); 1249 1241 map *tmpPath = getMapFromMaps (conf, "openapi", "rootUrl"); 1250 map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier");1251 1242 map *sessId = getMapFromMaps (conf, "lenv", "usid"); 1252 1243 if(sessId==NULL){ … … 1254 1245 } 1255 1246 char *Url0=(char*) malloc((strlen(tmpPath->value)+ 1256 strlen(cIdentifier->value)+1257 1247 strlen(sessId->value)+18)*sizeof(char)); 1258 1248 int needResult=-1; 1259 1249 char *message, *status; 1260 sprintf(Url0,"%s/ processes/%s/jobs/%s",1250 sprintf(Url0,"%s/jobs/%s", 1261 1251 tmpPath->value, 1262 cIdentifier->value,1263 1252 sessId->value); 1264 1253 if(getMapFromMaps(conf,"lenv","gs_location")==NULL) … … 1276 1265 free(Url0); 1277 1266 Url0=(char*) malloc((strlen(tmpPath->value)+ 1278 strlen( cIdentifier->value)+strlen(sessId->value)+1267 strlen(sessId->value)+ 1279 1268 25)*sizeof(char)); 1280 sprintf(Url0,"%s/ processes/%s/jobs/%s/results",1269 sprintf(Url0,"%s/jobs/%s/results", 1281 1270 tmpPath->value, 1282 cIdentifier->value,1283 1271 sessId->value); 1284 1272 json_object* val1=json_object_new_object(); … … 1305 1293 char* json_getStatusFilePath(maps* conf){ 1306 1294 map *tmpPath = getMapFromMaps (conf, "main", "tmpPath"); 1307 map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier");1308 1295 map *sessId = getMapFromMaps (conf, "lenv", "usid"); 1309 1296 if(sessId!=NULL){ … … 1313 1300 }else 1314 1301 sessId = getMapFromMaps (conf, "lenv", "gs_usid"); 1302 1315 1303 char *tmp1=(char*) malloc((strlen(tmpPath->value)+ 1316 strlen( cIdentifier->value)+14)*sizeof(char));1317 sprintf(tmp1,"%s/ statusInfos/%s",1304 strlen(sessId->value)+14)*sizeof(char)); 1305 sprintf(tmp1,"%s/%s_status.json", 1318 1306 tmpPath->value, 1319 cIdentifier->value);1320 if(zMkdir(tmp1) != 0 && errno != EEXIST){1321 fprintf(stderr,"Issue creating directory %s\n",tmp1);1322 return NULL;1323 }1324 tmp1=(char*) realloc(tmp1,(strlen(tmpPath->value)+1325 strlen(cIdentifier->value)+1326 strlen(sessId->value)+21)*sizeof(char));1327 int needResult=0;1328 char *message, *rstatus;1329 sprintf(tmp1,"%s/statusInfos/%s/%s.json",1330 tmpPath->value,1331 cIdentifier->value,1332 1307 sessId->value); 1333 1308 return tmp1; … … 1336 1311 char* getResultPath(maps* conf,char* jobId){ 1337 1312 map *tmpPath = getMapFromMaps (conf, "main", "tmpPath"); 1338 map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier");1339 1313 char *pacUrl=(char*) malloc((strlen(tmpPath->value)+ 1340 strlen(cIdentifier->value)+1341 1314 strlen(jobId)+8)*sizeof(char)); 1342 sprintf(pacUrl,"%s/%s_%s.json",tmpPath->value, 1343 cIdentifier->value,jobId); 1315 sprintf(pacUrl,"%s/%s.json",tmpPath->value,jobId); 1344 1316 return pacUrl; 1345 1317 } … … 1472 1444 if(sessId!=NULL) 1473 1445 json_object_object_add(res,"jobID",json_object_new_string(sessId->value)); 1446 1474 1447 json_object_object_add(res,"status",json_object_new_string(rstatus)); 1475 1448 map* mMap=getMapFromMaps(conf,"lenv","gs_message"); … … 1486 1459 json_object* res1=json_object_new_array(); 1487 1460 map *tmpPath = getMapFromMaps (conf, "openapi", "rootUrl"); 1488 map *cIdentifier = getMapFromMaps (conf, "lenv", "oIdentifier"); 1489 char *Url0=(char*) malloc((strlen(tmpPath->value)+ 1490 strlen(cIdentifier->value)+ 1491 17)*sizeof(char)); 1492 sprintf(Url0,"%s/processes/%s/jobs", 1493 tmpPath->value, 1494 cIdentifier->value); 1461 char *Url0=(char*) malloc((strlen(tmpPath->value)+17)*sizeof(char)); 1462 sprintf(Url0,"%s/jobs",tmpPath->value); 1495 1463 json_object* val=json_object_new_object(); 1496 1464 json_object_object_add(val,"title", -
trunk/zoo-project/zoo-kernel/sqlapi.c
r972 r985 565 565 return NULL; 566 566 OGRFeature *poFeature = NULL; 567 c onst char *tmp1;567 char *tmp1; 568 568 int hasRes=-1; 569 569 while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){ -
trunk/zoo-project/zoo-kernel/ulinet.c
r955 r985 32 32 #include <assert.h> 33 33 #include <ctype.h> 34 #include "fcgi_stdio.h"35 34 36 35 /** -
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r984 r985 443 443 } 444 444 445 446 /** 447 * Parse the ZOO-Service ZCFG to fill the service datastructure 448 * 449 * @param zooRegistry the populated registry 450 * @param m the maps pointer to the content of main.cfg file 451 * @param spService the pointer to the service pointer to be filled 452 * @param request_inputs the map pointer for http request inputs 453 * @param ntmp the path where the ZCFG files are stored 454 * @param cIdentifier the service identifier 455 * @param funcError the error function to be used in case of error 456 */ 457 int fetchService(registry* zooRegistry,maps* m,service** spService, map* request_inputs,char* ntmp,char* cIdentifier,void (funcError) (maps*, map*)){ 458 char tmps1[1024]; 459 map *r_inputs=NULL; 460 service* s1=*spService; 461 map* pmExecutionType=getMapFromMaps(m,"main","executionType"); 462 map* import = getMapFromMaps (m, IMPORTSERVICE, cIdentifier); 463 if (import != NULL && import->value != NULL) { 464 strncpy(tmps1, import->value, 1024); 465 setMapInMaps (m, "lenv", "Identifier", cIdentifier); 466 setMapInMaps (m, "lenv", "oIdentifier", cIdentifier); 467 } 468 else { 469 snprintf (tmps1, 1024, "%s/%s.zcfg", ntmp, cIdentifier); 470 #ifdef DEBUG 471 fprintf (stderr, "Trying to load %s\n", tmps1); 472 #endif 473 if (strstr (cIdentifier, ".") != NULL) 474 { 475 setMapInMaps (m, "lenv", "oIdentifier", cIdentifier); 476 char *identifier = zStrdup (cIdentifier); 477 parseIdentifier (m, ntmp, identifier, tmps1); 478 map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); 479 if (tmpMap != NULL) 480 addToMap (request_inputs, "metapath", tmpMap->value); 481 free (identifier); 482 } 483 else 484 { 485 setMapInMaps (m, "lenv", "oIdentifier", cIdentifier); 486 setMapInMaps (m, "lenv", "Identifier", cIdentifier); 487 } 488 } 489 490 r_inputs = getMapFromMaps (m, "lenv", "Identifier"); 491 492 #ifdef META_DB 493 int metadb_id=_init_sql(m,"metadb"); 494 //FAILED CONNECTING DB 495 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){ 496 fprintf(stderr,"ERROR CONNECTING METADB\n"); 497 } 498 if(metadb_id>=0) 499 *spService=extractServiceFromDb(m,cIdentifier,0); 500 if(s1!=NULL){ 501 inheritance(zooRegistry,spService); 502 #ifdef USE_HPC 503 addNestedOutputs(spService); 504 #endif 505 if(zooRegistry!=NULL){ 506 freeRegistry(&zooRegistry); 507 free(zooRegistry); 508 } 509 }else /* Not found in MetaDB */{ 510 #endif 511 *spService = createService(); 512 if (*spService == NULL) 513 { 514 freeMaps (&m); 515 free (m); 516 if(zooRegistry!=NULL){ 517 freeRegistry(&zooRegistry); 518 free(zooRegistry); 519 } 520 map* error=createMap("code","InternalError"); 521 if(pmExecutionType!=NULL && strncasecmp(pmExecutionType->value,"xml",3)==0){ 522 addToMap(error,"locator", "NULL"); 523 addToMap(error,"text",_("Unable to allocate memory")); 524 } 525 else{ 526 addToMap(error,"message",_("Unable to allocate memory")); 527 } 528 529 setMapInMaps(m,"lenv","status_code","404 Bad Request"); 530 funcError(m,error); 531 532 return 1; /*errorException (m, _("Unable to allocate memory"), 533 "InternalError", NULL);*/ 534 } 535 536 int saved_stdout = zDup (fileno (stdout)); 537 zDup2 (fileno (stderr), fileno (stdout)); 538 int t = readServiceFile (m, tmps1, spService, cIdentifier); 539 if(t>=0){ 540 inheritance(zooRegistry,spService); 541 #ifdef USE_HPC 542 addNestedOutputs(spService); 543 #endif 544 } 545 if(zooRegistry!=NULL){ 546 freeRegistry(&zooRegistry); 547 free(zooRegistry); 548 } 549 fflush(stderr); 550 fflush (stdout); 551 zDup2 (saved_stdout, fileno (stdout)); 552 zClose (saved_stdout); 553 if (t < 0) 554 { 555 r_inputs = getMapFromMaps (m, "lenv", "oIdentifier"); 556 if(r_inputs!=NULL){ 557 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); 558 sprintf (tmpMsg, 559 _ 560 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), 561 r_inputs->value); 562 map* error=createMap("code","NoSuchProcess"); 563 if(pmExecutionType!=NULL && strncasecmp(pmExecutionType->value,"xml",3)==0){ 564 addToMap(error,"locator", "identifier"); 565 addToMap(error,"text",tmpMsg); 566 addToMap(error,"code","InvalidParameterValue"); 567 } 568 else{ 569 addToMap(error,"message",tmpMsg); 570 } 571 //setMapInMaps(conf,"lenv","status_code","404 Bad Request"); 572 funcError(m,error); 573 574 //errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 575 free (tmpMsg); 576 free (*spService); 577 freeMaps (&m); 578 free (m); 579 return 1; 580 } 581 } 582 #ifdef META_DB 583 } 584 #endif 585 return 0; 586 } 445 587 446 588 /** … … 1923 2065 } 1924 2066 addMapsToMaps(&m,m1); 2067 freeMaps(&m1); 2068 free(m1); 1925 2069 map* pmTmp0=getMapFromMaps(m,"openapi","full_html_support"); 1926 2070 if(strstr(cgiQueryString,".html")==NULL && strstr(cgiAccept,"text/html")!=NULL && pmTmp0!=NULL && strncasecmp(pmTmp0->value,"true",4)==0){ … … 1928 2072 char* pacTmpUrl=NULL; 1929 2073 if(strcmp(cgiQueryString,"/")!=0){ 1930 1931 2074 pacTmpUrl=(char*)malloc((strlen(cgiQueryString)+strlen(pmTmpUrl->value)+6)*sizeof(char)); 2075 sprintf(pacTmpUrl,"%s%s.html",pmTmpUrl->value,cgiQueryString); 1932 2076 } 1933 2077 else{ … … 1946 2090 /* - Root url */ 1947 2091 if(cgiContentLength==1){ 2092 if(strncasecmp(cgiRequestMethod,"GET",3)!=0){ 2093 setMapInMaps(m,"lenv","status_code","405"); 2094 map* pamError=createMap("code","InvalidMethod"); 2095 const char* pccErr=_("This API does not support the method."); 2096 addToMap(pamError,"message",pccErr); 2097 printExceptionReportResponseJ(m,pamError); 2098 // TODO: cleanup memory 2099 return 1; 2100 } 1948 2101 map* tmpMap=getMapFromMaps(m,"main","serverAddress"); 1949 2102 json_object *res1=json_object_new_array(); 1950 const char* urls[4]={ 1951 "/","/api","/conformance","/processes" 1952 }; 2103 2104 map* pmVal=getMapFromMaps(m,"openapi","links"); 2105 char *orig=zStrdup(pmVal->value); 2106 char *saveptr; 2107 char *tmps = strtok_r (orig, ",", &saveptr); 1953 2108 map* tmpUrl=getMapFromMaps(m,"openapi","rootUrl"); 1954 for(int kk=0;kk<4;kk++){1955 maps* tmpMaps=getMaps(m, urls[kk]);2109 while(tmps!=NULL){ 2110 maps* tmpMaps=getMaps(m,tmps); 1956 2111 if(tmpMaps!=NULL){ 1957 2112 json_object *res2; 1958 2113 res2=mapToJson(tmpMaps->content); 1959 char* tmpStr=(char*) malloc((strlen(tmpUrl->value)+strlen( urls[kk])+2)*sizeof(char));1960 sprintf(tmpStr,"%s%s",tmpUrl->value, urls[kk]);2114 char* tmpStr=(char*) malloc((strlen(tmpUrl->value)+strlen(tmps)+2)*sizeof(char)); 2115 sprintf(tmpStr,"%s%s",tmpUrl->value,tmps); 1961 2116 json_object_object_add(res2,"href",json_object_new_string(tmpStr)); 1962 2117 free(tmpStr); … … 1967 2122 if(pmTmp!=NULL) 1968 2123 pacTitle=zStrdup(pmTmp->value); 1969 char* pacTmp=(char*) malloc((strlen( urls[kk])+6)*sizeof(char));1970 sprintf(pacTmp,"%s.html", urls[kk]);2124 char* pacTmp=(char*) malloc((strlen(tmps)+6)*sizeof(char)); 2125 sprintf(pacTmp,"%s.html",tmps); 1971 2126 tmpMaps=getMaps(m,pacTmp); 1972 2127 if(tmpMaps==NULL && strncasecmp(pacTmp,"/.html",6)==0) … … 1982 2137 tmpStr=(char*) malloc((strlen(tmpUrl->value)+12)*sizeof(char)); 1983 2138 sprintf(tmpStr,"%s/index.html",tmpUrl->value); 1984 }else{ 1985 tmpStr=(char*) malloc((strlen(tmpUrl->value)+strlen( urls[kk])+6)*sizeof(char));1986 sprintf(tmpStr,"%s%s.html",tmpUrl->value, urls[kk]);2139 }else{map* tmpUrl=getMapFromMaps(m,"openapi","rootUrl"); 2140 tmpStr=(char*) malloc((strlen(tmpUrl->value)+strlen(tmps)+6)*sizeof(char)); 2141 sprintf(tmpStr,"%s%s.html",tmpUrl->value,tmps); 1987 2142 } 1988 2143 json_object_object_add(res3,"href",json_object_new_string(tmpStr)); … … 1994 2149 free(pacTitle); 1995 2150 } 2151 tmps = strtok_r (NULL, ",", &saveptr); 1996 2152 } 2153 free(orig); 2154 1997 2155 map* pmTmp=getMapFromMaps(m,"identification","title"); 1998 2156 if(pmTmp!=NULL) … … 2044 2202 res=res3; 2045 2203 //json_object_object_add(res,"processes",res3); 2046 }else{ 2204 } 2205 else if(strstr(cgiQueryString,"/processes")==NULL && (strstr(cgiQueryString,"/jobs")!=NULL || strstr(cgiQueryString,"/jobs/")!=NULL)){ 2206 /* - /jobs url */ 2207 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 2208 fflush(stderr); 2209 if(strncasecmp(cgiRequestMethod,"DELETE",6)==0) { 2210 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 2211 fflush(stderr); 2212 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2213 setMapInMaps(m,"lenv","gs_usid",jobId); 2214 setMapInMaps(m,"lenv","file.statusFile",json_getStatusFilePath(m)); 2215 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 2216 fflush(stderr); 2217 runDismiss(m,jobId); 2218 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 2219 fflush(stderr); 2220 map* pmError=getMapFromMaps(m,"lenv","error"); 2221 if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){ 2222 printExceptionReportResponseJ(m,getMapFromMaps(m,"lenv","code")); 2223 return 1; 2224 } 2225 else{ 2226 setMapInMaps(m,"lenv","gs_location","false"); 2227 res=createStatus(m,SERVICE_DISMISSED); 2228 } 2229 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 2230 fflush(stderr); 2231 } 2232 else if(strcasecmp(cgiRequestMethod,"get")==0){ 2233 /* - /jobs List (GET) */ 2234 if(strlen(cgiQueryString)<=6) 2235 res=printJobList(m); 2236 else{ 2237 2238 2239 char* tmpUrl=strstr(cgiQueryString,"/jobs/"); 2240 if(tmpUrl!=NULL && strlen(tmpUrl)>6){ 2241 if(strncasecmp(cgiRequestMethod,"DELETE",6)==0){ 2242 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2243 setMapInMaps(m,"lenv","gs_usid",jobId); 2244 setMapInMaps(m,"lenv","file.statusFile",json_getStatusFilePath(m)); 2245 runDismiss(m,jobId); 2246 map* pmError=getMapFromMaps(m,"lenv","error"); 2247 if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){ 2248 printExceptionReportResponseJ(m,getMapFromMaps(m,"lenv","code")); 2249 return 1; 2250 } 2251 else{ 2252 setMapInMaps(m,"lenv","gs_location","false"); 2253 res=createStatus(m,SERVICE_DISMISSED); 2254 } 2255 }else{ 2256 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2257 if(strlen(jobId)==36){ 2258 res=printJobStatus(m,jobId); 2259 }else{ 2260 2261 // In case the service has run, then forward request to target result file 2262 //char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2263 jobId[strlen(jobId)-8]=0; 2264 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId); 2265 fflush(stderr); 2266 char *sid=getStatusId(m,jobId); 2267 if(sid==NULL){ 2268 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId); 2269 fflush(stderr); 2270 map* error=createMap("code","NoSuchJob"); 2271 addToMap(error,"message",_("The JobID from the request does not match any of the Jobs running on this server")); 2272 printExceptionReportResponseJ(m,error); 2273 return 1; 2274 }else{ 2275 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId); 2276 fflush(stderr); 2277 if(isRunning(m,jobId)>0){ 2278 map* error=createMap("code","ResultNotReady"); 2279 addToMap(error,"message",_("The job is still running.")); 2280 printExceptionReportResponseJ(m,error); 2281 return 1; 2282 }else{ 2283 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId); 2284 fflush(stderr); 2285 char *Url0=getResultPath(m,jobId); 2286 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,Url0); 2287 fflush(stderr); 2288 //map *cIdentifier = getMapFromMaps (m, "lenv", "oIdentifier"); 2289 zStatStruct f_status; 2290 int s=zStat(Url0, &f_status); 2291 if(s==0 && f_status.st_size>0){ 2292 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,Url0); 2293 fflush(stderr); 2294 2295 if(f_status.st_size>15){ 2296 json_object* pjoTmp=json_readFile(m,Url0); 2297 json_object* pjoCode=NULL; 2298 json_object* pjoMessage=NULL; 2299 if(pjoTmp!=NULL && 2300 json_object_object_get_ex(pjoTmp,"code",&pjoCode)!=FALSE && 2301 json_object_object_get_ex(pjoTmp,"description",&pjoMessage)!=FALSE){ 2302 map* error=createMap("code",json_object_get_string(pjoCode)); 2303 addToMap(error,"message",json_object_get_string(pjoMessage)); 2304 printExceptionReportResponseJ(m,error); 2305 return 1; 2306 }else{ 2307 2308 map* tmpPath = getMapFromMaps (m, "main", "tmpUrl"); 2309 Url0=(char*) realloc(Url0,(strlen(tmpPath->value)+ 2310 //strlen(cIdentifier->value)+ 2311 strlen(jobId)+8)*sizeof(char)); 2312 sprintf(Url0,"%s/%s.json",tmpPath->value,jobId); 2313 setMapInMaps(m,"headers","Location",Url0); 2314 } 2315 free(Url0); 2316 }else{ 2317 // Service Failed 2318 map* statusInfo=createMap("JobID",jobId); 2319 readFinalRes(m,jobId,statusInfo); 2320 { 2321 map* pmStatus=getMap(statusInfo,"status"); 2322 if(pmStatus!=NULL) 2323 setMapInMaps(m,"lenv","status",pmStatus->value); 2324 } 2325 char* tmpStr=_getStatus(m,jobId); 2326 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 2327 char *tmpStr1=zStrdup(tmpStr); 2328 char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1); 2329 free(tmpStr); 2330 tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0'; 2331 addToMap(statusInfo,"PercentCompleted",tmpStr1); 2332 addToMap(statusInfo,"Message",tmpStr0); 2333 setMapInMaps(m,"lenv","PercentCompleted",tmpStr1); 2334 setMapInMaps(m,"lenv","Message",tmpStr0); 2335 free(tmpStr0); 2336 free(tmpStr1); 2337 } 2338 map* error=createMap("code","NoApplicableCode"); 2339 addToMap(error,"message",_("The service failed to execute.")); 2340 printExceptionReportResponseJ(m,error); 2341 return 1; 2342 } 2343 2344 }else{ 2345 map* error=createMap("code","NoSuchJob"); 2346 addToMap(error,"message",_("The JobID seem to be running on this server but not for this process id")); 2347 printExceptionReportResponseJ(m,error); 2348 return 1; 2349 } 2350 } 2351 } 2352 2353 2354 } 2355 free(jobId); 2356 } 2357 } 2358 } 2359 2360 }else if(strcasecmp(cgiRequestMethod,"post")==0 && (strcmp(cgiQueryString,"/jobs")==0 || strcmp(cgiQueryString,"/jobs/")==0)){ 2361 /* - /jobs Execution (POST) */ 2362 eres = SERVICE_STARTED; 2363 initAllEnvironment(m,request_inputs,ntmp,"jrequest"); 2364 map* req=getMapFromMaps(m,"renv","jrequest"); 2365 json_object *jobj = NULL; 2366 const char *mystring = NULL; 2367 int slen = 0; 2368 enum json_tokener_error jerr; 2369 struct json_tokener* tok=json_tokener_new(); 2370 do { 2371 mystring = req->value; // get JSON string, e.g. read from file, etc... 2372 slen = strlen(mystring); 2373 jobj = json_tokener_parse_ex(tok, mystring, slen); 2374 } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue); 2375 if (jerr != json_tokener_success) { 2376 map* pamError=createMap("code","InvalidParameterValue"); 2377 const char* pcTmpErr=json_tokener_error_desc(jerr); 2378 const char* pccErr=_("ZOO-Kernel cannot parse your POST data: %s"); 2379 char* pacMessage=(char*)malloc((strlen(pcTmpErr)+strlen(pccErr)+1)*sizeof(char)); 2380 sprintf(pacMessage,pccErr,pcTmpErr); 2381 addToMap(pamError,"message",pacMessage); 2382 printExceptionReportResponseJ(m,pamError); 2383 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 2384 return 1; 2385 } 2386 if (tok->char_offset < slen){ 2387 map* pamError=createMap("code","InvalidParameterValue"); 2388 const char* pcTmpErr="None"; 2389 const char* pccErr=_("ZOO-Kernel cannot parse your POST data: %s"); 2390 char* pacMessage=(char*)malloc((strlen(pcTmpErr)+strlen(pccErr)+1)*sizeof(char)); 2391 sprintf(pacMessage,pccErr,pcTmpErr); 2392 addToMap(pamError,"message",pacMessage); 2393 printExceptionReportResponseJ(m,pamError); 2394 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 2395 return 1; 2396 } 2397 2398 json_object* json_io=NULL; 2399 char* cIdentifier=NULL; 2400 if(json_object_object_get_ex(jobj,"id",&json_io)!=FALSE){ 2401 cIdentifier=zStrdup(json_object_get_string(json_io)); 2402 } 2403 fprintf(stderr,"%s %d \n", __FILE__,__LINE__); 2404 fflush(stderr); 2405 fetchService(zooRegistry,m,&s1,request_inputs,ntmp,cIdentifier,printExceptionReportResponseJ); 2406 fprintf(stderr,"%s %d \n", __FILE__,__LINE__); 2407 fflush(stderr); 2408 //maps* inputs_real_format=NULL, *outputs_real_format= NULL; 2409 parseJRequest(m,s1,jobj,request_inputs,&request_input_real_format,&request_output_real_format); 2410 fprintf(stderr,"%s %d \n", __FILE__,__LINE__); 2411 fflush(stderr); 2412 map* preference=getMapFromMaps(m,"renv","HTTP_PREFER"); 2413 map* mode=getMap(request_inputs,"mode"); 2414 if((preference!=NULL && strcasecmp(preference->value,"respond-async")==0) || 2415 (mode!=NULL && strncasecmp(mode->value,"async",5)==0)) { 2416 int pid; 2417 #ifdef DEBUG 2418 fprintf (stderr, "\nPID : %d\n", cpid); 2419 #endif 2420 #ifndef WIN32 2421 pid = fork (); 2422 #else 2423 if (cgiSid == NULL) 2424 { 2425 createProcess (m, request_inputs, s1, NULL, cpid, 2426 request_input_real_format, 2427 request_output_real_format); 2428 pid = cpid; 2429 } 2430 else 2431 { 2432 pid = 0; 2433 cpid = atoi (cgiSid); 2434 updateStatus(m,0,_("Initializing")); 2435 } 2436 #endif 2437 if (pid > 0) 2438 { 2439 // 2440 // dady : 2441 // set status to SERVICE_ACCEPTED 2442 // 2443 #ifdef DEBUG 2444 fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid, 2445 zGetpid ()); 2446 #endif 2447 eres = SERVICE_ACCEPTED; 2448 createStatusFile(m,eres); 2449 //invokeBasicCallback(m,SERVICE_ACCEPTED); 2450 printHeaders(m); 2451 printf("Status: 201 Created \r\n\r\n"); 2452 return 1; 2453 } 2454 else if (pid == 0) 2455 { 2456 eres = SERVICE_STARTED; 2457 // 2458 // son : have to close the stdout, stdin and stderr to let the parent 2459 // process answer to http client. 2460 // 2461 map* oid = getMapFromMaps (m, "lenv", "oIdentifier"); 2462 map* usid = getMapFromMaps (m, "lenv", "uusid"); 2463 map* tmpm = getMapFromMaps (m, "lenv", "osid"); 2464 int cpid = atoi (tmpm->value); 2465 pid=cpid; 2466 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 2467 setMapInMaps (m, "lenv", "async","true"); 2468 map* r_inputs1 = createMap("ServiceName", s1->name); 2469 // Create the filename for the result file (.res) 2470 fbkpres = 2471 (char *) 2472 malloc ((strlen (r_inputs->value) + 2473 strlen (usid->value) + 7) * sizeof (char)); 2474 sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value); 2475 bmap = createMaps("status"); 2476 bmap->content=createMap("usid",usid->value); 2477 addToMap(bmap->content,"sid",tmpm->value); 2478 addIntToMap(bmap->content,"pid",zGetpid()); 2479 2480 // Create PID file referencing the OS process identifier 2481 fbkpid = 2482 (char *) 2483 malloc ((strlen (r_inputs->value) + 2484 strlen (usid->value) + 7) * sizeof (char)); 2485 sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value); 2486 setMapInMaps (m, "lenv", "file.pid", fbkpid); 2487 2488 f0 = freopen (fbkpid, "w+",stdout); 2489 printf("%d",zGetpid()); 2490 fflush(stdout); 2491 2492 // Create SID file referencing the semaphore name 2493 fbkp = 2494 (char *) 2495 malloc ((strlen (r_inputs->value) + strlen (oid->value) + 2496 strlen (usid->value) + 7) * sizeof (char)); 2497 sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value); 2498 setMapInMaps (m, "lenv", "file.sid", fbkp); 2499 FILE* f2 = freopen (fbkp, "w+",stdout); 2500 printf("%s",tmpm->value); 2501 fflush(f2); 2502 free(fbkp); 2503 2504 fbkp = 2505 (char *) 2506 malloc ((strlen (r_inputs->value) + 2507 strlen (usid->value) + 7) * sizeof (char)); 2508 sprintf (fbkp, "%s/%s.json", r_inputs->value, 2509 usid->value); 2510 setMapInMaps (m, "lenv", "file.responseInit", fbkp); 2511 flog = 2512 (char *) 2513 malloc ((strlen (r_inputs->value) + strlen (oid->value) + 2514 strlen (usid->value) + 13) * sizeof (char)); 2515 sprintf (flog, "%s/%s_%s_error.log", r_inputs->value, 2516 oid->value, usid->value); 2517 setMapInMaps (m, "lenv", "file.log", flog); 2518 #ifdef DEBUG 2519 fprintf (stderr, "RUN IN BACKGROUND MODE \n"); 2520 fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid, 2521 zGetpid ()); 2522 fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value); 2523 #endif 2524 freopen (flog, "w+", stderr); 2525 fflush (stderr); 2526 f0 = freopen (fbkp, "w+", stdout); 2527 rewind (stdout); 2528 #ifndef WIN32 2529 fclose (stdin); 2530 #endif 2531 #ifdef RELY_ON_DB 2532 init_sql(m); 2533 recordServiceStatus(m); 2534 #endif 2535 #ifdef USE_CALLBACK 2536 invokeCallback(m,NULL,NULL,0,0); 2537 #endif 2538 invokeBasicCallback(m,SERVICE_STARTED); 2539 createStatusFile(m,SERVICE_STARTED); 2540 fbkp1 = 2541 (char *) 2542 malloc ((strlen (r_inputs->value) + strlen (oid->value) + 2543 strlen (usid->value) + 15) * sizeof (char)); 2544 sprintf (fbkp1, "%s/%s_final_%s.json", r_inputs->value, 2545 oid->value, usid->value); 2546 setMapInMaps (m, "lenv", "file.responseFinal", fbkp1); 2547 2548 f1 = freopen (fbkp1, "w+", stdout); 2549 2550 map* serviceTypeMap=getMap(s1->content,"serviceType"); 2551 if(serviceTypeMap!=NULL) 2552 setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value); 2553 2554 char *flenv = 2555 (char *) 2556 malloc ((strlen (r_inputs->value) + 2557 strlen (usid->value) + 12) * sizeof (char)); 2558 sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value); 2559 maps* lenvMaps=getMaps(m,"lenv"); 2560 dumpMapsToFile(lenvMaps,flenv,1); 2561 free(flenv); 2562 2563 map* testMap=getMapFromMaps(m,"main","memory"); 2564 loadHttpRequests(m,request_input_real_format); 2565 2566 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0) 2567 return -1; 2568 loadServiceAndRun (&m, s1, request_inputs, 2569 &request_input_real_format, 2570 &request_output_real_format, &eres); 2571 setMapInMaps(m,"lenv","force","true"); 2572 createStatusFile(m,eres); 2573 setMapInMaps(m,"lenv","force","false"); 2574 setMapInMaps(m,"lenv","no-headers","true"); 2575 fflush(stdout); 2576 rewind(stdout); 2577 res=printJResult(m,s1,request_output_real_format,eres); 2578 const char* jsonStr0=json_object_to_json_string_ext(res,JSON_C_TO_STRING_PLAIN); 2579 if(getMapFromMaps(m,"lenv","jsonStr")==NULL) 2580 setMapInMaps(m,"lenv","jsonStr",jsonStr0); 2581 invokeBasicCallback(m,eres); 2582 } 2583 }else{ 2584 loadHttpRequests(m,request_input_real_format); 2585 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0) 2586 return -1; 2587 loadServiceAndRun (&m,s1,request_inputs, 2588 &request_input_real_format, 2589 &request_output_real_format,&eres); 2590 res=printJResult(m,s1,request_output_real_format,eres); 2591 } 2592 2593 2594 }//else error 2595 2596 } 2597 else{ 2047 2598 service* s1=NULL; 2048 2599 int t=0; … … 2061 2612 if(strstr(cgiQueryString,"/jobs")==NULL && strstr(cgiQueryString,"/jobs/")==NULL){ 2062 2613 /* - /processes/{id}/ */ 2063 DIR *dirp = opendir (ntmp);2614 //DIR *dirp = opendir (ntmp); 2064 2615 json_object *res3=json_object_new_object(); 2065 char *orig = zStrdup (strstr(cgiQueryString,"/processes/")+11); 2616 char *orig = NULL; 2617 orig = zStrdup (strstr(cgiQueryString,"/processes/")+11); 2066 2618 if(orig[strlen(orig)-1]=='/') 2067 2619 orig[strlen(orig)-1]=0; … … 2080 2632 } 2081 2633 res=json_object_get(res3); 2082 }else{ 2083 char* queryString=zStrdup(cgiQueryString); 2084 int len0=strlen(strstr(cgiQueryString,"/processes/")+11); 2085 int len1=strlen(cgiQueryString)-strlen(strstr(cgiQueryString,"/job")); 2086 char* cIdentifier=(char*)malloc((len1-10)*sizeof(char)); 2087 int cnt=0; 2088 for(int j=11;j<len1;j++){ 2089 cIdentifier[cnt]=cgiQueryString[j]; 2090 cIdentifier[cnt+1]=0; 2091 cnt++; 2634 }else{ 2635 char* cIdentifier=NULL; 2636 if(strstr(cgiQueryString,"/processes/")!=NULL){ 2637 2638 2639 int len0=strlen(strstr(cgiQueryString,"/processes/")+11); 2640 int len1=strlen(cgiQueryString)-strlen(strstr(cgiQueryString,"/job")); 2641 cIdentifier=(char*)malloc((len1-10)*sizeof(char)); 2642 int cnt=0; 2643 for(int j=11;j<len1;j++){ 2644 cIdentifier[cnt]=cgiQueryString[j]; 2645 cIdentifier[cnt+1]=0; 2646 cnt++; 2647 } 2648 2649 fprintf(stderr,"%s %d \n", __FILE__,__LINE__); 2650 fflush(stderr); 2651 fetchService(zooRegistry,m,&s1,request_inputs,ntmp,cIdentifier,printExceptionReportResponseJ); 2652 fprintf(stderr,"%s %d \n", __FILE__,__LINE__); 2653 fflush(stderr); 2654 2655 2092 2656 } 2093 char tmps1[1024]; 2094 map* import = getMapFromMaps (m, IMPORTSERVICE, cIdentifier); 2095 if (import != NULL && import->value != NULL) { 2096 strncpy(tmps1, import->value, 1024); 2097 setMapInMaps (m, "lenv", "Identifier", cIdentifier); 2098 setMapInMaps (m, "lenv", "oIdentifier", cIdentifier); 2099 } 2100 else { 2101 snprintf (tmps1, 1024, "%s/%s.zcfg", ntmp, cIdentifier); 2102 #ifdef DEBUG 2103 fprintf (stderr, "Trying to load %s\n", tmps1); 2104 #endif 2105 if (strstr (cIdentifier, ".") != NULL) 2106 { 2107 setMapInMaps (m, "lenv", "oIdentifier", cIdentifier); 2108 char *identifier = zStrdup (cIdentifier); 2109 parseIdentifier (m, ntmp, identifier, tmps1); 2110 map *tmpMap = getMapFromMaps (m, "lenv", "metapath"); 2111 if (tmpMap != NULL) 2112 addToMap (request_inputs, "metapath", tmpMap->value); 2113 free (identifier); 2114 } 2115 else 2116 { 2117 setMapInMaps (m, "lenv", "oIdentifier", cIdentifier); 2118 setMapInMaps (m, "lenv", "Identifier", cIdentifier); 2119 } 2120 } 2121 2122 r_inputs = getMapFromMaps (m, "lenv", "Identifier"); 2123 2124 #ifdef META_DB 2125 int metadb_id=_init_sql(m,"metadb"); 2126 //FAILED CONNECTING DB 2127 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){ 2128 fprintf(stderr,"ERROR CONNECTING METADB\n"); 2129 } 2130 if(metadb_id>=0) 2131 s1=extractServiceFromDb(m,cIdentifier,0); 2132 if(s1!=NULL){ 2133 inheritance(zooRegistry,&s1); 2134 #ifdef USE_HPC 2135 addNestedOutputs(&s1); 2136 #endif 2137 if(zooRegistry!=NULL){ 2138 freeRegistry(&zooRegistry); 2139 free(zooRegistry); 2140 } 2141 }else /* Not found in MetaDB */{ 2142 #endif 2143 s1 = createService(); 2144 if (s1 == NULL) 2145 { 2146 freeMaps (&m); 2147 free (m); 2148 if(zooRegistry!=NULL){ 2149 freeRegistry(&zooRegistry); 2150 free(zooRegistry); 2151 } 2152 free (REQUEST); 2153 free (SERVICE_URL); 2154 map* error=createMap("code","InternalError"); 2155 addToMap(error,"message",_("Unable to allocate memory")); 2156 setMapInMaps(m,"lenv","status_code","404 Bad Request"); 2157 printExceptionReportResponseJ(m,error); 2158 2159 return 1; /*errorException (m, _("Unable to allocate memory"), 2160 "InternalError", NULL);*/ 2161 } 2162 2163 int saved_stdout = zDup (fileno (stdout)); 2164 zDup2 (fileno (stderr), fileno (stdout)); 2165 t = readServiceFile (m, tmps1, &s1, cIdentifier); 2166 if(t>=0){ 2167 inheritance(zooRegistry,&s1); 2168 #ifdef USE_HPC 2169 addNestedOutputs(&s1); 2170 #endif 2171 } 2172 if(zooRegistry!=NULL){ 2173 freeRegistry(&zooRegistry); 2174 free(zooRegistry); 2175 } 2176 fflush(stderr); 2177 fflush (stdout); 2178 zDup2 (saved_stdout, fileno (stdout)); 2179 zClose (saved_stdout); 2180 if (t < 0) 2181 { 2182 r_inputs = getMapFromMaps (m, "lenv", "oIdentifier"); 2183 if(r_inputs!=NULL){ 2184 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value)); 2185 sprintf (tmpMsg, 2186 _ 2187 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."), 2188 r_inputs->value); 2189 map* error=createMap("code","NoSuchProcess"); 2190 addToMap(error,"message",tmpMsg); 2191 //setMapInMaps(conf,"lenv","status_code","404 Bad Request"); 2192 printExceptionReportResponseJ(m,error); 2193 2194 //errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 2195 free (tmpMsg); 2196 free (s1); 2197 freeMaps (&m); 2198 free (m); 2199 free (REQUEST); 2200 free (SERVICE_URL); 2201 return 0; 2202 } 2203 } 2204 #ifdef META_DB 2205 } 2206 #endif 2207 if(strstr(cgiQueryString,"/jobs/")!=NULL && strlen(strstr(cgiQueryString,"/jobs/"))>6) { 2208 /* - /jobs/{jobID} and /jobs/{jobID}/result urls */ 2209 if(strstr(cgiQueryString,"/results")!=NULL){ 2210 // In case the service has run, then forward request to target result file 2211 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2212 jobId[strlen(jobId)-8]=0; 2213 char *sid=getStatusId(m,jobId); 2214 if(sid==NULL){ 2215 map* error=createMap("code","NoSuchJob"); 2216 addToMap(error,"message",_("The JobID from the request does not match any of the Jobs running on this server")); 2217 printExceptionReportResponseJ(m,error); 2218 return 1; 2219 }else{ 2220 if(isRunning(m,jobId)>0){ 2221 map* error=createMap("code","ResultNotReady"); 2222 addToMap(error,"message",_("The job is still running.")); 2223 printExceptionReportResponseJ(m,error); 2224 return 1; 2225 }else{ 2226 char *Url0=getResultPath(m,jobId); 2227 map *cIdentifier = getMapFromMaps (m, "lenv", "oIdentifier"); 2228 zStatStruct f_status; 2229 int s=zStat(Url0, &f_status); 2230 if(s==0 && f_status.st_size>0){ 2231 if(f_status.st_size>15){ 2232 json_object* pjoTmp=json_readFile(m,Url0); 2233 json_object* pjoCode=NULL; 2234 json_object* pjoMessage=NULL; 2235 if(pjoTmp!=NULL && 2236 json_object_object_get_ex(pjoTmp,"code",&pjoCode)!=FALSE && 2237 json_object_object_get_ex(pjoTmp,"description",&pjoMessage)!=FALSE){ 2238 map* error=createMap("code",json_object_get_string(pjoCode)); 2239 addToMap(error,"message",json_object_get_string(pjoMessage)); 2240 printExceptionReportResponseJ(m,error); 2241 return 1; 2242 }else{ 2243 2244 map* tmpPath = getMapFromMaps (m, "main", "tmpUrl"); 2245 Url0=(char*) realloc(Url0,(strlen(tmpPath->value)+ 2246 strlen(cIdentifier->value)+ 2247 strlen(jobId)+8)*sizeof(char)); 2248 sprintf(Url0,"%s/%s_%s.json",tmpPath->value, 2249 cIdentifier->value,jobId); 2250 setMapInMaps(m,"headers","Location",Url0); 2251 } 2252 free(Url0); 2253 }else{ 2254 // Service Failed 2255 map* statusInfo=createMap("JobID",jobId); 2256 readFinalRes(m,jobId,statusInfo); 2257 { 2258 map* pmStatus=getMap(statusInfo,"status"); 2259 if(pmStatus!=NULL) 2260 setMapInMaps(m,"lenv","status",pmStatus->value); 2261 } 2262 char* tmpStr=_getStatus(m,jobId); 2263 if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){ 2264 char *tmpStr1=zStrdup(tmpStr); 2265 char *tmpStr0=zStrdup(strstr(tmpStr,"|")+1); 2266 free(tmpStr); 2267 tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0'; 2268 addToMap(statusInfo,"PercentCompleted",tmpStr1); 2269 addToMap(statusInfo,"Message",tmpStr0); 2270 setMapInMaps(m,"lenv","PercentCompleted",tmpStr1); 2271 setMapInMaps(m,"lenv","Message",tmpStr0); 2272 free(tmpStr0); 2273 free(tmpStr1); 2274 } 2275 map* error=createMap("code","NoApplicableCode"); 2276 addToMap(error,"message",_("The service failed to execute.")); 2277 printExceptionReportResponseJ(m,error); 2278 return 1; 2279 } 2280 2281 }else{ 2282 map* error=createMap("code","NoSuchJob"); 2283 addToMap(error,"message",_("The JobID seem to be running on this server but not for this process id")); 2284 printExceptionReportResponseJ(m,error); 2285 return 1; 2286 } 2287 } 2288 } 2289 }else{ 2290 char* tmpUrl=strstr(cgiQueryString,"/jobs/"); 2291 if(tmpUrl!=NULL && strlen(tmpUrl)>6){ 2292 if(strncasecmp(cgiRequestMethod,"DELETE",6)==0){ 2293 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2294 setMapInMaps(m,"lenv","gs_usid",jobId); 2295 setMapInMaps(m,"lenv","file.statusFile",json_getStatusFilePath(m)); 2296 runDismiss(m,jobId); 2297 map* pmError=getMapFromMaps(m,"lenv","error"); 2298 if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){ 2299 printExceptionReportResponseJ(m,getMapFromMaps(m,"lenv","code")); 2300 return 1; 2301 } 2302 else{ 2303 setMapInMaps(m,"lenv","gs_location","false"); 2304 res=createStatus(m,SERVICE_DISMISSED); 2305 } 2306 }else{ 2307 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2308 res=printJobStatus(m,jobId); 2309 free(jobId); 2310 } 2311 } 2312 } 2313 }else{ 2314 /* - /jobs url */ 2315 if(strcasecmp(cgiRequestMethod,"get")==0){ 2316 /* - /jobs List (GET) */ 2317 res=printJobList(m); 2318 }else if(strcasecmp(cgiRequestMethod,"post")==0){ 2319 /* - /jobs Execution (POST) */ 2320 eres = SERVICE_STARTED; 2321 initAllEnvironment(m,request_inputs,ntmp,"jrequest"); 2322 map* req=getMapFromMaps(m,"renv","jrequest"); 2323 json_object *jobj = NULL; 2324 const char *mystring = NULL; 2325 int slen = 0; 2326 enum json_tokener_error jerr; 2327 struct json_tokener* tok=json_tokener_new(); 2328 do { 2329 mystring = req->value; // get JSON string, e.g. read from file, etc... 2330 slen = strlen(mystring); 2331 jobj = json_tokener_parse_ex(tok, mystring, slen); 2332 } while ((jerr = json_tokener_get_error(tok)) == json_tokener_continue); 2333 if (jerr != json_tokener_success) { 2334 map* pamError=createMap("code","InvalidParameterValue"); 2335 const char* pcTmpErr=json_tokener_error_desc(jerr); 2336 const char* pccErr=_("ZOO-Kernel cannot parse your POST data: %s"); 2337 char* pacMessage=(char*)malloc((strlen(pcTmpErr)+strlen(pccErr)+1)*sizeof(char)); 2338 sprintf(pacMessage,pccErr,pcTmpErr); 2339 addToMap(pamError,"message",pacMessage); 2340 printExceptionReportResponseJ(m,pamError); 2341 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 2342 return 1; 2343 } 2344 if (tok->char_offset < slen){ 2345 map* pamError=createMap("code","InvalidParameterValue"); 2346 const char* pcTmpErr="None"; 2347 const char* pccErr=_("ZOO-Kernel cannot parse your POST data: %s"); 2348 char* pacMessage=(char*)malloc((strlen(pcTmpErr)+strlen(pccErr)+1)*sizeof(char)); 2349 sprintf(pacMessage,pccErr,pcTmpErr); 2350 addToMap(pamError,"message",pacMessage); 2351 printExceptionReportResponseJ(m,pamError); 2352 fprintf(stderr, "Error: %s\n", json_tokener_error_desc(jerr)); 2353 return 1; 2354 } 2355 //maps* inputs_real_format=NULL, *outputs_real_format= NULL; 2356 parseJRequest(m,s1,jobj,request_inputs,&request_input_real_format,&request_output_real_format); 2357 map* preference=getMapFromMaps(m,"renv","HTTP_PREFER"); 2358 map* mode=getMap(request_inputs,"mode"); 2359 if((preference!=NULL && strcasecmp(preference->value,"respond-async")==0) || 2360 (mode!=NULL && strncasecmp(mode->value,"async",5)==0)) { 2361 int pid; 2362 #ifdef DEBUG 2363 fprintf (stderr, "\nPID : %d\n", cpid); 2364 #endif 2365 #ifndef WIN32 2366 pid = fork (); 2367 #else 2368 if (cgiSid == NULL) 2369 { 2370 createProcess (m, request_inputs, s1, NULL, cpid, 2371 request_input_real_format, 2372 request_output_real_format); 2373 pid = cpid; 2374 } 2375 else 2376 { 2377 pid = 0; 2378 cpid = atoi (cgiSid); 2379 updateStatus(m,0,_("Initializing")); 2380 } 2381 #endif 2382 if (pid > 0) 2383 { 2384 // 2385 // dady : 2386 // set status to SERVICE_ACCEPTED 2387 // 2388 #ifdef DEBUG 2389 fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid, 2390 zGetpid ()); 2391 #endif 2392 eres = SERVICE_ACCEPTED; 2393 createStatusFile(m,eres); 2394 //invokeBasicCallback(m,SERVICE_ACCEPTED); 2395 printHeaders(m); 2396 printf("Status: 201 Created \r\n\r\n"); 2397 return 1; 2398 } 2399 else if (pid == 0) 2400 { 2401 eres = SERVICE_STARTED; 2402 // 2403 // son : have to close the stdout, stdin and stderr to let the parent 2404 // process answer to http client. 2405 // 2406 map* oid = getMapFromMaps (m, "lenv", "oIdentifier"); 2407 map* usid = getMapFromMaps (m, "lenv", "uusid"); 2408 map* tmpm = getMapFromMaps (m, "lenv", "osid"); 2409 int cpid = atoi (tmpm->value); 2410 pid=cpid; 2411 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 2412 setMapInMaps (m, "lenv", "async","true"); 2413 map* r_inputs1 = createMap("ServiceName", s1->name); 2414 // Create the filename for the result file (.res) 2415 fbkpres = 2416 (char *) 2417 malloc ((strlen (r_inputs->value) + 2418 strlen (usid->value) + 7) * sizeof (char)); 2419 sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value); 2420 bmap = createMaps("status"); 2421 bmap->content=createMap("usid",usid->value); 2422 addToMap(bmap->content,"sid",tmpm->value); 2423 addIntToMap(bmap->content,"pid",zGetpid()); 2657 2424 2658 2425 // Create PID file referencing the OS process identifier2426 fbkpid =2427 (char *)2428 malloc ((strlen (r_inputs->value) +2429 strlen (usid->value) + 7) * sizeof (char));2430 sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value);2431 setMapInMaps (m, "lenv", "file.pid", fbkpid);2432 2433 f0 = freopen (fbkpid, "w+",stdout);2434 printf("%d",zGetpid());2435 fflush(stdout);2436 2437 // Create SID file referencing the semaphore name2438 fbkp =2439 (char *)2440 malloc ((strlen (r_inputs->value) + strlen (oid->value) +2441 strlen (usid->value) + 7) * sizeof (char));2442 sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value);2443 setMapInMaps (m, "lenv", "file.sid", fbkp);2444 FILE* f2 = freopen (fbkp, "w+",stdout);2445 printf("%s",tmpm->value);2446 fflush(f2);2447 free(fbkp);2448 2449 fbkp =2450 (char *)2451 malloc ((strlen (r_inputs->value) + strlen (oid->value) +2452 strlen (usid->value) + 7) * sizeof (char));2453 sprintf (fbkp, "%s/%s_%s.json", r_inputs->value, oid->value,2454 usid->value);2455 setMapInMaps (m, "lenv", "file.responseInit", fbkp);2456 flog =2457 (char *)2458 malloc ((strlen (r_inputs->value) + strlen (oid->value) +2459 strlen (usid->value) + 13) * sizeof (char));2460 sprintf (flog, "%s/%s_%s_error.log", r_inputs->value,2461 oid->value, usid->value);2462 setMapInMaps (m, "lenv", "file.log", flog);2463 #ifdef DEBUG2464 fprintf (stderr, "RUN IN BACKGROUND MODE \n");2465 fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,2466 zGetpid ());2467 fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);2468 #endif2469 freopen (flog, "w+", stderr);2470 fflush (stderr);2471 f0 = freopen (fbkp, "w+", stdout);2472 rewind (stdout);2473 #ifndef WIN322474 fclose (stdin);2475 #endif2476 #ifdef RELY_ON_DB2477 init_sql(m);2478 recordServiceStatus(m);2479 #endif2480 #ifdef USE_CALLBACK2481 invokeCallback(m,NULL,NULL,0,0);2482 #endif2483 invokeBasicCallback(m,SERVICE_STARTED);2484 createStatusFile(m,SERVICE_STARTED);2485 fbkp1 =2486 (char *)2487 malloc ((strlen (r_inputs->value) + strlen (oid->value) +2488 strlen (usid->value) + 15) * sizeof (char));2489 sprintf (fbkp1, "%s/%s_final_%s.json", r_inputs->value,2490 oid->value, usid->value);2491 setMapInMaps (m, "lenv", "file.responseFinal", fbkp1);2492 2493 f1 = freopen (fbkp1, "w+", stdout);2494 2495 map* serviceTypeMap=getMap(s1->content,"serviceType");2496 if(serviceTypeMap!=NULL)2497 setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value);2498 2499 char *flenv =2500 (char *)2501 malloc ((strlen (r_inputs->value) +2502 strlen (usid->value) + 12) * sizeof (char));2503 sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value);2504 maps* lenvMaps=getMaps(m,"lenv");2505 dumpMapsToFile(lenvMaps,flenv,1);2506 free(flenv);2507 2508 map* testMap=getMapFromMaps(m,"main","memory");2509 loadHttpRequests(m,request_input_real_format);2510 2511 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0)2512 return -1;2513 loadServiceAndRun (&m, s1, request_inputs,2514 &request_input_real_format,2515 &request_output_real_format, &eres);2516 setMapInMaps(m,"lenv","force","true");2517 createStatusFile(m,eres);2518 setMapInMaps(m,"lenv","force","false");2519 setMapInMaps(m,"lenv","no-headers","true");2520 fflush(stdout);2521 rewind(stdout);2522 res=printJResult(m,s1,request_output_real_format,eres);2523 const char* jsonStr0=json_object_to_json_string_ext(res,JSON_C_TO_STRING_PLAIN);2524 if(getMapFromMaps(m,"lenv","jsonStr")==NULL)2525 setMapInMaps(m,"lenv","jsonStr",jsonStr0);2526 invokeBasicCallback(m,eres);2527 }2528 }else{2529 loadHttpRequests(m,request_input_real_format);2530 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,NULL)<0)2531 return -1;2532 loadServiceAndRun (&m,s1,request_inputs,2533 &request_input_real_format,2534 &request_output_real_format,&eres);2535 res=printJResult(m,s1,request_output_real_format,eres);2536 }2537 2538 2539 }//else error2540 2541 }2542 2659 } 2660 2543 2661 } 2544 2662 map* pmHasPrinted=getMapFromMaps(m,"lenv","hasPrinted"); … … 2910 3028 } 2911 3029 s1 = NULL; 2912 3030 2913 3031 r_inputs = getMap (request_inputs, "Identifier"); 3032 3033 fetchService(zooRegistry,m,&s1,request_inputs,ntmp,r_inputs->value,printExceptionReportResponse); 3034 /* 3035 //***************** 3036 // Fetch S1 3037 //***************** 2914 3038 map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value); 2915 3039 if (import != NULL && import->value != NULL) { … … 2959 3083 free(zooRegistry); 2960 3084 } 2961 }else /* Not found in MetaDB */{3085 }else /* Not found in MetaDB /{ 2962 3086 #endif 2963 3087 s1 = createService(); … … 3011 3135 } 3012 3136 #endif 3137 //***************** 3138 // End Fetch S1 3139 //***************** 3140 */ 3013 3141 3014 3142 #ifdef DEBUG
Note: See TracChangeset
for help on using the changeset viewer.