dmlite  0.6
pooldriver.h
Go to the documentation of this file.
1 /// @file include/dmlite/cpp/pooldriver.h
2 /// @brief Pool handling API.
3 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch>
4 #ifndef DMLITE_CPP_POOLDRIVER_H
5 #define DMLITE_CPP_POOLDRIVER_H
6 
7 #include "dmlite/common/config.h"
8 #include "base.h"
9 #include "exceptions.h"
10 #include "inode.h"
11 #include "utils/urls.h"
12 
13 #include <map>
14 #include <vector>
15 
16 namespace dmlite {
17 
18  // Forward declarations.
19  class Pool;
20  class StackInstance;
21 
22  /// Represents a chunk of a file.
23  struct Chunk {
24  Chunk();
25  Chunk(const std::string& url, uint64_t offset, uint64_t size);
26  /// Chunk from a serialized string
27  explicit Chunk(const std::string& str);
28 
29  uint64_t offset;
30  uint64_t size;
32 
33  bool operator == (const Chunk&) const;
34  bool operator != (const Chunk&) const;
35  bool operator < (const Chunk&) const;
36  bool operator > (const Chunk&) const;
37 
38  std::string toString(void) const;
39  };
40 
41  /// Represent the complete location of a file.
42  struct Location: public std::vector<Chunk> {
43  Location() {}
44  Location(int nitems, const Chunk& proto): std::vector<Chunk>(nitems, proto) {}
45 
46  Location(const Location& l): std::vector<Chunk>(l) {}
47 
48  // Location from serialized string
49  explicit Location(const std::string& str);
50 
51  std::string toString(void) const;
52  };
53 
54  /// Handler for a pool. Works similary to a file handler.
55  class PoolHandler {
56  public:
57  /// Destructor
58  virtual ~PoolHandler();
59 
60  /// Get the pool type of this pool.
61  virtual std::string getPoolType(void) throw (DmException);
62 
63  /// Get the pool name of this pool.
64  virtual std::string getPoolName(void) throw (DmException);
65 
66  /// Get the total space of this pool.
67  virtual uint64_t getTotalSpace(void) throw (DmException);
68 
69  /// Get the free space of this pool.
70  virtual uint64_t getFreeSpace(void) throw (DmException);
71 
72  /// Check if the pool is actually available.
73  virtual bool poolIsAvailable(bool write = true) throw (DmException);
74 
75  /// Check if a replica is available.
76  virtual bool replicaIsAvailable(const Replica& replica) throw (DmException);
77 
78  /// Get the actual location of the file replica. This is pool-specific.
79  virtual Location whereToRead(const Replica& replica) throw (DmException);
80 
81  /// Remove a replica from the pool.
82  virtual void removeReplica(const Replica& replica) throw (DmException);
83 
84  /// Get where to put a file.
85  virtual Location whereToWrite(const std::string& path) throw (DmException);
86 
87  /// Cancel a write.
88  virtual void cancelWrite(const Location& loc) throw (DmException);
89  };
90 
91  /// Interface for a pool driver
92  class PoolDriver: public virtual BaseInterface {
93  public:
94  /// Destructor
95  virtual ~PoolDriver();
96 
97  /// Create a handler.
98  virtual PoolHandler* createPoolHandler(const std::string& poolName) throw (DmException);
99 
100  /// Called just before adding the pool to the database.
101  /// To be used by a plugin, in case it needs to do some previous preparations.
102  /// (i.e. legacy filesystem will actually create the pool here)
103  virtual void toBeCreated(const Pool& pool) throw (DmException);
104 
105  /// Called just after a pool is added to the database.
106  virtual void justCreated(const Pool& pool) throw (DmException);
107 
108  /// Called when updating a pool.
109  virtual void update(const Pool& pool) throw (DmException);
110 
111  /// Called just before a pool of this type is removed.
112  /// @note The driver may remove the pool itself (i.e. filesystem)
113  virtual void toBeDeleted(const Pool& pool) throw (DmException);
114  };
115 
116  /// PoolDriver factory
117  class PoolDriverFactory: public virtual BaseFactory {
118  public:
119  /// Destructor.
120  virtual ~PoolDriverFactory();
121 
122  /// Supported pool type
123  virtual std::string implementedPool() throw ();
124 
125  protected:
126  friend class StackInstance;
127 
128  /// Instantiate the implemented pool driver.
129  virtual PoolDriver* createPoolDriver(void) throw (DmException);
130  };
131 
132 };
133 
134 #endif // DMLITE_CPP_POOLDRIVER_H
bool operator>(const Chunk &) const
virtual std::string getPoolName(void)
Get the pool name of this pool.
Base class for interfaces.
Definition: base.h:18
Common methods and functions for URL and path.
virtual bool poolIsAvailable(bool write=true)
Check if the pool is actually available.
Definition: dmlite.h:161
virtual void justCreated(const Pool &pool)
Called just after a pool is added to the database.
Handler for a pool. Works similary to a file handler.
Definition: pooldriver.h:55
Url url
Definition: pooldriver.h:31
Header generated by CMake with the build configuration used.
Represent the complete location of a file.
Definition: pooldriver.h:42
Base exception class.
Definition: exceptions.h:17
Location(int nitems, const Chunk &proto)
Definition: pooldriver.h:44
File replica metadata.
Definition: inode.h:87
std::string toString(void) const
virtual std::string getPoolType(void)
Get the pool type of this pool.
virtual bool replicaIsAvailable(const Replica &replica)
Check if a replica is available.
virtual std::string implementedPool()
Supported pool type.
virtual uint64_t getFreeSpace(void)
Get the free space of this pool.
virtual Location whereToWrite(const std::string &path)
Get where to put a file.
bool operator!=(const Chunk &) const
Definition: urls.h:13
virtual ~PoolDriverFactory()
Destructor.
Exceptions used by the API.
virtual Location whereToRead(const Replica &replica)
Get the actual location of the file replica. This is pool-specific.
Represents a chunk of a file.
Definition: pooldriver.h:23
Base class for factories.
Definition: base.h:48
bool operator==(const Chunk &) const
PoolDriver factory.
Definition: pooldriver.h:117
uint64_t offset
Definition: pooldriver.h:29
uint64_t size
Definition: pooldriver.h:30
virtual void toBeCreated(const Pool &pool)
virtual ~PoolDriver()
Destructor.
virtual void removeReplica(const Replica &replica)
Remove a replica from the pool.
Internal interface for handling pool metadata.
Definition: poolmanager.h:22
Base interfaces.
bool operator<(const Chunk &) const
virtual PoolHandler * createPoolHandler(const std::string &poolName)
Create a handler.
Location(const Location &l)
Definition: pooldriver.h:46
virtual void cancelWrite(const Location &loc)
Cancel a write.
virtual void toBeDeleted(const Pool &pool)
virtual ~PoolHandler()
Destructor.
virtual PoolDriver * createPoolDriver(void)
Instantiate the implemented pool driver.
Interface for a pool driver.
Definition: pooldriver.h:92
Low-level access API.
Location()
Definition: pooldriver.h:43
std::string toString(void) const
virtual void update(const Pool &pool)
Called when updating a pool.
virtual uint64_t getTotalSpace(void)
Get the total space of this pool.