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
DistributedStorageManagerClient.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 #ifndef OBJECTQUERYMODEL_DISTRIBUTEDSTORAGEMANAGERCLIENT_CC
19 #define OBJECTQUERYMODEL_DISTRIBUTEDSTORAGEMANAGERCLIENT_CC
20 
22 
23 #include "SimpleRequest.h"
33 
34 namespace pdb {
35 
37 
39  std::string addressIn,
40  PDBLoggerPtr myLoggerIn)
41  : port(portIn), address(addressIn), logger(myLoggerIn) {
42  // no-op
43 }
44 
46  // no-op
47 }
48 
50  // no-op
51 }
52 
53 bool DistributedStorageManagerClient::createDatabase(const std::string& databaseName,
54  std::string& errMsg) {
55  return simpleRequest<DistributedStorageAddDatabase, SimpleRequestResult, bool>(
56  logger,
57  port,
58  address,
59  false,
60  1024,
61  generateResponseHandler("Could not add database to distributed storage manager", errMsg),
62  databaseName);
63 }
64 
65 bool DistributedStorageManagerClient::createSet(const std::string& databaseName,
66  const std::string& setName,
67  const std::string& typeName,
68  std::string& errMsg,
69  size_t pageSize) {
70  return simpleRequest<DistributedStorageAddSet, SimpleRequestResult, bool>(
71  logger,
72  port,
73  address,
74  false,
75  1024,
76  generateResponseHandler("Could not add set to distributed storage manager:", errMsg),
77  databaseName,
78  setName,
79  typeName,
80  pageSize);
81 }
82 
83 bool DistributedStorageManagerClient::createTempSet(const std::string& databaseName,
84  const std::string& setName,
85  const std::string& typeName,
86  std::string& errMsg,
87  size_t pageSize) {
88  return simpleRequest<DistributedStorageAddTempSet, SimpleRequestResult, bool>(
89  logger,
90  port,
91  address,
92  false,
93  1024,
94 
95  generateResponseHandler("Could not add temp set to distributed storage manager:", errMsg),
96  databaseName,
97  setName,
98  typeName,
99  pageSize);
100 }
101 
102 bool DistributedStorageManagerClient::removeDatabase(const std::string& databaseName,
103  std::string& errMsg) {
104  return simpleRequest<DistributedStorageRemoveDatabase, SimpleRequestResult, bool>(
105  logger,
106  port,
107  address,
108  false,
109  1024,
110  generateResponseHandler("Could not remove database from distributed storage manager",
111  errMsg),
112  databaseName);
113 }
114 
115 bool DistributedStorageManagerClient::removeSet(const std::string& databaseName,
116  const std::string& setName,
117  std::string& errMsg) {
118  return simpleRequest<DistributedStorageRemoveSet, SimpleRequestResult, bool>(
119  logger,
120  port,
121  address,
122  false,
123  1024,
124  generateResponseHandler("Could not remove set to distributed storage manager", errMsg),
125  databaseName,
126  setName);
127 }
128 
129 bool DistributedStorageManagerClient::removeTempSet(const std::string& databaseName,
130  const std::string& setName,
131  const std::string& typeName,
132  std::string& errMsg) {
133  return simpleRequest<DistributedStorageRemoveTempSet, SimpleRequestResult, bool>(
134  logger,
135  port,
136  address,
137  false,
138  1024,
139  generateResponseHandler("Could not remove temp set to distributed storage manager", errMsg),
140  databaseName,
141  setName,
142  typeName);
143 }
144 
145 
146 bool DistributedStorageManagerClient::exportSet(const std::string& databaseName,
147  const std::string& setName,
148  const std::string& outputFilePath,
149  const std::string& format,
150  std::string& errMsg) {
151  return simpleRequest<DistributedStorageExportSet, SimpleRequestResult, bool>(
152  logger,
153  port,
154  address,
155  false,
156  1024,
157  generateResponseHandler("Could not export set", errMsg),
158  databaseName,
159  setName,
160  outputFilePath,
161  format);
162 }
163 
164 
165 bool DistributedStorageManagerClient::clearSet(const std::string& databaseName,
166  const std::string& setName,
167  const std::string& typeName,
168  std::string& errMsg) {
169  return simpleRequest<DistributedStorageClearSet, SimpleRequestResult, bool>(
170  logger,
171  port,
172  address,
173  false,
174  1024,
175  generateResponseHandler("Could not clear set to distributed storage manager", errMsg),
176  databaseName,
177  setName,
178  typeName);
179 }
180 
181 
183  return simpleRequest<DistributedStorageCleanup, SimpleRequestResult, bool>(
184  logger,
185  port,
186  address,
187  false,
188  1024,
189  generateResponseHandler("Could not cleanup buffered records in distributed storage servers",
190  errMsg));
191 }
192 
193 
194 std::function<bool(Handle<SimpleRequestResult>)>
196  std::string& errMsg) {
197  return [&](Handle<SimpleRequestResult> result) {
198  if (result != nullptr) {
199  if (!result->getRes().first) {
200  errMsg = description + result->getRes().second;
201  logger->error(description + ": " + result->getRes().second);
202  return false;
203  }
204  return true;
205  }
206  errMsg = "Received nullptr as response";
207  logger->error(description + ": received nullptr as response");
208  return false;
209  };
210 }
211 }
212 
213 #endif
std::function< bool(Handle< SimpleRequestResult >)> generateResponseHandler(std::string description, std::string &errMsg)
bool createSet(const std::string &databaseName, const std::string &setName, const std::string &typeName, std::string &errMsg, size_t pageSize=DEFAULT_PAGE_SIZE)
bool createTempSet(const std::string &databaseName, const std::string &setName, const std::string &typeName, std::string &errMsg, size_t pageSize=DEFAULT_PAGE_SIZE)
bool clearSet(const std::string &databaseName, const std::string &setName, const std::string &typeName, std::string &errMsg)
bool removeTempSet(const std::string &databaseName, const std::string &setName, const std::string &typeName, std::string &errMsg)
bool createDatabase(const std::string &databaseName, std::string &errMsg)
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
bool removeSet(const std::string &databaseName, const std::string &setName, std::string &errMsg)
bool exportSet(const std::string &databaseName, const std::string &setName, const std::string &outputFilePath, const std::string &format, std::string &errMsg)
bool removeDatabase(const std::string &databaseName, std::string &errMsg)