Back to index

nordugrid-arc-nox  1.1.0~rc6
FileCache.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifndef FILECACHE_H_
00004 #define FILECACHE_H_
00005 
00006 #include <sstream>
00007 #include <vector>
00008 #include <map>
00009 #include <arc/DateTime.h>
00010 // Independent implementaion of std roundf() 
00011 #define roundf(num) ((fmod(num,1) < 0.5) ? floor(num):ceil(num))
00012 
00013 #include "FileCacheHash.h"
00014 
00015 namespace Arc {
00016 
00017   class Logger;
00018 
00022   struct CacheParameters {
00023     std::string cache_path;
00024     std::string cache_link_path;
00025   };
00026 
00027 #ifndef WIN32
00028 
00065   class FileCache {
00066   private:
00070     std::map <std::string, int> _cache_map;
00075     std::vector<struct CacheParameters> _caches;
00080     std::vector<struct CacheParameters> _remote_caches;
00084     std::vector<struct CacheParameters> _draining_caches;
00088     std::string _id;
00093     uid_t _uid;
00094     gid_t _gid;
00098     std::string _hostname;
00102     std::string _pid;
00107     int _max_used;
00108     int _min_used;
00112     static const std::string CACHE_DATA_DIR;
00116     static const std::string CACHE_JOB_DIR;
00120     static const int CACHE_DIR_LENGTH;
00124     static const int CACHE_DIR_LEVELS;
00128     static const std::string CACHE_LOCK_SUFFIX;
00132     static const std::string CACHE_META_SUFFIX;
00136     static const int CACHE_DEFAULT_AUTH_VALIDITY;
00140     bool _init(std::vector<std::string> caches,
00141                std::vector<std::string> remote_caches,
00142                std::vector<std::string> draining_caches,
00143                std::string id,
00144                uid_t job_uid,
00145                gid_t job_gid,
00146                int cache_max = 100,
00147                int cache_min = 100);
00151     std::string _getLockFileName(std::string url);
00155     std::string _getMetaFileName(std::string url);
00160     bool _checkLock(std::string url);
00167     bool _cacheMkDir(std::string dir, bool all_read);
00173     int _chooseCache(std::string url);
00177     std::pair <unsigned long long , unsigned long long> _getCacheInfo(std::string path);
00181     static Logger logger;
00182   public:
00197     FileCache(std::string cache_path,
00198               std::string id,
00199               uid_t job_uid,
00200               gid_t job_gid);
00201 
00212     FileCache(std::vector<std::string> caches,
00213               std::string id,
00214               uid_t job_uid,
00215               gid_t job_gid);       
00236     FileCache(std::vector<std::string> caches,
00237               std::vector<std::string> remote_caches,
00238               std::vector<std::string> draining_caches, 
00239               std::string id,
00240               uid_t job_uid,
00241               gid_t job_gid,
00242               int cache_max = 100,
00243               int cache_min = 100);
00247     FileCache() {
00248       _caches.clear();
00249     }
00250 
00268     bool Start(std::string url, bool& available, bool& is_locked, bool use_remote = true);
00279     bool Stop(std::string url);
00289     bool StopAndDelete(std::string url);
00294     std::string File(std::string url);
00309     bool Link(std::string link_path, std::string url);
00313     bool Copy(std::string dest_path, std::string url, bool executable = false);
00319     bool Release();
00327     bool AddDN(std::string url, std::string DN, Time expiry_time);
00334     bool CheckDN(std::string url, std::string DN);
00342     bool CheckCreated(std::string url);
00349     Time GetCreated(std::string url);
00355     bool CheckValid(std::string url);
00362     Time GetValid(std::string url);
00369     bool SetValid(std::string url, Time val);
00373     operator bool() {
00374       return (_caches.size() != 0);
00375     };
00379     bool operator==(const FileCache& a);
00380 
00381   };
00382 
00383 #else
00384 
00385   class FileCache {
00386   public:
00387     FileCache(std::string cache_path,
00388               std::string id,
00389               int job_uid,
00390               int job_gid) {}
00391     FileCache(std::vector<std::string> caches,
00392               std::string id,
00393               int job_uid,
00394               int job_gid) {}
00395     FileCache(std::vector<std::string> caches,
00396               std::vector<std::string> remote_caches,
00397               std::vector<std::string> draining_caches, 
00398               std::string id,
00399               int job_uid,
00400               int job_gid,
00401               int cache_max,
00402               int cache_min) {}
00403     FileCache(const FileCache& cache) {}
00404     FileCache() {}
00405     bool Start(std::string url, bool& available, bool& is_locked, bool& use_remote) { return false; }
00406     bool Stop(std::string url) { return false; }
00407     bool StopAndDelete(std::string url) {return false; }
00408     std::string File(std::string url) { return url; }
00409     bool Link(std::string link_path, std::string url)  { return false; }
00410     bool Copy(std::string dest_path, std::string url, bool executable = false) { return false; }
00411     bool Release() { return false;}
00412     bool AddDN(std::string url, std::string DN, Time expiry_time) { return false;}
00413     bool CheckDN(std::string url, std::string DN) { return false; }
00414     bool CheckCreated(std::string url){ return false; }
00415     Time GetCreated(std::string url) { return Time(); }
00416     bool CheckValid(std::string url) { return false; }
00417     Time GetValid(std::string url)  { return Time(); }
00418     bool SetValid(std::string url, Time val) { return false; }
00419     operator bool() {
00420       return false;
00421     };
00422     bool operator==(const FileCache& a)  { return false; }
00423   };
00424 #endif /*WIN32*/
00425 
00426 
00427 } // namespace Arc
00428 
00429 #endif /*FILECACHE_H_*/