Changeset 986 for trunk/zoo-project/zoo-kernel/zoo_service_loader.c
- Timestamp:
- Mar 9, 2021, 4:50:02 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r985 r986 2061 2061 errorException (NULL, _("Unable to load the oas.cfg file."), 2062 2062 "InternalError", NULL); 2063 free (m );2063 free (m1); 2064 2064 return 1; 2065 2065 } … … 2089 2089 setMapInMaps(m,"headers","Content-Type","application/json;charset=UTF-8"); 2090 2090 /* - Root url */ 2091 if(cgiContentLength==1){ 2091 if((strncasecmp(cgiRequestMethod,"post",4)==0 && 2092 (strstr(cgiQueryString,"/processes/")==NULL || 2093 strlen(cgiQueryString)<=11)) 2094 || 2095 (strncasecmp(cgiRequestMethod,"DELETE",6)==0 && 2096 (strstr(cgiQueryString,"/jobs/")==NULL || strlen(cgiQueryString)<=6)) ){ 2097 setMapInMaps(m,"lenv","status_code","405"); 2098 map* error=createMap("code","InvalidMethod"); 2099 addToMap(error,"message",_("The request method used to access the current path is not supported.")); 2100 printExceptionReportResponseJ(m,error); 2101 json_object_put(res); 2102 // TODO: cleanup memory 2103 return 1; 2104 } 2105 else if(cgiContentLength==1){ 2092 2106 if(strncasecmp(cgiRequestMethod,"GET",3)!=0){ 2093 2107 setMapInMaps(m,"lenv","status_code","405"); … … 2205 2219 else if(strstr(cgiQueryString,"/processes")==NULL && (strstr(cgiQueryString,"/jobs")!=NULL || strstr(cgiQueryString,"/jobs/")!=NULL)){ 2206 2220 /* - /jobs url */ 2207 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);2208 fflush(stderr);2209 2221 if(strncasecmp(cgiRequestMethod,"DELETE",6)==0) { 2210 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);2211 fflush(stderr);2212 2222 char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2213 2223 setMapInMaps(m,"lenv","gs_usid",jobId); 2214 2224 setMapInMaps(m,"lenv","file.statusFile",json_getStatusFilePath(m)); 2215 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);2216 fflush(stderr);2217 2225 runDismiss(m,jobId); 2218 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);2219 fflush(stderr);2220 2226 map* pmError=getMapFromMaps(m,"lenv","error"); 2221 2227 if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){ … … 2227 2233 res=createStatus(m,SERVICE_DISMISSED); 2228 2234 } 2229 fprintf(stderr,"%s %d \n",__FILE__,__LINE__);2230 fflush(stderr);2231 2235 } 2232 2236 else if(strcasecmp(cgiRequestMethod,"get")==0){ … … 2262 2266 //char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6); 2263 2267 jobId[strlen(jobId)-8]=0; 2264 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);2265 fflush(stderr);2266 2268 char *sid=getStatusId(m,jobId); 2267 2269 if(sid==NULL){ 2268 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);2269 fflush(stderr);2270 2270 map* error=createMap("code","NoSuchJob"); 2271 2271 addToMap(error,"message",_("The JobID from the request does not match any of the Jobs running on this server")); … … 2273 2273 return 1; 2274 2274 }else{ 2275 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);2276 fflush(stderr);2277 2275 if(isRunning(m,jobId)>0){ 2278 2276 map* error=createMap("code","ResultNotReady"); … … 2281 2279 return 1; 2282 2280 }else{ 2283 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);2284 fflush(stderr);2285 2281 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 2282 zStatStruct f_status; 2290 2283 int s=zStat(Url0, &f_status); 2291 2284 if(s==0 && f_status.st_size>0){ 2292 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,Url0);2293 fflush(stderr);2294 2295 2285 if(f_status.st_size>15){ 2296 2286 json_object* pjoTmp=json_readFile(m,Url0); … … 2358 2348 } 2359 2349 2360 }else if(strcasecmp(cgiRequestMethod,"post")==0 && (strcmp(cgiQueryString,"/jobs")==0 || strcmp(cgiQueryString,"/jobs/")==0)){ 2361 /* - /jobs Execution (POST) */ 2350 } 2351 } 2352 else{ 2353 service* s1=NULL; 2354 int t=0; 2355 if(strstr(cgiQueryString,"/processes/")==NULL){ 2356 map* error=createMap("code","BadRequest"); 2357 addToMap(error,"message",_("The ressource is not available")); 2358 //setMapInMaps(conf,"lenv","status_code","404 Bad Request"); 2359 printExceptionReportResponseJ(m,error); 2360 freeMaps (&m); 2361 free (m); 2362 free (REQUEST); 2363 xmlCleanupParser (); 2364 zooXmlCleanupNs (); 2365 return 1; 2366 }else if(strcasecmp(cgiRequestMethod,"post")==0){ 2367 /* - /processes/{processId} Execution (POST) */ 2362 2368 eres = SERVICE_STARTED; 2363 2369 initAllEnvironment(m,request_inputs,ntmp,"jrequest"); … … 2400 2406 if(json_object_object_get_ex(jobj,"id",&json_io)!=FALSE){ 2401 2407 cIdentifier=zStrdup(json_object_get_string(json_io)); 2408 }else{ 2409 if(strstr(cgiQueryString,"/processes/")!=NULL && strlen(cgiQueryString)>11) 2410 cIdentifier=zStrdup(strstr(cgiQueryString,"/processes/")+11); 2402 2411 } 2403 fprintf(stderr,"%s %d \n", __FILE__,__LINE__);2404 fflush(stderr);2405 2412 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 2413 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 2414 map* preference=getMapFromMaps(m,"renv","HTTP_PREFER"); 2413 2415 map* mode=getMap(request_inputs,"mode"); … … 2593 2595 2594 2596 }//else error 2595 2596 } 2597 else{ 2598 service* s1=NULL; 2599 int t=0; 2600 if(strstr(cgiQueryString,"/processes/")==NULL){ 2601 map* error=createMap("code","BadRequest"); 2602 addToMap(error,"message",_("The ressource is not available")); 2603 //setMapInMaps(conf,"lenv","status_code","404 Bad Request"); 2604 printExceptionReportResponseJ(m,error); 2605 freeMaps (&m); 2606 free (m); 2607 free (REQUEST); 2608 xmlCleanupParser (); 2609 zooXmlCleanupNs (); 2610 return 1; 2611 } else 2597 else 2612 2598 if(strstr(cgiQueryString,"/jobs")==NULL && strstr(cgiQueryString,"/jobs/")==NULL){ 2613 2599 /* - /processes/{id}/ */ … … 2647 2633 } 2648 2634 2649 fprintf(stderr,"%s %d \n", __FILE__,__LINE__);2650 fflush(stderr);2651 2635 fetchService(zooRegistry,m,&s1,request_inputs,ntmp,cIdentifier,printExceptionReportResponseJ); 2652 fprintf(stderr,"%s %d \n", __FILE__,__LINE__);2653 fflush(stderr);2654 2636 2655 2637 … … 3032 3014 3033 3015 fetchService(zooRegistry,m,&s1,request_inputs,ntmp,r_inputs->value,printExceptionReportResponse); 3034 /*3035 //*****************3036 // Fetch S13037 //*****************3038 map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value);3039 if (import != NULL && import->value != NULL) {3040 strncpy(tmps1, import->value, 1024);3041 setMapInMaps (m, "lenv", "Identifier", r_inputs->value);3042 setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);3043 }3044 else {3045 snprintf (tmps1, 1024, "%s/%s.zcfg", conf_dir, r_inputs->value);3046 #ifdef DEBUG3047 fprintf (stderr, "Trying to load %s\n", tmps1);3048 #endif3049 if (strstr (r_inputs->value, ".") != NULL)3050 {3051 char *identifier = zStrdup (r_inputs->value);3052 parseIdentifier (m, conf_dir, identifier, tmps1);3053 map *tmpMap = getMapFromMaps (m, "lenv", "metapath");3054 if (tmpMap != NULL)3055 addToMap (request_inputs, "metapath", tmpMap->value);3056 free (identifier);3057 }3058 else3059 {3060 setMapInMaps (m, "lenv", "Identifier", r_inputs->value);3061 setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);3062 }3063 }3064 3065 r_inputs = getMapFromMaps (m, "lenv", "Identifier");3066 3067 #ifdef META_DB3068 int metadb_id=_init_sql(m,"metadb");3069 //FAILED CONNECTING DB3070 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){3071 fprintf(stderr,"ERROR CONNECTING METADB\n");3072 }3073 if(metadb_id>=0)3074 s1=extractServiceFromDb(m,r_inputs->value,0);3075 //close_sql(m,0);3076 if(s1!=NULL){3077 inheritance(zooRegistry,&s1);3078 #ifdef USE_HPC3079 addNestedOutputs(&s1);3080 #endif3081 if(zooRegistry!=NULL){3082 freeRegistry(&zooRegistry);3083 free(zooRegistry);3084 }3085 }else /* Not found in MetaDB /{3086 #endif3087 s1 = createService();3088 if (s1 == NULL)3089 {3090 freeMaps (&m);3091 free (m);3092 if(zooRegistry!=NULL){3093 freeRegistry(&zooRegistry);3094 free(zooRegistry);3095 }3096 free (REQUEST);3097 free (SERVICE_URL);3098 return errorException (m, _("Unable to allocate memory"),3099 "InternalError", NULL);3100 }3101 3102 int saved_stdout = zDup (fileno (stdout));3103 zDup2 (fileno (stderr), fileno (stdout));3104 t = readServiceFile (m, tmps1, &s1, r_inputs->value);3105 if(t>=0){3106 inheritance(zooRegistry,&s1);3107 #ifdef USE_HPC3108 addNestedOutputs(&s1);3109 #endif3110 }3111 if(zooRegistry!=NULL){3112 freeRegistry(&zooRegistry);3113 free(zooRegistry);3114 }3115 fflush (stdout);3116 zDup2 (saved_stdout, fileno (stdout));3117 if (t < 0)3118 {3119 char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value));3120 sprintf (tmpMsg,3121 _3122 ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."),3123 r_inputs->value);3124 errorException (m, tmpMsg, "InvalidParameterValue", "identifier");3125 free (tmpMsg);3126 free (s1);3127 freeMaps (&m);3128 free (m);3129 free (REQUEST);3130 free (SERVICE_URL);3131 return 0;3132 }3133 zClose (saved_stdout);3134 #ifdef META_DB3135 }3136 #endif3137 //*****************3138 // End Fetch S13139 //*****************3140 */3141 3016 3142 3017 #ifdef DEBUG
Note: See TracChangeset
for help on using the changeset viewer.