Changeset 839


Ignore:
Timestamp:
Aug 7, 2017, 2:56:24 PM (7 years ago)
Author:
djay
Message:

Update the source code for HPC support. Automatically adding nested outputs for the HPC support (should this be available for every support?). Add capability to store the metadata in the Collection DataBase?. Addition of the zcfg2sql to import any existing ZCFG file into the Collection DB. Add the support to invoke a callback (for history purpose) in case a [callback] section contains at least one parameter defined (url). Add support to convert maps and map to JSON (for callback use only by now). Fix some memory leaks (some are still there).

Location:
branches/prototype-v0
Files:
9 added
28 edited

Legend:

Unmodified
Added
Removed
  • branches/prototype-v0/thirds/otb2zcfg/otb2zcfg.cxx

    r783 r839  
    312312          std::string s=m_Application->GetParameterDescription(paramKey);
    313313          if(s.length()>0){
     314            s=ReplaceAll(ReplaceAll(s,std::string("\n"),std::string("")),std::string("\t"),std::string(""));
    314315            std::cout << "   Title = " << s << std::endl;
    315316            std::cout << "   Abstract = " << s << std::endl;
  • branches/prototype-v0/zoo-project/zoo-kernel/Makefile.in

    r822 r839  
    4141        g++ -fPIC ${CFLAGS} -c sshapi.c
    4242
     43service_json.o: service_json.c
     44        g++ -fPIC ${JSON_CFLAGS} ${CFLAGS} -c service_json.c
     45
     46service_callback.o: service_callback.c
     47        g++ -fPIC ${JSON_CFLAGS} ${CFLAGS} -c service_callback.c
     48
    4349request_parser.o: request_parser.c request_parser.h
    4450        g++ -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c request_parser.c
     
    5157
    5258response_print.o: response_print.c response_print.h
    53         g++ -fPIC ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c response_print.c
     59        g++ -fPIC ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} ${HPC_ENABLED} -c response_print.c
    5460
    5561server_internal.o: server_internal.c server_internal.h service.h mimetypes.h
     
    7682
    7783service_internal_hpc.o: service_internal_hpc.c service_internal_hpc.h service.h
    78         g++  ${XML2CFLAGS} ${HPCCFLAGS} ${CFLAGS} -c service_internal_hpc.c
     84        g++  ${JSON_CFLAGS} ${XML2CFLAGS} ${HPCCFLAGS} ${CFLAGS} -c service_internal_hpc.c
    7985
    8086service_internal_saga.o: service_internal_saga.c service_internal_saga.h service.h
     
    109115
    110116zoo_service_loader.o: zoo_service_loader.c service.h version.h ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${MONO_FILE} ${HPC_FILES} ${METADB_FILE}
    111         g++ -g -O2 ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${MONO_CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${SAGA_ENABLED} ${OTB_ENABLED} ${HPC_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} ${MONO_ENABLED} ${METADB_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
     117        g++ -g -O2 ${JSON_CFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${MONO_CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${SAGA_ENABLED} ${OTB_ENABLED} ${HPC_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} ${MONO_ENABLED} ${METADB_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
    112118
    113119libzoo_service.${EXT}: version.h service_internal.o service.o sqlapi.o
    114         gcc -shared  ${GDAL_CFLAGS} ${DEFAULT_OPTS} -fpic -o libzoo_service.${EXT} ${CFLAGS}  service_internal.o service.o sqlapi.o ${FCGI_LDFLAGS} ${GDAL_LIBS}
     120        gcc -shared  ${GDAL_CFLAGS} ${DEFAULT_OPTS} -fpic -o libzoo_service.${EXT} ${CFLAGS}  service_internal.o service.o sqlapi.o ${FCGI_LDFLAGS} ${GDAL_LIBS} ${ZOO_LDFLAGS}
    115121
    116 zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_loader.c zoo_service_loader.o  ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${HPC_FILES} ${METADB_FILE}
    117         g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
    118         g++  ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${MONO_FILE} ${HPC_FILES} ${METADB_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS}
     122zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_loader.c zoo_service_loader.o  ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${HPC_FILES} ${METADB_FILE} ${JSON_FILE} service_callback.o
     123        g++ -g -O2 ${JSON_CFLAGS} ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
     124        g++  ${JSON_CFLAGS} ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${MONO_FILE} ${HPC_FILES} ${METADB_FILE} ${JSON_FILE} service_callback.o response_print.o server_internal.o caching.o request_parser.o ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS}
    119125
    120126zcfg2yaml: zcfg2yaml.c service.h lex.sr.o service_conf.tab.o service_conf.y main_conf_read.tab.o lex.cr.o response_print.o server_internal.o service_internal.o ${MS_FILE} ${YAML_FILE}
  • branches/prototype-v0/zoo-project/zoo-kernel/ZOOMakefile.opts.in

    r822 r839  
    2929YAML_FILE=@YAML_FILE@
    3030YAML_FILE1=@YAML_FILE1@
     31
     32JSON_CFLAGS=@JSON_CPPFLAGS@
     33JSON_LDFLAGS=@JSON_LDFLAGS@
     34JSON_FILE=@JSON_FILE@
    3135
    3236METADB_ENABLED=@METADB@
     
    111115
    112116CFLAGS=@SSH2_CPPFLAGS@ @GETTEXT_CFLAGS@ @PROJ_CPPFLAGS@ @RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ @UUID_CFLAGS@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
    113 LDFLAGS=-lzoo_service @SSH2_LDFLAGS@ @PROJ_LDFLAGS@ @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS}  ${FCGI_LDFLAGS} @OPENSSL_LDFLAGS@ @UUID_LDFLAGS@ ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} ${MONO_LDFLAGS} @GETTEXT_LDFLAGS@
     117LDFLAGS=-lzoo_service @SSH2_LDFLAGS@ @PROJ_LDFLAGS@ @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS}  ${FCGI_LDFLAGS} @OPENSSL_LDFLAGS@ @UUID_LDFLAGS@ ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} ${MONO_LDFLAGS} @GETTEXT_LDFLAGS@ @JSON_LDFLAGS@
    114118
    115119DATAROOTDIR=@datarootdir@/zoo-project
  • branches/prototype-v0/zoo-project/zoo-kernel/caching.c

    r822 r839  
    158158 */
    159159int readCurrentInput(maps** m,maps** in,int* index,HINTERNET* hInternet,map** error){
     160 
    160161  map* tmp1;
    161162  char sindex[5];
     
    212213    sprintf(sindex,"%d",*index+1);
    213214    if((tmp1=getMap(content->content,xname))!=NULL && tmap!=NULL && strcasecmp(tmap->value,sindex)==0){
    214      
    215       if(getMap(content->content,icname)==NULL){
     215
     216      if(getMap(content->content,icname)==NULL){       
    216217        fcontent=(char*)malloc((hInternet->ihandle[*index].nDataLen+1)*sizeof(char));
    217218        if(fcontent == NULL){
     
    266267          char* md5str=NULL;
    267268          if((tmp2=getMap(content->content,bname))!=NULL){
    268             dumpMap(tmp2);
    269269            char *tmpStr=(char*)malloc((strlen(tmp1->value)+strlen(tmp2->value)+1)*sizeof(char));
    270270            sprintf(tmpStr,"%s%s",tmp1->value,tmp2->value);
    271271            if((tmp2=getMap(content->content,"headers"))!=NULL){
    272272              char *tmpStr2=zStrdup(tmpStr);
     273              free(tmpStr);
    273274              tmpStr=(char*)malloc((strlen(tmpStr2)+strlen(tmp2->value)+1)*sizeof(char));
    274275              sprintf(tmpStr,"%s%s",tmpStr2,tmp2->value);
     
    293294        free(mimeType);
    294295        free(request);
    295         *index++;
    296        
     296        (*index)++;
    297297      }
    298298    }
     
    361361    free(oreq);
    362362  }else{
    363     setMapArray(oreq->content,"value",hInternet->nb-1,url);
     363    setMapArray(oreq->content,"value",hInternet->nb,url);
    364364  }
    365365}
     
    444444      addToMap(*content,"cache_file",fname);
    445445      free(fname);
     446      free(md5str);
    446447    }
    447448  }
  • branches/prototype-v0/zoo-project/zoo-kernel/configure.ac

    r822 r839  
    6060AC_SUBST([UUID_CFLAGS])
    6161AC_SUBST([UUID_LDFLAGS])
     62
     63#============================================================================
     64# Detect if json-c is available
     65#============================================================================
     66
     67AC_ARG_WITH([json],
     68    [AS_HELP_STRING([--with-json=PATH], [Specifies an alternative location for the json-c library])],
     69    [JSON_DIR="$withval"], [JSON_DIR="/usr/"])
     70JSON_CPPFLAGS="-I$JSON_DIR/include/json-c/"
     71JSON_LDFLAGS="-L$JSON_DIR/lib -ljson-c"
     72CPPFLAGS_SAVE="$CPPFLAGS"
     73CPPFLAGS="$JSON_CPPFLAGS"
     74LIBS_SAVE="$LIBS"
     75LIBS="$JSON_LDFLAGS"
     76echo $CPPFLAGS
     77AC_CHECK_HEADERS([json_object.h],
     78                        [], [AC_MSG_ERROR([could not find header file json_object.h])])
     79AC_CHECK_LIB([json-c], [json_object_new_object],
     80                        [], [AC_MSG_ERROR([could not find function in json-c library])])
     81CPPFLAGS="$CPPFLAGS_SAVE"
     82JSON_FILE="service_json.o"
     83JSON_ENABLED="-DJSON"
     84AC_SUBST([JSON_CPPFLAGS])
     85AC_SUBST([JSON_LDFLAGS])
     86AC_SUBST([JSON_FILE])
     87AC_SUBST([JSON_ENABLED])
    6288
    6389#============================================================================
  • branches/prototype-v0/zoo-project/zoo-kernel/main_conf_read.y

    r790 r839  
    9999  }
    100100  free(curr_key);
     101  curr_key=NULL;
    101102  }
    102103| SPAIR  {curr_key=zStrdup($1);if(debug) printf("SPAIR FOUND !!\n"); }
     
    162163    free(current_content);
    163164  }
     165  if(curr_key!=NULL){
     166    free(curr_key);
     167  }
    164168
    165169  fclose(crin);
  • branches/prototype-v0/zoo-project/zoo-kernel/mimetypes.h

    r601 r839  
    180180        { "application/vnd.dece.unspecified", "uvx" },
    181181        { "application/vnd.dece.zip", "uvz" },
    182         { "application/vnd.denovo.fcselayout-link", "fe_launch" },
     182        { "application/vnd.denovo.fcselayout-link", "fe_launch" },     
    183183        { "application/vnd.dna", "dna" },
    184184        { "application/vnd.dolby.mlp", "mlp" },
     
    836836        return ext;
    837837}
     838
     839static int isGeographic(const char* mimeType){
     840  char* imageMimeType[4]={
     841    "image/tiff",
     842    "image/png",
     843    "image/jpeg",
     844    "application/vnd.google-earth.kmz"
     845  };
     846  char* vectorMimeType[5]={
     847    "text/xml",
     848    "application/json",
     849    "application/gml+xml",
     850    "application/zip",
     851    "application/vnd.google-earth.kml+xml"
     852  };
     853  int i=0;
     854  for(;i<4;i++){
     855    if(strncmp(imageMimeType[i],mimeType,strlen(imageMimeType[i]))==0)
     856      return 1;
     857  }
     858  i=0;
     859  for(;i<5;i++){
     860    if(strncmp(vectorMimeType[i],mimeType,strlen(vectorMimeType[i]))==0)
     861      return 2;
     862  }
     863  return -1;
     864}
  • branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c

    r802 r839  
    533533            xmlChar *val = xmlGetProp (cur, BAD_CAST "id");
    534534            tmpmaps = createMaps((char *) val);
     535            xmlFree(val);
    535536          }
    536537
     
    624625                            tmpmaps->content =
    625626                              createMap (refs[l], (char *) val);
    626 
    627627                          map *ltmp = getMap (tmpmaps->content, "method");
    628628                          if (l == 4 )
     
    750750                                      map *btmp =
    751751                                        getMap (tmpmaps->content, "Reference");
     752                                      addToMap (tmpmaps->content, "Body", tmp);
    752753                                      if (btmp != NULL)
    753754                                        {
     
    815816                                                  &bRead);
    816817                                tmp[bInternet.ihandle[0].nDataLen] = 0;
    817                                 InternetCloseHandle (&bInternet);
     818                                InternetCloseHandle(&bInternet);
     819                                addToMap (tmpmaps->content, "Body", tmp);
    818820                                map *btmp =
    819821                                  getMap (tmpmaps->content, "href");
     
    832834                                  }
    833835                                free (tmp);
     836                                xmlFree (val);
    834837                              }
    835838                        }
     
    11201123      const char ress[4][13] =
    11211124        { "mimeType", "encoding", "schema", "transmission" };
     1125      xmlFree (val);
    11221126      for (l = 0; l < 4; l++){
    11231127        val = xmlGetProp (cur, BAD_CAST ress[l]);
     
    11391143        while (ccur != NULL){
    11401144          if(ccur->type == XML_ELEMENT_NODE){
    1141             char *xpathExpr=(char*)malloc(65+strlen(tmpmaps->name));
    1142             sprintf(xpathExpr,"/*/*[local-name()='Output' and @id='%s']/*[local-name()='Output']",tmpmaps->name);
     1145            char *xpathExpr=(char*)malloc(66+strlen(tmpmaps->name));
     1146            sprintf(xpathExpr,"/*/*[local-name()='Output' and @id='%s']/*[local-name()='Output']",tmpmaps->name);           
    11431147            xmlXPathObjectPtr tmpsptr = extractFromDoc (doc, xpathExpr);
    11441148            xmlNodeSet* cnodes = tmpsptr->nodesetval;
    11451149            xmlParseOutputs2(main_conf,request_inputs,&tmpmaps->child,doc,cnodes);
     1150            xmlXPathFreeObject (tmpsptr);
     1151            free(xpathExpr);
    11461152            break;
    11471153          }
     
    14241430          else
    14251431            addToMap(*request_inputs,"mode","auto");
     1432          xmlFree(val);
    14261433          val = xmlGetProp (cur, BAD_CAST "response");
    14271434          if(val!=NULL){
     
    14361443            addToMap(*request_inputs,"ResponseDocument","");
    14371444          }
     1445          xmlFree(val);
    14381446        }
    14391447      }
  • branches/prototype-v0/zoo-project/zoo-kernel/response_print.c

    r822 r839  
    2323 */
    2424
     25#include "service.h"
    2526#include "response_print.h"
    2627#include "request_parser.h"
     
    644645 * @return the generated wps:ProcessOfferings xmlNodePtr
    645646 */
    646 void printGetCapabilitiesForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){
     647void printGetCapabilitiesForProcess(registry *reg, maps* m,xmlDocPtr doc,xmlNodePtr nc,service* serv){
    647648  xmlNsPtr ns,ns_ows,ns_xml,ns_xlink;
    648649  xmlNodePtr n=NULL,nc1,nc2,nc3;
     
    692693    tmp1=serv->metadata;
    693694
    694     addMetadata(tmp1,nc1,ns_ows,ns_xlink);
    695 
    696     /*while(tmp1!=NULL){
    697       nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
    698       if(strcmp(tmp1->name,"title")==0 ||
    699          strcmp(tmp1->name,"href")==0 ||
    700          strcmp(tmp1->name,"role")==0 ||
    701          strcmp(tmp1->name,"link_type")==0){
    702         xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
    703         xmlAddChild(nc1,nc2);
    704       }else{
    705         if(nc3==NULL)
    706           nc3 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
    707         xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Name");
    708         xmlAddChild(nc4,xmlNewText(BAD_CAST tmp1->name));
    709         xmlNodePtr nc5 = xmlNewNode(ns_ows, BAD_CAST "Value");
    710         xmlAddChild(nc5,xmlNewText(BAD_CAST tmp1->value));
    711         xmlAddChild(nc3,nc4);
    712         xmlAddChild(nc3,nc5);
    713       }
    714       tmp1=tmp1->next;
    715       }*/
     695    addMetadata(tmp1,doc,nc1,ns_ows,ns_xlink);
     696    tmp1=serv->additional_parameters;
     697    int fromDb=-1;
     698    map* test=getMap(serv->content,"fromDb");
     699    if(test!=NULL && strncasecmp(test->value,"true",4)==0)
     700      fromDb=1;
     701    addAdditionalParameters(tmp1,doc,nc1,ns_ows,ns_xlink,fromDb);
     702
    716703    if(nc3!=NULL)
    717704      xmlAddChild(nc1,nc3);
     
    756743}
    757744
    758 int addMetadata(map* meta,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink){
     745int addMetadata(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink){
    759746    int hasTitle=-1;
    760747    int hasValue=-1;
     
    830817}
    831818
     819
     820int addAdditionalParameters(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int fromDb){
     821    int hasTitle=-1;
     822    int hasValue=-1;
     823    xmlNodePtr nc1;
     824    map* oMeta=meta;
     825    int isAdditionalParameters=-1;
     826    //if(count(oMeta)>=2){
     827    int level=0;
     828    map* test=getMap(meta,"title");
     829    if(test!=NULL)
     830      level+=1;
     831    test=getMap(meta,"href");
     832    if(test!=NULL)
     833      level+=1;
     834    test=getMap(meta,"role");
     835    if(test!=NULL)
     836      level+=1;
     837    if(count(oMeta)>level+1)
     838      isAdditionalParameters=1;
     839    //}
     840    char *ctitle=NULL;
     841    while(meta!=NULL){
     842      if(hasTitle<0)
     843        if(hasValue<0)
     844          nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
     845      if(strncasecmp(meta->name,"title",5)==0 ||
     846         strcasecmp(meta->name,"href")==0 ||
     847         strcasecmp(meta->name,"role")==0 ){
     848        int index=5;
     849        if(strncasecmp(meta->name,"title",5)==0){
     850          index=6;
     851          hasTitle=1;
     852          if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){
     853              xmlAddChild(nc,nc1);
     854              nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
     855              free(ctitle);
     856              ctitle=NULL;
     857          }
     858          if(ctitle==NULL){
     859            char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char));
     860            snprintf(tmp,index,"%s",meta->name);
     861            xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value);
     862            free(tmp);
     863          }       
     864          if(ctitle!=NULL)
     865            free(ctitle);
     866          ctitle=zStrdup(meta->value);
     867        }
     868      }else{
     869        xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
     870        xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name");
     871        xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name));
     872        xmlAddChild(nc2,nc3);
     873        if(fromDb<0){
     874          char *mptr;
     875          char* meta_values=strtok_r(meta->value,",",&mptr);
     876          while(meta_values!=NULL){
     877            xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
     878            xmlAddChild(nc4,xmlNewText(BAD_CAST meta_values));
     879            xmlAddChild(nc2,nc4);
     880            meta_values=strtok_r(NULL,",",&mptr);
     881          }
     882        }else{
     883          xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
     884          xmlAddChild(nc4,xmlNewCDataBlock(doc,BAD_CAST meta->value,strlen(meta->value)));
     885          xmlAddChild(nc2,nc4);
     886        }
     887        xmlAddChild(nc1,nc2);
     888        hasTitle=-1;
     889      }
     890      meta=meta->next;
     891      if(hasTitle<0){
     892        xmlAddChild(nc,nc1);
     893        hasValue=1;
     894      }
     895    }
     896    if(oMeta!=NULL && hasValue<0 && nc1!=NULL){
     897      xmlAddChild(nc,nc1);
     898    }
     899}
     900
    832901/**
    833902 * Add the ows:Metadata nodes relative to the profile registry
     
    886955 * @return the generated wps:ProcessOfferings xmlNodePtr
    887956 */
    888 void printDescribeProcessForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){
     957void printDescribeProcessForProcess(registry *reg, maps* m,xmlDocPtr doc,xmlNodePtr nc,service* serv){
    889958  xmlNsPtr ns,ns_ows,ns_xlink;
    890959  xmlNodePtr n,nc1;
     
    892961  map* version=getMapFromMaps(m,"main","rversion");
    893962  int vid=getVersionId(version->value);
     963  int fromDb=-1;
     964  map* serviceType=getMap(serv->content,"serviceType");
     965  map* test=getMap(serv->content,"fromDb");
     966  if(test!=NULL && strncasecmp(test->value,"true",4)==0)
     967    fromDb=1;
    894968
    895969  n=nc;
     
    9371011    tmp1=serv->metadata;
    9381012    while(tmp1!=NULL){
    939       addMetadata(tmp1,nc,ns_ows,ns_xlink);
     1013      addMetadata(tmp1,doc,nc,ns_ows,ns_xlink);
    9401014      /*nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
    9411015      xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
     
    9511025  }else{
    9521026    tmp1=serv->metadata;
    953     addMetadata(tmp1,nc,ns_ows,ns_xlink);
     1027    addMetadata(tmp1,doc,nc,ns_ows,ns_xlink);
    9541028    addInheritedMetadata(nc,ns_ows,ns_xlink,reg,m,serv);
     1029    tmp1=serv->additional_parameters;
     1030    addAdditionalParameters(tmp1,doc,nc,ns_ows,ns_xlink,fromDb);
    9551031  }
    9561032
     
    9591035    if(vid==0){
    9601036      nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs");
    961       printFullDescription(1,e,"Input",ns,ns_ows,nc1,vid);
     1037      printFullDescription(doc,1,e,"Input",ns,ns_ows,nc1,vid,fromDb,NULL);
    9621038      xmlAddChild(nc,nc1);
    9631039    }
    9641040    else{
    965       printFullDescription(1,e,"wps:Input",ns,ns_ows,nc,vid);
     1041      printFullDescription(doc,1,e,"wps:Input",ns,ns_ows,nc,vid,fromDb,NULL);
    9661042    }
    9671043  }
     
    9701046  if(vid==0){
    9711047    nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs");
    972     printFullDescription(0,e,"Output",ns,ns_ows,nc1,vid);
     1048    printFullDescription(doc,0,e,"Output",ns,ns_ows,nc1,vid,fromDb,NULL);
    9731049    xmlAddChild(nc,nc1);
    9741050  }
    9751051  else{
    976     printFullDescription(0,e,"wps:Output",ns,ns_ows,nc,vid);
     1052    printFullDescription(doc,0,e,"wps:Output",ns,ns_ows,nc,vid,fromDb,serviceType);
    9771053  }
    9781054  if(vid==0)
     
    9961072 * @param nc1 the XML node to use to add the created tree
    9971073 * @param vid the WPS version id (0 for 1.0.0, 1 for 2.0.0)
    998  */
    999 void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid){
     1074 * @param fromDb 1 in case the metadata comes from the DB, -1 in other cases
     1075 * @param serviceType the serviceType found in the ZCFG file or the DB
     1076 */
     1077void printFullDescription(xmlDocPtr doc,int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid,int fromDb,const map* serviceType){
    10001078  xmlNsPtr ns1=NULL;
    10011079  if(vid==1)
     
    10321110
    10331111    if(e->format!=NULL){
     1112#ifdef USE_HPC     
     1113    DEFAULT_OUT:
     1114#endif
    10341115      const char orderedFields[13][14]={
    10351116        "mimeType",
     
    11381219              char *tmps=strdup(token);
    11391220              tmps[strlen(tmps)]=0;
    1140               xmlAddChild(nc7,xmlNewText(BAD_CAST tmps));
     1221              nc8 = xmlNewText(BAD_CAST tmps);
     1222              xmlAddChild(nc7,nc8);
    11411223              free(tmps);
    11421224              xmlAddChild(nc6,nc7);
     
    14371519        xmlNsPtr ns_xlink=usedNs[xlinkId];
    14381520
    1439         dumpMap(metadata);
    1440         addMetadata(metadata,nc2,ns_ows,ns_xlink);
     1521        //dumpMap(metadata);
     1522        addMetadata(metadata,doc,nc2,ns_ows,ns_xlink);
     1523        addAdditionalParameters(e->additional_parameters,doc,nc2,ns_ows,ns_xlink,fromDb);
    14411524
    14421525      }
     
    15831666      xmlAddChild(nc2,nc3);
    15841667    }else{
    1585       if(e->child!=NULL && vid!=0){
    1586         printFullDescription(in,e->child,type,ns,ns_ows,nc2,vid);
    1587       }
    1588     }
    1589    
     1668      if(e->child!=NULL){
     1669        if(e->child!=NULL && vid!=0){
     1670          printFullDescription(doc,in,e->child,type,ns,ns_ows,nc2,vid,fromDb,NULL);
     1671        }
     1672      }
     1673    }
    15901674    if(e->child!=NULL && vid==0){
    15911675      elements* children=dupElements(e->child);
     
    15981682        cursor=cursor->next;
    15991683      }
    1600       printFullDescription(in,children,type,ns,ns_ows,nc2,vid);
     1684      printFullDescription(doc,in,children,type,ns,ns_ows,nc2,vid,fromDb,serviceType);
    16011685      xmlAddChild(nc1,nc2);
    16021686      freeElements(&children);
     
    16041688    }else
    16051689      xmlAddChild(nc1,nc2);
    1606    
    16071690    e=e->next;
    16081691  }
     
    25882671      toto=getMap(tmpI->content,"asReference");
    25892672#ifdef USE_MS
    2590       if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL)
     2673      if(toto!=NULL && strcasecmp(toto->value,"true")==0 && (testMap==NULL || strncasecmp(testMap->value,"true",4)!=0) )
    25912674#else
    25922675      if(toto!=NULL && strcasecmp(toto->value,"true")==0)
  • branches/prototype-v0/zoo-project/zoo-kernel/response_print.h

    r822 r839  
    209209  xmlNodePtr printWPSHeader(xmlDocPtr,maps*,const char*,const char*,const char*,int);
    210210  xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,maps*,const char*);
    211   void printGetCapabilitiesForProcess(registry*,maps*,xmlNodePtr,service*);
    212   void printDescribeProcessForProcess(registry*,maps*,xmlNodePtr,service*);
    213   void printFullDescription(int,elements*,const char*,xmlNsPtr,xmlNsPtr,xmlNodePtr,int);
     211  void printGetCapabilitiesForProcess(registry*,maps*,xmlDocPtr,xmlNodePtr,service*);
     212  void printDescribeProcessForProcess(registry*,maps*,xmlDocPtr,xmlNodePtr,service*);
     213  void printFullDescription(xmlDocPtr,int,elements*,const char*,xmlNsPtr,xmlNsPtr,xmlNodePtr,int,int,const map*);
    214214  void printDocument(maps*,xmlDocPtr,int);
    215215  void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*,int);
     
    220220  void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
    221221  void printStatusInfo(maps*,map*,char*);
    222   int addMetadata(map* meta,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink);
     222  int addAdditionalParameters(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int);
     223  int addMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr);
    223224
    224225  void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
  • branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c

    r822 r839  
    597597          setMapArray(res,"value",nb,out1->name);
    598598        }
    599 
    600599        nb++;
    601600        result=out1->name;
     
    806805         */
    807806        if(tmpIoType!=NULL){
    808           map* tmpCheck=getMap(tmpIoType->content,"useMapServer");
    809           if(tmpCheck!=NULL){
     807          map* tmpCheck=getMap(tmpIoType->content,"useMapserver");
     808          if(tmpCheck!=NULL && strncasecmp(tmpCheck->value,"true",4)==0){
    810809            // Get the default value
    811810            tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,NULL);
     
    841840      }
    842841    }
    843     /*if(tmpInputs->child!=NULL){
     842    if(tmpInputs->child!=NULL){
    844843      tmpInputss=tmpInputs->next;
    845844      tmpInputs=tmpInputs->child;
     
    848847        out1s=tmpMaps;
    849848      }
    850       }else*/
    851       tmpInputs=tmpInputs->next;
     849    }
     850    tmpInputs=tmpInputs->next;
    852851  }
    853852  if(tmpInputss!=NULL){
     
    980979    if(isRunning(conf,pid)>0){
    981980      if(strncasecmp(req,"GetResult",strlen(req))==0){
    982         errorException (conf, _("The result for the requested JobID has not yet been generated. "),
     981        errorException (conf, _("The result for the requested JobID has not yet been generated. (1)"),
    983982                        "ResultNotReady", pid);
    984983        return;
     
    10121011          return;
    10131012        }else{
    1014           errorException (conf, _("The result for the requested JobID has not yet been generated. "),
     1013          errorException (conf, _("The result for the requested JobID has not yet been generated. (2)"),
    10151014                          "ResultNotReady", pid);
    10161015          freeMap(&statusInfo);
     
    10341033        }
    10351034    }
     1035    free(sid);
    10361036    printStatusInfo(conf,statusInfo,req);
    10371037    freeMap(&statusInfo);
  • branches/prototype-v0/zoo-project/zoo-kernel/service.c

    r822 r839  
    146146
    147147/**
     148 * Create a new iotype*
     149 *
     150 * @return a pointer to the allocated iotype
     151 */
     152iotype* createIoType(){
     153  iotype* io=(iotype*)malloc(IOTYPE_SIZE);
     154  io->content=NULL;
     155  io->next=NULL;
     156  return io;
     157}
     158
     159/**
    148160 * Create a new map
    149161 *
     
    400412    if(tmp->metadata!=NULL)
    401413      free(tmp->metadata);
     414    freeMap(&tmp->additional_parameters);
     415    if(tmp->additional_parameters!=NULL)
     416      free(tmp->additional_parameters);
    402417    if(tmp->format!=NULL)
    403418      free(tmp->format);
     
    831846    }
    832847  }
    833   else
     848  else{
    834849    sprintf(tmp,"%s",key);
     850    addToMap(m,"length","1");
     851  }
    835852  map* tmpSize=getMapArray(m,"size",index);
    836853  if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
     
    964981  res->content=NULL;
    965982  res->metadata=NULL;
     983  res->additional_parameters=NULL; 
    966984  res->format=NULL;
    967985  res->defaults=NULL;
     
    9831001  res->content=NULL;
    9841002  res->metadata=NULL;
     1003  res->additional_parameters=NULL;
    9851004  res->format=NULL;
    9861005  res->defaults=NULL;
     
    10221041    fprintf(stderr," > METADATA [%s]\n",tmp->name);
    10231042    dumpMap(tmp->metadata);
     1043    fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n",tmp->name);
     1044    dumpMap(tmp->additional_parameters);
    10241045    fprintf(stderr," > FORMAT [%s]\n",tmp->format);
    10251046    iotype* tmpio=tmp->defaults;
     
    11391160  elements* cursor=e;
    11401161  elements* tmp=NULL;
    1141   if(cursor!=NULL){
     1162  if(cursor!=NULL && e->name!=NULL){
    11421163#ifdef DEBUG
    11431164    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
     
    11511172    tmp->metadata=NULL;
    11521173    addMapToMap(&tmp->metadata,e->metadata);
     1174    tmp->additional_parameters=NULL;
     1175    addMapToMap(&tmp->additional_parameters,e->additional_parameters);
    11531176    if(e->format!=NULL)
    11541177      tmp->format=zStrdup(e->format);
     
    11871210    else
    11881211      tmp->child=NULL;
    1189     tmp->next=dupElements(cursor->next);
     1212    if(cursor->next!=NULL)
     1213      tmp->next=dupElements(cursor->next);
     1214    else
     1215      tmp->next=NULL;
    11901216  }
    11911217  return tmp;
     
    12341260    fprintf(stderr,"CONTENT MAP\n");
    12351261    dumpMap(s->content);
    1236     fprintf(stderr,"CONTENT METADATA\n");
     1262    if(s->metadata!=NULL)
     1263      fprintf(stderr,"CONTENT METADATA\n");
    12371264    dumpMap(s->metadata);
     1265    if(s->additional_parameters!=NULL)
     1266      fprintf(stderr,"CONTENT AdditionalParameters\n");
     1267    dumpMap(s->additional_parameters);
    12381268  }
    12391269  if(s->inputs!=NULL){
     
    12931323  res->metadata=NULL;
    12941324  addMapToMap(&res->metadata,s->metadata);
     1325  res->additional_parameters=NULL;
     1326  addMapToMap(&res->additional_parameters,s->additional_parameters);
    12951327  res->inputs=dupElements(s->inputs);
    12961328  res->outputs=dupElements(s->outputs);
  • branches/prototype-v0/zoo-project/zoo-kernel/service.h

    r822 r839  
    139139 * The memory size to create an elements
    140140 */
    141 #define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+(2*sizeof(elements*)))
     141#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*3)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+(2*sizeof(elements*)))
    142142/**
    143143 * The memory size to create a map
     
    159159 */
    160160//#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
    161 #define SERVICE_SIZE sizeof(char*) + 2*sizeof(map*) + 2*sizeof(elements*)
     161#define SERVICE_SIZE sizeof(char*) + 3*sizeof(map*) + 2*sizeof(elements*)
    162162/**
    163163 * The memory size to create a services
     
    228228    struct map* content; //!< the content map
    229229    struct map* metadata; //!< the metadata map
     230    struct map* additional_parameters; //!< the additional parameters map
    230231    char* format; //!< the format: LiteralData or ComplexData or BoundingBoxData
    231232    struct iotype* defaults; //!< the default iotype
     
    242243    struct map* content; //!< the content map
    243244    struct map* metadata; //!< the metadata map
     245    struct map* additional_parameters; //!< the additional parameters map
    244246    struct elements* inputs; //!< the inputs elements
    245247    struct elements* outputs; //!< the outputs elements
     
    278280  ZOO_DLL_EXPORT void freeMap(map**);
    279281  ZOO_DLL_EXPORT void freeMaps(maps** mo);
    280  
    281 
     282  ZOO_DLL_EXPORT iotype* createIoType();
    282283  ZOO_DLL_EXPORT elements* createEmptyElements();
    283284  ZOO_DLL_EXPORT elements* createElements(const char*);
  • branches/prototype-v0/zoo-project/zoo-kernel/service_conf.y

    r790 r839  
    3333static bool wait_maincontent=true;
    3434static bool wait_mainmetadata=false;
     35static bool wait_mainap=false;
    3536static bool wait_metadata=false;
     37static bool wait_ap=false;
    3638static bool wait_nested=false;
    3739static bool wait_inputs=false;
     
    156158    current_content=NULL;
    157159    my_service->metadata=NULL;
     160    my_service->additional_parameters=NULL;
    158161    wait_maincontent=false;
    159162  }
    160163  if(strncasecmp($2,"EndNested",9)==0){
    161164#ifdef DEBUG_SERVICE_CONF
    162       fprintf(stderr,"(ENDNESTED - %d) \n",__LINE__);
    163       fflush(stderr);
    164 #endif
    165       nested_level-=1;
    166       if(nested_level==0){
    167         wait_nested=false;
    168       }
     165    fprintf(stderr,"(ENDNESTED - %d) \n",__LINE__);
     166    fflush(stderr);
     167#endif
     168    nested_level-=1;
     169    if(nested_level==0){
     170      wait_nested=false;
     171    }
    169172  }
    170173
     
    229232    }
    230233    else
    231       if(strncasecmp($2,"MetaData",8)==0){
    232         previous_data=current_data;
    233         current_data=3;
    234         if(current_element!=NULL){
    235 #ifdef DEBUG_SERVICE_CONF
    236           fprintf(stderr,"add current_content to current_element->content\n");
    237           fprintf(stderr,"LINE %d",__LINE__);
    238 #endif
    239           addMapToMap(&current_element->content,current_content);
    240           freeMap(&current_content);
    241           free(current_content);
    242           if(previous_data==1 || previous_data==2)
    243             wait_metadata=true;
    244           else
    245             wait_mainmetadata=true;
    246         }
    247         else{
    248           if(previous_data==1 || previous_data==2)
    249             wait_metadata=true;
    250           else
    251             wait_mainmetadata=true;
     234      if(strncasecmp($2,"MetaData",8)==0 ||
     235         strncasecmp($2,"AdditionalParameters",8)==0){
     236        if(strncasecmp($2,"AdditionalParameters",8)==0){
     237          previous_data=current_data;
     238          current_data=4;
     239          if(current_element!=NULL){
     240#ifdef DEBUG_SERVICE_CONF
     241            fprintf(stderr,"add current_content to current_element->content\n");
     242            fprintf(stderr,"LINE %d",__LINE__);
     243#endif
     244            if(wait_mainmetadata)
     245              addMapToMap(&my_service->metadata,current_content);
     246            else
     247              if(wait_metadata)
     248                addMapToMap(&current_element->metadata,current_content);
     249              else
     250                addMapToMap(&current_element->content,current_content);         
     251            freeMap(&current_content);
     252            free(current_content);
     253            if(previous_data==1 || previous_data==2)
     254              wait_ap=true;
     255            else
     256              wait_mainap=true;
     257          }
     258          else{
     259            if(previous_data==1 || previous_data==2)
     260              wait_ap=true;
     261            else
     262              wait_mainap=true;
     263          }
     264        }else{
     265          previous_data=current_data;
     266          current_data=3;
     267          if(current_element!=NULL){
     268#ifdef DEBUG_SERVICE_CONF
     269            fprintf(stderr,"add current_content to current_element->content\n");
     270            fprintf(stderr,"LINE %d",__LINE__);
     271#endif
     272            addMapToMap(&current_element->content,current_content);
     273            freeMap(&current_content);
     274            free(current_content);
     275            if(previous_data==1 || previous_data==2)
     276              wait_metadata=true;
     277            else
     278              wait_mainmetadata=true;
     279          }
     280          else{
     281            if(previous_data==1 || previous_data==2)
     282              wait_metadata=true;
     283            else
     284              wait_mainmetadata=true;
     285          }
    252286        }
    253287        current_content=NULL;
     
    425459  if(strcmp($3,"DataOutputs")==0){
    426460    current_data=2;
     461  } 
     462  if(strcmp($3,"AdditionalParameters")==0){
     463    if(current_content!=NULL){
     464#ifdef DEBUG_SERVICE_CONF
     465      fprintf(stderr,"add current_content to current_element->content\n");
     466      fprintf(stderr,"LINE %d",__LINE__);
     467#endif
     468      if(wait_ap){
     469        current_element->additional_parameters=NULL;
     470        addMapToMap(&current_element->additional_parameters,current_content);
     471        current_element->next=NULL;
     472        current_element->defaults=NULL;
     473        current_element->supported=NULL;
     474        current_element->child=NULL;
     475      }else{
     476        if(wait_mainap){
     477          addMapToMap(&my_service->additional_parameters,current_content);
     478        }
     479      }
     480
     481      freeMap(&current_content);
     482      free(current_content);
     483      current_content=NULL;
     484    }
     485    current_data=previous_data;
     486    wait_mainap=false;
     487    wait_ap=false;
    427488  }
    428489  if(strcmp($3,"MetaData")==0){
     
    866927  wait_mainmetadata=false;
    867928  wait_metadata=false;
     929  wait_mainap=false;
     930  wait_ap=false;
    868931  wait_inputs=false;
    869932  wait_defaults=false;
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c

    r788 r839  
    148148
    149149    //FILE* f0 = fopen (fileName, "r");
    150         // knut: open file in binary mode to avoid conversion of line endings (yielding extra bytes) on Windows platforms
    151         FILE* f0 = fopen(fileName, "rb");
     150    // knut: open file in binary mode to avoid conversion of line endings (yielding extra bytes) on Windows platforms
     151    FILE* f0 = fopen(fileName, "rb");
    152152    if(f0!=NULL){
    153153      fseek (f0, 0, SEEK_END);
     
    162162        free(stat);
    163163      }
    164 
    165164      return tmps1;
    166165    }
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c

    r822 r839  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2015 GeoLabs SARL
     4 * Copyright (c) 2017 GeoLabs SARL
     5 *
     6 * This work was supported by public funds received in the framework of GEOSUD,
     7 * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed
     8 * by the French National Research Agency
    59 *
    610 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    2226 * THE SOFTWARE.
    2327 *
    24  * See Ref: http://hg.orfeo-toolbox.org/OTB/ Copyright
    25  * Some parts of this code are derived from ITK. See ITKCopyright.txt for
    26  * details.
    2728 */
    2829
     
    3031#include "response_print.h"
    3132#include "server_internal.h"
     33#include "service_callback.h"
     34#include "mimetypes.h"
    3235#include <sys/un.h>
    3336
    34 void appendOutputParameters(maps* input,char** parameters,int* cnt,service* s,map* uuid,map* targetPathMap){
    35   while(input!=NULL){
    36     if(input->child==NULL){
    37       *cnt+=1;
    38       if(*cnt==1)
    39         parameters=(char**)malloc((*cnt)*sizeof(char*));
    40       else
    41         parameters=(char**)realloc(parameters,(*cnt)*sizeof(char*));
    42       // Name every files that should be produced by the service execution
    43       char* targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+10)*sizeof(char));
    44       sprintf(targetName,"output_%s_%s_%s",s->name,input->name,uuid->value);
    45       // TODO: We should verify if any optional tag for output is required (i.e. -out output.tiff int8)
    46       char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
    47       sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
    48       parameters[*cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char));
    49       sprintf(parameters[*cnt-1],"-%s %s",input->name,targetPath);
    50     }else
    51       appendOutputParameters(input->child,parameters,cnt,s,uuid,targetPathMap);
    52     input=input->next;
     37typedef struct {
     38  maps* conf;
     39  char* local_file;
     40  char* target_file;
     41} local_params;
     42
     43#ifdef PTHREADS
     44#endif
     45
     46void addNestedOutputs(service** s){
     47  if((*s)==NULL){
     48    return;
     49  }   
     50  if(*s==NULL || (*s)->outputs==NULL){
     51    return;
     52  }
     53  elements *out=(*s)->outputs;
     54  elements* cur=out;
     55  map* serviceType=getMap((*s)->content,"ServiceType");
     56  if(strncmp(serviceType->value,"HPC",3)!=0)
     57    return;
     58  while(cur!=NULL && cur->defaults!=NULL){
     59    map* mimeType=getMap(cur->defaults->content,"mimeType");
     60    if(mimeType!=NULL){
     61      int geo=isGeographic(mimeType->value);
     62      if(geo>0){
     63        elements *tmp[3]={
     64          dupElements(cur),
     65          dupElements(cur),
     66          dupElements(cur)
     67        };
     68        char *geoLink="wcs_link";
     69        if(geo==2){
     70          geoLink="wfs_link";
     71        }
     72        int i=0;
     73        for(;i<3;i++){
     74          if(tmp[i]->next!=NULL){
     75            freeElements(&tmp[i]->next);
     76            free(tmp[i]->next);
     77            tmp[i]->next=NULL;
     78          }
     79          free(tmp[i]->name);
     80          tmp[i]->format=zStrdup("ComplexData");
     81          freeMap(&tmp[i]->content);
     82          free(tmp[i]->content);
     83          tmp[i]->content=NULL;
     84          switch(i){
     85          case 0:
     86            tmp[i]->name=zStrdup("download_link");
     87            tmp[i]->content=createMap("Title",_("Download link"));
     88            addToMap(tmp[i]->content,"Abstract",_("The download link"));
     89            addToMap(tmp[i]->defaults->content,"useMapserver","false");
     90            if(tmp[i]->supported!=NULL){
     91              freeIOType(&tmp[i]->supported);
     92              free(tmp[i]->supported);
     93              tmp[i]->supported=NULL;
     94            }
     95            break;
     96          case 1:
     97            tmp[i]->name=zStrdup("wms_link");
     98            tmp[i]->content=createMap("Title",_("WMS link"));
     99            addToMap(tmp[i]->content,"Abstract",_("The WMS link"));
     100            if(tmp[i]->supported!=NULL && tmp[i]->supported->next!=NULL){
     101              freeIOType(&tmp[i]->supported->next);
     102              free(tmp[i]->supported->next);
     103              tmp[i]->supported->next=NULL;
     104            }else{
     105              if(tmp[i]->supported!=NULL)
     106                addToMap(tmp[i]->supported->content,"useMapserver","true");
     107              addToMap(tmp[i]->defaults->content,"useMapserver","true");
     108            }
     109            break;
     110          case 2:
     111            if(geo==2){
     112              tmp[i]->name=zStrdup("wfs_link");
     113              tmp[i]->content=createMap("Title",_("WFS link"));
     114              addToMap(tmp[i]->content,"Abstract",_("The WFS link"));
     115            }else{
     116              tmp[i]->name=zStrdup("wcs_link");
     117              tmp[i]->content=createMap("Title",_("WCS link"));
     118              addToMap(tmp[i]->content,"Abstract",_("The WCS link"));
     119            }
     120            if(tmp[i]->supported!=NULL && tmp[i]->supported->next!=NULL &&
     121               tmp[i]->supported->next->content!=NULL){
     122              freeIOType(&tmp[i]->supported);
     123              free(tmp[i]->supported);
     124              tmp[i]->supported=NULL;
     125              tmp[i]->supported=createIoType();
     126              iotype* cnext=cur->supported->next;
     127              tmp[i]->supported->content=createMap(cnext->content->name,cnext->content->value);
     128              addMapToMap(&tmp[i]->supported->content,cnext->content->next);
     129              addToMap(tmp[i]->supported->content,"useMapserver","true");
     130            }else
     131              addToMap(tmp[i]->defaults->content,"useMapserver","true");
     132            break;
     133          }
     134        }
     135       
     136        addToElements(&cur->child,tmp[0]);
     137        addToElements(&cur->child,tmp[1]);
     138        addToElements(&cur->child,tmp[2]);
     139        free(cur->format);
     140        cur->format=NULL;
     141        if(cur->defaults!=NULL){
     142          freeIOType(&cur->defaults);
     143          cur->defaults=NULL;
     144        }
     145        if(cur->supported!=NULL){
     146          freeIOType(&cur->supported);
     147          cur->supported=NULL;
     148        }
     149        freeElements(&tmp[2]);
     150        free(tmp[2]);
     151        freeElements(&tmp[1]);
     152        free(tmp[1]);
     153        freeElements(&tmp[0]);
     154        free(tmp[0]);
     155        //addToMap(cur->content,"internal","true");
     156      }
     157    }
     158    cur=cur->next;
    53159  }
    54160}
     
    71177  map* tmp=NULL;
    72178  int res=-1;
    73   map* targetPathMap=getMapFromMaps(*main_conf,"HPC","storagePath");
     179  char *serviceType;
     180  map* mServiceType=getMap(s->content,"serviceType");
     181  if(mServiceType!=NULL)
     182    serviceType=mServiceType->value;
     183  else
     184    serviceType="HPC";
     185  map* targetPathMap=getMapFromMaps(*main_conf,serviceType,"storagePath");
    74186  map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
    75187  map* uuid=getMapFromMaps(*main_conf,"lenv","usid");
    76 
    77   sleep(5);
     188  pthread_t threads_pool[50];
     189  // Force the HPC services to be called asynchronously
     190  map* isAsync=getMapFromMaps(*main_conf,"lenv","async");
     191  if(isAsync==NULL){
     192    errorException(*main_conf,_("The synchronous mode is not supported by this type of service"),"NoSuchMode",s->name);
     193    return -1;
     194  }
    78195
    79196  maps* input=*real_inputs;
    80197  char **parameters=NULL;
    81198  int parameters_cnt=0;
    82   while(input!=NULL){
    83     parameters_cnt+=1;
    84     if(parameters_cnt==1)
    85       parameters=(char**)malloc(parameters_cnt*sizeof(char*));
    86     else
    87       parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*));
    88     if(getMap(input->content,"mimeType")!=NULL){
    89       // Input is ComplexData
    90       SSHCON *test=ssh_connect(*main_conf);
    91       dumpMaps(getMaps(*main_conf,"lenv"));
    92       if(test==NULL){   
    93         sleep(3600);
    94         return -1;
    95       }
    96       if(getMap(input->content,"cache_file")==NULL){
    97         // Input data has been passed by value
    98         // TODO: store data remotely
    99         // TODO: publish input through MapServer / use output publication
    100         dumpMapsValuesToFiles(main_conf,&input);
    101       }
    102       if(getMap(input->content,"cache_file")!=NULL){
    103         // Input data passed by reference or by value
    104         map* tmp=getMap(input->content,"cache_file");
    105         char* targetName=strrchr(tmp->value,'/');
    106         char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
    107         sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
    108         ssh_copy(*main_conf,tmp->value,targetPath);
    109         parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char));
    110         sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath);
    111         free(targetPath);
     199  while(input!=NULL && input->content!=NULL){
     200    if(getMaps(*real_outputs,input->name)==NULL){
     201      parameters_cnt+=1;
     202      if(parameters_cnt==1)
     203        parameters=(char**)malloc(parameters_cnt*sizeof(char*));
     204      else
     205        parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*));
     206      if(getMap(input->content,"mimeType")!=NULL){
     207        // Input is ComplexData
     208        if(getMap(input->content,"cache_file")==NULL){
     209          // Input data has been passed by value
     210          // TODO: publish input through MapServer / use output publication
     211          dumpMapsValuesToFiles(main_conf,&input);
     212          addToMap(input->content,"toPublish","true");
     213        }
     214        if(getMap(input->content,"cache_file")!=NULL){
     215          map* length=getMap(input->content,"length");
     216          if(length==NULL){
     217            addToMap(input->content,"length","1");
     218            length=getMap(input->content,"length");
     219          }
     220          int len=atoi(length->value);
     221          int i=0;
     222          for(i=0;i<len;i++){
     223            map* tmp=getMapArray(input->content,"cache_file",i);
     224            char* targetName=strrchr(tmp->value,'/');
     225            char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
     226            sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
     227            setMapArray(input->content,"targetPath",i,targetPath);
     228            setMapArray(input->content,"localPath",i,tmp->value);
     229            addToUploadQueue(main_conf,input);
     230            if(i==0){
     231              parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char));
     232              sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath);
     233            }else{
     234              char *tmpStr=zStrdup(parameters[parameters_cnt-1]);
     235              parameters[parameters_cnt-1]=(char*)realloc(parameters[parameters_cnt-1],(strlen(tmpStr)+strlen(targetPath)+2)*sizeof(char));
     236              sprintf(parameters[parameters_cnt-1],"%s %s",tmpStr,targetPath);
     237              free(tmpStr);
     238            }
     239            free(targetPath);
     240          }
     241        }else{
     242          // ???
     243          fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     244          fflush(stderr);
     245        }
    112246      }else{
    113         // ???
    114         fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    115         fflush(stderr);
    116       }
    117     }else{
    118       // LitteralData and BboxData
    119       if(getMap(input->content,"dataType")!=NULL){
    120         // For LitteralData, simply pass the value
    121         map* val=getMap(input->content,"value");
    122         sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,val->value);
    123       }
    124      
     247        // LitteralData and BboxData
     248        if(getMap(input->content,"dataType")!=NULL){
     249          // For LitteralData, simply pass the value
     250          map* val=getMap(input->content,"value");
     251          parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(val->value)+3)*sizeof(char));
     252          sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,val->value);
     253        }
     254      }
    125255    }
    126256    input=input->next;
    127257  }
     258
     259  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     260  invokeCallback(m,inputs,NULL,2,0);
     261  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     262
     263  // Upload data on HPC
     264  runUpload(main_conf);
     265 
     266  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     267  invokeCallback(m,inputs,NULL,2,1);
     268  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    128269
    129270  // Add the filename to generate for every output to the parameters
     
    140281        parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*));
    141282      // Name every files that should be produced by the service execution
    142       char* targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+10)*sizeof(char));
    143       sprintf(targetName,"output_%s_%s_%s",s->name,input->name,uuid->value);
    144       // TODO: We should verify if any optional tag for output is required (i.e. -out output.tiff *int8*)
    145       // TODO: Add support for Array values
     283      map* mime=getMap(input->content,"mimeType");
     284      char* targetName;
     285      if(mime!=NULL){
     286        bool hasExt=false;
     287        map* fileExt=getFileExtensionMap(mime->value,&hasExt);
     288        targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+strlen(fileExt->value)+11)*sizeof(char));
     289        sprintf(targetName,"output_%s_%s_%s.%s",s->name,input->name,uuid->value,fileExt->value);
     290        freeMap(&fileExt);
     291        free(fileExt);
     292      }else{
     293        targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+14)*sizeof(char));
     294        sprintf(targetName,"output_%s_%s_%s.tif",s->name,input->name,uuid->value);
     295      }
    146296      char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
    147297      sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
    148298      setMapInMaps(*real_outputs,input->name,"generated_file",targetPath);
    149       parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char));
    150       sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath);
     299      // We should verify if any optional tag for output is required
     300      // (i.e. -out output.tiff *int8*), meaning that we should search
     301      // for a corresponding inputs name.
     302      map* inValue=getMapFromMaps(*real_inputs,input->name,"value");
     303      if(inValue!=NULL){
     304        parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+strlen(inValue->value)+4)*sizeof(char));
     305        sprintf(parameters[parameters_cnt-1],"-%s %s %s",input->name,targetPath,inValue->value);
     306      }else{
     307        parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char));
     308        sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath);
     309      }
     310      free(targetPath);
     311    }// In other case it means we need to return the cache_file as generated_file
     312    else{
     313      parameters_cnt+=1;
     314      if(parameters_cnt==1)
     315        parameters=(char**)malloc(parameters_cnt*sizeof(char*));
     316      else
     317        parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*));
     318      // Name every files that should be produced by the service execution
     319      map* mime=getMap(input->child->content,"mimeType");
     320      char* targetName;
     321      if(mime!=NULL){
     322        bool hasExt=false;
     323        map* fileExt=getFileExtensionMap(mime->value,&hasExt);
     324        targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+strlen(fileExt->value)+11)*sizeof(char));
     325        sprintf(targetName,"output_%s_%s_%s.%s",s->name,input->name,uuid->value,fileExt->value);
     326        freeMap(&fileExt);
     327        free(fileExt);
     328      }else{
     329        targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+14)*sizeof(char));
     330        sprintf(targetName,"output_%s_%s_%s.tif",s->name,input->name,uuid->value);
     331      }
     332      char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
     333      sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
     334      addToMap(input->content,"generated_file",targetPath);
     335      // We should verify if any optional tag for output is required
     336      // (i.e. -out output.tiff *int8*), meaning that we should search
     337      // for a corresponding inputs name.
     338      map* inValue=getMapFromMaps(*real_inputs,input->name,"value");
     339      if(inValue!=NULL){
     340        parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+strlen(inValue->value)+4)*sizeof(char));
     341        sprintf(parameters[parameters_cnt-1],"-%s %s %s",input->name,targetPath,inValue->value);
     342      }else{
     343        parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char));
     344        sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath);
     345      }
     346      free(targetPath);
    151347    }
    152348    input=input->next;
    153349  }
    154350 
     351  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     352  fflush(stderr);
     353  invokeCallback(m,inputs,NULL,3,0);
     354  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     355  fflush(stderr);
     356
    155357  // Produce the SBATCH File locally
    156   char *scriptPath=(char*)malloc((strlen(s->name)+strlen(tmpPath->value)+strlen(uuid->value)+9)*sizeof(char));
     358  char *scriptPath=(char*)malloc((strlen(s->name)+strlen(tmpPath->value)+strlen(uuid->value)+10)*sizeof(char));
    157359  sprintf(scriptPath,"%s/zoo_%s_%s.sh",tmpPath->value,s->name,uuid->value);
     360  setMapInMaps(*main_conf,"lenv","local_script",scriptPath);
     361  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     362  fflush(stderr);
     363  invokeCallback(m,inputs,NULL,3,0);
     364  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     365  fflush(stderr);
    158366  FILE* scriptFile=fopen(scriptPath,"w+");
    159   maps* hpc_opts=getMaps(*main_conf,"sbatch_options");
    160   map* hpc_opts_content=hpc_opts->content;
    161   map* headerMap=getMapFromMaps(*main_conf,"HPC","header");
     367  map* headerMap=getMapFromMaps(*main_conf,serviceType,"header");
    162368  if(headerMap!=NULL){
    163369    // Use the header file if defined in the HPC section of the main.cfg file
     
    171377      fcontent[fsize]=0;
    172378      fclose(f);
    173       fprintf(scriptFile,"%s\n### --- ZOO-Service HEADER end --- ###",fcontent);
     379      fprintf(scriptFile,"%s\n### --- ZOO-Service HEADER end --- ###\n\n",fcontent);
    174380      free(fcontent);
    175381    }else
     
    177383  }else
    178384    fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service HEADER *** ###\n\n");
    179  
    180   while(hpc_opts_content!=NULL){
    181     fprintf(scriptFile,"#SBATCH --%s=%s\n",hpc_opts_content->name,hpc_opts_content->value);
    182     hpc_opts_content=hpc_opts_content->next;
     385  maps* hpc_opts=getMaps(*main_conf,"sbatch_options");
     386  if(hpc_opts!=NULL){
     387    map* hpc_opts_content=hpc_opts->content;
     388    while(hpc_opts_content!=NULL){
     389      fprintf(scriptFile,"#SBATCH --%s=%s\n",hpc_opts_content->name,hpc_opts_content->value);
     390      hpc_opts_content=hpc_opts_content->next;
     391    }
    183392  }
    184393  fprintf(scriptFile,"#SBATCH --job-name=ZOO-Project_%s_%s\n\n",uuid->value,s->name);
     
    186395  if(mods!=NULL)
    187396    fprintf(scriptFile,"#SBATCH --export=MODULES=%s\n",mods->value);
    188   else
    189     fprintf(scriptFile,"#SBATCH --export=MODULES=\n");
     397
     398  map* bodyMap=getMapFromMaps(*main_conf,serviceType,"body");
     399  if(bodyMap!=NULL){
     400    // Use the header file if defined in the HPC section of the main.cfg file
     401    struct stat f_status;
     402    int s=stat(bodyMap->value, &f_status);
     403    if(s==0){
     404      char* fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
     405      FILE* f=fopen(bodyMap->value,"rb");
     406      fread(fcontent,f_status.st_size,1,f);
     407      int fsize=f_status.st_size;
     408      fcontent[fsize]=0;
     409      fclose(f);
     410      fprintf(scriptFile,"%s\n### --- ZOO-Service BODY end --- ###\n\n",fcontent);
     411      free(fcontent);
     412    }else
     413      fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service BODY (no body found) *** ###\n\n");
     414  }else
     415    fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service BODY *** ###\n\n");
     416
     417 
    190418  map* sp=getMap(s->content,"serviceProvider");
     419 
    191420  // Require to produce the command line to be executed
    192421  fprintf(scriptFile,"\n\necho \"Job started at: $(date)\"\n");
     
    195424  for(int i=0;i<parameters_cnt;i++){
    196425    fprintf(scriptFile," %s",parameters[i]);
    197     //free(parameters[i]);
     426  }
     427  for(int i=parameters_cnt-1;i>=0;i--){
     428    free(parameters[i]);
    198429  }
    199430  free(parameters);
    200431  fprintf(scriptFile,"\n");
    201432  fprintf(scriptFile,"echo \"Job finished at: $(date)\"\n");
    202  
    203433  fflush(scriptFile);
    204434  fclose(scriptFile);
     435 
     436  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     437  invokeCallback(m,inputs,NULL,3,1);
     438  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    205439
    206440  // Upload the SBATCH File to the remote host
    207   targetPathMap=getMapFromMaps(*main_conf,"HPC","executePath");
     441  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     442  invokeCallback(m,inputs,NULL,4,0);
     443  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     444  targetPathMap=getMapFromMaps(*main_conf,serviceType,"executePath");
    208445  if(targetPathMap==NULL){
    209446    setMapInMaps(*main_conf,"lenv","message",_("There is no executePath defined in you HPC section!"));
     
    213450  char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
    214451  sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
     452  setMapInMaps(*main_conf,"lenv","remote_script",targetPath);
    215453  SSHCON *test=ssh_connect(*main_conf);
    216   ssh_copy(*main_conf,scriptPath,targetPath);
     454  ssh_copy(*main_conf,scriptPath,targetPath,ssh_get_cnt(*main_conf));
    217455 
    218456  // Execute the SBATCH script remotely
    219457  map* subStr=getMapFromMaps(*main_conf,"HPC","subStr");
    220   //char *command=(char*)malloc((strlen(targetPath)+strlen(targetPathMap->value)+strlen(subStr->value)+strlen(uuid->value)+37)*sizeof(char));
    221458  char *command=(char*)malloc((strlen(targetPath)+strlen(targetPathMap->value)+strlen(subStr->value)+strlen(uuid->value)+137)*sizeof(char));
    222   //sprintf(command,"ls # %s 2> %s/error_%s.log | sed \"s:%s::g\"",targetPath,targetPathMap->value,uuid->value,subStr->value);
    223459  sprintf(command,"sbatch %s 2> %s/error_%s.log | sed \"s:%s::g\"",targetPath,targetPathMap->value,uuid->value,subStr->value);
    224   if(ssh_exec(*main_conf,command)==0){
     460  if(ssh_exec(*main_conf,command,ssh_get_cnt(m))==0){
    225461    // The sbatch command has failed!
    226462    // Download the error log file from the HPC server
    227463    char tmpS[1024];
    228464    free(command);
    229     command=(char*)malloc((strlen(targetPathMap->value)+strlen(uuid->value)+22)*sizeof(char));
     465    command=(char*)malloc((strlen(targetPathMap->value)+strlen(uuid->value)+11)*sizeof(char));
    230466    sprintf(command,"%s/error_%s.log",targetPathMap->value,uuid->value);
    231467    targetName=strrchr(command,'/');
     
    233469    targetPath=(char*)malloc((strlen(tmpPath->value)+strlen(targetName)+2)*sizeof(char));
    234470    sprintf(targetPath,"%s/%s",tmpPath->value,targetName);
    235     if(ssh_fetch(*main_conf,targetPath,command)==0){
     471    if(ssh_fetch(*main_conf,targetPath,command,ssh_get_cnt(m))==0){
    236472      struct stat f_status;
    237473      int ts=stat(targetPath, &f_status);
     
    251487      setMapInMaps(*main_conf,"lenv","message",_("Unable to fetch the remote error log file"));
    252488    tmpPath=getMapFromMaps(*main_conf,"lenv","message");
     489    invokeCallback(m,NULL,NULL,7,1);
    253490    sprintf(tmpS, "Cannot execute the HPC ZOO-Service %s: %s", s->name, tmpPath->value);
    254491    errorException(m,tmpS,"NoApplicableCode",NULL);
     
    259496    return -1;
    260497  }
     498  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     499  fflush(stderr);
     500  invokeCallback(m,NULL,NULL,4,1);
     501  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     502  fflush(stderr);
     503  free(command);
    261504
    262505  struct sockaddr_un addr;
     
    264507  addr.sun_family = AF_UNIX;
    265508  int rc, cl, fd = socket(AF_UNIX, SOCK_STREAM, 0);
    266   char buf[100];
    267   char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(uuid->value)+19));
     509  char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(uuid->value)+20));
    268510  sprintf(sname,"%s/.wait_socket_%s.sock",tmpPath->value,uuid->value);
    269511  strncpy(addr.sun_path, sname, sizeof(addr.sun_path)-1);
     512 
    270513  if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
    271514    perror("bind error");
     
    274517  }
    275518  if (listen(fd, 5) == -1) {
    276     perror("listen error");
    277     sleep(120);
     519    setMapInMaps(*main_conf,"lenv","message",_("Listen error"));
    278520    return -1;
    279521  }
    280   /*fd_set master, read_fds;
    281   int fdmax;
    282   FD_ZERO(&master);
    283   FD_ZERO(&read_fds);
    284   FD_SET(fd, &master);
    285   if (select(fd+1, &master, NULL, NULL, NULL) == -1) {
    286     perror("select");
    287     sleep(120);
     522  if ( (cl = accept(fd, NULL, NULL)) == -1) {
     523    setMapInMaps(*main_conf,"lenv","message",_("Accept error"));
    288524    return -1;
    289   }
    290   if (FD_ISSET(fd, &master)) {*/
    291     if ( (cl = accept(fd, NULL, NULL)) == -1) {
    292       perror("accept error");
     525  }else{
     526    int hasPassed=-1;
     527    char buf[11];
     528    memset(&buf,0,11);
     529    while ( (rc=read(cl,buf,10)) ) {     
     530      if(rc==0){
     531        sleep(1);
     532        setMapInMaps(*main_conf,"lenv","message",_("Read closed"));
     533        return -1;
     534      }else{
     535        if(rc<0){
     536          setMapInMaps(*main_conf,"lenv","message",_("Read error"));
     537          return -1;
     538        }
     539      }
     540      hasPassed=1;
     541      res=atoi(buf);
     542      unlink(sname);
     543      //free(sname); 
     544
     545      if(res==3){
     546        fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     547        fflush(stderr);
     548        invokeCallback(m,NULL,outputs,5,0);
     549        fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     550        fflush(stderr);
     551        input=*real_outputs;
     552        while(input!=NULL){
     553          if(input->child==NULL){
     554            map* generatedFile=getMap(input->content,"generated_file");
     555            if(generatedFile!=NULL){
     556              char* filename=strrchr(generatedFile->value,'/');
     557              char* targetPath=(char*)malloc((strlen(tmpPath->value)+strlen(filename)+2)*sizeof(char));
     558              sprintf(targetPath,"%s/%s",tmpPath->value,filename);
     559              test=ssh_connect(*main_conf);
     560              if(ssh_fetch(*main_conf,targetPath,generatedFile->value,ssh_get_cnt(m))==0){
     561                setMapInMaps(*real_outputs,input->name,"generated_file",targetPath);
     562                free(targetPath);
     563              }else{
     564                char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char));
     565                sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename);
     566                setMapInMaps(*main_conf,"lenv","message",tmpStr);
     567                free(tmpStr);
     568                return SERVICE_FAILED;
     569              }
     570            }       
     571          }else{
     572            fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     573            fflush(stderr);
     574            map* generatedFile=getMap(input->content,"generated_file");
     575            if(generatedFile!=NULL){
     576              char* filename=strrchr(generatedFile->value,'/');
     577              char* targetPath=(char*)malloc((strlen(tmpPath->value)+strlen(filename)+2)*sizeof(char));
     578              sprintf(targetPath,"%s/%s",tmpPath->value,filename);
     579              test=ssh_connect(*main_conf);
     580              if(ssh_fetch(*main_conf,targetPath,generatedFile->value,ssh_get_cnt(m))==0){
     581                maps* tmp=getMaps(*real_outputs,input->name);
     582                freeMap(&tmp->content);
     583                free(tmp->content);
     584                tmp->content=NULL;
     585                maps* output=getMaps(*real_outputs,input->name);
     586                setMapInMaps(output->child,"download_link","generated_file",targetPath);
     587                setMapInMaps(output->child,"download_link","useMapserver","false");
     588                setMapInMaps(output->child,"WMS_LINK","generated_file",targetPath);
     589                setMapInMaps(output->child,"WMS_LINK","useMapserver","true");
     590                setMapInMaps(output->child,"WCS_LINK","generated_file",targetPath);
     591                setMapInMaps(output->child,"WCS_LINK","useMapserver","true");
     592              }
     593            }
     594          }
     595          input=input->next;
     596        }
     597      }
     598      //free(buf);
     599    }
     600    if(hasPassed<0){
     601      perror("Failed to read");
     602      setMapInMaps(*main_conf,"lenv","message",_("Unable to parse the value returned by remote execution"));
    293603      sleep(120);
    294       return -1;
    295     }else{
    296       int hasPassed=-1;
    297       /*FD_SET(cl,&read_fds);
    298       if (select(cl+1, &read_fds, NULL, NULL, NULL) == -1) {
    299         perror("select");
    300         sleep(120);
    301         return -1;
    302         }*/
    303       while ( (rc=read(cl,buf,10)) ) {   
    304         if(rc==0){
    305           sleep(120);
    306           return -1;
    307         }else{
    308           if(rc<0){
    309             perror("read");
    310             sleep(120);
    311             return -1;
    312           }
    313         }
    314         hasPassed=1;
    315         res=atoi(buf);
    316         unlink(sname);
    317         if(res==3){
    318           input=*real_outputs;
    319           while(input!=NULL){
    320             // TODO: parse all outputs including inner outputs if required.
    321             if(input->child==NULL){
    322               //map* dataPath=getMapFromMaps(*main_conf,"main","dataPath");
    323               map* generatedFile=getMap(input->content,"generated_file");
    324               if(generatedFile!=NULL){
    325                 char* filename=strrchr(generatedFile->value,'/');
    326                 char* targetPath=(char*)malloc((strlen(tmpPath->value)+strlen(filename)+2)*sizeof(char));
    327                 sprintf(targetPath,"%s/%s",tmpPath->value,filename);
    328                 test=ssh_connect(*main_conf);
    329                 if(ssh_fetch(*main_conf,targetPath,generatedFile->value)==0){
    330                   setMapInMaps(*real_outputs,input->name,"generated_file",targetPath);
    331                 }else{
    332                   char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char));
    333                   sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename);
    334                   setMapInMaps(*main_conf,"lenv","message",tmpStr);
    335                   free(tmpStr);
    336                   return SERVICE_FAILED;
    337                 }
    338               }
    339             }/*else{
    340              // Generate the nested outputs based on each input value
    341              if(getMaps(*real_inputs,input->name)!=NULL && getMapFromMaps(*real_inputs,input->name,"mimeType")!=NULL){
    342              // Input was ComplexeData
    343              maps* output=getMaps(*real_outputs,input->name);
    344              map* cache=getMapFromMaps(*real_inputs,input->name,"cache_file");
    345              setMapInMaps(output->child,"download","generated_file",cache->value);
    346              setMapInMaps(output->child,"WCS_LINK","generated_file",cache->value);
    347              setMapInMaps(output->child,"WCS_LINK","useMs","true");
    348              setMapInMaps(output->child,"WMS_LINK","generated_file",cache->value);
    349              setMapInMaps(output->child,"WMS_LINK","useMs","true");
    350              }
    351              }*/
    352             input=input->next;
    353           }
    354         }
    355       }
    356       if(hasPassed<0){
    357         perror("Failed to read");
    358         setMapInMaps(*main_conf,"lenv","message",_("Unable to parse the value returned by remote execution"));
    359         sleep(120);
    360         return SERVICE_FAILED;
    361       }
     604      return SERVICE_FAILED;
    362605    }
    363     //}
     606  }
    364607  ssh_close(*main_conf);
    365   //sleep(120);
    366608  return res;
    367609}
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.h

    r822 r839  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2015 GeoLabs SARL
     4 * Copyright (c) 2017 GeoLabs SARL
     5 *
     6 * This work was supported by public funds received in the framework of GEOSUD,
     7 * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed
     8 * by the French National Research Agency
    59 *
    610 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    3741#include "sshapi.h"
    3842
     43void addNestedOutputs(service**);
    3944int zoo_hpc_support(maps**,map*,service*,maps**,maps**);
    4045
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal_js.c

    r790 r839  
    934934  }else{
    935935    if(argc==3){
    936       char *body=JSValToChar(cx,&argv[2]);
    937       InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],body,strlen(body),
    938                       INTERNET_FLAG_NO_CACHE_WRITE,0);
    939       processDownloads(&hInternet);
    940       free(body);
     936      if(strncasecmp(method,"GET",3)==0){
     937        header=JSVAL_TO_OBJECT(argv[2]);
     938        if(JS_IsArrayObject(cx,header)){
     939          setHeader(&hInternet,cx,header);
     940        }
     941        InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],NULL,0,
     942                        INTERNET_FLAG_NO_CACHE_WRITE,0);
     943        processDownloads(&hInternet);
     944      }else{
     945        char *body=JSValToChar(cx,&argv[2]);
     946        InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],body,strlen(body),
     947                        INTERNET_FLAG_NO_CACHE_WRITE,0);
     948        processDownloads(&hInternet);
     949        free(body);
     950      }
    941951    }else{
    942952      InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],NULL,0,
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c

    r822 r839  
    131131 */
    132132void setReferenceUrl(maps* m,maps* tmpI){
    133   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    134   fflush(stderr);
    135   dumpMaps(tmpI);
    136   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    137   fflush(stderr);
    138133  outputMapfile(m,tmpI);
    139   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    140   fflush(stderr);
    141   dumpMaps(tmpI);
    142   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    143   fflush(stderr);
    144134  map *msUrl=getMapFromMaps(m,"main","mapserverAddress");
    145135  if(msUrl==NULL){
     
    169159  if(strncasecmp(rformat->value,"text/xml",8)==0)
    170160    proto=1;
    171   if(strncasecmp(rformat->value,"image/tiff",10)==0)
     161  if(strncasecmp(rformat->value,"image/tiff",10)==0 ||
     162     strncasecmp(rformat->value,"image/geotiff",10)==0)
    172163    proto=2;
    173164  if(protoMap!=NULL){
     
    478469    fprintf(stderr,"Unable to access the DataSource as ZIP File\n");
    479470    setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode");
    480     OGR_DS_Destroy(poDS1);
     471    //OGR_DS_Destroy(poDS1);
    481472  }else{
    482473#ifdef DEBUGMS
     
    549540#endif
    550541    setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode");
    551     OGR_DS_Destroy(poDS);
    552     OGRCleanupAll();
     542    //OGR_DS_Destroy(poDS);
     543    //OGRCleanupAll();
    553544#ifdef DEBUGMS
    554545    fprintf(stderr,"Unable to access the DataSource, exit! \n");
     
    652643    if (OGR_L_GetExtent(poLayer,&oExt, TRUE) == OGRERR_NONE){
    653644      setMsExtent(output,m,myLayer,oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
     645      char extent[1024];
     646      memset(&extent,0,1024);
     647      sprintf(extent,"%d,%d,%d,%d",oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
     648      addToMap(output->content,"boundingbox",extent);
    654649    }
    655650 
     
    724719  }
    725720
    726   OGR_DS_Destroy(poDS);
    727   OGRCleanupAll();
     721  //OGR_DS_Destroy(poDS);
     722  //OGRCleanupAll();
    728723
    729724  return 1;
     
    819814  }
    820815
    821 
    822816  /**
    823817   * Set extent
     
    836830        + adfGeoTransform[4] * GDALGetRasterXSize(hDataset);
    837831
    838        setMsExtent(output,m,myLayer,minX,minY,maxX,maxY);
    839 
     832      setMsExtent(output,m,myLayer,minX,minY,maxX,maxY);
     833      char extent[1024];
     834      memset(&extent,0,1024);
     835      sprintf(extent,"%d,%d,%d,%d",minX,minY,maxX,maxY);
     836      addToMap(output->content,"boundingbox",extent);
    840837    }
    841838  }
     
    846843   */
    847844  char nBands[3];
     845  memset(&nBands,0,3);
    848846  int nBandsI=GDALGetRasterCount( hDataset );
    849   sprintf(nBands,"%d",GDALGetRasterCount( hDataset ));
    850   msInsertHashTable(&(myLayer->metadata), "ows_bandcount", nBands);
     847  if(nBandsI<100){
     848    sprintf(nBands,"%d",GDALGetRasterCount( hDataset ));
     849    msInsertHashTable(&(myLayer->metadata), "ows_bandcount", nBands);
     850  }
    851851  if(nBandsI>=3)
    852852    msLayerAddProcessing(myLayer,"BANDS=1,2,3");
     
    860860   */
    861861  char lBands[7];
     862  memset(&nBands,0,7);
    862863  char *nameBands=NULL;
    863864  for( iBand = 0; iBand < nBandsI; iBand++ ){
    864     sprintf(lBands,"Band%d",iBand+1);
     865    sprintf(lBands,"Band%d",iBand+1);   
    865866    if(nameBands==NULL){
    866867      nameBands=(char*)malloc((strlen(lBands)+1)*sizeof(char));
     
    869870      if(iBand<4){
    870871        char *tmpS=zStrdup(nameBands);
    871         nameBands=(char*)realloc(nameBands,(strlen(nameBands)+strlen(lBands)+1)*sizeof(char));
     872        nameBands=(char*)realloc(nameBands,(strlen(tmpS)+strlen(lBands)+2)*sizeof(char));
    872873        sprintf(nameBands,"%s %s",tmpS,lBands);
    873874        free(tmpS);
     
    875876    }
    876877  }
    877   msInsertHashTable(&(myLayer->metadata), "ows_bandnames", nameBands);
    878  
     878  if(nameBands!=NULL){
     879    msInsertHashTable(&(myLayer->metadata), "ows_bandnames", nameBands);
     880    free(nameBands);
     881  }
     882
    879883  /**
    880884   * Loops over metadata information to setup specific information
     
    894898      char tmpMm[100];
    895899      sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]);
    896       char tmpI[21];
     900      char tmpI[31];     
    897901      sprintf(tmpI,"%s_interval",tmpN);
    898902      msInsertHashTable(&(myLayer->metadata), tmpI, tmpMm);
     
    977981    }
    978982    if( strlen(GDALGetRasterUnitType(hBand)) > 0 ){
    979       char tmpU[21];
     983      char tmpU[31];
    980984      sprintf(tmpU,"%s_band_uom",tmpN);
    981985      msInsertHashTable(&(myLayer->metadata), tmpU, GDALGetRasterUnitType(hBand));
     
    988992  GDALClose( hDataset );
    989993  GDALDestroyDriverManager();
     994
    990995  CPLCleanupTLS();
    991996  return 1;
     
    9991004 */
    10001005void outputMapfile(maps* conf,maps* outputs){
    1001   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1002   fflush(stderr);
    1003   dumpMaps(outputs);
    1004   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1005   fflush(stderr);
    10061006  /**
    10071007   * First store the value on disk
     
    10131013      ext="json";
    10141014
    1015   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1016   fflush(stderr);
    10171015  map* tmpMap=getMapFromMaps(conf,"main","dataPath");
    10181016  map* sidMap=getMapFromMaps(conf,"lenv","usid");
    10191017  char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char));
    1020   sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext); 
     1018  sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext);
    10211019  int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
    10221020  map *gfile=getMap(outputs->content,"generated_file");
     
    10261024  map* sizeMap=getMap(outputs->content,"size");
    10271025  map* vData=getMap(outputs->content,"value");
    1028   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1029   fflush(stderr);
    10301026  if(sizeMap!=NULL){
    10311027    zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char));
     
    10341030    zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char));
    10351031  }
    1036   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1037   fflush(stderr);
    10381032  close(f);
    1039   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1040   fflush(stderr);
    10411033  addToMap(outputs->content,"storage",pszDataSource);
    10421034  free(pszDataSource);
    1043   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1044   fflush(stderr);
    10451035
    10461036  /*
     
    10491039  mapObj *myMap=msNewMapObj();
    10501040  free(myMap->name);
    1051   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1052   fflush(stderr);
    10531041  myMap->name=zStrdup("ZOO-Project_WXS_Server");
    1054   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1055   fflush(stderr);
    10561042  msMapSetSize(myMap,2048,2048);
    1057   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1058   fflush(stderr);
    10591043  msMapSetExtent(myMap,-1,-1,1,1);
    1060   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1061   fflush(stderr);
    10621044 
    10631045  /*
     
    10681050  tmp1=getMapFromMaps(conf,"main","tmpUrl");
    10691051  myMap->web.imageurl=zStrdup(tmp1->value);
    1070   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1071   fflush(stderr);
    10721052 
    10731053  /*
     
    10801060  msAppendOutputFormat(myMap,msCloneOutputFormat(o1));
    10811061  msFreeOutputFormat(o1);
    1082   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1083   fflush(stderr);
    10841062
    10851063#ifdef USE_KML
     
    10941072  }
    10951073#endif
    1096   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1097   fflush(stderr);
    10981074
    10991075  outputFormatObj *o3=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","tiff");
     
    11061082    msFreeOutputFormat(o3);
    11071083  }
    1108   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1109   fflush(stderr);
    11101084
    11111085  outputFormatObj *o4=msCreateDefaultOutputFormat(NULL,"GDAL/AAIGRID","grd");
     
    11181092    msFreeOutputFormat(o4);
    11191093  }
    1120   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1121   fflush(stderr);
    11221094
    11231095#ifdef USE_CAIRO
     
    11331105  }
    11341106#endif
    1135   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1136   fflush(stderr);
    11371107
    11381108  /*
     
    11411111  msLoadProjectionStringEPSG(&myMap->projection,"EPSG:4326");
    11421112  myMap->transparent=1;
    1143   fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
    1144   fflush(stderr);
    11451113
    11461114  /**
  • branches/prototype-v0/zoo-project/zoo-kernel/sql/schema.sql

    r781 r839  
    4545       creation_time timestamp with time zone default now(),
    4646       end_time timestamp with time zone default NULL,
     47       -- queue_duration ,
     48       -- run_duration ,
    4749       progress int,
    48        message TEXT
     50       message TEXT,
     51       -- data_lifetime timestamp with time zone default now() + interval '48 hours',
     52       rps_step int4 default 0
    4953);
    5054--------------------------------------------------------------------------------
     
    5256-- Used to store the response provided by a services running asynchronously
    5357create table responses (
    54        uuid text references services(uuid) ON DELETE CASCADE,
     58       uuid text references process(uuid) ON DELETE CASCADE,
    5559       content text,
    5660       creation_time timestamp with time zone default now()
  • branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c

    r822 r839  
    4343OGRDataSource
    4444#endif
    45  *zoo_DS = NULL;
     45 **zoo_DS = NULL;
    4646
    4747/**
     
    7070  int i=0;
    7171  maps* cconf=getMaps(conf,key);
     72  if(cconf==NULL)
     73    return "-1";
    7274  int len=0;
    7375  for(i=0;i<6;i++){
    7476    map* tmp=getMap(cconf->content,keywords[i]);
    75     fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    76     fflush(stderr);
    7777    if(tmp!=NULL){
    78       fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    79       fflush(stderr);
    8078      if(res==NULL){
    8179        res=(char*)malloc((strlen(keywords[i])+strlen(tmp->value)+4)*sizeof(char));
     
    8987        len+=strlen(res1);
    9088        res[len]=0;
    91         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    92         fflush(stderr);
    9389        free(res1);
    9490      }
    9591    }
    96     fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    97     fflush(stderr);
    98   }
    99   fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    100   fflush(stderr);
     92  }
    10193  map* tmp=getMap(cconf->content,"type");
    10294  if(tmp!=NULL){
     
    125117 * @see createInitString
    126118 */
    127 void _init_sql(maps* conf,const char* key){
     119int _init_sql(maps* conf,const char* key){
    128120  char* sqlInitString=_createInitString(conf,key);
     121  if(strncmp(sqlInitString,"-1",2)==0)
     122    return -1;
    129123  OGRSFDriver *poDriver = NULL;
    130124  OGRRegisterAll();
    131 
     125  int zoo_ds_nb=0;
     126  map* dsNb=getMapFromMaps(conf,"lenv","ds_nb");
     127  if(dsNb==NULL){
     128    setMapInMaps(conf,"lenv","ds_nb","1");
     129  }else{
     130    zoo_ds_nb=atoi(dsNb->value);
     131    char* tmp=(char*)malloc(11*sizeof(char));
     132    sprintf(tmp,"%d",zoo_ds_nb+1);
     133    setMapInMaps(conf,"lenv","ds_nb",(const char*)tmp);
     134    free(tmp);
     135  }
     136  if(zoo_DS==NULL)
     137    zoo_DS=
    132138#if GDAL_VERSION_MAJOR >= 2
    133   zoo_DS = (GDALDataset*) GDALOpenEx( sqlInitString,
     139      (GDALDataset**) malloc(sizeof(GDALDataset*))
     140#else
     141      (OGRDataSource**) malloc(sizeof(OGRDataSource*))
     142#endif
     143      ;
     144  else
     145    zoo_DS=     
     146#if GDAL_VERSION_MAJOR >= 2
     147      (GDALDataset**)realloc(zoo_DS,(zoo_ds_nb+1)*sizeof(GDALDataset*))
     148#else
     149      (OGRDataSource**)realloc(zoo_DS,(zoo_ds_nb+1)*sizeof(OGRDataSource*))
     150#endif
     151      ;
     152 
     153#if GDAL_VERSION_MAJOR >= 2
     154  zoo_DS[zoo_ds_nb] = (GDALDataset*) GDALOpenEx( sqlInitString,
    134155                                      GDAL_OF_UPDATE | GDAL_OF_VECTOR,
    135156                                      NULL, NULL, NULL );
    136157#else
    137   zoo_DS = OGRSFDriverRegistrar::Open(sqlInitString,false,&poDriver);
    138 #endif
    139   if( zoo_DS == NULL ){
     158  zoo_DS[zoo_ds_nb] = OGRSFDriverRegistrar::Open(sqlInitString,false,&poDriver);
     159#endif
     160  if( zoo_DS[zoo_ds_nb] == NULL ){
    140161#ifdef DEBUG
    141162    fprintf(stderr,"sqlInitString: %s FAILED !\n",sqlInitString);
     
    143164#endif
    144165    free(sqlInitString);
    145     setMapInMaps(conf,"lenv","message","Failed to connect to the database backend");
    146     return;
     166    setMapInMaps(conf,"lenv","dbIssue","1");
     167    setMapInMaps(conf,"lenv","message",_("Failed to connect to the database backend"));
     168    return -2;
    147169  }
    148170#ifdef DEBUG
     
    150172  fflush(stderr);
    151173#endif
     174  fprintf(stderr,"sqlInitString: %s SUCEED %d !\n",sqlInitString,zoo_ds_nb);
     175  fflush(stderr); 
    152176  free(sqlInitString);
     177  zoo_ds_nb++;
     178  return zoo_ds_nb;
    153179}
    154180
     
    159185 * @see createInitString
    160186 */
    161 void init_sql(maps* conf){
     187int init_sql(maps* conf){
    162188  return _init_sql(conf,"database");
    163189}
     
    168194 * @param conf the maps containing the setting of the main.cfg file
    169195 */
    170 void close_sql(maps* conf){
     196void close_sql(maps* conf,int cid){
    171197  if( zoo_ResultSet != NULL )
    172     zoo_DS->ReleaseResultSet( zoo_ResultSet );
     198    zoo_DS[cid]->ReleaseResultSet( zoo_ResultSet );
    173199  if(zoo_DS!=NULL){
    174200#if GDAL_VERSION_MAJOR >= 2
    175     GDALClose(zoo_DS);
    176 #else
    177     OGRDataSource::DestroyDataSource( zoo_DS );
    178 #endif
    179     zoo_DS=NULL;
     201    GDALClose(zoo_DS[cid]);
     202#else
     203    OGRDataSource::DestroyDataSource( zoo_DS[cid] );
     204#endif
     205    zoo_DS[cid]=NULL;
    180206  }
    181207}
     
    196222 * @return NULL in case of failure or an OGRLayer pointer if the query succeed.
    197223 */
    198 OGRLayer *fetchSql(maps* conf,const char* sqlQuery){
     224OGRLayer *fetchSql(maps* conf,int cid,const char* sqlQuery){
     225  if(zoo_DS[cid]==NULL)
     226    return NULL;
    199227  OGRLayer *res=NULL;
    200   res = zoo_DS->ExecuteSQL( sqlQuery, NULL, NULL);
     228#ifdef DEBUG
     229  fprintf(stderr,"************************* %s %s %d\n\n",sqlQuery,__FILE__,__LINE__);
     230  fflush(stderr);
     231#endif
     232  res = zoo_DS[cid]->ExecuteSQL( sqlQuery, NULL, NULL);
    201233  return res;
    202234}
    203235
    204 void cleanFetchSql(maps* conf,OGRLayer *objects){
     236void cleanFetchSql(maps* conf,int cid,OGRLayer *objects){
    205237  if( objects != NULL ){
    206     zoo_DS->ReleaseResultSet( objects );
     238    zoo_DS[cid]->ReleaseResultSet( objects );
    207239    objects=NULL;
    208240  }
     
    216248 * @return -1 in case of failure and 1 if the query succeed.
    217249 */
    218 int execSql(maps* conf,const char* sqlQuery){
     250int execSql(maps* conf,int cid,const char* sqlQuery){
    219251  int res=-1;
    220   zoo_ResultSet = zoo_DS->ExecuteSQL( sqlQuery, NULL, NULL);
     252  zoo_ResultSet = zoo_DS[cid]->ExecuteSQL( sqlQuery, NULL, NULL);
    221253  if( zoo_ResultSet != NULL ){
    222254    res=1;
    223255  }
    224   zoo_DS->ReleaseResultSet( zoo_ResultSet );
    225256  return res;
    226257}
     
    233264 * @return -1 in case of failure and 1 if the query succeed.
    234265 */
    235 void cleanUpResultSet(const maps* conf){
     266void cleanUpResultSet(const maps* conf,int cid){
    236267  if( zoo_ResultSet != NULL ){
    237     zoo_DS->ReleaseResultSet( zoo_ResultSet );
     268    zoo_DS[cid]->ReleaseResultSet( zoo_ResultSet );
    238269    zoo_ResultSet=NULL;
    239270  }
     271}
     272
     273#ifdef RELY_ON_DB
     274int getCurrentId(maps* conf){
     275  int res=0;
     276  map* dsNb=getMapFromMaps(conf,"lenv","ds_nb");
     277  if(dsNb!=NULL)
     278    res=atoi(dsNb->value);
     279  return res;
    240280}
    241281
     
    249289 */
    250290void recordStoredFile(maps* conf,const char* filename,const char* type,const char* name){
     291  int zoo_ds_nb=getCurrentId(conf);
    251292  map *uusid=getMapFromMaps(conf,"lenv","usid");
    252293  map *schema=getMapFromMaps(conf,"database","schema");
     
    256297  else
    257298    sprintf(sqlQuery,"INSERT INTO %s.files (uuid,filename,nature,name) VALUES ('%s','%s','%s',NULL);",schema->value,uusid->value,filename,type);
    258   execSql(conf,sqlQuery);
    259   free(sqlQuery);
    260   cleanUpResultSet(conf);
     299  execSql(conf,zoo_ds_nb-1,sqlQuery);
     300  free(sqlQuery);
     301  cleanUpResultSet(conf,zoo_ds_nb-1);
    261302}
    262303
     
    267308 */
    268309void recordServiceStatus(maps* conf){
     310  int zoo_ds_nb=getCurrentId(conf);
    269311  map *sid=getMapFromMaps(conf,"lenv","sid");
    270312  map *osid=getMapFromMaps(conf,"lenv","osid");
     
    284326          osid->value,
    285327          wpsStatus[2]);
    286   execSql(conf,sqlQuery);
    287   free(sqlQuery);
    288   cleanUpResultSet(conf);
     328  execSql(conf,zoo_ds_nb-1,sqlQuery);
     329  free(sqlQuery);
     330  cleanUpResultSet(conf,zoo_ds_nb-1);
    289331}
    290332
     
    296338 */
    297339void recordResponse(maps* conf,char* filename){
     340  int zoo_ds_nb=getCurrentId(conf);
    298341  FILE *file = fopen (filename, "rb");
    299342  fseek (file, 0, SEEK_END);
     
    308351  char *sqlQuery=(char*)malloc((strlen(schema->value)+flen+strlen(sid->value)+57+1)*sizeof(char));
    309352  sprintf(sqlQuery,"INSERT INTO %s.responses (content,uuid) VALUES ($$%s$$,$$%s$$);",schema->value,tmps,sid->value);
    310   execSql(conf,sqlQuery);
     353  execSql(conf,zoo_ds_nb-1,sqlQuery);
    311354  free(sqlQuery);
    312355  free(tmps);
    313   cleanUpResultSet(conf);
    314 }
    315 
    316 #ifdef RELY_ON_DB
     356  cleanUpResultSet(conf,zoo_ds_nb-1);
     357}
     358
    317359/**
    318360 * Update the current status of the running service.
     
    322364 */
    323365int _updateStatus(maps* conf){
     366  int zoo_ds_nb=getCurrentId(conf);
    324367  map *sid=getMapFromMaps(conf,"lenv","usid");
    325368  map *p=getMapFromMaps(conf,"lenv","status");
     
    328371  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(msg->value)+strlen(p->value)+strlen(sid->value)+64+1)*sizeof(char));
    329372  sprintf(sqlQuery,"UPDATE %s.services set status=$$%s$$,message=$$%s$$ where uuid=$$%s$$;",schema->value,p->value,msg->value,sid->value);
    330   fflush(stderr);
    331   if( zoo_DS == NULL )
     373  if( zoo_ds_nb==
     374#ifdef META_DB
     375      1
     376#else
     377      0
     378#endif
     379      ){
    332380    init_sql(conf);
    333   execSql(conf,sqlQuery);
    334   cleanUpResultSet(conf);
     381    zoo_ds_nb++;
     382  }
     383  execSql(conf,zoo_ds_nb-1,sqlQuery);
     384  cleanUpResultSet(conf,zoo_ds_nb-1);
    335385  free(sqlQuery);
    336386  return 0;
     
    345395 */
    346396char* _getStatus(maps* conf,char* pid){
     397  int zoo_ds_nb=getCurrentId(conf);
    347398  map *schema=getMapFromMaps(conf,"database","schema");
    348399  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
    349400  sprintf(sqlQuery,"select status||'|'||message from %s.services where uuid=$$%s$$;",schema->value,pid);
    350   if( zoo_DS == NULL )
     401  if( zoo_ds_nb==
     402#ifdef META_DB
     403      1
     404#else
     405      0
     406#endif
     407      ){
    351408    init_sql(conf);
    352   execSql(conf,sqlQuery);
     409    zoo_ds_nb++;
     410  }
     411  execSql(conf,zoo_ds_nb-1,sqlQuery);
    353412  OGRFeature  *poFeature = NULL;
    354413  const char *tmp1;
     
    363422    OGRFeature::DestroyFeature( poFeature );
    364423  }
    365   cleanUpResultSet(conf);
     424  cleanUpResultSet(conf,zoo_ds_nb-1);
    366425  free(sqlQuery);
    367426  return (char*)tmp1;
     
    376435 */
    377436char* _getStatusFile(maps* conf,char* pid){
     437  int zoo_ds_nb=getCurrentId(conf);
    378438  map *schema=getMapFromMaps(conf,"database","schema");
    379439  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+82+1)*sizeof(char));
     
    381441          "select content from %s.responses where uuid=$$%s$$"
    382442          " order by creation_time desc limit 1",schema->value,pid);
    383   if( zoo_DS == NULL )
     443  if( zoo_ds_nb==
     444#ifdef META_DB
     445      1
     446#else
     447      0
     448#endif
     449      ){
    384450    init_sql(conf);
    385   execSql(conf,sqlQuery);
     451    zoo_ds_nb++;
     452  }
     453  execSql(conf,zoo_ds_nb-1,sqlQuery);
    386454  OGRFeature  *poFeature = NULL;
    387455  const char *tmp1;
    388456  int hasRes=-1;
    389   while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
    390     for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
    391       if( poFeature->IsFieldSet( iField ) ){
    392         tmp1=strdup(poFeature->GetFieldAsString( iField ));
    393         hasRes=1;
     457  if(zoo_ResultSet!=NULL){
     458      while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
     459        for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
     460          if( poFeature->IsFieldSet( iField ) ){
     461            tmp1=strdup(poFeature->GetFieldAsString( iField ));
     462            hasRes=1;
     463          }
     464          else
     465            tmp1=NULL;
     466        }
     467        OGRFeature::DestroyFeature( poFeature );
    394468      }
    395       else
    396         tmp1=NULL;
    397     }
    398     OGRFeature::DestroyFeature( poFeature );
    399469  }
    400470  if(hasRes<0)
    401471    tmp1=NULL;
    402   cleanUpResultSet(conf);
     472  else
     473    cleanUpResultSet(conf,zoo_ds_nb-1);
    403474  free(sqlQuery);
    404475  return (char*)tmp1;
     
    412483 */
    413484void removeService(maps* conf,char* pid){
     485  int zoo_ds_nb=getCurrentId(conf);
    414486  map *schema=getMapFromMaps(conf,"database","schema");
    415487  char *sqlQuery=(char*)
    416488    malloc((strlen(pid)+strlen(schema->value)+38+1)
    417489           *sizeof(char));
    418   if( zoo_DS == NULL )
     490  if( zoo_ds_nb==
     491#ifdef META_DB
     492      1
     493#else
     494      0
     495#endif
     496      ){
    419497    init_sql(conf);
     498    zoo_ds_nb++;
     499  }
    420500  sprintf(sqlQuery,
    421501          "DELETE FROM %s.services where uuid=$$%s$$;",
    422502          schema->value,pid);
    423   execSql(conf,sqlQuery);
    424   cleanUpResultSet(conf);
    425   close_sql(conf);
     503  execSql(conf,zoo_ds_nb-1,sqlQuery);
     504  cleanUpResultSet(conf,zoo_ds_nb-1);
     505  close_sql(conf,zoo_ds_nb-1);
    426506  free(sqlQuery);
    427507  end_sql();
     
    434514 */
    435515void unhandleStatus(maps* conf){
     516  int zoo_ds_nb=getCurrentId(conf);
    436517  map *schema=getMapFromMaps(conf,"database","schema");
    437518  map *sid=getMapFromMaps(conf,"lenv","usid");
     
    447528          " where uuid=$$%s$$;",
    448529          schema->value,(fstate!=NULL?fstate->value:"Failed"),sid->value);
    449   execSql(conf,sqlQuery);
    450   cleanUpResultSet(conf);
    451   close_sql(conf);
     530  execSql(conf,zoo_ds_nb-1,sqlQuery);
     531  cleanUpResultSet(conf,zoo_ds_nb-1);
     532  close_sql(conf,zoo_ds_nb-1);
    452533  free(sqlQuery);
    453534  end_sql();
     
    462543 */
    463544char* getStatusId(maps* conf,char* pid){
     545  int zoo_ds_nb=getCurrentId(conf);
    464546  map *schema=getMapFromMaps(conf,"database","schema");
    465547  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
     
    467549          "select osid from %s.services where uuid=$$%s$$",
    468550          schema->value,pid);
    469   if( zoo_DS == NULL )
     551  if( zoo_ds_nb==0 ){
    470552    init_sql(conf);
    471   execSql(conf,sqlQuery);
     553    zoo_ds_nb++;
     554  }
     555  execSql(conf,zoo_ds_nb-1,sqlQuery);
    472556  OGRFeature  *poFeature = NULL;
    473557  const char *tmp1;
     
    486570    tmp1=NULL;
    487571  free(sqlQuery);
     572  cleanUpResultSet(conf,zoo_ds_nb-1);
    488573  return (char*)tmp1;
    489574}
     
    496581 */
    497582void readFinalRes(maps* conf,char* pid,map* statusInfo){
     583  int zoo_ds_nb=getCurrentId(conf);
    498584  map *schema=getMapFromMaps(conf,"database","schema");
    499585  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
     
    503589  if( zoo_DS == NULL )
    504590    init_sql(conf);
    505   execSql(conf,sqlQuery);
     591  execSql(conf,zoo_ds_nb-1,sqlQuery);
    506592  OGRFeature  *poFeature = NULL;
    507593  int hasRes=-1;
     
    531617int isRunning(maps* conf,char* pid){
    532618  int res=0;
     619  int zoo_ds_nb=getCurrentId(conf);
    533620  map *schema=getMapFromMaps(conf,"database","schema");
    534621  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+73+1)*sizeof(char));
    535622  sprintf(sqlQuery,"select count(*) as t from %s.services where uuid=$$%s$$ and end_time is null;",schema->value,pid);
    536   if( zoo_DS == NULL )
     623  if( zoo_ds_nb == 0 ){
    537624    init_sql(conf);
    538   execSql(conf,sqlQuery);
     625    zoo_ds_nb++;
     626  }
     627  execSql(conf,zoo_ds_nb-1,sqlQuery);
    539628  OGRFeature  *poFeature = NULL;
    540629  const char *tmp1;
     
    549638    OGRFeature::DestroyFeature( poFeature );
    550639  }
    551   cleanUpResultSet(conf);
     640  cleanUpResultSet(conf,zoo_ds_nb-1);
    552641  free(sqlQuery);
    553642  return res;
  • branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.h

    r822 r839  
    4242#ifdef META_DB
    4343  ZOO_DLL_EXPORT char* _createInitString(maps*,const char*);
    44   ZOO_DLL_EXPORT void _init_sql(maps*,const char*);
    45   ZOO_DLL_EXPORT OGRLayer *fetchSql(maps*,const char*);
     44  ZOO_DLL_EXPORT int _init_sql(maps*,const char*);
     45  ZOO_DLL_EXPORT OGRLayer *fetchSql(maps*,int,const char*);
     46  ZOO_DLL_EXPORT void cleanFetchSql(maps*,int,OGRLayer*);
    4647#endif
    4748#ifdef RELY_ON_DB
    48   ZOO_DLL_EXPORT void init_sql(maps*);
    49   ZOO_DLL_EXPORT void close_sql(maps*);
    50   ZOO_DLL_EXPORT int execSql(maps*,const char*);
     49  ZOO_DLL_EXPORT int init_sql(maps*);
     50  ZOO_DLL_EXPORT void close_sql(maps*,int);
     51  ZOO_DLL_EXPORT int execSql(maps*,int,const char*);
    5152  ZOO_DLL_EXPORT void recordStoredFile(maps*,const char*,const char*,const char*);
    5253  ZOO_DLL_EXPORT void recordServiceStatus(maps*);
     
    5657  ZOO_DLL_EXPORT char* getStatusId(maps*,char*);
    5758  ZOO_DLL_EXPORT void removeService(maps*,char*);
     59  ZOO_DLL_EXPORT void end_sql();
    5860#endif
    5961
  • branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c

    r822 r839  
    99 * by the French National Research Agency
    1010 *
    11  * permission is hereby granted, free of charge, to any person obtaining a copy
     11 * Permission is hereby granted, free of charge, to any person obtaining a copy
    1212 * of this software and associated documentation files (the "Software"), to deal
    1313 * in the Software without restriction, including without limitation the rights
     
    249249 * @return true in case of success, false if failure occured
    250250 */
    251 size_t ssh_file_exists(maps* conf,const char* targetPath){
     251size_t ssh_file_exists(maps* conf,const char* targetPath,int cnt){
    252252  size_t result=-1;
    253   int cnt=ssh_get_cnt(conf);
    254253  if(cnt>0)
    255254    cnt-=1;
     
    303302 * @return true in case of success, false if failure occured
    304303 */
    305 bool ssh_copy(maps* conf,const char* localPath,const char* targetPath){
     304bool ssh_copy(maps* conf,const char* localPath,const char* targetPath,int cnt){
    306305  char mem[1024 * 1000];
    307306  size_t nread;
     
    310309  long total = 0;
    311310  int duration;
    312   int cnt=ssh_get_cnt(conf);
    313311  int rc;
    314312  LIBSSH2_SFTP_HANDLE *sftp_handle;
     
    323321  if (!local) {
    324322    fprintf(stderr, "Can't open local file %s\n", localPath);
    325     return -1;
     323    return false;
    326324  }
    327325
     
    382380  duration = (int)(time(NULL)-start);
    383381  fclose(local);
    384   libssh2_sftp_close(sftp_handle);
     382  libssh2_sftp_close_handle(sftp_handle);
    385383
    386384  libssh2_sftp_shutdown(sessions[cnt]->sftp_session);
     
    396394 * @return true in case of success, false if failure occured
    397395 */
    398 int ssh_fetch(maps* conf,const char* localPath,const char* targetPath){
     396int ssh_fetch(maps* conf,const char* localPath,const char* targetPath,int cnt){
    399397  char mem[1024];
    400398  size_t nread;
     
    403401  long total = 0;
    404402  int duration;
    405   int cnt=ssh_get_cnt(conf);
    406403  int rc;
    407404  LIBSSH2_SFTP_HANDLE *sftp_handle;
     
    428425        if (!sftp_handle) {
    429426            if (libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN) {
    430 
    431427                fprintf(stderr, "Unable to open file with SFTP\n");
    432428                return -1;
     
    443439        do {
    444440            rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
    445             fprintf(stderr, "libssh2_sftp_read returned %d\n",
    446                     rc);
    447  
     441            /*fprintf(stderr, "libssh2_sftp_read returned %d\n",
     442              rc);*/
    448443            if(rc > 0) {
    449                 write(2, mem, rc);
     444              //write(2, mem, rc);
    450445                fwrite(mem, rc, 1, local);
    451446            }
     
    479474  duration = (int)(time(NULL)-start);
    480475  fclose(local);
    481   libssh2_sftp_close(sftp_handle);
     476  libssh2_sftp_close_handle(sftp_handle);
    482477
    483478  libssh2_sftp_shutdown(sessions[cnt]->sftp_session);
     
    491486 * @return bytecount resulting from the execution of the command
    492487 */
    493 int ssh_exec(maps* conf,const char* command){
    494   int cnt=ssh_get_cnt(conf);
     488int ssh_exec(maps* conf,const char* command,int cnt){
    495489  LIBSSH2_CHANNEL *channel;
    496490  int rc;
     
    571565  while (libssh2_session_disconnect(con->session, "Normal Shutdown, Thank you for using the ZOO-Project sshapi")
    572566         == LIBSSH2_ERROR_EAGAIN);
    573   libssh2_session_free(con->session);
    574567#ifdef WIN32
    575568  closesocket(con->sock_id);
     
    577570  close(con->sock_id);
    578571#endif
     572  libssh2_session_free(con->session);
    579573  return true;
    580574}
     
    596590  return true;
    597591}
     592
     593bool addToUploadQueue(maps** conf,maps* input){
     594  map* queueMap=getMapFromMaps(*conf,"uploadQueue","length");
     595  if(queueMap==NULL){
     596    maps* queueMaps=createMaps("uploadQueue");
     597    queueMaps->content=createMap("length","0");
     598    addMapsToMaps(conf,queueMaps);
     599    freeMaps(&queueMaps);
     600    free(queueMaps);
     601    queueMap=getMapFromMaps(*conf,"uploadQueue","length");
     602  }
     603  maps* queueMaps=getMaps(*conf,"uploadQueue");
     604  int queueIndex=atoi(queueMap->value);
     605  if(input!=NULL){
     606    if(getMap(input->content,"cache_file")!=NULL){
     607      map* length=getMap(input->content,"length");
     608      if(length==NULL){
     609        addToMap(input->content,"length","1");
     610        length=getMap(input->content,"length");
     611      }
     612      int len=atoi(length->value);
     613      int i=0;
     614      for(i=0;i<len;i++){
     615       
     616        map* tmp[2]={getMapArray(input->content,"localPath",i),
     617                     getMapArray(input->content,"targetPath",i)};
     618
     619        setMapArray(queueMaps->content,"input",queueIndex,input->name);
     620        setMapArray(queueMaps->content,"localPath",queueIndex,tmp[0]->value);
     621        setMapArray(queueMaps->content,"targetPath",queueIndex,tmp[1]->value);
     622        queueIndex+=1;
     623      }
     624    }
     625  }
     626#ifdef DEBUG 
     627  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     628  fflush(stderr);
     629  dumpMaps(queueMaps);
     630  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     631  fflush(stderr);
     632  dumpMaps(*conf);
     633  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     634  fflush(stderr);
     635#endif
     636  return true;
     637}
     638
     639bool runUpload(maps** conf){
     640  SSHCON *test=ssh_connect(*conf);
     641  if(test==NULL){
     642    return false;
     643  }
     644#ifdef DEBUG
     645  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     646  fflush(stderr);
     647  dumpMaps(getMaps(*conf,"uploadQueue"));
     648  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     649  fflush(stderr);
     650#endif
     651  map* queueLengthMap=getMapFromMaps(*conf,"uploadQueue","length");
     652  maps* queueMaps=getMaps(*conf,"uploadQueue");
     653  if(queueLengthMap!=NULL){
     654    int cnt=atoi(queueLengthMap->value);
     655    int i=0;
     656    for(i=0;i<cnt;i++){
     657      map* argv[3]={
     658        getMapArray(queueMaps->content,"input",i),
     659        getMapArray(queueMaps->content,"localPath",i),
     660        getMapArray(queueMaps->content,"targetPath",i)
     661      };
     662      fprintf(stderr,"%s %d %s %s\n",__FILE__,__LINE__,argv[1]->value,argv[2]->value);
     663      ssh_copy(*conf,argv[1]->value,argv[2]->value,ssh_get_cnt(*conf));
     664    }   
     665  }
     666  return true;
     667}
  • branches/prototype-v0/zoo-project/zoo-kernel/sshapi.h

    r822 r839  
    8585 
    8686  ZOO_DLL_EXPORT SSHCON *ssh_connect(maps*);
    87   ZOO_DLL_EXPORT bool ssh_copy(maps*,const char*,const char*);
    88   ZOO_DLL_EXPORT int ssh_fetch(maps*,const char*,const char*);
    89   ZOO_DLL_EXPORT int ssh_exec(maps*,const char*);
     87  ZOO_DLL_EXPORT bool ssh_copy(maps*,const char*,const char*,int);
     88  ZOO_DLL_EXPORT int ssh_get_cnt(maps*);
     89  ZOO_DLL_EXPORT int ssh_fetch(maps*,const char*,const char*,int);
     90  ZOO_DLL_EXPORT int ssh_exec(maps*,const char*,int);
    9091  ZOO_DLL_EXPORT bool ssh_close_session(maps*,SSHCON*);
    9192  ZOO_DLL_EXPORT bool ssh_close(maps*);
     93  ZOO_DLL_EXPORT bool addToUploadQueue(maps**,maps*);
     94  ZOO_DLL_EXPORT bool runUpload(maps**);
    9295 
    9396#ifdef __cplusplus
  • branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c

    r821 r839  
    7070/**
    7171 * In case of presence of "Set-Cookie" in the headers red, store the cookie
    72  * identifier in CCookie
     72 * identifier in cookie
    7373 *
    7474 * @param buffer the buffer to read
     
    7777 * @param data the _HINTERNET structure to write in
    7878 * @return the size red, -1 if buffer is NULL
    79  * @see CCookie
     79 * @see cookie
    8080 */
    8181size_t header_write_data(void *buffer, size_t size, size_t nmemb, void *data){
    8282  if(strncmp("Set-Cookie: ",(char*)buffer,12)==0){
    8383    int i;
    84     char env[256];
    85     char path[256];
    86     char domain[256];
    8784    char* tmp;
    8885    for(i=0;i<12;i++)
     
    9289        ;
    9390#endif
    94     sscanf((char*)buffer,"%s; path=%s; domain=%s",env,path,domain);
     91    tmp=strtok(buffer,";");
     92    int cnt=0;
    9593    _HINTERNET *psInternet=(_HINTERNET *)data;
    96     tmp=strcat(env,CCookie[psInternet->id][0]);
    97 #ifdef MSG_LAF_OUT
    98     printf("\n**Cookie env : [%s] , path : [%s], domain : [%s]**\n",env,path,domain);
    99     printf("buffer : %d (%s) (%s) (%s)\n",(buffer==NULL),buffer,tmp,CCookie);
    100 #endif
    101     strcpy(CCookie[psInternet->id][0],tmp);
     94    if(tmp!=NULL && psInternet!=NULL){
     95      psInternet->cookie=(char*)malloc(sizeof(char)*(strlen(tmp)+1));
     96      sprintf(psInternet->cookie,"%s",tmp);
     97    }
    10298  }
    10399  return size * nmemb;//write_data_into(buffer,size,nmemb,data,HEADER);
     
    340336    if(handle.url!=NULL)
    341337      free(handle.url);
    342     free(handle.mimeType);
    343     handle.mimeType = NULL;
     338    if(handle.mimeType!=NULL)
     339      free(handle.mimeType);
     340    if(handle.cookie!=NULL)
     341      free(handle.cookie);
    344342  }
    345343  if(handle0->handle)
     
    371369  hInternet->ihandle[hInternet->nb].url = NULL;
    372370  hInternet->ihandle[hInternet->nb].mimeType = NULL;
     371  hInternet->ihandle[hInternet->nb].cookie = NULL;
    373372  hInternet->ihandle[hInternet->nb].nDataLen = 0;
    374373  hInternet->ihandle[hInternet->nb].id = hInternet->nb;
     
    376375  hInternet->ihandle[hInternet->nb].pabyData = NULL;
    377376  hInternet->ihandle[hInternet->nb].post = NULL;
    378 
     377 
    379378  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_COOKIEFILE, "ALL");
    380379#ifndef TIGER
     
    475474    curl_multi_remove_handle(hInternet->handle, hInternet->ihandle[i].handle);
    476475    curl_easy_cleanup(hInternet->ihandle[i].handle);
     476    //fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,hInternet->ihandle[i].mimeType);
     477    //fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,hInternet->ihandle[i].pabyData);
    477478  }
    478479  return 0;
     
    480481
    481482/**
    482  * Initialize the CCookie for a specific index (hInternet.nb)
    483  *
    484  * @param hInternet the HINTERNET structure to know the CCookie index to reset
     483 * Initialize the cookie for a specific index (hInternet.nb)
     484 *
     485 * @param hInternet the HINTERNET structure to know the cookie index to reset
    485486 * @return 1
    486487 * @see HINTERNET
    487488 */
    488489int freeCookieList(HINTERNET hInternet){
    489   memset(&CCookie[hInternet.nb][0],0,1024);
     490  hInternet.ihandle[hInternet.nb].cookie=strdup("");
    490491#ifndef TIGER
    491492  curl_easy_setopt(hInternet.ihandle[hInternet.nb].handle, CURLOPT_COOKIELIST, "ALL");
     
    536537  }
    537538
    538   CCookie[hInternet.id][0]=0;
    539 
    540539  if( *lpdwNumberOfBytesRead < dwDataSize )
    541540      return 0;
  • branches/prototype-v0/zoo-project/zoo-kernel/ulinet.h

    r817 r839  
    5454#define MAX_REQ 50
    5555
    56 #ifdef _ULINET
    57 static char CCookie[MAX_REQ][1024];
    58 #else
    59 /**
    60  * The cookies found
    61  */
    62 extern char CCookie[MAX_REQ][1024];
    63 #endif
    64 
    6556#ifdef __cplusplus
    6657extern "C" {
     
    8879    char *mimeType; //!< the mimeType returned by the server
    8980    char *post; //!< the potential POST XML content
     81    char* cookie; //!< The potential Cookie returned by the server
    9082    int hasCacheFile; //!< 1 if we used a cache file
    9183    int nDataLen; //!< the length of the downloaded content
  • branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c

    r822 r839  
    102102#endif
    103103
     104#include "service_json.h"
     105#include "service_callback.h"
     106
    104107#include <dirent.h>
    105108#include <signal.h>
     
    158161
    159162#ifdef WIN32
    160   #ifndef PROGRAMNAME
    161     #define PROGRAMNAME "zoo_loader.cgi"
    162   #endif
     163#ifndef PROGRAMNAME
     164#define PROGRAMNAME "zoo_loader.cgi"
     165#endif
    163166#endif
    164167
     
    213216  fclose (f2);
    214217  fclose (f3);
     218  free(tmps1);
    215219  return 1;
    216220}
     
    233237 */
    234238int
    235 recursReaddirF ( maps * m, registry *r, xmlNodePtr n, char *conf_dir,
     239recursReaddirF ( maps * m, registry *r, xmlDocPtr doc, xmlNodePtr n, char *conf_dir,
    236240                 char *prefix, int saved_stdout, int level,
    237                  void (func) (registry *, maps *, xmlNodePtr, service *) )
     241                 void (func) (registry *, maps *, xmlDocPtr, xmlNodePtr, service *) )
    238242{
    239243  struct dirent *dp;
     
    282286            setMapInMaps (m, "lenv", "level", levels1);
    283287            res =
    284               recursReaddirF (m, r, n, tmp, prefix, saved_stdout, level + 1,
     288              recursReaddirF (m, r, doc, n, tmp, prefix, saved_stdout, level + 1,
    285289                              func);
    286290            sprintf (levels1, "%d", level);
     
    320324                  return -1;
    321325                }
    322   #ifndef DEBUG
     326  #ifdef DEBUG
    323327              fprintf (stderr, "#################\n%s\n#################\n",
    324328                       tmps1);
     
    346350  #endif
    347351              inheritance(r,&s1);
    348               func (r, m, n, s1);
     352              func (r, m, doc, n, s1);
    349353              freeService (&s1);
    350354              free (s1);
     
    949953#endif
    950954
     955 
    951956  map *r_inputs = NULL;
    952957  map *request_inputs = *inputs;
     958  //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapToJson(request_inputs),JSON_C_TO_STRING_PLAIN));
     959 
    953960#ifdef IGNORE_METAPATH
    954961  addToMap(request_inputs, "metapath", "");
     
    13051312            }
    13061313            inheritance(zooRegistry, &svc);
    1307             printGetCapabilitiesForProcess(zooRegistry, m, n, svc);
     1314            printGetCapabilitiesForProcess(zooRegistry, m, doc, n, svc);
    13081315            freeService(&svc);
    13091316            free(svc);                             
     
    13141321
    13151322      if (int res =               
    1316           recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
     1323          recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0,
    13171324                          printGetCapabilitiesForProcess) < 0)
    13181325        {
     
    13311338      dup2 (saved_stdout, fileno (stdout));
    13321339#ifdef META_DB
    1333       fetchServicesFromDb(zooRegistry,m,n,printGetCapabilitiesForProcess);
     1340      fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1);
     1341      fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__);
     1342      close_sql(m,0);
    13341343#endif     
    13351344      printDocument (m, doc, getpid ());
     
    13531362          runGetStatus(m,r_inputs->value,REQUEST);
    13541363          freeMaps (&m);
    1355           free (m);
     1364          free(m);
    13561365          if(zooRegistry!=NULL){
    13571366            freeRegistry(&zooRegistry);
     
    14291438                      }
    14301439                      inheritance(zooRegistry, &svc);
    1431                       printDescribeProcessForProcess(zooRegistry, m, n, svc);
     1440#ifdef USE_HPC
     1441                      addNestedOutputs(&svc);
     1442#endif
     1443
     1444                      printDescribeProcessForProcess(zooRegistry, m, doc, n, svc);
    14321445                      freeService(&svc);
    14331446                      free(svc);                             
     
    14381451 
    14391452                if (int res =
    1440                     recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
     1453                    recursReaddirF (m, zooRegistry, doc, n, conf_dir, NULL, saved_stdout, 0,
    14411454                                    printDescribeProcessForProcess) < 0)
    14421455                  return res;
    14431456#ifdef META_DB
    1444                 fetchServicesFromDb(zooRegistry,m,n,printDescribeProcessForProcess);
     1457                fetchServicesFromDb(zooRegistry,m,doc,n,printDescribeProcessForProcess,0);
     1458                close_sql(m,0);
    14451459#endif     
    14461460
     
    14611475                      {
    14621476#ifdef META_DB                 
    1463                         service* s2=extractServiceFromDb(m,import->name);
    1464                         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    1465                         fflush(stderr);
     1477                        service* s2=extractServiceFromDb(m,import->name,0);
    14661478                        if(s2==NULL){
    14671479#endif
     
    15001512                          dumpService (s1);
    15011513#endif
    1502 
    15031514                          inheritance(zooRegistry,&s1);
    1504                           printDescribeProcessForProcess (zooRegistry,m, n, s1);
     1515#ifdef USE_HPC
     1516                          addNestedOutputs(&s1);
     1517#endif
     1518                          printDescribeProcessForProcess (zooRegistry, m, doc, n, s1);
    15051519                          freeService (&s1);
    15061520                          free (s1);
     
    15201534                          addToMap (request_inputs, "metapath", tmpMap->value);
    15211535                        map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier");
    1522 
    15231536#ifdef META_DB
    1524                         service* s2=extractServiceFromDb(m,tmpMapI->name);
    1525                         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    1526                         fflush(stderr);
     1537                        service* s2=extractServiceFromDb(m,tmpMapI->name,0);
    15271538                        if(s2==NULL){
    15281539#endif
     
    15671578#endif
    15681579                          inheritance(zooRegistry,&s1);
    1569                           printDescribeProcessForProcess (zooRegistry,m, n, s1);
     1580#ifdef USE_HPC
     1581                          addNestedOutputs(&s1);
     1582#endif
     1583                          printDescribeProcessForProcess (zooRegistry, m, doc, n, s1);
    15701584                          freeService (&s1);
    15711585                          free (s1);
     
    15801594                    else
    15811595                      {
    1582                         fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    1583                         fflush(stderr);
    15841596#ifdef META_DB
    15851597                        _init_sql(m,"metadb");
    1586                         service* s2=extractServiceFromDb(m,corig);
     1598                        //FAILED CONNECTING DB
     1599                        if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){
     1600                          fprintf(stderr,"ERROR CONNECTING METADB");
     1601                        }
     1602                        service* s2=extractServiceFromDb(m,corig,0);
    15871603                        if(s2!=NULL){
    1588                           fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
    1589                           fflush(stderr);
    15901604                          inheritance(zooRegistry,&s2);
    1591                           printDescribeProcessForProcess (zooRegistry,m, n, s2);
     1605#ifdef USE_HPC
     1606                          addNestedOutputs(&s2);
     1607#endif
     1608                          printDescribeProcessForProcess (zooRegistry,m, doc, n, s2);
    15921609                          freeService (&s2);
    15931610                          free (s2);
     
    16641681#endif
    16651682                                  inheritance(zooRegistry,&s1);
    1666                                   printDescribeProcessForProcess (zooRegistry,m, n, s1);
     1683#ifdef USE_HPC
     1684                                  addNestedOutputs(&s1);
     1685#endif
     1686                                  printDescribeProcessForProcess (zooRegistry,m, doc, n, s1);
    16671687                                  freeService (&s1);
    16681688                                  free (s1);
     
    17251745            free (SERVICE_URL);
    17261746            fflush (stdout);
     1747#ifdef META_DB
     1748            close_sql(m,0);
     1749      //end_sql();
     1750#endif
    17271751            return 0;
    17281752          }
     
    18031827  }
    18041828  s1 = NULL;
    1805   s1 = (service *) malloc (SERVICE_SIZE);
    1806   if (s1 == NULL)
    1807     {
    1808       freeMaps (&m);
    1809       free (m);
    1810       if(zooRegistry!=NULL){
    1811         freeRegistry(&zooRegistry);
    1812         free(zooRegistry);
    1813       }
    1814       free (REQUEST);
    1815       free (SERVICE_URL);
    1816       return errorException (m, _("Unable to allocate memory"),
    1817                              "InternalError", NULL);
    1818     }
    1819 
     1829  if(postRequest!=NULL)
     1830    setMapInMaps (m, "lenv", "xrequest", postRequest->value);
     1831 
    18201832  r_inputs = getMap (request_inputs, "Identifier");
    1821 
    18221833  map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value);
    18231834  if (import != NULL && import->value != NULL) {
     
    18481859
    18491860  r_inputs = getMapFromMaps (m, "lenv", "Identifier");
     1861 
     1862#ifdef META_DB
     1863  int metadb_id=_init_sql(m,"metadb");
     1864  fprintf(stderr,"CONNECTING METADB!\n");
     1865  //FAILED CONNECTING DB
     1866  if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){
     1867    fprintf(stderr,"ERROR CONNECTING METADB\n");
     1868  }
     1869  s1=extractServiceFromDb(m,r_inputs->value,0);
     1870  //close_sql(m,0);
     1871  if(s1!=NULL){
     1872    inheritance(zooRegistry,&s1);
     1873#ifdef USE_HPC
     1874    addNestedOutputs(&s1);
     1875#endif
     1876    if(zooRegistry!=NULL){
     1877      freeRegistry(&zooRegistry);
     1878      free(zooRegistry);
     1879    }
     1880  }else /* Not found in MetaDB */{
     1881#endif
     1882  s1 = (service *) malloc (SERVICE_SIZE);
     1883  if (s1 == NULL)
     1884    {
     1885      freeMaps (&m);
     1886      free (m);
     1887      if(zooRegistry!=NULL){
     1888        freeRegistry(&zooRegistry);
     1889        free(zooRegistry);
     1890      }
     1891      free (REQUEST);
     1892      free (SERVICE_URL);
     1893      return errorException (m, _("Unable to allocate memory"),
     1894                             "InternalError", NULL);
     1895    }
     1896
    18501897  int saved_stdout = dup (fileno (stdout));
    18511898  dup2 (fileno (stderr), fileno (stdout));
    18521899  t = readServiceFile (m, tmps1, &s1, r_inputs->value);
    18531900  inheritance(zooRegistry,&s1);
     1901#ifdef USE_HPC
     1902  addNestedOutputs(&s1);
     1903#endif
    18541904  if(zooRegistry!=NULL){
    18551905    freeRegistry(&zooRegistry);
     
    18751925    }
    18761926  close (saved_stdout);
    1877 
     1927#ifdef META_DB
     1928  }
     1929#endif
     1930 
    18781931#ifdef DEBUG
    18791932  dumpService (s1);
     
    19121965    return 0;
    19131966  }
    1914 
     1967  //InternetCloseHandle (&hInternet);
     1968 
    19151969  // Define each env variable in runing environment
    19161970  maps *curs = getMaps (m, "env");
     
    20522106  int cpid = getpid ();
    20532107
     2108  // Create a map containing a copy of the request map
     2109  maps *_tmpMaps = createMaps("request");
     2110  addMapToMap(&_tmpMaps->content,request_inputs);
     2111  addMapsToMaps (&m, _tmpMaps);
     2112  freeMaps (&_tmpMaps);
     2113  free (_tmpMaps);
    20542114  /**
    20552115   * Initialize the specific [lenv] section which contains runtime variables:
     
    20722132   *
    20732133   */
    2074   maps *_tmpMaps = createMaps("lenv");
     2134  _tmpMaps = createMaps("lenv");
    20752135  char tmpBuff[100];
    20762136  struct ztimeval tp;
     
    21822242#endif
    21832243  int ei = 1;
    2184   char *s =
     2244  char **orig =
    21852245#ifdef WIN32
    2186     GetEnvironmentStrings();
     2246    GetEnvironmentStrings()
    21872247#else
    2188     *environ;
    2189 #endif
     2248    environ
     2249#endif
     2250    ;
     2251  char *s=*orig;
    21902252  _tmpMaps = createMaps("renv");
    21912253  for (; s; ei++) {
    21922254    char* tmpName=zStrdup(s);
    21932255    char* tmpValue=strstr(s,"=")+1;
    2194     tmpName[strlen(tmpName)-strlen(tmpValue)-1]=0;
     2256    char* tmpName1=(char*)malloc((1+(strlen(tmpName)-strlen(tmpValue)))*sizeof(char));
     2257    snprintf(tmpName1,(strlen(tmpName)-strlen(tmpValue)),"%s",tmpName);
    21952258    if(_tmpMaps->content == NULL)
    2196       _tmpMaps->content = createMap (tmpName,tmpValue);
     2259      _tmpMaps->content = createMap (tmpName1,tmpValue);
    21972260    else
    2198       addToMap (_tmpMaps->content,tmpName,tmpValue);
     2261      addToMap (_tmpMaps->content,tmpName1,tmpValue);
    21992262    free(tmpName);
    2200     s = *(environ+ei);
     2263    free(tmpName1);
     2264    s = *(orig+ei);
    22012265  }
    22022266  addMapsToMaps (&m, _tmpMaps);
     
    22282292  }
    22292293#endif
     2294  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     2295  invokeCallback(m,NULL,NULL,0,0);
     2296  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    22302297
    22312298  char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog;
     
    22362303  if (status == NULLMAP)
    22372304    {
     2305      /*        hInternet = InternetOpen (
     2306#ifndef WIN32
     2307                                  (LPCTSTR)
     2308#endif
     2309                                  "ZooWPSClient\0",
     2310                                  INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);*/
     2311
    22382312      if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
    22392313        freeService (&s1);
     
    22512325        return -1;
    22522326      }
     2327      fprintf(stderr,"*************************\n\n");
     2328      //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapsToJson(request_input_real_format),JSON_C_TO_STRING_PLAIN));
     2329      fprintf(stderr,"*************************\n\n");
    22532330      loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format,
    22542331                         &request_output_real_format, &eres);
     
    23002377          int cpid = atoi (tmpm->value);
    23012378          r_inputs = getMapFromMaps (m, "main", "tmpPath");
     2379          setMapInMaps (m, "lenv", "async","true");
    23022380          map* r_inputs1 = createMap("ServiceName", s1->name);
    23032381
     
    23962474          f1 = freopen (fbkp1, "w+", stdout);
    23972475
     2476          map* serviceTypeMap=getMap(s1->content,"serviceType");
     2477          if(serviceTypeMap!=NULL)
     2478            setMapInMaps (m, "lenv", "serviceType", serviceTypeMap->value);
     2479
     2480          char *flenv =
     2481            (char *)
     2482            malloc ((strlen (r_inputs->value) +
     2483                     strlen (usid->value) + 12) * sizeof (char));
     2484          sprintf (flenv, "%s/%s_lenv.cfg", r_inputs->value, usid->value);
     2485          maps* lenvMaps=getMaps(m,"lenv");
     2486          dumpMapsToFile(lenvMaps,flenv,0);
     2487          free(flenv);
     2488
     2489          fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     2490          invokeCallback(m,request_input_real_format,NULL,1,0);
     2491          fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    23982492          if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
    23992493            freeService (&s1);
     
    24192513            return -1;
    24202514          }
     2515          setMapInMaps(m,"lenv","ds_nb","1");
    24212516          loadServiceAndRun (&m, s1, request_inputs,
    24222517                             &request_input_real_format,
     
    24352530    }
    24362531
    2437   //#ifdef DEBUG
     2532#ifdef DEBUG
     2533  fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
    24382534  dumpMaps (request_output_real_format);
    2439   //#endif
    2440   //sleep(120);
     2535  fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
     2536#endif
    24412537  if (eres != -1)
    24422538    outputResponse (s1, request_input_real_format,
     
    24622558    {
    24632559      fclose (stdout);
    2464       fclose (stderr);
    24652560
    24662561      fclose (f0);
     
    24862581#else
    24872582      recordResponse(m,fbkp1);
     2583      fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     2584      invokeCallback(m,NULL,request_output_real_format,5,1);
     2585      fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    24882586#endif
    24892587      freeMaps(&bmap);
     
    24922590      unlink (flog);
    24932591      unhandleStatus (m);
     2592#ifdef META_DB
     2593      close_sql(m,0);
     2594      //end_sql();
     2595#endif
    24942596      free(fbkpid);
    24952597      free(fbkpres);
     
    24992601      if(cgiSid!=NULL)
    25002602        free(cgiSid);
    2501     }
    2502 
     2603      //InternetCloseHandle (&hInternet); 
     2604      fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
     2605      fflush(stderr);
     2606      fclose (stderr);
     2607    }
     2608  else{
     2609    //InternetCloseHandle (&hInternet); 
     2610#ifdef META_DB
     2611    //close_sql(m,0);
     2612#endif
     2613  }
     2614 
    25032615  freeService (&s1);
    25042616  free (s1);
  • branches/prototype-v0/zoo-project/zoo-services/utils/status/service.c

    r788 r839  
    8585       */
    8686      char *tmpStr=_getStatus(conf,tmpMap->value);
    87 #ifdef DEBUG
     87      //#ifdef DEBUG
    8888      fprintf(stderr,"DEBUG: %s \n",tmpStr);
    89 #endif
     89      //#endif
    9090      if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){
    9191        char *tmpStr1=strdup(tmpStr);
     
    140140      char message[10];
    141141      sprintf(message,"Step %d",i);
     142      fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
     143      fflush(stderr);
    142144      updateStatus(conf,i,message);
    143145#ifndef WIN32
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