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  /// Some implementations need to pass two urls per chunk, e.g. one for PUT and one for POST
34  std::string url_alt;
35 
36 
37  /// Some implementations need to pass an ID for a chunk
38  std::string chunkid;
39 
40  bool operator == (const Chunk&) const;
41  bool operator != (const Chunk&) const;
42  bool operator < (const Chunk&) const;
43  bool operator > (const Chunk&) const;
44 
45  std::string toString(void) const;
46  };
47 
48  /// Represent the complete location of a file.
49  struct Location: public std::vector<Chunk> {
50  Location() {}
51  Location(int nitems, const Chunk& proto): std::vector<Chunk>(nitems, proto) {}
52 
53  Location(const Location& l): std::vector<Chunk>(l) {}
54 
55  // Location from serialized string
56  explicit Location(const std::string& str);
57 
58  std::string toString(void) const;
59  };
60 
61  /// Handler for a pool. Works similary to a file handler.
62  class PoolHandler {
63  public:
64  /// Destructor
65  virtual ~PoolHandler();
66 
67  /// Get the pool type of this pool.
68  virtual std::string getPoolType(void) ;
69 
70  /// Get the pool name of this pool.
71  virtual std::string getPoolName(void) ;
72 
73  /// Get the total space of this pool.
74  virtual uint64_t getTotalSpace(void) ;
75 
76  /// Get the free space of this pool.
77  virtual uint64_t getFreeSpace(void) ;
78 
79  /// Check if the pool is actually available.
80  virtual bool poolIsAvailable(bool write = true) ;
81 
82  /// Check if a replica is available.
83  virtual bool replicaIsAvailable(const Replica& replica) ;
84 
85  /// Get the actual location of the file replica. This is pool-specific.
86  virtual Location whereToRead(const Replica& replica) ;
87 
88  /// Remove a replica from the pool.
89  virtual void removeReplica(const Replica& replica) ;
90 
91  /// Get where to put a file.
92  virtual Location whereToWrite(const std::string& path) ;
93 
94  /// Cancel a write.
95  virtual void cancelWrite(const Location& loc) ;
96  };
97 
98  /// Interface for a pool driver
99  class PoolDriver: public virtual BaseInterface {
100  public:
101  /// Destructor
102  virtual ~PoolDriver();
103 
104  /// Create a handler.
105  virtual PoolHandler* createPoolHandler(const std::string& poolName) ;
106 
107  /// Called just before adding the pool to the database.
108  /// To be used by a plugin, in case it needs to do some previous preparations.
109  /// (i.e. legacy filesystem will actually create the pool here)
110  virtual void toBeCreated(const Pool& pool) ;
111 
112  /// Called just after a pool is added to the database.
113  virtual void justCreated(const Pool& pool) ;
114 
115  /// Called when updating a pool.
116  virtual void update(const Pool& pool) ;
117 
118  /// Called just before a pool of this type is removed.
119  /// @note The driver may remove the pool itself (i.e. filesystem)
120  virtual void toBeDeleted(const Pool& pool) ;
121  };
122 
123  /// PoolDriver factory
124  class PoolDriverFactory: public virtual BaseFactory {
125  public:
126  /// Destructor.
127  virtual ~PoolDriverFactory();
128 
129  /// Supported pool type
130  virtual std::string implementedPool() throw ();
131 
132  protected:
133  friend class StackInstance;
134 
135  /// Instantiate the implemented pool driver.
136  virtual PoolDriver* createPoolDriver(void) ;
137  };
138 
139 };
140 
141 #endif // DMLITE_CPP_POOLDRIVER_H
virtual std::string getPoolName(void)
Get the pool name of this pool.
bool operator!=(const Chunk &) const
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:62
std::string toString(void) const
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:49
Location(int nitems, const Chunk &proto)
Definition: pooldriver.h:51
File replica metadata.
Definition: inode.h:70
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.
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.
std::string url_alt
Some implementations need to pass two urls per chunk, e.g. one for PUT and one for POST...
Definition: pooldriver.h:34
Represents a chunk of a file.
Definition: pooldriver.h:23
Base class for factories.
Definition: base.h:48
PoolDriver factory.
Definition: pooldriver.h:124
bool operator<(const Chunk &) const
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
bool operator==(const Chunk &) const
virtual PoolHandler * createPoolHandler(const std::string &poolName)
Create a handler.
Location(const Location &l)
Definition: pooldriver.h:53
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:99
Namespace for the dmlite C++ API.
Definition: authn.h:15
std::string toString(void) const
Low-level access API.
Location()
Definition: pooldriver.h:50
std::string chunkid
Some implementations need to pass an ID for a chunk.
Definition: pooldriver.h:38
virtual void update(const Pool &pool)
Called when updating a pool.
virtual uint64_t getTotalSpace(void)
Get the total space of this pool.