source: branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c @ 839

Last change on this file since 839 was 839, checked in by djay, 7 years ago

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

  • Property svn:keywords set to Id
File size: 18.5 KB
Line 
1/*
2 * Authors : David Saggiorato
3 *           Gérald Fenoy
4 *  Copyright 2015 GeoLabs SARL. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#include "ogr_api.h"
26#include "ogrsf_frmts.h"
27#include "ogr_p.h"
28#include "response_print.h"
29#if GDAL_VERSION_MAJOR >= 2
30#include <gdal_priv.h>
31#endif
32
33#include "sqlapi.h"
34#include <fcgi_stdio.h>
35#include <stdlib.h>
36
37/**
38 * Global GDALDataset pointer
39 */
40#if GDAL_VERSION_MAJOR >=2
41GDALDataset
42#else
43OGRDataSource
44#endif
45 **zoo_DS = NULL;
46
47/**
48 * Global OGRLayer pointer pointing to the lastest result set
49 */
50OGRLayer *zoo_ResultSet = NULL;
51
52/**
53 * Create a GDAL / OGR string for connecting to a db backend defined in the
54 * key section.
55 *
56 * @param conf the maps containing the setting of the main.cfg file
57 * @param key the name of the section containing the connection setting
58 * @return the OGR connection string
59 */
60char* _createInitString(maps* conf,const char* key){
61  char* res=NULL;
62  char keywords[6][14]={
63    "dbname",
64    "host",
65    "port",
66    "user",
67    "password",
68    "active_schema"   
69  };
70  int i=0;
71  maps* cconf=getMaps(conf,key);
72  if(cconf==NULL)
73    return "-1";
74  int len=0;
75  for(i=0;i<6;i++){
76    map* tmp=getMap(cconf->content,keywords[i]);
77    if(tmp!=NULL){
78      if(res==NULL){
79        res=(char*)malloc((strlen(keywords[i])+strlen(tmp->value)+4)*sizeof(char));
80        sprintf(res,"%s='%s'",keywords[i],tmp->value);
81        len+=strlen(res);
82      }else{
83        char* res1=(char*)malloc((strlen(keywords[i])+strlen(tmp->value)+5)*sizeof(char));
84        sprintf(res1," %s='%s'",keywords[i],tmp->value);
85        res=(char*)realloc(res,(len+strlen(keywords[i])+strlen(tmp->value)+5)*sizeof(char));
86        memcpy(res+len,res1,(strlen(keywords[i])+strlen(tmp->value)+5)*sizeof(char));
87        len+=strlen(res1);
88        res[len]=0;
89        free(res1);
90      }
91    }
92  }
93  map* tmp=getMap(cconf->content,"type");
94  if(tmp!=NULL){
95    char* fres=(char*)malloc((strlen(res)+strlen(tmp->value)+2)*sizeof(char));
96    sprintf(fres,"%s:%s",tmp->value,res);
97    free(res);
98    return fres;
99  }
100  return res;
101}
102
103/**
104 * Create a GDAL / OGR string for connecting to the db backend
105 *
106 * @param conf the maps containing the setting of the main.cfg file
107 * @return the OGR connection string
108 */
109char* createInitString(maps* conf){
110  return _createInitString(conf,"database");
111}
112
113/**
114 * Connect to a db backend.
115 *
116 * @param conf the maps containing the setting of the main.cfg file
117 * @see createInitString
118 */
119int _init_sql(maps* conf,const char* key){
120  char* sqlInitString=_createInitString(conf,key);
121  if(strncmp(sqlInitString,"-1",2)==0)
122    return -1;
123  OGRSFDriver *poDriver = NULL;
124  OGRRegisterAll();
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=
138#if GDAL_VERSION_MAJOR >= 2
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,
155                                      GDAL_OF_UPDATE | GDAL_OF_VECTOR,
156                                      NULL, NULL, NULL );
157#else
158  zoo_DS[zoo_ds_nb] = OGRSFDriverRegistrar::Open(sqlInitString,false,&poDriver);
159#endif
160  if( zoo_DS[zoo_ds_nb] == NULL ){
161#ifdef DEBUG
162    fprintf(stderr,"sqlInitString: %s FAILED !\n",sqlInitString);
163    fflush(stderr);
164#endif
165    free(sqlInitString);
166    setMapInMaps(conf,"lenv","dbIssue","1");
167    setMapInMaps(conf,"lenv","message",_("Failed to connect to the database backend"));
168    return -2;
169  }
170#ifdef DEBUG
171  fprintf(stderr,"sqlInitString: %s SUCEED !\n",sqlInitString);
172  fflush(stderr);
173#endif
174  fprintf(stderr,"sqlInitString: %s SUCEED %d !\n",sqlInitString,zoo_ds_nb);
175  fflush(stderr); 
176  free(sqlInitString);
177  zoo_ds_nb++;
178  return zoo_ds_nb;
179}
180
181/**
182 * Connect to the db backend.
183 *
184 * @param conf the maps containing the setting of the main.cfg file
185 * @see createInitString
186 */
187int init_sql(maps* conf){
188  return _init_sql(conf,"database");
189}
190
191/**
192 * Close any connection to the db backend.
193 *
194 * @param conf the maps containing the setting of the main.cfg file
195 */
196void close_sql(maps* conf,int cid){
197  if( zoo_ResultSet != NULL )
198    zoo_DS[cid]->ReleaseResultSet( zoo_ResultSet );
199  if(zoo_DS!=NULL){
200#if GDAL_VERSION_MAJOR >= 2
201    GDALClose(zoo_DS[cid]);
202#else
203    OGRDataSource::DestroyDataSource( zoo_DS[cid] );
204#endif
205    zoo_DS[cid]=NULL;
206  }
207}
208
209/**
210 * Call OGRCleanupAll.
211 *
212 */
213void end_sql(){
214  OGRCleanupAll();
215}
216
217/**
218 * Fetch a tuple set by executing a SQL query to the Database Backend.
219 *
220 * @param conf the maps containing the setting of the main.cfg file
221 * @param sqlQuery the SQL query to run
222 * @return NULL in case of failure or an OGRLayer pointer if the query succeed.
223 */
224OGRLayer *fetchSql(maps* conf,int cid,const char* sqlQuery){
225  if(zoo_DS[cid]==NULL)
226    return NULL;
227  OGRLayer *res=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);
233  return res;
234}
235
236void cleanFetchSql(maps* conf,int cid,OGRLayer *objects){
237  if( objects != NULL ){
238    zoo_DS[cid]->ReleaseResultSet( objects );
239    objects=NULL;
240  }
241}
242
243/**
244 * Execute a SQL query to the SQL Database Backend.
245 *
246 * @param conf the maps containing the setting of the main.cfg file
247 * @param sqlQuery the SQL query to run
248 * @return -1 in case of failure and 1 if the query succeed.
249 */
250int execSql(maps* conf,int cid,const char* sqlQuery){
251  int res=-1;
252  zoo_ResultSet = zoo_DS[cid]->ExecuteSQL( sqlQuery, NULL, NULL);
253  if( zoo_ResultSet != NULL ){
254    res=1;
255  }
256  return res;
257}
258
259/**
260 * Clean any memory allocated by executing a request
261 *
262 * @param conf the maps containing the setting of the main.cfg file
263 * @param sqlQuery the SQL query to run
264 * @return -1 in case of failure and 1 if the query succeed.
265 */
266void cleanUpResultSet(const maps* conf,int cid){
267  if( zoo_ResultSet != NULL ){
268    zoo_DS[cid]->ReleaseResultSet( zoo_ResultSet );
269    zoo_ResultSet=NULL;
270  }
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;
280}
281
282/**
283 * Record a file stored during ZOO-Kernel execution
284 *
285 * @param conf the maps containing the setting of the main.cfg file
286 * @param filename the file's name
287 * @param type the type (Intput,Output,Response)
288 * @param name the maps containing the setting of the main.cfg file
289 */
290void recordStoredFile(maps* conf,const char* filename,const char* type,const char* name){
291  int zoo_ds_nb=getCurrentId(conf);
292  map *uusid=getMapFromMaps(conf,"lenv","usid");
293  map *schema=getMapFromMaps(conf,"database","schema");
294  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(uusid->value)+strlen(filename)+strlen(type)+(name!=NULL?strlen(name):2)+68+1)*sizeof(char));
295  if(name!=NULL)
296    sprintf(sqlQuery,"INSERT INTO %s.files (uuid,filename,nature,name) VALUES ('%s','%s','%s','%s');",schema->value,uusid->value,filename,type,name);
297  else
298    sprintf(sqlQuery,"INSERT INTO %s.files (uuid,filename,nature,name) VALUES ('%s','%s','%s',NULL);",schema->value,uusid->value,filename,type);
299  execSql(conf,zoo_ds_nb-1,sqlQuery);
300  free(sqlQuery);
301  cleanUpResultSet(conf,zoo_ds_nb-1);
302}
303
304/**
305 * Insert the reference tuple corresponding to the running service
306 *
307 * @param conf the maps containing the setting of the main.cfg file
308 */
309void recordServiceStatus(maps* conf){
310  int zoo_ds_nb=getCurrentId(conf);
311  map *sid=getMapFromMaps(conf,"lenv","sid");
312  map *osid=getMapFromMaps(conf,"lenv","osid");
313  map *uusid=getMapFromMaps(conf,"lenv","usid");
314  map *schema=getMapFromMaps(conf,"database","schema");
315  char *sqlQuery=(char*)malloc((strlen(schema->value)+
316                                strlen(uusid->value)+
317                                strlen(osid->value)+
318                                strlen(sid->value)+
319                                strlen(wpsStatus[2])+66+1)*sizeof(char));
320  sprintf(sqlQuery,
321          "INSERT INTO %s.services (uuid,sid,osid,fstate)"
322          "VALUES ('%s','%s','%s','%s');",
323          schema->value,
324          uusid->value,
325          sid->value,
326          osid->value,
327          wpsStatus[2]);
328  execSql(conf,zoo_ds_nb-1,sqlQuery);
329  free(sqlQuery);
330  cleanUpResultSet(conf,zoo_ds_nb-1);
331}
332
333/**
334 * Store the content of the result file
335 *
336 * @param conf the maps containing the setting of the main.cfg file
337 * @param filename the file's name
338 */
339void recordResponse(maps* conf,char* filename){
340  int zoo_ds_nb=getCurrentId(conf);
341  FILE *file = fopen (filename, "rb");
342  fseek (file, 0, SEEK_END);
343  long flen = ftell (file);
344  fseek (file, 0, SEEK_SET);
345  char *tmps = (char *) malloc ((flen + 1) * sizeof (char));
346  fread (tmps, flen, 1, file);
347  tmps[flen]=0;
348  fclose(file);
349  map *sid=getMapFromMaps(conf,"lenv","usid");
350  map *schema=getMapFromMaps(conf,"database","schema");
351  char *sqlQuery=(char*)malloc((strlen(schema->value)+flen+strlen(sid->value)+57+1)*sizeof(char));
352  sprintf(sqlQuery,"INSERT INTO %s.responses (content,uuid) VALUES ($$%s$$,$$%s$$);",schema->value,tmps,sid->value);
353  execSql(conf,zoo_ds_nb-1,sqlQuery);
354  free(sqlQuery);
355  free(tmps);
356  cleanUpResultSet(conf,zoo_ds_nb-1);
357}
358
359/**
360 * Update the current status of the running service.
361 *
362 * @param conf the map containing the setting of the main.cfg file
363 * @return 0 on success, -2 if shmget failed, -1 if shmat failed
364 */
365int _updateStatus(maps* conf){
366  int zoo_ds_nb=getCurrentId(conf);
367  map *sid=getMapFromMaps(conf,"lenv","usid");
368  map *p=getMapFromMaps(conf,"lenv","status");
369  map *msg=getMapFromMaps(conf,"lenv","message");
370  map *schema=getMapFromMaps(conf,"database","schema");
371  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(msg->value)+strlen(p->value)+strlen(sid->value)+64+1)*sizeof(char));
372  sprintf(sqlQuery,"UPDATE %s.services set status=$$%s$$,message=$$%s$$ where uuid=$$%s$$;",schema->value,p->value,msg->value,sid->value);
373  if( zoo_ds_nb==
374#ifdef META_DB
375      1
376#else
377      0
378#endif
379      ){
380    init_sql(conf);
381    zoo_ds_nb++;
382  }
383  execSql(conf,zoo_ds_nb-1,sqlQuery);
384  cleanUpResultSet(conf,zoo_ds_nb-1);
385  free(sqlQuery);
386  return 0;
387}
388
389/**
390 * Get the ongoing status of a running service
391 *
392 * @param conf the maps containing the setting of the main.cfg file
393 * @param pid the service identifier (usid key from the [lenv] section)
394 * @return the reported status char* (MESSAGE|POURCENTAGE)
395 */
396char* _getStatus(maps* conf,char* pid){
397  int zoo_ds_nb=getCurrentId(conf);
398  map *schema=getMapFromMaps(conf,"database","schema");
399  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
400  sprintf(sqlQuery,"select status||'|'||message from %s.services where uuid=$$%s$$;",schema->value,pid);
401  if( zoo_ds_nb==
402#ifdef META_DB
403      1
404#else
405      0
406#endif
407      ){
408    init_sql(conf);
409    zoo_ds_nb++;
410  }
411  execSql(conf,zoo_ds_nb-1,sqlQuery);
412  OGRFeature  *poFeature = NULL;
413  const char *tmp1;
414  while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
415    for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
416      if( poFeature->IsFieldSet( iField ) ){
417        tmp1=strdup(poFeature->GetFieldAsString( iField ));
418      }
419      else
420        tmp1=NULL;
421    }
422    OGRFeature::DestroyFeature( poFeature );
423  }
424  cleanUpResultSet(conf,zoo_ds_nb-1);
425  free(sqlQuery);
426  return (char*)tmp1;
427}
428
429/**
430 * Read the cache file of a running service
431 *
432 * @param conf the maps containing the setting of the main.cfg file
433 * @param pid the service identifier (usid key from the [lenv] section)
434 * @return the reported status char* (temporary/final result)
435 */
436char* _getStatusFile(maps* conf,char* pid){
437  int zoo_ds_nb=getCurrentId(conf);
438  map *schema=getMapFromMaps(conf,"database","schema");
439  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+82+1)*sizeof(char));
440  sprintf(sqlQuery,
441          "select content from %s.responses where uuid=$$%s$$"
442          " order by creation_time desc limit 1",schema->value,pid);
443  if( zoo_ds_nb==
444#ifdef META_DB
445      1
446#else
447      0
448#endif
449      ){
450    init_sql(conf);
451    zoo_ds_nb++;
452  }
453  execSql(conf,zoo_ds_nb-1,sqlQuery);
454  OGRFeature  *poFeature = NULL;
455  const char *tmp1;
456  int 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 );
468      }
469  }
470  if(hasRes<0)
471    tmp1=NULL;
472  else
473    cleanUpResultSet(conf,zoo_ds_nb-1);
474  free(sqlQuery);
475  return (char*)tmp1;
476}
477
478/**
479 * Delete a service reference from the database.
480 *
481 * @param conf the map containing the setting of the main.cfg file
482 * @param pid the service identifier (usid key from the [lenv] section)
483 */
484void removeService(maps* conf,char* pid){
485  int zoo_ds_nb=getCurrentId(conf);
486  map *schema=getMapFromMaps(conf,"database","schema");
487  char *sqlQuery=(char*)
488    malloc((strlen(pid)+strlen(schema->value)+38+1)
489           *sizeof(char));
490  if( zoo_ds_nb==
491#ifdef META_DB
492      1
493#else
494      0
495#endif
496      ){
497    init_sql(conf);
498    zoo_ds_nb++;
499  }
500  sprintf(sqlQuery,
501          "DELETE FROM %s.services where uuid=$$%s$$;",
502          schema->value,pid);
503  execSql(conf,zoo_ds_nb-1,sqlQuery);
504  cleanUpResultSet(conf,zoo_ds_nb-1);
505  close_sql(conf,zoo_ds_nb-1);
506  free(sqlQuery);
507  end_sql();
508}
509
510/**
511 * Stop handling status repport.
512 *
513 * @param conf the map containing the setting of the main.cfg file
514 */
515void unhandleStatus(maps* conf){
516  int zoo_ds_nb=getCurrentId(conf);
517  map *schema=getMapFromMaps(conf,"database","schema");
518  map *sid=getMapFromMaps(conf,"lenv","usid");
519  map *fstate=getMapFromMaps(conf,"lenv","fstate");
520  char *sqlQuery=(char*)malloc((strlen(sid->value)+
521                                strlen(schema->value)+
522                                (fstate!=NULL?
523                                 strlen(fstate->value):
524                                 6)
525                                +66+1)*sizeof(char));
526  sprintf(sqlQuery,
527          "UPDATE %s.services set end_time=now(), fstate=$$%s$$"
528          " where uuid=$$%s$$;",
529          schema->value,(fstate!=NULL?fstate->value:"Failed"),sid->value);
530  execSql(conf,zoo_ds_nb-1,sqlQuery);
531  cleanUpResultSet(conf,zoo_ds_nb-1);
532  close_sql(conf,zoo_ds_nb-1);
533  free(sqlQuery);
534  end_sql();
535}
536
537/**
538 * Read the sid identifier attached of a service if any
539 *
540 * @param conf the maps containing the setting of the main.cfg file
541 * @param pid the service identifier (usid key from the [lenv] section)
542 * @return the sid value
543 */
544char* getStatusId(maps* conf,char* pid){
545  int zoo_ds_nb=getCurrentId(conf);
546  map *schema=getMapFromMaps(conf,"database","schema");
547  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
548  sprintf(sqlQuery,
549          "select osid from %s.services where uuid=$$%s$$",
550          schema->value,pid);
551  if( zoo_ds_nb==0 ){
552    init_sql(conf);
553    zoo_ds_nb++;
554  }
555  execSql(conf,zoo_ds_nb-1,sqlQuery);
556  OGRFeature  *poFeature = NULL;
557  const char *tmp1;
558  int hasRes=-1;
559  while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
560    for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
561      if( poFeature->IsFieldSet( iField ) ){
562        tmp1=zStrdup(poFeature->GetFieldAsString( iField ));
563        hasRes=1;
564        break;
565      }
566    }
567    OGRFeature::DestroyFeature( poFeature );
568  }
569  if(hasRes<0)
570    tmp1=NULL;
571  free(sqlQuery);
572  cleanUpResultSet(conf,zoo_ds_nb-1);
573  return (char*)tmp1;
574}
575
576/**
577 * Read the Result file (.res).
578 *
579 * @param conf the maps containing the setting of the main.cfg file
580 * @param pid the service identifier (usid key from the [lenv] section)
581 */
582void readFinalRes(maps* conf,char* pid,map* statusInfo){
583  int zoo_ds_nb=getCurrentId(conf);
584  map *schema=getMapFromMaps(conf,"database","schema");
585  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
586  sprintf(sqlQuery,
587          "select fstate from %s.services where uuid=$$%s$$",
588          schema->value,pid);
589  if( zoo_DS == NULL )
590    init_sql(conf);
591  execSql(conf,zoo_ds_nb-1,sqlQuery);
592  OGRFeature  *poFeature = NULL;
593  int hasRes=-1;
594  while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
595    for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
596      if( poFeature->IsFieldSet( iField ) ){
597        addToMap(statusInfo,"Status",poFeature->GetFieldAsString( iField ));
598        hasRes=1;
599        break;
600      }
601    }
602    OGRFeature::DestroyFeature( poFeature );
603  }
604  if(hasRes<0)
605    addToMap(statusInfo,"Status","Failed");
606  free(sqlQuery);
607  return;
608}
609
610/**
611 * Check if a service is running.
612 *
613 * @param conf the maps containing the setting of the main.cfg file
614 * @param pid the unique service identifier (usid from the lenv section)
615 * @return 1 in case the service is still running, 0 otherwise
616 */
617int isRunning(maps* conf,char* pid){
618  int res=0;
619  int zoo_ds_nb=getCurrentId(conf);
620  map *schema=getMapFromMaps(conf,"database","schema");
621  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+73+1)*sizeof(char));
622  sprintf(sqlQuery,"select count(*) as t from %s.services where uuid=$$%s$$ and end_time is null;",schema->value,pid);
623  if( zoo_ds_nb == 0 ){
624    init_sql(conf);
625    zoo_ds_nb++;
626  }
627  execSql(conf,zoo_ds_nb-1,sqlQuery);
628  OGRFeature  *poFeature = NULL;
629  const char *tmp1;
630  while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
631    for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
632      if( poFeature->IsFieldSet( iField ) && 
633          atoi(poFeature->GetFieldAsString( iField ))>0 ){
634        res=1;
635        break;
636      }
637    }
638    OGRFeature::DestroyFeature( poFeature );
639  }
640  cleanUpResultSet(conf,zoo_ds_nb-1);
641  free(sqlQuery);
642  return res;
643}
644
645#endif
Note: See TracBrowser for help on using the repository browser.

Search

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