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.cc
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 
19 #ifndef PDBCLIENT_CC
20 #define PDBCLIENT_CC
21 
22 #include "PDBClient.h"
23 
24 namespace pdb {
25 
27 
28  PDBClient::PDBClient(int portIn, std::string addressIn)
29  : port(portIn), address(addressIn) {
30 
31  logger = make_shared<PDBLogger>("clientLog");
32 
34  std::make_shared<pdb::CatalogClient>(
35  portIn,
36  addressIn,
37  make_shared<pdb::PDBLogger>("catalogClientLog"));
38 
40  std::make_shared<pdb::DispatcherClient>(
41  portIn,
42  addressIn,
43  make_shared<pdb::PDBLogger>("dispatcherClientLog"));
44 
46  std::make_shared<pdb::DistributedStorageManagerClient>(
47  portIn,
48  addressIn,
49  make_shared<pdb::PDBLogger>("distributedStorageClientLog"));
50 
51  queryClient =
52  std::make_shared<pdb::QueryClient>(
53  portIn,
54  addressIn,
55  make_shared<pdb::PDBLogger>("queryClientLog"),
56  true);
57  }
58 
60 
62 
64  return errorMsg;
65  }
66 
67  /****
68  * Methods for invoking DistributedStorageManager-related operations
69  */
70  bool PDBClient::createDatabase(const std::string &databaseName) {
71 
72  bool result = distributedStorageClient->createDatabase(databaseName, returnedMsg);
73  if (result==false) {
74  errorMsg = "Not able to create database: " + returnedMsg;
75  exit(-1);
76  } else {
77  cout << "Created database.\n";
78  }
79  return result;
80  }
81 
82  bool PDBClient::createSet(const std::string &databaseName,
83  const std::string &setName,
84  const std::string &typeName) {
85 
86 
87  bool result = distributedStorageClient->createSet(databaseName, setName, typeName,
89 
90  if (result==false) {
91  errorMsg = "Not able to create set: " + returnedMsg;
92  exit(-1);
93  } else {
94  cout << "Created set.\n";
95  }
96  return result;
97  }
98 
99  bool PDBClient::createSet(const std::string &databaseName,
100  const std::string &setName,
101  const std::string &typeName,
102  size_t pageSize) {
103 
104 
105  bool result = distributedStorageClient->createSet(databaseName, setName, typeName,
106  returnedMsg, pageSize);
107  if (result==false) {
108  errorMsg = "Not able to create set: " + returnedMsg;
109  exit(-1);
110  } else {
111  cout << "Created set.\n";
112  }
113  return result;
114  }
115 
116  bool PDBClient::createTempSet(const std::string &databaseName,
117  const std::string &setName,
118  const std::string &typeName,
119  size_t pageSize) {
120 
121 
122  bool result = distributedStorageClient->createTempSet(databaseName, setName, typeName,
123  returnedMsg, pageSize);
124  if (result==false) {
125  errorMsg = "Not able to create temp set: " + returnedMsg;
126  exit(-1);
127  } else {
128  cout << "Created temp set.\n";
129  }
130  return result;
131  }
132 
133  bool PDBClient::removeDatabase(const std::string &databaseName) {
134 
135 
136  bool result = distributedStorageClient->removeDatabase(databaseName, returnedMsg);
137  if (result==false) {
138  errorMsg = "Not able to remove database: " + returnedMsg;
139  } else {
140  cout << "Database has been removed.\n";
141  }
142  return result;
143  }
144 
145  bool PDBClient::removeSet(const std::string &databaseName,
146  const std::string &setName) {
147 
148  bool result = distributedStorageClient->removeSet(databaseName, setName, returnedMsg);
149  if (result==false) {
150  errorMsg = "Not able to remove set: " + returnedMsg;
151  } else {
152  cout << "Set has been removed.\n";
153  }
154  return result;
155  }
156 
157  bool PDBClient::removeTempSet(const std::string &databaseName,
158  const std::string &setName,
159  const std::string &typeName) {
160 
161  bool result = distributedStorageClient->removeTempSet(databaseName, setName, typeName,
162  returnedMsg);
163  if (result==false) {
164  errorMsg = "Not able to remove Temp set: " + returnedMsg;
165  } else {
166  cout << "Temp set removed.\n";
167  }
168  return result;
169  }
170 
171  bool PDBClient::exportSet(const std::string &databaseName,
172  const std::string &setName,
173  const std::string &outputFilePath,
174  const std::string &format) {
175 
176  bool result = distributedStorageClient->exportSet(databaseName, setName,
177  outputFilePath, format, returnedMsg);
178  if (result==false) {
179  errorMsg = "Not able to export set: " + returnedMsg;
180  exit(-1);
181  } else {
182  cout << "Set has been exported.\n";
183  }
184  return result;
185  }
186 
187  bool PDBClient::clearSet(const std::string &databaseName,
188  const std::string &setName,
189  const std::string &typeName) {
190 
191  bool result = distributedStorageClient->clearSet(databaseName, setName, typeName,
192  returnedMsg);
193  if (result==false) {
194  errorMsg = "Not able to clear set: " + returnedMsg;
195  } else {
196  cout << "Set has been cleared.\n";
197  }
198  return result;
199  }
200 
202 
203  bool result = distributedStorageClient->flushData(returnedMsg);
204  if (result==false) {
205  errorMsg = "Not able to flush data: " + returnedMsg;
206  exit(-1);
207  } else {
208  cout << "Data has been flushed.\n";
209  }
210  return result;
211  }
212 
213  std::function<bool(Handle<SimpleRequestResult>)>
214  PDBClient::generateResponseHandler(std::string description, std::string &returnedMsg) {
215 
216  return [&](Handle<SimpleRequestResult> result) {
217  if (result != nullptr) {
218  if (!result->getRes().first) {
219  errorMsg = description + result->getRes().second;
220  logger->error(description + ": " + result->getRes().second);
221  return false;
222  }
223  return true;
224  }
225  errorMsg = "Received nullptr as response";
226  logger->error(description + ": received nullptr as response");
227  return false;
228  };
229  }
230 
231  /****
232  * Methods for invoking Catalog-related operations
233  */
234 
235  bool PDBClient::registerNode(string &localIP, int localPort, string &nodeName,
236  string &nodeType, int nodeStatus) {
237 
238  makeObjectAllocatorBlock(1024 * 1024 * 1, true);
239 
241  pdb::makeObject<pdb::CatalogNodeMetadata>(
242  String(localIP + ":" + std::to_string(localPort)), String(localIP),
243  localPort, String(nodeName), String(nodeType), 1);
244 
245 
246  bool result = catalogClient->registerNodeMetadata(nodeInfo, returnedMsg);
247  if (result==false) {
248  errorMsg = "Not able to register node: " + returnedMsg;
249  exit(-1);
250  } else {
251  cout << "Node has been registered.\n";
252  }
253  return result;
254  }
255 
256  bool PDBClient::registerType(std::string fileContainingSharedLib) {
257 
258 
259  bool result = catalogClient->registerType(fileContainingSharedLib, returnedMsg);
260  if (result==false) {
261  errorMsg = "Not able to register type: " + returnedMsg;
262  exit(-1);
263  } else {
264  cout << "Type has been registered.\n";
265  }
266  return result;
267  }
268 
271  cout << catalogClient->printCatalogMetadata (
272  itemToSearch,
273  returnedMsg) ;
274  }
275 
277  cout << catalogClient->listAllRegisteredMetadata(returnedMsg);
278  }
279 
281  cout << catalogClient->listRegisteredDatabases(returnedMsg);
282  }
283 
284  void PDBClient::listRegisteredSetsForADatabase(std::string databaseName) {
285  cout << catalogClient->listRegisteredSetsForADatabase(databaseName, returnedMsg);
286  }
287 
289  cout << catalogClient->listNodesInCluster(returnedMsg);
290  }
291 
293  cout << catalogClient->listUserDefinedTypes(returnedMsg);
294  }
295 
296  /****
297  * Methods for invoking Dispatcher-related operations
298  */
299 
300  bool PDBClient::registerSet(std::pair<std::string, std::string> setAndDatabase,
301  PartitionPolicy::Policy policy) {
302 
303  bool result = dispatcherClient->registerSet(setAndDatabase, policy, returnedMsg);
304  if (result==false) {
305  errorMsg = "Not able to register set: " + returnedMsg;
306  exit(-1);
307  } else {
308  cout << "Set has been registered.\n";
309  }
310  return result;
311  }
312 
313  /****
314  * Methods for invoking Query-related operations
315  */
316  bool PDBClient::deleteSet(std::string databaseName, std::string setName) {
317 
318  bool result = queryClient->deleteSet(databaseName, setName);
319 
320  if (result==false) {
321  errorMsg = "Not able to delete set: ";
322  exit(-1);
323  } else {
324  cout << "Set has been deleted.\n";
325  }
326  return result;
327  }
328 }
329 
330 #endif
void listRegisteredDatabases()
Definition: PDBClient.cc:280
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
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
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
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 flushData()
Definition: PDBClient.cc:201
bool registerType(std::string fileContainingSharedLib)
Definition: PDBClient.cc:256
#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
void makeObjectAllocatorBlock(size_t numBytesIn, bool throwExceptionOnFail)