A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PDBClient.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 #ifndef PDBCLIENT_H
19 #define PDBCLIENT_H
20 
21 #include "CatalogClient.h"
22 #include "DispatcherClient.h"
24 #include "QueryClient.h"
25 #include "ServerFunctionality.h"
26 
27 #include "Handle.h"
28 #include "PDBObject.h"
29 #include "PDBVector.h"
30 #include "PartitionPolicy.h"
31 #include "PartitionComp.h"
32 #include "Partitioner.h"
33 #include "SimpleRequest.h"
34 
46 namespace pdb {
47 
48  class PDBClient : public ServerFunctionality {
49 
50  public:
51  /* Creates PDBClient
52  *
53  * portIn: the port number of the PDB manager server
54  * addressIn: the IP address of the PDB manager server
55  * myLoggerIn: the logger
56  *
57  */
58 
59  PDBClient(int portIn, std::string addressIn);
60 
61  PDBClient();
62 
63  ~PDBClient();
64 
65  void registerHandlers(PDBServer &forMe); // no - op
66 
67  /* Returns the error message generated by a function call.*/
68  string getErrorMessage();
69 
70  /****
71  * Methods for invoking DistributedStorageManager-related operations
72  */
73 
74  /* Creates a database */
75  bool createDatabase(const std::string &databaseName);
76 
77  /* Creates a set with a given type for an existing database, no page_size
78  * needed in arg. */
79  bool createSet(const std::string &databaseName, const std::string &setName,
80  const std::string &typeName);
81 
82  /* Creates a set with a given type (using a template) for an existing
83  * database, no page_size needed in arg. */
84  template <class DataType>
85  bool createSet(const std::string &databaseName, const std::string &setName);
86 
87  /* Creates a set with a given type for an existing database */
88  bool createSet(const std::string &databaseName, const std::string &setName,
89  const std::string &typeName,
90  size_t pageSize = DEFAULT_PAGE_SIZE);
91 
92  /* Creates a set with a given type (using a template) for an existing
93  * database with page_size value. */
94  template <class DataType>
95  bool createSet(const std::string &databaseName,
96  const std::string &setName, size_t pageSize);
97 
98  /* Creates a temporary set with a given type for an existing database (only
99  * goes through storage) */
100  bool createTempSet(const std::string &databaseName,
101  const std::string &setName, const std::string &typeName,
102  size_t pageSize = DEFAULT_PAGE_SIZE);
103 
104 
105 
106  /* Partitions data in a created set using a partitioner */
107  /* @param inputSet: identifier to input set
108  @param outputSet: identifier to output set
109  @param PartitionComp: partition comp used to partition the input set, and resulting in the output set
110  @return: success or not
111  */
112  template <class KeyClass, class ValueClass>
113  bool partitionSet(std::pair<std::string, std::string> inputSet,
114  std::pair<std::string, std::string> outputSet,
116 
117 
118  /* Partitions and transform data stored in a created set using a partitioner */
119  /* @param inputSet: identifier to input set
120  @param outputSet: identifier to output set
121  @param PartitionComp: partition comp used to partition the input set, and resulting in the output set
122  @return: success or not
123  */
124  template <class KeyClass, class ValueClass>
125  bool partitionAndTransformSet(std::pair<std::string, std::string> inputSet,
126  std::pair<std::string, std::string> outputSet,
128 
129 
130  /* Flushes data currently in memory into disk. */
131  bool flushData();
132 
133  /* Removes a database from storage. */
134  bool removeDatabase(const std::string &databaseName);
135 
136  /* Removes a set for an existing database from storage. */
137  bool removeSet(const std::string &databaseName, const std::string &setName);
138 
139  /* Removes a set given a type from an existing database. */
140  bool clearSet(const std::string &databaseName, const std::string &setName,
141  const std::string &typeName);
142 
143  /* Removes a temporary set given a type from an existing database (only goes
144  * through storage). */
145  bool removeTempSet(const std::string &databaseName,
146  const std::string &setName, const std::string &typeName);
147 
148  /* Exports the content of a set from a database into a file. Note that the
149  * objects in
150  * set must be instances of ExportableObject
151  */
152  bool exportSet(const std::string &databaseName, const std::string &setName,
153  const std::string &outputFilePath, const std::string &format);
154 
155  /****
156  * Methods for invoking Catalog-related operations
157  */
158 
159  /* Sends a request to the Catalog Server to register a user-defined type
160  * defined
161  * in a shared library. */
162  bool registerType(std::string fileContainingSharedLib);
163 
164  /* Sends a request to the Catalog Server to register metadata about a node in
165  * the cluster */
166  bool registerNode(string &localIP, int localPort, string &nodeName,
167  string &nodeType, int nodeStatus);
168 
169  /* Prints the content of the catalog. */
170  void
172 
173  /* Lists all metadata registered in the catalog. */
175 
176  /* Lists the Databases registered in the catalog. */
178 
179  /* Lists the Sets for a given database registered in the catalog. */
180  void listRegisteredSetsForADatabase(std::string databaseName);
181 
182  /* Lists the Nodes registered in the catalog. */
183  void listNodesInCluster();
184 
185  /* Lists user-defined types registered in the catalog. */
186  void listUserDefinedTypes();
187 
188  /****
189  * Methods for invoking Dispatcher-related operations
190  *
191  * @param setAndDatabase
192  * @return
193  */
194  bool registerSet(std::pair<std::string, std::string> setAndDatabase,
195  PartitionPolicy::Policy policy);
196 
202  template <class DataType>
203  bool sendData(std::pair<std::string, std::string> setAndDatabase,
204  Handle<Vector<Handle<DataType>>> dataToSend);
205 
206  template <class DataType>
207  bool sendBytes(std::pair<std::string, std::string> setAndDatabase,
208  char *bytes, size_t numBytes);
209 
210  /****
211  * Methods for invoking Query-related operations
212  */
213 
214  /* Executes some computations */
215  template <class... Types>
217  Handle<Types>... args);
218 
219  /* Deletes a set. */
220  bool deleteSet(std::string databaseName, std::string setName);
221 
222  /* Gets a set iterator. */
223  template <class Type>
224  SetIterator<Type> getSetIterator(std::string databaseName,
225  std::string setName);
226 
227  private:
228  std::shared_ptr<pdb::CatalogClient> catalogClient;
229  std::shared_ptr<pdb::DispatcherClient> dispatcherClient;
230  std::shared_ptr<pdb::DistributedStorageManagerClient> distributedStorageClient;
231  std::shared_ptr<pdb::QueryClient> queryClient;
232 
233  std::function<bool(Handle<SimpleRequestResult>)>
234  generateResponseHandler(std::string description, std::string &errMsg);
235 
236  // Port of the PlinyCompute manager node
237  int port;
238 
239  // IP address of the PlinyCompute manager node
240  std::string address;
241 
242  // Error Message (if an error occurred)
243  std::string errorMsg;
244 
245  // Message returned by a PlinyCompute function
246  std::string returnedMsg;
247 
248  // Client logger
250  };
251 }
252 
253 #include "PDBClientTemplate.cc"
255 #include "StorageClientTemplate.cc"
256 
257 #endif
bool sendData(std::pair< std::string, std::string > setAndDatabase, Handle< Vector< Handle< DataType >>> dataToSend)
void listRegisteredDatabases()
Definition: PDBClient.cc:280
bool sendBytes(std::pair< std::string, std::string > setAndDatabase, char *bytes, size_t numBytes)
bool removeTempSet(const std::string &databaseName, const std::string &setName, const std::string &typeName)
Definition: PDBClient.cc:157
bool createDatabase(const std::string &databaseName)
Definition: PDBClient.cc:70
std::function< bool(Handle< SimpleRequestResult >)> generateResponseHandler(std::string description, std::string &errMsg)
Definition: PDBClient.cc:214
PDBLoggerPtr logger
Definition: PDBClient.h:249
std::string address
Definition: PDBClient.h:240
void listUserDefinedTypes()
Definition: PDBClient.cc:292
std::shared_ptr< pdb::DistributedStorageManagerClient > distributedStorageClient
Definition: PDBClient.h:230
bool registerSet(std::pair< std::string, std::string > setAndDatabase, PartitionPolicy::Policy policy)
Definition: PDBClient.cc:300
string getErrorMessage()
Definition: PDBClient.cc:63
bool removeDatabase(const std::string &databaseName)
Definition: PDBClient.cc:133
void listRegisteredSetsForADatabase(std::string databaseName)
Definition: PDBClient.cc:284
std::shared_ptr< pdb::DispatcherClient > dispatcherClient
Definition: PDBClient.h:229
bool deleteSet(std::string databaseName, std::string setName)
Definition: PDBClient.cc:316
std::string errorMsg
Definition: PDBClient.h:243
std::string returnedMsg
Definition: PDBClient.h:246
bool clearSet(const std::string &databaseName, const std::string &setName, const std::string &typeName)
Definition: PDBClient.cc:187
SetIterator< Type > getSetIterator(std::string databaseName, std::string setName)
bool exportSet(const std::string &databaseName, const std::string &setName, const std::string &outputFilePath, const std::string &format)
Definition: PDBClient.cc:171
std::shared_ptr< pdb::CatalogClient > catalogClient
Definition: PDBClient.h:228
bool removeSet(const std::string &databaseName, const std::string &setName)
Definition: PDBClient.cc:145
void listAllRegisteredMetadata()
Definition: PDBClient.cc:276
bool partitionAndTransformSet(std::pair< std::string, std::string > inputSet, std::pair< std::string, std::string > outputSet, Handle< PartitionTransformationComp< KeyClass, ValueClass >> partitionComp)
void listNodesInCluster()
Definition: PDBClient.cc:288
void printCatalogMetadata(pdb::Handle< pdb::CatalogPrintMetadata > itemToSearch)
Definition: PDBClient.cc:269
bool createSet(const std::string &databaseName, const std::string &setName, const std::string &typeName)
Definition: PDBClient.cc:82
std::shared_ptr< pdb::QueryClient > queryClient
Definition: PDBClient.h:231
bool executeComputations(Handle< Computation > firstParam, Handle< Types >...args)
bool flushData()
Definition: PDBClient.cc:201
bool registerType(std::string fileContainingSharedLib)
Definition: PDBClient.cc:256
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
#define DEFAULT_PAGE_SIZE
Definition: Configuration.h:36
bool registerNode(string &localIP, int localPort, string &nodeName, string &nodeType, int nodeStatus)
Definition: PDBClient.cc:235
void registerHandlers(PDBServer &forMe)
Definition: PDBClient.cc:61
bool createTempSet(const std::string &databaseName, const std::string &setName, const std::string &typeName, size_t pageSize=DEFAULT_PAGE_SIZE)
Definition: PDBClient.cc:116
bool partitionSet(std::pair< std::string, std::string > inputSet, std::pair< std::string, std::string > outputSet, Handle< PartitionComp< KeyClass, ValueClass >> partitionComp)