source: branches/prototype-v0/zoo-project/zoo-services/utils/hpc/service2.c @ 854

Last change on this file since 854 was 854, checked in by djay, 6 years ago

HPC support update. Add inputs for create options in Gdal_Dem.

  • Property svn:keywords set to Id
File size: 8.3 KB
Line 
1/**
2 * Author : Gérald FENOY
3 *
4 * Copyright 2008-2009 GeoLabs SARL. All rights reserved.
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
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * THE SOFTWARE.
27 */
28
29
30#include "service.h"
31#include "service_internal.h"
32
33#include <libxml/tree.h>
34#include <libxml/parser.h>
35#include <libxml/xpath.h>
36#include <libxml/xpathInternals.h>
37
38#include <libxslt/xslt.h>
39#include <libxslt/xsltInternals.h>
40#include <libxslt/transform.h>
41#include <libxslt/xsltutils.h>
42
43#include <dirent.h>
44extern "C" {
45
46  /**
47   * Try to delete a cache file.
48   *
49   * @param storage the full path to store the file
50   * @param filename the filename to store
51   * @param ext the extention of the file
52   * @return 0 in case of success
53   */
54  int tryDeleteCacheFile(const char* storage,const char* filename,const char* ext){
55    char *filename_noext=(char*)malloc((strlen(filename)-3)*sizeof(char));
56    snprintf(filename_noext,strlen(filename)-4,"%s",filename);
57    char* filename_full=(char*)malloc((strlen(filename)+1)*sizeof(char));
58    sprintf(filename_full,"%s.%s",filename_noext,ext);
59    char* fullpath=(char*)malloc((strlen(storage)+strlen(filename_full)+2)*sizeof(char));
60    sprintf(fullpath,"%s/%s",storage,filename_full);
61    if(unlink(fullpath)==0){
62      // TODO store the filename_full in the deletedfiles
63      fprintf(stderr,"#### DeleteData #### %s %d %s has been successfully deleted\n",__FILE__,__LINE__,filename_full);
64    }else{
65      fprintf(stderr,"#### DeleteData #### unable to delete %s \n",fullpath);
66    }
67    free(fullpath);
68    free(filename_full);
69    return 0;
70  } 
71
72  /**
73   * Try to delete a data file.
74   *
75   * @param storage the full path to store the file
76   * @param filename the filename to store
77   * @return 0 in case of success
78   */
79  int tryDeleteDataFile(const char* storage,const char* filename){
80    char* fullpath=(char*)malloc((strlen(storage)+strlen(filename)+2)*sizeof(char));
81    sprintf(fullpath,"%s/%s",storage,filename);
82    if(unlink(fullpath)==0){
83      // TODO store the filename_full in the deletedfiles
84      fprintf(stderr,"#### DeleteData #### %s %d %s has been successfully deleted\n",__FILE__,__LINE__,filename);
85    }else{
86      fprintf(stderr,"#### DeleteData #### unable to delete %s \n",fullpath);
87    }
88    free(fullpath);
89    return 0;
90  } 
91 
92 
93  /**
94   * DeleteData ZOO-Service :
95   * This service is used in the ZOO-Project to delete the data file
96   * associated with input or output.
97   */
98  ZOO_DLL_EXPORT int DeleteData(maps*& conf,maps*& inputs,maps*& outputs){
99    map* dataPath=getMapFromMaps(conf,"main","dataPath");
100    map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
101    map* cacheDir=getMapFromMaps(conf,"main","cacheDir");
102    map* jobid=getMapFromMaps(inputs,"jobid","value");
103    map* filename=getMapFromMaps(inputs,"filename","value");
104    map* ioname=getMapFromMaps(inputs,"ioname","value");
105    char tmp0[4];
106    sprintf(tmp0,"%c%c%c",filename->value[strlen(filename->value)-4],filename->value[strlen(filename->value)-3],filename->value[strlen(filename->value)-2]);
107    char *cfilename=NULL;
108    if(strcasecmp(tmp0,"zca")==0){
109      cfilename=(char*) malloc((strlen(filename->value)+strlen(cacheDir->value)+2)*sizeof(char));
110      sprintf(cfilename,"%s/%s",cacheDir->value,filename->value);
111    }
112    else{
113      cfilename=(char*) malloc((strlen(filename->value)+strlen(tmpPath->value)+2)*sizeof(char));
114      sprintf(cfilename,"%s/%s",tmpPath->value,filename->value);
115    }
116    zooLock* lck=lockFile(conf,cfilename,'w');
117    char** deletedfiles;
118    if(lck!=NULL){
119      if(strcasecmp(tmp0,"zca")==0){
120        // Read the zcp file to verify if it comes from a shared source
121        char *filename_noext=(char*)malloc((strlen(filename->value)-3)*sizeof(char));
122        snprintf(filename_noext,strlen(filename->value)-4,"%s",filename->value);
123        char* filename_full=(char*)malloc((strlen(filename->value)+1)*sizeof(char));
124        sprintf(filename_full,"%s.zcp",filename_noext);
125        char* fullpath=(char*)malloc((strlen(cacheDir->value)+strlen(filename_full)+2)*sizeof(char));
126        sprintf(fullpath,"%s/%s",cacheDir->value,filename_full);
127        FILE* f0=fopen(fullpath,"rb");
128        char *fcontent=NULL;
129        if(f0!=NULL){
130          long flen;
131          fseek (f0, 0, SEEK_END);
132          flen = ftell (f0);
133          fseek (f0, 0, SEEK_SET);
134          fcontent = (char *) malloc ((flen + 1) * sizeof (char));
135          fread(fcontent,flen,1,f0);
136          fcontent[flen]=0;
137          fclose(f0);
138        }
139        if(fcontent!=NULL && strcasecmp(fcontent,"SHARED")!=0){
140          // Delete associated zcm and zcp
141          tryDeleteCacheFile(cacheDir->value,filename->value,"zca");
142          tryDeleteCacheFile(cacheDir->value,filename->value,"zcm");
143          tryDeleteCacheFile(cacheDir->value,filename->value,"zcp");
144          // Delete ZOO_DATA_<input>_<sid>.data and <input>_<sid>.map
145          char* datafile=(char*)malloc((strlen(jobid->value)+strlen(ioname->value)+19)*sizeof(char));
146          sprintf(datafile,"ZOO_DATA_%s_%s.data",ioname->value,jobid->value);
147          tryDeleteDataFile(dataPath->value,datafile);
148          free(datafile);
149          datafile=(char*)malloc((strlen(jobid->value)+strlen(ioname->value)+19)*sizeof(char));
150          sprintf(datafile,"%s_%s.map",ioname->value,jobid->value);
151          tryDeleteDataFile(dataPath->value,datafile);
152          free(datafile);
153        }else{
154          setMapInMaps(conf,"lenv","message",_ss("The file you try to delete is a shared ressource and cannot be deleted by nature."));
155          unlockFile(conf,lck);
156          return SERVICE_FAILED;
157        }
158        setMapInMaps(outputs,"Result","value",_ss("The input data has been correclty removed"));
159      }else{
160        char tmp1[8];
161        snprintf(tmp1,7,"%s",filename->value);
162        if(strcasecmp(tmp1,"output")==0){
163          tryDeleteDataFile(tmpPath->value,filename->value);
164          // Delete ZOO_DATA_<output>_<sid>.data and <output>_<sid>.map
165          char* datafile=(char*)malloc((strlen(jobid->value)+strlen(ioname->value)+19)*sizeof(char));
166          sprintf(datafile,"ZOO_DATA_%s_%s.data",ioname->value,jobid->value);
167          tryDeleteDataFile(dataPath->value,datafile);
168          free(datafile);
169          datafile=(char*)malloc((strlen(jobid->value)+strlen(ioname->value)+19)*sizeof(char));
170          sprintf(datafile,"%s_%s.map",ioname->value,jobid->value);
171          tryDeleteDataFile(dataPath->value,datafile);
172          free(datafile);
173          char* webServices[3]={"wms","wfs","wcs"};
174          int i=0;
175          // Delete ZOO_DATA_<ws>_link_<sid>.data and <ws>_link_<sid>.map
176          // with <ws> is the corresponding OGC web service (wms,wfs,wcs)
177          for(i=0;i<3;i++){
178            datafile=(char*)malloc((strlen(jobid->value)+24)*sizeof(char));
179            sprintf(datafile,"ZOO_DATA_%s_link_%s.data",webServices[i],jobid->value);
180            tryDeleteDataFile(dataPath->value,datafile);
181            free(datafile);
182            datafile=(char*)malloc((strlen(jobid->value)+14)*sizeof(char));
183            sprintf(datafile,"%s_link_%s.map",webServices[i],jobid->value);
184            tryDeleteDataFile(dataPath->value,datafile);
185            free(datafile);
186          }
187          setMapInMaps(outputs,"Result","value",_ss("The output data has been correclty removed"));
188        }else{
189          setMapInMaps(conf,"lenv","message",_ss("The file you try to delete is nor an input, nor and output."));
190          unlockFile(conf,lck);
191          return SERVICE_FAILED;
192        }
193      }
194      unlockFile(conf,lck);
195    }
196    else{
197      setMapInMaps(conf,"lenv","message",_ss("Failed to acquire lock for deletion, please try again later."));
198      return SERVICE_FAILED;
199    }
200    return SERVICE_SUCCEEDED;
201  }
202
203}
Note: See TracBrowser for help on using the repository browser.

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