Ignore:
Timestamp:
Feb 1, 2018, 11:27:28 AM (6 years ago)
Author:
djay
Message:

Add the capability to publish heatmap or any templated mapfile using the epecific msInclude and msLayer keys for an output. For MapServer? published output, define 4096 as the default maxsize and use pixel width or height for raster files. use the correct MapServer? imagemode depending on GDALGetRasterDataType (MS_IMAGEMODE_BYTE for GDT_Byte, MS_IMAGEMODE_INT16 for GDT_Int16 and MS_IMAGEMODE_FLOAT32 for GDT_Float32). Create a text file (.maps) listing every mapfiles created for a MapServer? published output (or inputs) using saveMapNames function. Fixes in ulinet, use uuid for naming temporary files. Add dialect input to the ogr2ogr service. Use the .maps file for removing a file from the DeleteData? service

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c

    r860 r862  
    112112  }
    113113
    114 
    115114  /**
    116115   * Practically invoke the callback, meaning sending the HTTP POST request.
     
    121120    local_params* arg=(local_params*)args;
    122121    HINTERNET hInternet,res1;
     122    const struct tm *tm;
     123    size_t len;
     124    time_t now;
     125    char *tmp1;
     126    map *tmpStatus;
    123127    hInternet=InternetOpen("ZooWPSClient\0",
    124128                           INTERNET_OPEN_TYPE_PRECONFIG,
     
    134138    free(URL);
    135139#ifdef CALLBACK_DEBUG
     140    now = time ( NULL );
     141    tm = localtime ( &now );
     142    tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char));
     143    len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
    136144    fprintf(stderr,"************************* From thread %d %s %d: REQUEST PARAMETERS cStep %d %d\n",pthread_self(),__FILE__,__LINE__,cStep,isOngoing);
    137145    fprintf(stderr," * JSON: [%s] \n",jsonStr);
    138146    fprintf(stderr," * URL: %s/ \n\n",hInternet.waitingRequests[0]);
     147    fprintf(stderr," * DATE: %s/ \n\n",tmp1);
    139148    fprintf(stderr,"************************* From thread %d %s %d: REQUEST PARAMETERS\n",pthread_self(),__FILE__,__LINE__);
     149    free(tmp1);
    140150#endif
    141151    while( (arg->step!=7 || isOngoing>0) &&
     
    152162    }
    153163#endif
    154     const struct tm *tm;
    155     size_t len;
    156     time_t now;
    157     char *tmp1;
    158     map *tmpStatus;
    159164   
    160165    now = time ( NULL );
     
    184189#ifdef CALLBACK_DEBUG   
    185190    fprintf(stderr,"************************* From thread %d %s %d: REQUEST END (%s)\n\n",pthread_self(),__FILE__,__LINE__,tmp1);
    186 #endif   
     191#endif
    187192    free(tmp1);
    188193    char *tmp = (char *) malloc ((hInternet.ihandle[0].nDataLen + 1)
     
    206211    if(cStep==0 || cStep==6 || arg->state==1)
    207212      cStep=arg->step+1;
    208 #ifdef CALLBACK_DEBUG   
    209     fprintf(stderr,"************************* From thread %d %s %d: RESPONSE CONTENT\n",pthread_self(),__FILE__,__LINE__);
     213#ifdef CALLBACK_DEBUG
     214    now = time ( NULL );
     215    tm = localtime ( &now );
     216    tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char));
     217    len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
     218    fprintf(stderr,"************************* From thread %d %s %d: RESPONSE CONTENT (%s)\n",pthread_self(),__FILE__,__LINE__,,tmp1);
    210219    for(i=0;i<7;i++){
    211220      fprintf(stderr,"%d) %d %d\n",i,steps[i][0],steps[i][1]);
     
    214223    fprintf(stderr,"************************* From thread %d %s %d\n\n",pthread_self(),__FILE__,__LINE__);
    215224    fflush(stderr);
     225    free(tmp1);
    216226#endif
    217227    steps[arg->step][arg->state]=true;
    218228    free(tmp);
    219     //free(args);
     229#ifdef CALLBACK_DEBUG
    220230    fprintf(stderr,"************************* From thread %d %s %d: EXIT\n\n",pthread_self(),__FILE__,__LINE__);
    221231    fflush(stderr);
     232#endif
    222233    pthread_exit(NULL);
    223234  }
     
    305316      // Update the execute request stored on disk at step 0,0 to modify the references used.
    306317      if(state==1){
    307         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    308         fflush(stderr);
    309318        maps* curs=inputs;
    310         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    311         fflush(stderr);
    312319        xmlInitParser();
    313         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    314         fflush(stderr);
    315320        map* xmlPath=getMapFromMaps(conf,"lenv","execute_file");
    316         dumpMap(xmlPath);
    317         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    318         fflush(stderr);
    319321        while(curs!=NULL){
    320           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    321           fflush(stderr);
    322           dumpMap(curs->content);
    323           //map* bvMap=getMap(curs->content,"byValue");
    324           // TODO handle mapArray
    325           //if(bvMap!=NULL && strncasecmp(bvMap->value,"true",4)==0){
    326           if(getMap(curs->content,"href")==NULL && getMap(curs->content,"mimeType")!=NULL){
    327             map* tmpMap=getMap(curs->content,"value");
    328             char tmpStr[100];
    329             sprintf(tmpStr,"%d",strlen(tmpMap->value));
    330             addToMap(curs->content,"size",tmpStr);
    331             tmpMap=getMap(curs->content,"mimeType");
    332             addToMap(curs->content,"fmimeType",tmpMap->value);
    333             tmpMap=getMap(curs->content,"cache_file");
    334             addToMap(curs->content,"generated_file",tmpMap->value);
    335             addToMap(curs->content,"storage",tmpMap->value);
    336             setReferenceUrl(conf,curs);
    337             fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    338             fflush(stderr);
    339             dumpMap(curs->content);
    340             fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    341             fflush(stderr);
    342             const char *params[5];
    343             int xmlLoadExtDtdDefaultValue;
    344             int hasFile=-1;
    345             map* xslPath=getMapFromMaps(conf,"callback","template");
    346             fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    347             fflush(stderr);
    348             dumpMap(xslPath);
    349             fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    350             fflush(stderr);
    351             map* filePath=getMap(curs->content,"ref_wfs_link");
    352             if(filePath==NULL)
    353               filePath=getMap(curs->content,"ref_wcs_link");
    354             fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    355             fflush(stderr);
    356             dumpMap(filePath);
    357             fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    358             fflush(stderr);
    359             char* inputName=curs->name;
    360             fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    361             fflush(stderr);
    362             if(xslPath==NULL || xmlPath==NULL || filePath==NULL)
    363               break;
    364             fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    365             fflush(stderr);
    366             char *tmpParam=(char*)malloc((strlen(curs->name)+11)*sizeof(char));
    367             char *tmpParam1=(char*)malloc((strlen(filePath->value)+11)*sizeof(char));
    368             addToMap(curs->content,"href",filePath->value);
    369             addToMap(curs->content,"xlink:href",filePath->value);
    370             sprintf(tmpParam,"string(\"%s\")",curs->name);
    371             sprintf(tmpParam1,"string(\"%s\")",filePath->value);
    372             params[0]="attr";
    373             params[1]=tmpParam;
    374             params[2]="value";
    375             params[3]=tmpParam1;//filePath->value;
    376             params[4]=NULL;
    377             fprintf(stderr, "## XSLT PARAMETERS ATTR: %s VALUE: %s \n",
    378                     tmpParam,tmpParam1);
    379             xmlSubstituteEntitiesDefault(1);
    380             fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    381             fflush(stderr);
    382             xmlLoadExtDtdDefaultValue = 0;
    383             xsltStylesheetPtr cur = NULL;
    384             xmlDocPtr doc, res;
    385             cur = xsltParseStylesheetFile(BAD_CAST xslPath->value);
    386             doc = xmlParseFile(xmlPath->value);
    387             fflush(stderr);
    388             res = xsltApplyStylesheet(cur, doc, params);
    389             xmlChar *xmlbuff;
    390             int buffersize;
    391             xmlDocDumpFormatMemory(res, &xmlbuff, &buffersize, 1);
    392             // Store the executeRequest in file again
    393             free(tmpParam);
    394             free(tmpParam1);
    395             fprintf(stderr," # Request / XSLT: %s\n",xmlbuff);
    396             fflush(stderr);
    397             FILE* saveExecute=fopen(xmlPath->value,"wb");
    398             fwrite(xmlbuff,1,buffersize,saveExecute);
    399             fflush(saveExecute);
    400             fclose(saveExecute);
    401             xmlFree(xmlbuff);
    402             xmlFreeDoc(doc);
    403             xsltFreeStylesheet(cur);
     322          map* length=getMap(curs->content,"length");
     323          map* useMS=getMap(curs->content,"useMapserver");
     324          if(length==NULL){
     325            addToMap(curs->content,"length","1");
     326            length=getMap(curs->content,"length");
    404327          }
    405           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    406           fflush(stderr);
     328          int len=atoi(length->value);
     329          for(int ii=0;ii<len;ii++){
     330            if(getMapArray(curs->content,"byValue",ii)!=NULL && getMapArray(curs->content,"mimeType",ii)!=NULL && useMS!=NULL && strncasecmp(useMS->value,"true",4)==0){
     331              map* tmpMap=getMapArray(curs->content,"value",ii);
     332              char tmpStr[100];
     333              sprintf(tmpStr,"%d",strlen(tmpMap->value));
     334              setMapArray(curs->content,"size",ii,tmpStr);
     335              tmpMap=getMapArray(curs->content,"mimeType",ii);
     336              setMapArray(curs->content,"fmimeType",ii,tmpMap->value);
     337              tmpMap=getMapArray(curs->content,"cache_file",ii);
     338              setMapArray(curs->content,"generated_file",ii,tmpMap->value);
     339              setMapArray(curs->content,"storage",ii,tmpMap->value);
     340              setReferenceUrl(conf,curs);
     341              addIntToMap(curs->content,"published_id",ii+1);
     342              const char *params[7];
     343              int xmlLoadExtDtdDefaultValue;
     344              int hasFile=-1;
     345              map* xslPath=getMapFromMaps(conf,"callback","template");
     346              map* filePath=getMapArray(curs->content,"ref_wfs_link",ii);
     347              if(filePath==NULL)
     348                filePath=getMap(curs->content,"ref_wcs_link");
     349              char* inputName=curs->name;
     350              if(xslPath==NULL || xmlPath==NULL || filePath==NULL)
     351                break;
     352              char *tmpParam=(char*)malloc((strlen(curs->name)+11)*sizeof(char));
     353              char *tmpParam1=(char*)malloc((strlen(filePath->value)+11)*sizeof(char));
     354              char tmpParam2[16];
     355              sprintf(tmpParam2,"string(\"%d\")",ii);
     356              setMapArray(curs->content,"href",ii,filePath->value);
     357              setMapArray(curs->content,"xlink:href",ii,filePath->value);
     358              tmpMap=getMapArray(curs->content,"cache_url",ii);
     359              if(tmpMap!=NULL)
     360                setMapArray(curs->content,"xlink:href",ii,tmpMap->value);
     361              else
     362                setMapArray(curs->content,"xlink:href",ii,filePath->value);
     363              sprintf(tmpParam,"string(\"%s\")",curs->name);
     364              sprintf(tmpParam1,"string(\"%s\")",filePath->value);
     365              sprintf(tmpParam2,"string(\"%d\")",ii);
     366              params[0]="attr";
     367              params[1]=tmpParam;
     368              params[2]="value";
     369              params[3]=tmpParam1;//filePath->value;
     370              params[4]="cnt";
     371              params[5]=tmpParam2;
     372              params[6]=NULL;
     373              fprintf(stderr, "## XSLT PARAMETERS ATTR: %s VALUE: %s INDEX: %s\n",
     374                      tmpParam,tmpParam1,tmpParam2);
     375              fflush(stderr);
     376              xmlSubstituteEntitiesDefault(1);
     377              xmlLoadExtDtdDefaultValue = 0;
     378              xsltStylesheetPtr cur = NULL;
     379              xmlDocPtr doc, res;
     380              cur = xsltParseStylesheetFile(BAD_CAST xslPath->value);
     381              doc = xmlParseFile(xmlPath->value);
     382              fflush(stderr);
     383              res = xsltApplyStylesheet(cur, doc, params);
     384              xmlChar *xmlbuff;
     385              int buffersize;
     386              xmlDocDumpFormatMemory(res, &xmlbuff, &buffersize, 1);
     387              // Store the executeRequest in file again
     388              free(tmpParam);
     389              free(tmpParam1);
     390              fprintf(stderr," # Request / XSLT: %s\n",xmlbuff);
     391              fflush(stderr);
     392              FILE* saveExecute=fopen(xmlPath->value,"wb");
     393              if(saveExecute!=NULL){
     394                fwrite(xmlbuff,1,buffersize,saveExecute);
     395                fflush(saveExecute);
     396                fclose(saveExecute);
     397              }
     398              xmlFree(xmlbuff);
     399              xmlFreeDoc(doc);
     400              xsltFreeStylesheet(cur);
     401            }
     402          }
     403          addIntToMap(curs->content,"published_id",0);
    407404          curs=curs->next;
    408405        }
    409         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    410         fflush(stderr);
    411406        xmlCleanupParser();
    412         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    413         fflush(stderr);
    414407        FILE* f0=fopen(xmlPath->value,"rb");
    415408        if(f0!=NULL){
     
    423416          fcontent[flen]=0;
    424417          fclose(f0);
    425           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    426           fflush(stderr);
    427418          map *schema=getMapFromMaps(conf,"database","schema");
    428419          map* sid=getMapFromMaps(conf,"lenv","usid");
    429           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    430           fflush(stderr);
    431420          char *req=(char*)malloc((flen+strlen(schema->value)+strlen(sid->value)+66)*sizeof(char));
    432           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    433           fflush(stderr);
    434421          sprintf(req,"UPDATE %s.services set request_execute_content=$$%s$$ WHERE uuid=$$%s$$",schema->value,fcontent,sid->value);
    435           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    436           fflush(stderr);
    437422          execSql(conf,1,req);
    438           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    439           fflush(stderr);
    440423          free(fcontent);
    441           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    442           fflush(stderr);
    443424          free(req);
    444           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    445           fflush(stderr);
    446425        }
    447426      }
     
    453432        {
    454433          "xlink:href",
    455           "ref"
     434          "ref_download_link"
    456435        },
    457436        {
     
    514493              setMapArray(curs->content,"storage",ii,tmpMap->value);
    515494            }
    516             fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    517             dumpMap(curs->content);
    518495            struct stat buf;
    519496            char timeStr[ 100 ] = "";
     
    553530        if(hasRef<0)
    554531          json_object_put(res3);
    555         else
    556           json_object_object_add(res1,curs->name,res3);
     532        else{
     533          json_object_object_add(res1,curs->name,json_object_get(res3));
     534          json_object_put(res3);
     535        }
    557536        addIntToMap(curs->content,"published_id",0);
    558537        curs=curs->next;
     
    570549        if(length!=NULL){
    571550          json_object *res1=json_object_new_object();
    572           json_object *res3=json_object_new_array();
    573551          int limit=atoi(length->value);
    574552          int i=0;
     
    589567                json_object_object_add(res1,tmp0->value,res2);
    590568              }else{
    591                 if(json_object_is_type(res4,json_type_object)){
    592                   json_object_array_add(res3,res4);
    593                 }
    594                 json_object_array_add(res3,res2);
    595                 if(json_object_is_type(res4,json_type_object)){
     569                if(json_object_is_type(res4,json_type_object) && !json_object_is_type(res4, json_type_array)){
     570                  json_object *res3=json_object_new_array();
     571                  json_object_array_add(res3,json_object_get(res4));
     572                  json_object_array_add(res3,res2);
    596573                  json_object_object_del(res1,tmp0->value);
    597574                  json_object_object_add(res1,tmp0->value,res3);
    598                 }
     575                }else
     576                  json_object_array_add(res4,res2);
    599577              }
    600578            }
    601579          }
    602           if(json_object_array_length(res3)==0)
    603             json_object_put(res3);
    604580          json_object_object_add(res,"inputs",res1);
    605581        }
    606         //json_object_object_add(res,"inputs",in);
    607582      }
    608583      break;
     
    631606    case 5: {
    632607      // Downloading process outputs from cluster
    633       //json_object* in=mapsToJson(outputs);
    634608      maps* curs=outputs;
    635609      dumpMaps(curs);
     
    708682            json_object *jsStr=json_object_new_string(sid->value);
    709683            json_object_object_add(res2,keys[i][1],jsStr);
    710             if(i==0)
     684            if(i==0){
    711685              hasRef=1;
     686              json_object_object_add(res2,"ref_download_link",jsStr);
     687            }
     688            if(i==1){
     689              struct stat buf;
     690              char timeStr[ 100 ] = "";
     691              if (stat(sid->value, &buf)==0){
     692                strftime(timeStr, 100, "%d-%m-%Y %H:%M:%S", localtime( &buf.st_mtime));
     693                json_object *jsStr=json_object_new_string(timeStr);
     694                json_object_object_add(res2,"creation_date",jsStr);
     695              }
     696            }
    712697          }
    713698        }
     
    724709              int i0=0;
    725710              for(;i0<6;i0++){
    726                 if(i0==0)
    727                   sid=getMap(specificMaps->content,specifics[i][1]);
    728                 else
    729                   sid=getMap(specificMaps->content,keys[i0][0]);
     711                sid=getMap(specificMaps->content,keys[i0][0]);
    730712                if(sid!=NULL){
    731713                  json_object *jsStr=json_object_new_string(sid->value);
     
    760742                  json_object *jsStr=json_object_new_string(sid->value);
    761743                  json_object_object_add(res3,keys[i0][1],jsStr);
    762                   //if(i0==0)
    763744                  hasRef0=1;
    764745                }
     
    858839    local_arguments[nbThreads]->step=step;
    859840    local_arguments[nbThreads]->state=state;
    860     //pthread_t p1;
    861841    if(myThreads==NULL)
    862842      myThreads=(pthread_t*)malloc((nbThreads+1)*sizeof(pthread_t));
     
    867847      return false;
    868848    }
    869     //free(argumentsA);
    870849    nbThreads++;
    871850    return true;
     
    878857    int i=0;
    879858    for(i=0;i<nbThreads;i++){
    880       fprintf(stderr,"%s %d %d \n",__FILE__,__LINE__,i);
    881       fflush(stderr);
    882859      pthread_join(myThreads[i],NULL);
    883860      free(local_arguments[i]);
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