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
StorageClient.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 STORAGE_CLIENT_CC
20 #define STORAGE_CLIENT_CC
21 
22 #include "StorageClient.h"
23 #include "StorageAddDatabase.h"
24 #include "StorageCleanup.h"
25 namespace pdb {
26 
28  std::string addressIn,
29  PDBLoggerPtr myLoggerIn,
30  bool usePangeaIn)
31  : myHelper(portIn, addressIn, myLoggerIn) {
32 
33  // get the communication information
34  port = portIn;
35  address = addressIn;
36  myLogger = myLoggerIn;
37  usePangea = usePangeaIn;
38 }
39 
40 void StorageClient::registerHandlers(PDBServer& forMe) { /* no handlers for a storage client!! */
41 }
42 
43 bool StorageClient::registerType(std::string regMe, std::string& errMsg) {
44  return myHelper.registerType(regMe, errMsg);
45 }
46 
47 bool StorageClient::shutDownServer(std::string& errMsg) {
48 
49  return myHelper.shutDownServer(errMsg);
50 }
51 
52 bool StorageClient::flushData(std::string& errMsg) {
53  return simpleRequest<StorageCleanup, SimpleRequestResult, bool>(
54  myLogger, port, address, false, 1024, [&](Handle<SimpleRequestResult> result) {
55  if (result != nullptr) {
56  if (!result->getRes().first) {
57  errMsg = "Error cleanup buffered records in storage server: " +
58  result->getRes().second;
59  myLogger->error("Error cleanup buffered records in storage server: " +
60  result->getRes().second);
61  return false;
62  }
63  return true;
64  }
65  errMsg = "Error cleanup buffered records in storage server";
66  return false;
67  });
68 }
69 
70 
71 bool StorageClient::createDatabase(std::string databaseName, std::string& errMsg) {
72  if (usePangea == false) {
73  return myHelper.createDatabase(databaseName, errMsg);
74  } else {
75  return simpleRequest<StorageAddDatabase, SimpleRequestResult, bool>(
76  myLogger,
77  port,
78  address,
79  false,
80  1024,
81  [&](Handle<SimpleRequestResult> result) {
82  if (result != nullptr) {
83  if (!result->getRes().first) {
84  errMsg = "Error creating database: " + result->getRes().second;
85  myLogger->error("Error creating database: " + result->getRes().second);
86  return false;
87  }
88  return true;
89  }
90  errMsg = "Error getting type name, nothing is back from storage";
91  return false;
92  },
93  databaseName);
94  }
95 }
96 
98  std::string databaseName,
99  std::string setName,
100  std::string typeName,
101  std::string& errMsg) {
102  return simpleSendDataRequest<StorageAddData, Handle<Object>, SimpleRequestResult, bool>(
103  myLogger,
104  port,
105  address,
106  false,
107  1024,
108  [&](Handle<SimpleRequestResult> result) {
109  if (result != nullptr)
110  if (!result->getRes().first) {
111  myLogger->error("Error sending data: " + result->getRes().second);
112  errMsg = "Error sending data: " + result->getRes().second;
113  }
114  return true;
115  },
116  data,
117  databaseName,
118  setName,
119  typeName,
120  true);
121 }
122 
123 
124 std::string StorageClient::getObjectType(std::string databaseName,
125  std::string setName,
126  std::string& errMsg) {
127  return myHelper.getObjectType(databaseName, setName, errMsg);
128 }
129 }
130 #endif
virtual void registerHandlers(PDBServer &forMe) override
PDBLoggerPtr myLogger
bool registerType(std::string fileContainingSharedLib, std::string &errMsg)
StorageClient(int port, std::string address, PDBLoggerPtr myLogger, bool usePangea=false)
std::string address
CatalogClient myHelper
std::string getObjectType(std::string databaseName, std::string setName, std::string &errMsg)
std::string getObjectType(std::string databaseName, std::string setName, std::string &errMsg)
bool shutDownServer(std::string &errMsg)
bool shutDownServer(std::string &errMsg)
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
bool createDatabase(std::string databaseName, std::string &errMsg)
bool flushData(std::string &errMsg)
bool storeData(Handle< Vector< Handle< DataType >>> data, std::string databaseName, std::string setName, std::string &errMsg, bool typeCheck=true)
bool createDatabase(std::string databaseName, std::string &errMsg)
bool registerType(std::string fileContainingSharedLib, std::string &errMsg)