Ignore:
Timestamp:
Mar 9, 2021, 4:50:02 PM (3 years ago)
Author:
djay
Message:

Move the execute endpoint to /processes/{processID}. Fixes in oas.cfg: use opengeospatial/ogcapi-processes github repo for schemas URLs.

File:
1 edited

Legend:

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

    r985 r986  
    20612061        errorException (NULL, _("Unable to load the oas.cfg file."),
    20622062                        "InternalError", NULL);
    2063         free (m);
     2063        free (m1);
    20642064        return 1;
    20652065      }
     
    20892089    setMapInMaps(m,"headers","Content-Type","application/json;charset=UTF-8");
    20902090    /* - 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){
    20922106      if(strncasecmp(cgiRequestMethod,"GET",3)!=0){
    20932107        setMapInMaps(m,"lenv","status_code","405");
     
    22052219    else if(strstr(cgiQueryString,"/processes")==NULL && (strstr(cgiQueryString,"/jobs")!=NULL || strstr(cgiQueryString,"/jobs/")!=NULL)){
    22062220      /* - /jobs url */
    2207       fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    2208       fflush(stderr);
    22092221      if(strncasecmp(cgiRequestMethod,"DELETE",6)==0) {
    2210         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    2211         fflush(stderr);
    22122222        char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6);
    22132223        setMapInMaps(m,"lenv","gs_usid",jobId);
    22142224        setMapInMaps(m,"lenv","file.statusFile",json_getStatusFilePath(m));
    2215         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    2216         fflush(stderr);
    22172225        runDismiss(m,jobId);
    2218         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    2219         fflush(stderr);
    22202226        map* pmError=getMapFromMaps(m,"lenv","error");
    22212227        if(pmError!=NULL && strncasecmp(pmError->value,"true",4)==0){
     
    22272233          res=createStatus(m,SERVICE_DISMISSED);
    22282234        }
    2229         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    2230         fflush(stderr);
    22312235      }
    22322236      else if(strcasecmp(cgiRequestMethod,"get")==0){
     
    22622266                //char* jobId=zStrdup(strstr(cgiQueryString,"/jobs/")+6);
    22632267                jobId[strlen(jobId)-8]=0;
    2264                 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);
    2265                 fflush(stderr);
    22662268                char *sid=getStatusId(m,jobId);
    22672269                if(sid==NULL){
    2268                   fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);
    2269                   fflush(stderr);
    22702270                  map* error=createMap("code","NoSuchJob");
    22712271                  addToMap(error,"message",_("The JobID from the request does not match any of the Jobs running on this server"));
     
    22732273                  return 1;
    22742274                }else{
    2275                   fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);
    2276                   fflush(stderr);
    22772275                  if(isRunning(m,jobId)>0){
    22782276                    map* error=createMap("code","ResultNotReady");
     
    22812279                    return 1;
    22822280                  }else{
    2283                     fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,jobId);
    2284                     fflush(stderr);
    22852281                    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");
    22892282                    zStatStruct f_status;
    22902283                    int s=zStat(Url0, &f_status);
    22912284                    if(s==0 && f_status.st_size>0){
    2292                       fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,Url0);
    2293                       fflush(stderr);
    2294                      
    22952285                      if(f_status.st_size>15){
    22962286                        json_object* pjoTmp=json_readFile(m,Url0);
     
    23582348        }
    23592349         
    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) */
    23622368        eres = SERVICE_STARTED;
    23632369        initAllEnvironment(m,request_inputs,ntmp,"jrequest");
     
    24002406        if(json_object_object_get_ex(jobj,"id",&json_io)!=FALSE){
    24012407          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);         
    24022411        }
    2403         fprintf(stderr,"%s %d \n", __FILE__,__LINE__);
    2404         fflush(stderr);
    24052412        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;
    24092413        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);
    24122414        map* preference=getMapFromMaps(m,"renv","HTTP_PREFER");
    24132415        map* mode=getMap(request_inputs,"mode");
     
    25932595           
    25942596      }//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
    26122598        if(strstr(cgiQueryString,"/jobs")==NULL && strstr(cgiQueryString,"/jobs/")==NULL){
    26132599          /* - /processes/{id}/ */
     
    26472633            }
    26482634
    2649             fprintf(stderr,"%s %d \n", __FILE__,__LINE__);
    2650             fflush(stderr);
    26512635            fetchService(zooRegistry,m,&s1,request_inputs,ntmp,cIdentifier,printExceptionReportResponseJ);
    2652             fprintf(stderr,"%s %d \n", __FILE__,__LINE__);
    2653             fflush(stderr);     
    26542636
    26552637
     
    30323014
    30333015    fetchService(zooRegistry,m,&s1,request_inputs,ntmp,r_inputs->value,printExceptionReportResponse);
    3034     /*
    3035     //*****************
    3036     // Fetch S1
    3037     //*****************
    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 DEBUG
    3047       fprintf (stderr, "Trying to load %s\n", tmps1);
    3048 #endif
    3049       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       else
    3059         {
    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_DB
    3068     int metadb_id=_init_sql(m,"metadb");
    3069     //FAILED CONNECTING DB
    3070     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_HPC
    3079       addNestedOutputs(&s1);
    3080 #endif
    3081       if(zooRegistry!=NULL){
    3082         freeRegistry(&zooRegistry);
    3083         free(zooRegistry);
    3084       }
    3085     }else /* Not found in MetaDB /{
    3086 #endif
    3087       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_HPC
    3108         addNestedOutputs(&s1);
    3109 #endif
    3110       }
    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_DB
    3135     }
    3136 #endif
    3137     //*****************
    3138     // End Fetch S1
    3139     //*****************
    3140 */
    31413016 
    31423017#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