Ignore:
Timestamp:
Mar 9, 2021, 10:00:04 AM (3 years ago)
Author:
djay
Message:

Move jobs management and execution endpoint from /processes/{procssId}/jobs to /jobs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r984 r985  
    443443}
    444444
     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 */
     457int 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}
    445587
    446588/**
     
    19232065      }
    19242066    addMapsToMaps(&m,m1);
     2067    freeMaps(&m1);
     2068    free(m1);
    19252069    map* pmTmp0=getMapFromMaps(m,"openapi","full_html_support");
    19262070    if(strstr(cgiQueryString,".html")==NULL && strstr(cgiAccept,"text/html")!=NULL && pmTmp0!=NULL && strncasecmp(pmTmp0->value,"true",4)==0){
     
    19282072      char* pacTmpUrl=NULL;
    19292073      if(strcmp(cgiQueryString,"/")!=0){
    1930          pacTmpUrl=(char*)malloc((strlen(cgiQueryString)+strlen(pmTmpUrl->value)+6)*sizeof(char));
    1931          sprintf(pacTmpUrl,"%s%s.html",pmTmpUrl->value,cgiQueryString);
     2074        pacTmpUrl=(char*)malloc((strlen(cgiQueryString)+strlen(pmTmpUrl->value)+6)*sizeof(char));
     2075        sprintf(pacTmpUrl,"%s%s.html",pmTmpUrl->value,cgiQueryString);
    19322076      }
    19332077      else{
     
    19462090    /* - Root url */
    19472091    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      }
    19482101      map* tmpMap=getMapFromMaps(m,"main","serverAddress");
    19492102      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);
    19532108      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);
    19562111        if(tmpMaps!=NULL){
    19572112          json_object *res2;
    19582113          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);
    19612116          json_object_object_add(res2,"href",json_object_new_string(tmpStr));
    19622117          free(tmpStr);
     
    19672122          if(pmTmp!=NULL)
    19682123            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);
    19712126          tmpMaps=getMaps(m,pacTmp);
    19722127          if(tmpMaps==NULL && strncasecmp(pacTmp,"/.html",6)==0)
     
    19822137              tmpStr=(char*) malloc((strlen(tmpUrl->value)+12)*sizeof(char));
    19832138              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);
    19872142            }
    19882143            json_object_object_add(res3,"href",json_object_new_string(tmpStr));
     
    19942149            free(pacTitle);       
    19952150        }
     2151        tmps = strtok_r (NULL, ",", &saveptr);
    19962152      }
     2153      free(orig);
     2154     
    19972155      map* pmTmp=getMapFromMaps(m,"identification","title");
    19982156      if(pmTmp!=NULL)
     
    20442202      res=res3;
    20452203      //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{
    20472598      service* s1=NULL;
    20482599      int t=0;
     
    20612612        if(strstr(cgiQueryString,"/jobs")==NULL && strstr(cgiQueryString,"/jobs/")==NULL){
    20622613          /* - /processes/{id}/ */
    2063           DIR *dirp = opendir (ntmp);
     2614          //DIR *dirp = opendir (ntmp);
    20642615          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);
    20662618          if(orig[strlen(orig)-1]=='/')
    20672619            orig[strlen(orig)-1]=0;
     
    20802632          }
    20812633          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
    20922656          }
    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
    24242658         
    2425                     // Create PID file referencing the OS process identifier
    2426                     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 name
    2438                     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 DEBUG
    2464                     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 #endif
    2469                     freopen (flog, "w+", stderr);
    2470                     fflush (stderr);
    2471                     f0 = freopen (fbkp, "w+", stdout);
    2472                     rewind (stdout);
    2473 #ifndef WIN32
    2474                     fclose (stdin);
    2475 #endif
    2476 #ifdef RELY_ON_DB
    2477                     init_sql(m);
    2478                     recordServiceStatus(m);
    2479 #endif
    2480 #ifdef USE_CALLBACK
    2481                     invokeCallback(m,NULL,NULL,0,0);
    2482 #endif
    2483                     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 error
    2540            
    2541           }
    25422659        }
     2660
    25432661    }
    25442662    map* pmHasPrinted=getMapFromMaps(m,"lenv","hasPrinted");
     
    29103028    }
    29113029    s1 = NULL;
    2912  
     3030
    29133031    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    //*****************
    29143038    map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value);
    29153039    if (import != NULL && import->value != NULL) {
     
    29593083        free(zooRegistry);
    29603084      }
    2961     }else /* Not found in MetaDB */{
     3085    }else /* Not found in MetaDB /{
    29623086#endif
    29633087      s1 = createService();
     
    30113135    }
    30123136#endif
     3137    //*****************
     3138    // End Fetch S1
     3139    //*****************
     3140*/
    30133141 
    30143142#ifdef DEBUG
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png