00001 /// @file include/dmlite/cpp/pooldriver.h 00002 /// @brief Pool handling API. 00003 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch> 00004 #ifndef DMLITE_CPP_POOLDRIVER_H 00005 #define DMLITE_CPP_POOLDRIVER_H 00006 00007 #include "dmlite/common/config.h" 00008 #include "base.h" 00009 #include "exceptions.h" 00010 #include "inode.h" 00011 #include "utils/urls.h" 00012 00013 #include <map> 00014 #include <vector> 00015 00016 namespace dmlite { 00017 00018 // Forward declarations. 00019 class Pool; 00020 class StackInstance; 00021 00022 /// Represents a chunk of a file. 00023 struct Chunk { 00024 Chunk(); 00025 Chunk(const std::string& url, uint64_t offset, uint64_t size); 00026 /// Chunk from a serialized string 00027 explicit Chunk(const std::string& str); 00028 00029 uint64_t offset; 00030 uint64_t size; 00031 Url url; 00032 00033 /// Some implementations need to pass two urls per chunk, e.g. one for PUT and one for POST 00034 std::string url_alt; 00035 00036 00037 /// Some implementations need to pass an ID for a chunk 00038 std::string chunkid; 00039 00040 bool operator == (const Chunk&) const; 00041 bool operator != (const Chunk&) const; 00042 bool operator < (const Chunk&) const; 00043 bool operator > (const Chunk&) const; 00044 00045 std::string toString(void) const; 00046 }; 00047 00048 /// Represent the complete location of a file. 00049 struct Location: public std::vector<Chunk> { 00050 Location() {} 00051 Location(int nitems, const Chunk& proto): std::vector<Chunk>(nitems, proto) {} 00052 00053 Location(const Location& l): std::vector<Chunk>(l) {} 00054 00055 // Location from serialized string 00056 explicit Location(const std::string& str); 00057 00058 std::string toString(void) const; 00059 }; 00060 00061 /// Handler for a pool. Works similary to a file handler. 00062 class PoolHandler { 00063 public: 00064 /// Destructor 00065 virtual ~PoolHandler(); 00066 00067 /// Get the pool type of this pool. 00068 virtual std::string getPoolType(void) ; 00069 00070 /// Get the pool name of this pool. 00071 virtual std::string getPoolName(void) ; 00072 00073 /// Get the total space of this pool. 00074 virtual uint64_t getTotalSpace(void) ; 00075 00076 /// Get the free space of this pool. 00077 virtual uint64_t getFreeSpace(void) ; 00078 00079 /// Check if the pool is actually available. 00080 virtual bool poolIsAvailable(bool write = true) ; 00081 00082 /// Check if a replica is available. 00083 virtual bool replicaIsAvailable(const Replica& replica) ; 00084 00085 /// Get the actual location of the file replica. This is pool-specific. 00086 virtual Location whereToRead(const Replica& replica) ; 00087 00088 /// Remove a replica from the pool. 00089 virtual void removeReplica(const Replica& replica) ; 00090 00091 /// Get where to put a file. 00092 virtual Location whereToWrite(const std::string& path) ; 00093 00094 /// Cancel a write. 00095 virtual void cancelWrite(const Location& loc) ; 00096 }; 00097 00098 /// Interface for a pool driver 00099 class PoolDriver: public virtual BaseInterface { 00100 public: 00101 /// Destructor 00102 virtual ~PoolDriver(); 00103 00104 /// Create a handler. 00105 virtual PoolHandler* createPoolHandler(const std::string& poolName) ; 00106 00107 /// Called just before adding the pool to the database. 00108 /// To be used by a plugin, in case it needs to do some previous preparations. 00109 /// (i.e. legacy filesystem will actually create the pool here) 00110 virtual void toBeCreated(const Pool& pool) ; 00111 00112 /// Called just after a pool is added to the database. 00113 virtual void justCreated(const Pool& pool) ; 00114 00115 /// Called when updating a pool. 00116 virtual void update(const Pool& pool) ; 00117 00118 /// Called just before a pool of this type is removed. 00119 /// @note The driver may remove the pool itself (i.e. filesystem) 00120 virtual void toBeDeleted(const Pool& pool) ; 00121 }; 00122 00123 /// PoolDriver factory 00124 class PoolDriverFactory: public virtual BaseFactory { 00125 public: 00126 /// Destructor. 00127 virtual ~PoolDriverFactory(); 00128 00129 /// Supported pool type 00130 virtual std::string implementedPool() throw (); 00131 00132 protected: 00133 friend class StackInstance; 00134 00135 /// Instantiate the implemented pool driver. 00136 virtual PoolDriver* createPoolDriver(void) ; 00137 }; 00138 00139 }; 00140 00141 #endif // DMLITE_CPP_POOLDRIVER_H