00001
00002
00003 #ifndef FILECACHE_H_
00004 #define FILECACHE_H_
00005
00006 #include <sstream>
00007 #include <vector>
00008 #include <map>
00009 #include <set>
00010 #include <arc/DateTime.h>
00011 #include <arc/Logger.h>
00012
00013 #include "FileCacheHash.h"
00014
00015 namespace Arc {
00016
00018 struct CacheParameters {
00019 std::string cache_path;
00020 std::string cache_link_path;
00021 };
00022
00023 #ifndef WIN32
00024
00026
00057 class FileCache {
00058 private:
00060 std::map <std::string, struct CacheParameters> _cache_map;
00063 std::vector<struct CacheParameters> _caches;
00066 std::vector<struct CacheParameters> _remote_caches;
00068 std::vector<struct CacheParameters> _draining_caches;
00071 std::set<std::string> _urls_unlocked;
00073 std::string _id;
00076 uid_t _uid;
00078 gid_t _gid;
00079
00081 static const std::string CACHE_DATA_DIR;
00083 static const std::string CACHE_JOB_DIR;
00085 static const int CACHE_DIR_LENGTH;
00087 static const int CACHE_DIR_LEVELS;
00089 static const std::string CACHE_META_SUFFIX;
00091 static const int CACHE_DEFAULT_AUTH_VALIDITY;
00094 static const int CACHE_LOCK_TIMEOUT;
00096 static const int CACHE_META_LOCK_TIMEOUT;
00097
00099 bool _init(const std::vector<std::string>& caches,
00100 const std::vector<std::string>& remote_caches,
00101 const std::vector<std::string>& draining_caches,
00102 const std::string& id,
00103 uid_t job_uid,
00104 gid_t job_gid);
00108 bool _checkMetaFile(const std::string& filename, const std::string& url, bool& is_locked);
00110 std::string _getMetaFileName(const std::string& url);
00112 std::string _getHash(const std::string& url) const;
00115 struct CacheParameters _chooseCache(const std::string& url) const;
00117 float _getCacheInfo(const std::string& path) const;
00119 bool _cleanFilesAndReturnFalse(const std::string& hard_link_file, bool& locked);
00120
00122 static Logger logger;
00123
00124 public:
00139 FileCache(const std::string& cache_path,
00140 const std::string& id,
00141 uid_t job_uid,
00142 gid_t job_gid);
00143
00154 FileCache(const std::vector<std::string>& caches,
00155 const std::string& id,
00156 uid_t job_uid,
00157 gid_t job_gid);
00174 FileCache(const std::vector<std::string>& caches,
00175 const std::vector<std::string>& remote_caches,
00176 const std::vector<std::string>& draining_caches,
00177 const std::string& id,
00178 uid_t job_uid,
00179 gid_t job_gid);
00180
00182 FileCache() {
00183 _caches.clear();
00184 }
00185
00187
00206 bool Start(const std::string& url,
00207 bool& available,
00208 bool& is_locked,
00209 bool use_remote = true,
00210 bool delete_first = false);
00211
00213
00224 bool Stop(const std::string& url);
00225
00227
00236 bool StopAndDelete(const std::string& url);
00237
00239
00244 std::string File(const std::string& url);
00245
00247
00281 bool Link(const std::string& link_path,
00282 const std::string& url,
00283 bool copy,
00284 bool executable,
00285 bool holding_lock,
00286 bool& try_again);
00287
00289
00294 bool Release() const;
00295
00297
00304 bool AddDN(const std::string& url, const std::string& DN, const Time& expiry_time);
00305
00307
00313 bool CheckDN(const std::string& url, const std::string& DN);
00314
00316
00322 bool CheckCreated(const std::string& url);
00323
00325
00330 Time GetCreated(const std::string& url);
00331
00333
00337 bool CheckValid(const std::string& url);
00338
00340
00345 Time GetValid(const std::string& url);
00346
00348
00353 bool SetValid(const std::string& url, const Time& val);
00354
00356 operator bool() {
00357 return (!_caches.empty());
00358 };
00359
00361 bool operator==(const FileCache& a);
00362
00363 };
00364
00365 #else
00366
00367 class FileCache {
00368 public:
00369 FileCache(const std::string& cache_path,
00370 const std::string& id,
00371 int job_uid,
00372 int job_gid) {}
00373 FileCache(const std::vector<std::string>& caches,
00374 const std::string& id,
00375 int job_uid,
00376 int job_gid) {}
00377 FileCache(const std::vector<std::string>& caches,
00378 const std::vector<std::string>& remote_caches,
00379 const std::vector<std::string>& draining_caches,
00380 const std::string& id,
00381 int job_uid,
00382 int job_gid,
00383 int cache_max=100,
00384 int cache_min=100) {}
00385 FileCache(const FileCache& cache) {}
00386 FileCache() {}
00387 bool Start(const std::string& url, bool& available, bool& is_locked, bool use_remote=true, bool delete_first=false) { return false; }
00388 bool Stop(const std::string& url) { return false; }
00389 bool StopAndDelete(const std::string& url) {return false; }
00390 std::string File(const std::string& url) { return url; }
00391 bool Link(const std::string& link_path, const std::string& url, bool copy, bool executable, bool holding_lock, bool& try_again) { return false; }
00392 bool Release() const { return false;}
00393 bool AddDN(const std::string& url, const std::string& DN, const Time& expiry_time) { return false;}
00394 bool CheckDN(const std::string& url, const std::string& DN) { return false; }
00395 bool CheckCreated(const std::string& url){ return false; }
00396 Time GetCreated(const std::string& url) { return Time(); }
00397 bool CheckValid(const std::string& url) { return false; }
00398 Time GetValid(const std::string& url) { return Time(); }
00399 bool SetValid(const std::string& url, const Time& val) { return false; }
00400 operator bool() {
00401 return false;
00402 };
00403 bool operator==(const FileCache& a) { return false; }
00404 };
00405 #endif
00406
00407
00408 }
00409
00410 #endif