18 #ifndef RESOURCE_MANAGER_SERVER_CC
19 #define RESOURCE_MANAGER_SERVER_CC
32 #include <arpa/inet.h>
44 this->
nodes =
nullptr;
50 bool pseudoClusterMode,
51 std::string pemFile) {
71 int maxNodeNum = 1000;
73 this->
resources = makeObject<Vector<Handle<ResourceInfo>>>(maxNodeNum);
74 this->
nodes = makeObject<Vector<Handle<NodeDispatcherData>>>(maxNodeNum);
78 std::string command = std::string(
"scripts/internal/collect_proc.sh ") + this->
pemFile;
80 int ret = system(command.c_str());
82 std::cout <<
"Resource manager: failed to collect cluster information, try to use the "
92 std::string inputLine;
95 bool connectSuccess =
true;
97 std::ifstream nodeFile(serverlist);
98 if (nodeFile.is_open()) {
99 while (!nodeFile.eof()) {
100 std::getline(nodeFile, inputLine);
101 size_t pos = inputLine.find(
"#");
103 if (inputLine.length() != 0 && pos == string::npos) {
104 pos = inputLine.find(
":");
105 if (pos != string::npos) {
106 port = stoi(inputLine.substr(pos + 1, inputLine.size()));
107 address = inputLine.substr(0, pos);
114 struct addrinfo hints;
115 struct addrinfo *result, *rp;
117 sprintf(portValue,
"%d", 22);
119 memset(&hints, 0,
sizeof(
struct addrinfo));
120 hints.ai_family = AF_INET;
121 hints.ai_socktype = SOCK_STREAM;
123 hints.ai_protocol = 0;
125 int s = getaddrinfo(address.c_str(), portValue, &hints, &result);
129 for (rp = result; rp != NULL; rp = rp->ai_next) {
132 sfd = socket(result->ai_family, result->ai_socktype,
133 result->ai_protocol);
137 int co = ::connect(sfd, rp->ai_addr, rp->ai_addrlen);
139 connectSuccess =
true;
142 this->
nodes->push_back(node);
146 connectSuccess =
false;
152 if (connectSuccess ==
true) {
159 if (
nodes->size() == 0) {
160 PDB_COUT <<
"No workers in the cluster, stopping" << std::endl;
165 std::cout <<
"file can't be open" << std::endl;
177 std::ifstream resourceFile(resourceFileName);
178 if (resourceFile.is_open()) {
179 while (!resourceFile.eof()) {
181 std::getline(resourceFile, line);
182 if (line.find(
"CPUNumber") != string::npos) {
185 const std::regex r(
"[0-9]+");
187 std::sregex_iterator N(line.begin(), line.end(), r);
188 std::stringstream SS(*N->begin());
191 PDB_COUT <<
"numCores =" << numCores << std::endl;
194 if (line.find(
"MemTotal") != string::npos) {
197 const std::regex r(
"[0-9]+");
199 std::sregex_iterator N(line.begin(), line.end(), r);
200 std::stringstream SS(*N->begin());
202 PDB_COUT <<
"memSize =" << memSize << std::endl;
204 numCores, memSize, (*this->
nodes)[numServers]->getAddress(),
port, numServers);
205 PDB_COUT << numServers <<
": address=" << resource->getAddress()
206 <<
", numCores=" << resource->getNumCores()
207 <<
", memSize=" << resource->getMemSize() << std::endl;
213 resourceFile.close();
217 std::cout << resourceFileName <<
"can't be open." << std::endl;
ResourceManagerServer(std::string pathToServerList, int port, bool pseudoClusterMode=false, std::string pemFile="conf/pdb.key")
Handle< Vector< Handle< ResourceInfo > > > resources
void analyzeResources(std::string resourceFileName)
Handle< Vector< Handle< ResourceInfo > > > getAllResources()
void analyzeNodes(std::string serverList)
void makeObjectAllocatorBlock(size_t numBytesIn, bool throwExceptionOnFail)
void initialize(std::string pathToServerList)
void registerHandlers(PDBServer &forMe) override
Handle< Vector< Handle< NodeDispatcherData > > > nodes
Handle< Vector< Handle< NodeDispatcherData > > > getAllNodes()