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
CatalogClient.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 CATALOG_CLIENT_H
19 #define CATALOG_CLIENT_H
20 
24 #include "CatalogNodeMetadata.h"
25 #include "CatalogPrintMetadata.h"
26 #include "CatalogSetMetadata.h"
27 #include "PDBLogger.h"
28 #include "PDBServer.h"
29 #include "ServerFunctionality.h"
30 
31 namespace pdb {
32 
34 
35 public:
36  /* Destructor */
38 
39  /* Default Constructor */
40  CatalogClient();
41 
42  /*
43  * Creates a Catalog Client given the port and address of the catalog
44  * for a local catalog the address is typically "localhost"
45  * for a remote catalog, the address is the IP address of the machine
46  * where the catalog resides
47  */
48  CatalogClient(int port, std::string address, PDBLoggerPtr myLogger);
49 
50  /*
51  * Creates a Catalog Client given the port and address of the catalog
52  * for a local catalog the address is typically "localhost"
53  * for a remote catalog, the address is the IP address of the machine
54  * where the catalog resides.
55  * If this catalog client points to a catalog in a remote machine, the
56  * pointsToCatalogManagerIn argument must be set to "true"
57  *
58  */
59  CatalogClient(int port, std::string address, PDBLoggerPtr myLogger,
60  bool pointsToCatalogManagerIn);
61 
62  /* Registers event handlers associated with this server functionality */
63  virtual void registerHandlers(PDBServer &forMe) override;
64 
65  /* Uses the name of the object type to find its corresponding typeId, returns
66  * -1
67  * if not found
68  */
69  int16_t searchForObjectTypeName(std::string objectTypeName);
70 
71  /* Retrieves the content of a Shared Library given it's Type Id */
72  bool getSharedLibrary(int16_t identifier, std::string sharedLibraryFileName);
73 
74  /* Retrieves the content of a Shared Library along with its registered
75  * metadata,
76  * given it's typeName. Typically this method is invoked by a remote machine
77  * that
78  * has no knowledge of the typeID
79  */
80  bool getSharedLibraryByTypeName(int16_t identifier, std::string &typeName,
81  std::string sharedLibraryFileName,
82  Handle<CatalogUserTypeMetadata> &typeMetadata,
83  string &sharedLibraryBytes,
84  std::string &errMsg);
85 
86  /* Sends a request to the Catalog Server to register a type with the catalog
87  * returns true on success, false on fail */
88  bool registerType(std::string fileContainingSharedLib, std::string &errMsg);
89 
90  /* Sends a request to the Catalog Server to shut down the server that we are
91  * connected to
92  * ... returns true on success */
93  bool shutDownServer(std::string &errMsg);
94 
95  /* Sends a request to the Catalog Server to return the typeName of a
96  * user-defined type in the
97  * specified database and set; returns "" on err */
98  std::string getObjectType(std::string databaseName, std::string setName,
99  std::string &errMsg);
100 
101  /* Sends a request to the Catalog Server to Create a new database
102  * returns true on success, false on fail
103  */
104  bool createDatabase(std::string databaseName, std::string &errMsg);
105 
106  /* Sends a request to the Catalog Server to register metadata about a database
107  */
108  bool registerDatabaseMetadata(std::string databaseName, std::string &errMsg);
109 
110  /* Sends a request to the Catalog Server to register metadata about a node in
111  * the cluster */
113  std::string &errMsg);
114 
115  /* Templated method for registering a piece of metadata in the catalog */
116  template <class Type>
117  bool registerGenericMetadata(pdb::Handle<Type> metadataItem,
118  std::string &errMsg);
119 
120  /* Templated method for removing a piece of metadata from the catalog */
121  template <class Type>
122  bool deleteGenericMetadata(pdb::Handle<Type> metadataItem,
123  std::string &errMsg);
124 
125  /* Sends a request to the Catalog Server to Creates a new set for a given
126  * DataType in a
127  * database;
128  * returns true on success, false on fail
129  */
130  template <class DataType>
131  bool createSet(std::string databaseName, std::string setName,
132  std::string &errMsg);
133 
134  /* same as above, but here we use the type code */
135  bool createSet(int16_t identifier, std::string databaseName,
136  std::string setName, std::string &errMsg);
137 
138  /* Sends a request to the Catalog Server to delete a database; returns true on
139  * success, false on
140  * fail
141  */
142  bool deleteDatabase(std::string databaseName, std::string &errMsg);
143 
144  /* Sends a request to the Catalog Server to delete a set returns true on
145  * success, false on fail
146  */
147  bool deleteSet(std::string databaseName, std::string setName,
148  std::string &errMsg);
149 
150  /* Sends a request to the Catalog Server to add information about a node to a
151  * set for a given
152  * database;
153  * returns true on success, false on fail
154  */
155  bool addNodeToSet(std::string nodeIP, std::string databaseName,
156  std::string setName, std::string &errMsg);
157 
158  /* Sends a request to the Catalog Server to add information about a node to a
159  * database;
160  * returns true on success, false on fail
161  */
162  bool addNodeToDB(std::string nodeIP, std::string databaseName,
163  std::string &errMsg);
164 
165  /* Sends a request to the Catalog Server to remove information about a node
166  * from a set, this is
167  * invoked when storage
168  * removes a set for a database in a node in the cluster; returns true on
169  * success, false on fail
170  */
171  bool removeNodeFromSet(std::string nodeIP, std::string databaseName,
172  std::string setName, std::string &errMsg);
173 
174  /* Sends a request to the Catalog Server to remove information about a node
175  * from a database,
176  * this is invoked when storage
177  * removes a database in a node in the cluster; returns true on success, false
178  * on fail
179  */
180  bool removeNodeFromDB(std::string nodeIP, std::string databaseName,
181  std::string &errMsg);
182 
183  /* Sends a request to the Catalog Server to print the content of the metadata
184  * stored in the
185  * catalog */
186  string
188  std::string &errMsg);
189 
190  /* Sends a request to the Catalog Server to print a category of metadata
191  * stored in the
192  * catalog */
193  string printCatalogMetadata(std::string &categoryToPrint,
194  std::string &errMsg);
195 
196  /* Returns true if this Catalog Client points to a remote
197  * Manager Catalog Server
198  */
200 
201  /* Sets to true if this Catalog Client points to the Manager Catalog Server */
202  void setPointsToManagerCatalog(bool pointsToManager);
203 
204  /* Sends a request to the Catalog Server to close the SQLite DB Handler */
205  bool closeCatalogSQLite(std::string &errMsg);
206 
207  /* Lists all metadata registered in the catalog. */
208  string listAllRegisteredMetadata(std::string &errMsg);
209 
210  /* Lists the Databases registered in the catalog. */
211  string listRegisteredDatabases(std::string &errMsg);
212 
213  /* Lists the Sets for a given database registered in the catalog. */
214  string listRegisteredSetsForADatabase(std::string databaseName,
215  std::string &errMsg);
216 
217  /* Lists the Nodes registered in the catalog. */
218  string listNodesInCluster(std::string &errMsg);
219 
220  /* Lists the user-defined types registered in the catalog. */
221  string listUserDefinedTypes(std::string &errMsg);
222 
223 
224 private:
225  /* True if this Catalog Client points to the Manager Catalog Server */
227 
228  /* The IP address where this Catalog Client is connected to */
229  std::string address;
230 
231  /* The port where this Catalog Client is connected to */
232  int port;
233 
234  /* Logger to debug information */
236 
237  /* To ensure serialized access */
238  pthread_mutex_t workingMutex;
239 };
240 }
241 
242 #include "CatalogClientTemplates.cc"
243 
244 #endif
bool registerType(std::string fileContainingSharedLib, std::string &errMsg)
string listNodesInCluster(std::string &errMsg)
string listRegisteredSetsForADatabase(std::string databaseName, std::string &errMsg)
string listAllRegisteredMetadata(std::string &errMsg)
bool registerDatabaseMetadata(std::string databaseName, std::string &errMsg)
void setPointsToManagerCatalog(bool pointsToManager)
bool deleteSet(std::string databaseName, std::string setName, std::string &errMsg)
virtual void registerHandlers(PDBServer &forMe) override
bool removeNodeFromSet(std::string nodeIP, std::string databaseName, std::string setName, std::string &errMsg)
bool deleteGenericMetadata(pdb::Handle< Type > metadataItem, std::string &errMsg)
std::string getObjectType(std::string databaseName, std::string setName, std::string &errMsg)
int16_t searchForObjectTypeName(std::string objectTypeName)
PDBLoggerPtr myLogger
bool addNodeToSet(std::string nodeIP, std::string databaseName, std::string setName, std::string &errMsg)
bool getSharedLibraryByTypeName(int16_t identifier, std::string &typeName, std::string sharedLibraryFileName, Handle< CatalogUserTypeMetadata > &typeMetadata, string &sharedLibraryBytes, std::string &errMsg)
bool shutDownServer(std::string &errMsg)
bool deleteDatabase(std::string databaseName, std::string &errMsg)
string listUserDefinedTypes(std::string &errMsg)
bool getPointsToManagerCatalog()
bool createSet(std::string databaseName, std::string setName, std::string &errMsg)
bool addNodeToDB(std::string nodeIP, std::string databaseName, std::string &errMsg)
pthread_mutex_t workingMutex
bool registerNodeMetadata(pdb::Handle< pdb::CatalogNodeMetadata > nodeData, std::string &errMsg)
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
bool closeCatalogSQLite(std::string &errMsg)
bool registerGenericMetadata(pdb::Handle< Type > metadataItem, std::string &errMsg)
std::string address
bool createDatabase(std::string databaseName, std::string &errMsg)
string listRegisteredDatabases(std::string &errMsg)
string printCatalogMetadata(pdb::Handle< pdb::CatalogPrintMetadata > itemToSearch, std::string &errMsg)
bool removeNodeFromDB(std::string nodeIP, std::string databaseName, std::string &errMsg)
bool getSharedLibrary(int16_t identifier, std::string sharedLibraryFileName)