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