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
CatalogNodeMetadata.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 /*
19  * CatalogNodeMetadata.h
20  *
21  */
22 
23 #ifndef CATALOG_NODE_METADATA_H_
24 #define CATALOG_NODE_METADATA_H_
25 
26 #include <iostream>
27 #include "Object.h"
28 #include "PDBString.h"
29 #include "PDBVector.h"
30 
31 // PRELOAD %CatalogNodeMetadata%
32 
33 using namespace std;
34 
35 namespace pdb {
36 
37 // This class serves to store information about a node in a cluster of PDB.
38 // It also provides methods for maintaining their associated metadata.
39 // Clients of this class will access this information using a handler to the catalog.
40 
41 class CatalogNodeMetadata : public Object {
42 public:
44 
46  pdb::String nodeIPValue,
47  int nodePortValue,
48  pdb::String nodeNameValue,
49  pdb::String nodeTypeValue,
50  int nodeStatusValue)
51  : nodeId(nodeIdValue),
52  nodeIP(nodeIPValue),
53  nodePort(nodePortValue),
54  nodeName(nodeNameValue),
55  nodeType(nodeTypeValue),
56  nodeStatus(nodeStatusValue) {
57  nodeAddress = std::string(nodeIP) + std::string(":") + std::to_string(nodePort);
58  }
59 
60  // Copy constructor
61  CatalogNodeMetadata(const CatalogNodeMetadata& pdbNodeToCopy) {
62  nodeId = pdbNodeToCopy.nodeId;
63  nodeIP = pdbNodeToCopy.nodeIP;
64  nodePort = pdbNodeToCopy.nodePort;
65  nodeName = pdbNodeToCopy.nodeName;
66  nodeType = pdbNodeToCopy.nodeType;
67  nodeStatus = pdbNodeToCopy.nodeStatus;
68  nodeAddress = std::string(nodeIP) + std::string(":") + std::to_string(nodePort);
69  }
70 
71  // Copy constructor
73  nodeId = pdbNodeToCopy->getItemId();
74  nodeIP = pdbNodeToCopy->getNodeIP();
75  nodePort = pdbNodeToCopy->getNodePort();
76  nodeName = pdbNodeToCopy->getItemName();
77  nodeType = pdbNodeToCopy->getNodeType();
78  nodeStatus = pdbNodeToCopy->getNodeStatus();
79  nodeAddress = std::string(nodeIP) + std::string(":") + std::to_string(nodePort);
80  }
81 
83 
84  void setValues(pdb::String nodeIdValue,
85  pdb::String nodeIPValue,
86  int nodePortValue,
87  pdb::String nodeNameValue,
88  pdb::String nodeTypeValue,
89  int nodeStatusValue) {
90  nodeId = nodeIdValue;
91  nodeIP = nodeIPValue;
92  nodePort = nodePortValue;
93  nodeName = nodeNameValue;
94  nodeType = nodeTypeValue;
95  nodeStatus = nodeStatusValue;
96  nodeAddress = std::string(nodeIP) + std::string(":") + std::to_string(nodePort);
97  }
98 
100  return nodeAddress;
101  }
102 
104  return nodeIP;
105  }
106 
108  return nodeId;
109  }
110 
112  return nodeName;
113  }
114 
116  return nodeType;
117  }
118 
119  int getNodePort() {
120  return nodePort;
121  }
122 
124  return nodeStatus;
125  }
126 
127  void setItemKey(pdb::String& itemKeyIn) {
128  nodeAddress = itemKeyIn;
129  }
130 
131  void setItemId(pdb::String& itemIdIn) {
132  nodeId = itemIdIn;
133  }
134 
135 
136  void setItemIP(pdb::String& itemIPIn) {
137  nodeIP = itemIPIn;
138  }
139 
140  void setItemName(pdb::String& itemNameIn) {
141  nodeName = itemNameIn;
142  }
143 
144  void setNodePort(int& portIn) {
145  nodePort = portIn;
146  }
147 
148  string printShort() {
149  string output;
150  output = " Node address: ";
151  output.append(getItemKey().c_str())
152  .append(" | ")
153  .append(getItemName().c_str())
154  .append(" | ")
155  .append(getNodeType().c_str());
156  return output;
157  }
158 
159 
160  friend std::ostream& operator<<(std::ostream& out, CatalogNodeMetadata& node) {
161  out << "\nCluster Node Metadata" << endl;
162  out << "-------------------" << endl;
163  out << " Node Id: " << node.getItemId().c_str() << endl;
164  out << " Node IP: " << node.getNodeIP().c_str() << endl;
165  out << " Node Port: " << node.getNodePort() << endl;
166  out << " Node Name: " << node.getItemName().c_str() << endl;
167  out << " Node Type: " << node.getNodeType().c_str() << endl;
168  out << "-------------------\n" << endl;
169  return out;
170  }
171 
173 
174 private:
177  int nodePort;
182 };
183 
184 } /* namespace pdb */
185 
186 #endif /* CATALOG_NODE_METADATA_H_ */
#define ENABLE_DEEP_COPY
Definition: DeepCopy.h:52
void setItemId(pdb::String &itemIdIn)
void setValues(pdb::String nodeIdValue, pdb::String nodeIPValue, int nodePortValue, pdb::String nodeNameValue, pdb::String nodeTypeValue, int nodeStatusValue)
void setItemName(pdb::String &itemNameIn)
void setItemIP(pdb::String &itemIPIn)
CatalogNodeMetadata(const CatalogNodeMetadata &pdbNodeToCopy)
friend std::ostream & operator<<(std::ostream &out, CatalogNodeMetadata &node)
void setItemKey(pdb::String &itemKeyIn)
CatalogNodeMetadata(const Handle< CatalogNodeMetadata > &pdbNodeToCopy)
CatalogNodeMetadata(pdb::String nodeIdValue, pdb::String nodeIPValue, int nodePortValue, pdb::String nodeNameValue, pdb::String nodeTypeValue, int nodeStatusValue)
char * c_str() const
Definition: PDBString.cc:184