Changeset 617


Ignore:
Timestamp:
Mar 19, 2015, 10:01:11 AM (7 years ago)
Author:
david
Message:

commit of partial async queue process management

Location:
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/Makefile.in

    r549 r617  
    1313
    1414CFLAGS=@DEB_DEF@  -fpic ${GLIB_CPPFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
    15 LDFLAGS=  -lcurl -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${GLIB_LDFLAGS}  ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${YAML_LDFLAGS}
     15LDFLAGS=  -lcurl -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${GLIB_LDFLAGS}  ${RABBITMQ_LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${YAML_LDFLAGS} ${JSON_LDFLAGS} ${MYSQL_LDFLAGS}
    1616
    1717PHPCFLAGS=@PHP_CPPFLAGS@
     
    2525PERL_ENABLED=@PERL_ENABLED@
    2626PERL_FILE=@PERL_FILE@
     27
     28JSON_LDFLAGS=@JSON_LDFLAGS@
     29JSON_CPPFLAGS=@JSON_CPPFLAGS@
     30
     31RABBITMQ_LDFLAGS=@RABBITMQ_LDFLAGS@
     32RABBITMQ_CPPFLAGS=@RABBITMQ_CPPFLAGS@
     33
     34MYSQL_LDFLAGS=@MYSQL_LDFLAGS@
     35MYSQL_CPPFLAGS=@MYSQL_CPPFLAGS@
     36
    2737
    2838
     
    6272        g++ ${GLIB_CPPFLAGS} ${XML2CFLAGS} -c service_zcfg.c
    6373
     74zoo_json.o:     zoo_json.c service.h
     75        g++ ${JSON_CPPFLAGS} ${XML2CFLAGS} -c zoo_json.c
     76
     77zoo_amqp.o: zoo_amqp.c
     78        g++ ${CFLAGS} -c zoo_amqp.c
     79
     80zoo_sql.o: zoo_sql.c
     81        g++ ${MYSQL_CPPFLAGS} -c zoo_sql.c
     82
     83
    6484service_internal.o: service_internal.c service.h
    6585        g++ ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c
     
    93113
    94114zoo_service_loader.o: zoo_service_loader.c service.h
    95         g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
     115        g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} ${JSON_CPPFLAGS} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
    96116
    97 zoo_loader.cgi: version.h zoo_loader.c service_zcfg.o 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 service_internal.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE}
    98         g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
    99         g++  ${JSCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o service_zcfg.o zoo_service_loader.o service_internal.o ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi ${LDFLAGS}
     117zoo_loader.cgi: version.h zoo_loader.c zoo_sql.o zoo_amqp.o zoo_json.o service_zcfg.o 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 service_internal.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE}
     118        g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS}  ${JSON_CPPFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
     119        g++  ${JSCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_sql.o zoo_amqp.o zoo_json.o zoo_loader.o service_zcfg.o zoo_service_loader.o service_internal.o ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi ${LDFLAGS}
    100120
    101121zcfg2yaml: zcfg2yaml.c  ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o ${MS_FILE} ${JS_FILE} ${RUBY_FILE}  ${YAML_FILE}
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/bdd/schema.sql

    r616 r617  
    88    end_date DATETIME,
    99    progress int,
    10     info TEXT
     10    info TEXT,
     11    identifier TEXT
    1112    );
    1213
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/configure.ac

    r549 r617  
    1515AC_CHECK_LIB([pthread], [main])
    1616AC_CHECK_LIB([ssl], [main])
     17
    1718
    1819# Checks for header files.
     
    135136AC_SUBST([FCGI_CPPFLAGS])
    136137AC_SUBST([FCGI_LDFLAGS])
     138
     139
     140# ===========================================================================
     141# Detect if json-c is available
     142# ===========================================================================
     143
     144AC_CHECK_LIB([json-c], [main])
     145JSON_LDFLAGS=`pkg-config --libs json-c`
     146JSON_CPPFLAGS=`pkg-config --cflags json-c`
     147
     148AC_SUBST([JSON_LDFLAGS])
     149AC_SUBST([JSON_CPPFLAGS])
     150
     151
     152
     153
     154# ===========================================================================
     155# Detect if librabbitmq is available
     156# ===========================================================================
     157
     158
     159AC_CHECK_LIB([rabbitmq], [main])
     160RABBITMQ_LDFLAGS=`pkg-config --libs librabbitmq`
     161RABBITMQ_CPPFLAGS=`pkg-config --cflags librabbitmq`
     162
     163AC_SUBST([RABBITMQ_LDFLAGS])
     164AC_SUBST([RABBITMQ_CPPFLAGS])
     165
     166# ===========================================================================
     167# Detect if libmysql is available
     168# ===========================================================================
     169
     170
     171AC_CHECK_LIB([mysqlclient], [main])
     172MYSQL_LDFLAGS=`mysql_config --libs`
     173MYSQL_CPPFLAGS=`mysql_config --cflags`
     174
     175AC_SUBST([MYSQL_LDFLAGS])
     176AC_SUBST([MYSQL_CPPFLAGS])
     177
     178
    137179
    138180# ===========================================================================
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/main.cfg

    r553 r617  
    11[server]
    2 req_worker=10
    3 async_worker=10
     2req_worker=1
     3async_worker=1
    44max_requests=200
    55listen=/tmp/zoo.sock
     
    1010uid=65534
    1111gid=65534
    12 #rootDir=/var/www/zoo-wps/cgi-bin
     12rootDir=/var/www/zoo-wps/cgi-bin
     13
     14[rabbitmq]
     15host=192.168.1.167
     16port=5672
     17user=david
     18passwd=pass
     19exchange=amq.direct
     20routingkey=zoo
     21queue=zoo_service_queue
     22
     23
     24[status]
     25driver=mysql
     26user=david
     27passwd=pass
     28bdd=zoo_status
     29host=127.0.0.1
     30port=3306
    1331
    1432[headers]
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_internal.c

    r549 r617  
    19771977  xmlDocSetRootElement (doc, nr);
    19781978
    1979   if (hasStoredExecuteResponse == true)
    1980     {
     1979
     1980  map * background = NULL;
     1981  background = getMapFromMaps(m,"lenv","background");
     1982
     1983    if (background != NULL){
     1984        /* requete asynchrone */
    19811985      /* We need to write the ExecuteResponse Document somewhere */
    19821986      FILE *output = fopen (stored_path, "w");
     
    20062010      fclose (output);
    20072011    }
     2012    else {
    20082013  printDocument (m, doc, pid,out);
    2009 
     2014    }
    20102015  xmlCleanupParser ();
    20112016  zooXmlCleanupNs ();
     
    20312036   */
    20322037  xmlDocDumpFormatMemoryEnc (doc, &xmlbuff, &buffersize, encoding, 1);
    2033   FCGX_FPrintF(out,(char *)xmlbuff);
    2034   FCGX_FFlush(out);
     2038 
     2039 
     2040  if (out != NULL){
     2041    FCGX_FPrintF(out,(char *)xmlbuff);
     2042    FCGX_FFlush(out);
     2043    }
    20352044  //printf ("%s", xmlbuff);
    20362045  //fflush (stdout);
     
    36873696  if (fsize == 0)
    36883697    {
     3698     
    36893699      return errorException (*m, _("Unable to download the file."),
    36903700                             "InternalError", NULL,NULL);
     
    36993709  free (tmpMap->value);
    37003710  tmpMap->value = (char *) malloc ((fsize + 1) * sizeof (char));
    3701   if (tmpMap->value == NULL)
     3711  if (tmpMap->value == NULL){
     3712
    37023713    return errorException (*m, _("Unable to allocate memory."),
    37033714                           "InternalError", NULL,NULL);
     3715  }
    37043716  memcpy (tmpMap->value, fcontent, (fsize + 1) * sizeof (char));
    37053717
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_json.c

    r606 r617  
     1/**
     2 * Author : David Saggiorato
     3 *
     4 *  Copyright 2008-2009 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
    126#include <string.h>
    227#include <stdio.h>
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_json.h

    r606 r617  
     1/**
     2 * Author : David Saggiorato
     3 *
     4 *  Copyright 2008-2009 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
    126#ifndef ZOO_JSON_H
    227#define ZOO_JSON_H 1
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_loader.c

    r553 r617  
    6767
    6868#include "service_zcfg.h"
     69#include "zoo_json.h"
     70#include "zoo_amqp.h"
     71#include "zoo_sql.h"
    6972//#include "service_internal.h"
     73
     74
     75void
     76loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
     77                   maps ** inputs, maps ** ioutputs, int *eres,FCGX_Stream *out, FCGX_Stream *err);
    7078
    7179xmlXPathObjectPtr extractFromDoc (xmlDocPtr, const char *);
     
    100108      int pid = getpid();
    101109      struct cgi_env *cgi;
    102       //PrintEnv(request.err, "Request environment", request.envp);
    103110      cgi = (struct cgi_env*)malloc(sizeof(struct cgi_env));
    104111      cgiMain_init (NULL, NULL,&cgi,request);
     
    455462      if (strQuery != NULL)
    456463        free (strQuery);
    457 
     464/*
     465      json_object *obj;
     466      maptojson(&obj,tmpMap);
     467      fprintf(stderr,"%s\n",json_object_to_json_string(obj));
     468      fflush(stderr);
     469  */   
    458470      runRequest (&tmpMap,&cgi,request);
    459471
     
    525537    return 1;
    526538  }
    527 
     539/*
     540 json_object *jobj;
     541  mapstojson(&jobj,conf);
     542  fprintf (stderr,"The json object created: %s\n",json_object_to_json_string(jobj));
     543    freeMaps(&conf);
     544 
     545  maps *conf_tmp;
     546  jsontomaps(jobj,&conf_tmp);
     547  dumpMaps(conf_tmp);
     548   return 1;
     549*/
    528550  char *rootDir;
    529551  map *m_rootDir = getMapFromMaps (conf, "server", "rootDir");
     
    684706    }
    685707  }
     708
     709
     710  char * amqp_host;
     711  map * m_amqp_host = getMapFromMaps (conf, "rabbitmq", "host");
     712  if (m_amqp_host == NULL){
     713    fprintf(stderr,"Configuration error: [rabbitmq] host");
     714    return 2;
     715  }
     716  else {
     717    amqp_host = (char *)malloc((strlen(m_amqp_host->value) +1)*sizeof(char*));
     718    strncpy(amqp_host,m_amqp_host->value,strlen(m_amqp_host->value));
     719    amqp_host[strlen(m_amqp_host->value)] = '\0';
     720 }
     721
     722  int amqp_port;
     723  map *m_amqp_port = getMapFromMaps (conf, "rabbitmq", "port");
     724  if (m_amqp_port == NULL){
     725    fprintf(stderr,"Configuration error: [rabbitmq] port");
     726    return 2;
     727  }
     728  else {
     729    amqp_port = atoi(m_amqp_port->value);
     730    if (amqp_port == 0){
     731        fprintf(stderr,"Configuration error: [rabbitmq] port");
     732        return 2;
     733    }
     734  }
     735
     736  char * amqp_user;
     737  map * m_amqp_user = getMapFromMaps (conf, "rabbitmq", "user");
     738  if (m_amqp_user == NULL){
     739    fprintf(stderr,"Configuration error: [rabbitmq] user");
     740    return 2;
     741  }
     742  else {
     743    amqp_user = (char *)malloc((strlen(m_amqp_user->value) +1)*sizeof(char*));
     744    strncpy(amqp_user,m_amqp_user->value,strlen(m_amqp_user->value));
     745    amqp_user[strlen(m_amqp_user->value)] = '\0';
     746 }
     747
     748  char * amqp_passwd;
     749  map * m_amqp_passwd = getMapFromMaps (conf, "rabbitmq", "passwd");
     750  if (m_amqp_passwd == NULL){
     751    fprintf(stderr,"Configuration error: [rabbitmq] passwd");
     752    return 2;
     753  }
     754  else {
     755    amqp_passwd = (char *)malloc((strlen(m_amqp_passwd->value) +1)*sizeof(char*));
     756    strncpy(amqp_passwd,m_amqp_passwd->value,strlen(m_amqp_passwd->value));
     757    amqp_passwd[strlen(m_amqp_passwd->value)] = '\0';
     758 }
     759
     760  char * amqp_exchange;
     761  map * m_amqp_exchange = getMapFromMaps (conf, "rabbitmq", "exchange");
     762  if (m_amqp_exchange == NULL){
     763    fprintf(stderr,"Configuration error: [rabbitmq] exchange");
     764    return 2;
     765  }
     766  else {
     767    amqp_exchange = (char *)malloc((strlen(m_amqp_exchange->value) +1)*sizeof(char*));
     768    strncpy(amqp_exchange,m_amqp_exchange->value,strlen(m_amqp_exchange->value));
     769    amqp_exchange[strlen(m_amqp_exchange->value)] = '\0';
     770 }
     771
     772  char * amqp_routingkey;
     773  map * m_amqp_routingkey = getMapFromMaps (conf, "rabbitmq", "routingkey");
     774  if (m_amqp_routingkey == NULL){
     775    fprintf(stderr,"Configuration error: [amqp] routingkey");
     776    return 2;
     777  }
     778  else {
     779    amqp_routingkey = (char *)malloc((strlen(m_amqp_routingkey->value) +1)*sizeof(char*));
     780    strncpy(amqp_routingkey,m_amqp_routingkey->value,strlen(m_amqp_routingkey->value));
     781    amqp_routingkey[strlen(m_amqp_routingkey->value)] = '\0';
     782 }
     783
     784  char * amqp_queue;
     785  map * m_amqp_queue = getMapFromMaps (conf, "rabbitmq", "queue");
     786  if (m_amqp_queue == NULL){
     787    fprintf(stderr,"Configuration error: [rabbitmq] queue");
     788    return 2;
     789  }
     790  else {
     791    amqp_queue = (char *)malloc((strlen(m_amqp_queue->value) +1)*sizeof(char*));
     792    strncpy(amqp_queue,m_amqp_queue->value,strlen(m_amqp_queue->value));
     793    amqp_queue[strlen(m_amqp_queue->value)] = '\0';
     794 }
     795
     796  char * status_user;
     797  map * m_status_user = getMapFromMaps (conf, "status", "user");
     798  if (m_status_user == NULL){
     799    fprintf(stderr,"Configuration error: [status] user");
     800    return 2;
     801  }
     802  else {
     803    status_user = (char *)malloc((strlen(m_status_user->value) +1)*sizeof(char*));
     804    strncpy(status_user,m_status_user->value,strlen(m_status_user->value));
     805    status_user[strlen(m_status_user->value)] = '\0';
     806  }
     807
     808
     809  char * status_passwd;
     810  map * m_status_passwd = getMapFromMaps (conf, "status", "passwd");
     811  if (m_status_passwd == NULL){
     812    fprintf(stderr,"Configuration error: [status] passwd");
     813    return 2;
     814  }
     815  else {
     816    status_passwd = (char *)malloc((strlen(m_status_passwd->value) +1)*sizeof(char*));
     817    strncpy(status_passwd,m_status_passwd->value,strlen(m_status_passwd->value));
     818    status_passwd[strlen(m_status_passwd->value)] = '\0';
     819  }
     820
     821  char * status_bdd;
     822  map * m_status_bdd = getMapFromMaps (conf, "status", "bdd");
     823  if (m_status_bdd == NULL){
     824    fprintf(stderr,"Configuration error: [status] bdd");
     825    return 2;
     826  }
     827  else {
     828    status_bdd = (char *)malloc((strlen(m_status_bdd->value) +1)*sizeof(char*));
     829    strncpy(status_bdd,m_status_bdd->value,strlen(m_status_bdd->value));
     830    status_bdd[strlen(m_status_bdd->value)] = '\0';
     831  }
     832
     833  char * status_host;
     834  map * m_status_host = getMapFromMaps (conf, "status", "host");
     835  if (m_status_host == NULL){
     836    fprintf(stderr,"Configuration error: [status] host");
     837    return 2;
     838  }
     839  else {
     840    status_host = (char *)malloc((strlen(m_status_host->value) +1)*sizeof(char*));
     841    strncpy(status_host,m_status_host->value,strlen(m_status_host->value));
     842    status_host[strlen(m_status_host->value)] = '\0';
     843  }
     844
     845  int status_port;
     846  map *m_status_port = getMapFromMaps (conf, "status", "port");
     847  if (m_status_port == NULL){
     848    fprintf(stderr,"Configuration error: [status] port");
     849    return 2;
     850  }
     851  else {
     852    status_port = atoi(m_status_port->value);
     853    if (status_port == 0){
     854        fprintf(stderr,"Configuration error: [status] port");
     855        return 2;
     856    }
     857  }
     858  init_sql(status_host,status_user,status_passwd,status_bdd,status_port);
    686859
    687860  int sock = FCGX_OpenSocket(listen, listen_queue);
     
    705878    return 3;
    706879  }
    707  
     880
     881  init_amqp(amqp_host,amqp_port,amqp_user, amqp_passwd, amqp_exchange, amqp_routingkey,amqp_queue);
     882
     883
    708884  int fork_status = fork();
    709885  if (fork_status == 0){
    710886    //child
    711     int forker_pid = getpid();
     887    int master_sync= getpid();
     888    fprintf(stderr,"Master sync%d\n",getpid());
    712889    FCGX_Init();
    713890    FCGX_Request request;
     
    718895        fork_status = fork();
    719896        if (fork_status == 0){
    720             fprintf(stderr,"child %d \n",i);
     897            fprintf(stderr,"child sync %d \n",getpid());
    721898            fflush(stderr);
    722899            break;
     
    724901    }
    725902    while(1){
    726         if (forker_pid != getpid()){
     903        /* mode synchrone */
     904        if (master_sync != getpid()){
    727905            while(FCGX_Accept_r(&request) == 0){
    728906                process(&request);
     
    737915        else {
    738916            wait(0);
    739             fprintf(stderr,"new child\n");
     917            fprintf(stderr,"Master sync %d\n",getpid());
     918            fprintf(stderr,"New sync Child\n");
    740919            fflush(stderr);
    741920            fork();
     
    744923  }
    745924  else {
    746  
    747   while(1);
     925   int master_async = getpid();
     926   fprintf(stderr,"Master async %d\n",master_async);
     927    int fork_s;
     928    int j;
     929    for (j = 0; j< async_worker; j++){
     930        fork_s = fork();
     931        if (fork_s == 0){
     932            fprintf(stderr,"child async %d \n",getpid());
     933            fflush(stderr);
     934            break;
     935        }
     936    }
     937    json_object *msg_obj;
     938    json_object *maps_obj;
     939    maps * map_c;
     940    json_object *req_format_jobj;
     941    maps * request_input_real_format;
     942    json_object *req_jobj;
     943    map * request_inputs;
     944    json_object *outputs_jobj;
     945    maps * request_output_real_format;
     946
     947    char *msg;
     948    int c;
     949    int eres;
     950    char * service_identifier;
     951    service * s1 = NULL;
     952    while(1){
     953        /* mode asynchrone */
     954        if( master_async != getpid()){
     955            /*traitement des requetes de la queue */
     956            bind_amqp();
     957            init_consumer();
     958            while(1){
     959               
     960                c = consumer_amqp(&msg);
     961                if (c == 0)
     962                    break;
     963                msg_obj = json_tokener_parse(msg);
     964               
     965                free(msg);
     966                maps_obj = json_object_object_get(msg_obj,"maps");
     967
     968                map_c = jsontomaps(maps_obj);
     969
     970                req_format_jobj = json_object_object_get(msg_obj,"request_input_real_format");
     971                request_input_real_format = jsontomaps(req_format_jobj);
     972
     973                req_jobj = json_object_object_get(msg_obj,"request_inputs");
     974                request_inputs = jsontomap(req_jobj);
     975
     976                outputs_jobj = json_object_object_get(msg_obj,"request_output_real_format");
     977                request_output_real_format = jsontomaps(outputs_jobj);
     978               
     979                json_object_put(msg_obj);
     980
     981                /* traitemement du message */
     982                /* Recherche des references */
     983                maps* tmp=request_input_real_format;
     984                HINTERNET hInternet = InternetOpen ((LPCTSTR) "ZooWPSClient\0",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
     985                while(tmp!=NULL){
     986                    map * tmp_map = getMap(tmp->content,"xlink:href");
     987                    if (tmp_map != NULL){
     988                        if (loadRemoteFile(&map_c, &tmp_map, &hInternet,tmp_map->value) < 0) {
     989                            /* passer le status failed dans la base de donnée */
     990                            fprintf(stderr,"Erreur de chargement \n");
     991                        }
     992                    }
     993                    tmp=tmp->next;
     994                }
     995                runHttpRequests (&map_c, &request_input_real_format, &hInternet);
     996                InternetCloseHandle (&hInternet);
     997                free(tmp);
     998                map * uuid = getMapFromMaps(map_c,"lenv","usid");
     999                if (uuid != NULL)
     1000                    start_job(uuid->value);
     1001                map *t=createMap("background","1");
     1002                maps * lenv = getMaps(map_c,"lenv");
     1003                addMapToMap(&lenv->content,t);
     1004                freeMap(&t);
     1005                free(t);
     1006               
     1007                map * m_identifier = getMap (request_inputs, "Identifier");
     1008               
     1009                service_identifier = zStrdup (m_identifier->value);
     1010
     1011                s1 = search_service (service_identifier);
     1012                free(service_identifier);
     1013               
     1014
     1015                //dumpMaps(request_input_real_format);
     1016
     1017                loadServiceAndRun(&map_c, s1,request_inputs,&request_input_real_format, &request_output_real_format, &eres,NULL,NULL);
     1018                if (eres == SERVICE_SUCCEEDED) {
     1019                    outputResponse (s1,request_input_real_format,request_output_real_format,request_inputs, 0, map_c, eres,NULL,NULL);
     1020                }
     1021                   
     1022                   
     1023                //dumpMaps(request_output_real_format);
     1024                //fprintf(stderr,"################################################################\n");
     1025                //dumpMaps(map_c);
     1026
     1027                outputResponse (s1,request_input_real_format,request_output_real_format,request_inputs, 0, map_c, eres,NULL,NULL);
     1028
     1029               
     1030                freeMaps(&map_c);
     1031                map_c= NULL;
     1032               
     1033                freeMaps(&request_input_real_format);
     1034                request_input_real_format = NULL;
     1035
     1036                //dumpMap(request_inputs);
     1037                freeMap(&request_inputs);
     1038                request_inputs = NULL;
     1039               
     1040                //dumpMaps(request_output_real_format);
     1041                freeMaps(&request_output_real_format);
     1042                request_output_real_format = NULL;
     1043                consumer_ack_amqp(c);
     1044               
     1045
     1046            }
     1047            close_amqp();
     1048           
     1049
     1050
     1051
     1052           
     1053        }
     1054        else {
     1055            wait(0);
     1056            fprintf(stderr,"Master async %d\n",getpid());
     1057            fprintf(stderr,"New async Child\n");
     1058            fflush(stderr);
     1059            fork();
     1060        }
     1061    }
    7481062
    7491063  }
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_service_loader.c

    r604 r617  
    3131#include "zoo_amqp.h"
    3232#include "zoo_sql.h"
     33#include "zoo_json.h"
    3334extern "C"
    3435{
     
    275276}
    276277
    277 #include "zoo_json.h"
    278278void
    279279loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
     
    281281{
    282282 
    283  json_object *obj;
    284  mapstojson(&obj,*myMap);
    285  fprintf(stderr,"myMaps: %s\n",json_object_to_json_string(obj));
    286 
    287 
    288 json_object *obj3;
    289 mapstojson(&obj3,*inputs);
    290 fprintf(stderr,"inputs: %s\n",json_object_to_json_string(obj3));
    291 
    292 
    293 json_object *obj1;
    294  maptojson(&obj1,request_inputs);
    295  fprintf(stderr,"request_inputs: %s\n",json_object_to_json_string(obj1));
    296 
    297 json_object *obj2;
    298 mapstojson(&obj2,*ioutputs);
    299 fprintf(stderr,"ioutputs: %s\n",json_object_to_json_string(obj2));
    300 
    301 
    302 
    303  fflush(stderr);
    304 
    305283
    306284 char tmps1[1024];
     
    309287  maps *request_output_real_format = *ioutputs;
    310288  maps *request_input_real_format = *inputs;
     289  map * background = NULL;
     290  map * uuid = getMapFromMaps(m,"lenv","usid");
     291  background = getMapFromMaps(m,"lenv","background");
     292
     293
    311294  /**
    312295   * Extract serviceType to know what kind of service should be loaded
     
    443426                           ("Error occured while running the %s function: %s"),
    444427                           s1->name, errstr);
    445                   errorException (m, tmpMsg, "InternalError", NULL,out);
     428
     429                  if (background == NULL){
     430                    errorException (m, tmpMsg, "InternalError", NULL,out);
     431                  }
     432                  else {
     433                    /* mise a jour de la table status */
     434                   }
    446435                  free (tmpMsg);
    447436#ifdef DEBUG
     
    466455              fflush (stderr);
    467456#endif
    468               *eres =
     457
     458            *eres =
    469459                execute (&m, &request_input_real_format,
    470460                         &request_output_real_format);
    471461#ifdef DEBUG
    472               fprintf (stderr, "Function loaded and returned %d\n", eres);
     462              fprintf (stderr, "Function loaded and returned %d\n", *eres);
    473463              fflush (stderr);
    474464#endif
     
    497487          sprintf (tmps, _("C Library can't be loaded %s"), errstr);
    498488          map *tmps1 = createMap ("text", tmps);
    499           printExceptionReportResponse (m, tmps1,out);
     489          if (background == NULL){
     490             printExceptionReportResponse (m, tmps1,out);
     491          }
     492          else {
     493            /* mise a jour table status */
     494           }
    500495          *eres = -1;
    501496          freeMap (&tmps1);
     
    578573               ("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"),
    579574               r_inputs->value);
    580       map *tmps = createMap ("text", tmpv);
    581       printExceptionReportResponse (m, tmps,out);
     575      if (background == NULL){
     576        map *tmps = createMap ("text", tmpv);
     577        printExceptionReportResponse (m, tmps,out);
     578      }
     579      else {
     580      /* mise jour table status */
     581      }
    582582      *eres = -1;
    583583    }
     
    30433043  if (status == NULLMAP)
    30443044    {
     3045
    30453046      loadServiceAndRun
    30463047        (&m, s1,
     
    30553056
    30563057    eres = SERVICE_ACCEPTED;
    3057     json_object * msg_jobj = json_object_new_object();
    3058     json_object_object_add(msg_jobj,"service_identifier",json_object_new_string(service_identifier));
    3059 
    3060 
     3058    json_object *msg_jobj = json_object_new_object();
    30613059    json_object *maps_obj;
    30623060    mapstojson(&maps_obj,m);
     
    30763074    mapstojson(&outputs_jobj,request_output_real_format);
    30773075    json_object_object_add(msg_jobj,"request_output_real_format",outputs_jobj);
    3078    
    3079     if ( (send_msg(json_object_to_json_string(msg_jobj),"application/json") != 0) || (add_status(uuid) != 0) ){     
     3076 
     3077    bind_amqp();
     3078
     3079    if ( (send_msg(json_object_to_json_string(msg_jobj),"application/json") != 0) || (add_job(uuid) != 0) ){     
    30803080        eres = SERVICE_FAILED;
    30813081    }
     3082    close_amqp();
     3083    json_object_put(msg_jobj);
     3084   
    30823085
    30833086}
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_sql.c

    r603 r617  
     1/**
     2 * Author : David Saggiorato
     3 *
     4 *  Copyright 2008-2009 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
     26
    127#include <string.h>
    228#include <stdio.h>
     
    5884 }
    5985
    60 int add_status(const char * uuid) {
     86int add_job(const char * uuid) {
    6187    init_connection();
    6288    const char * query = "insert into status (uuid,status,created_time) values ('%s','queue',now())";
     
    7298    return 0;
    7399}
     100
     101int start_job(const char *uuid){
     102    init_connection();
     103    const char * query = "update status set start_date=now(), status='running', progress=0 where uuid='%s';";
     104    char * query_f = (char*) malloc(strlen(query) + strlen(uuid) + 1);
     105    sprintf(query_f,query,uuid);
     106    if (mysql_query(con, query_f) != 0){
     107        fprintf(stderr, "%s\n", mysql_error(con));
     108        free(query_f);
     109        return -1;
     110    }
     111    free(query_f);
     112    mysql_close(con);
     113    return 0;
     114}
     115
     116
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_sql.h

    r603 r617  
     1/**
     2 * Author : David Saggiorato
     3 *
     4 *  Copyright 2008-2009 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
     26
    127#ifndef ZOO_SQL_H
    228#define ZOO_SQL_H 1
     
    531void init_sql(const char* host,const char *user, const char *passwd, const char * bdd,int port);
    632char * get_uuid();
    7 int add_status(const char * uuid);
     33int add_job(const char * uuid);
     34int start_job(const char *uuid);
     35
    836#endif
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