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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
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