-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCluster.h
68 lines (59 loc) · 1.95 KB
/
Cluster.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef CLUSTER_H
#define CLUSTER_H
#include "ThreadPool.h"
#include <utility>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <ctime>
#include <ifaddrs.h>
#include <netinet/in.h>
namespace pdfs {
const float CPU_RATIO = 1.0;
const float MEM_RATIO = 1.0;
const float DISK_RATIO = 1.0;
struct NodeStatus {
int starttime;
float overall;
float cpuUsage;
float memUsage;
float diskUsage;
};
typedef std::pair<std::string, pdfs::NodeStatus> clustermapType;
struct CmpClustermapByValue {
bool operator()(const clustermapType& lhs, const clustermapType& rhs) {
return lhs.second.overall < rhs.second.overall;
}
};
class Cluster {
public:
Cluster(){}
Cluster(const std::map<std::string, float> &clusterMap);
static NodeStatus &getLocalStatus(NodeStatus &status);
static void updateNodeStatus(std::string addr, const char *msg);
static std::vector<std::string> getTopKNode(unsigned short num = 3);
static std::vector<std::string> getMetaNode(std::string filename,
unsigned short num = 3);
static unsigned short isLocalIP(std::string ip);
static bool isNewNode(std::string node);
static void getLocalIPv4Addr(string localIPv4Addr);
static void getBroadcastIPAddr(string broadcastIPAddr);
static std::map<std::string, NodeStatus> &getNodeStatusMap();
static std::list<std::string> &getExpireNodes();
static void printClusterMap();
static long FNVHash1(std::string data);
static ssize_t checkExpireNode();
static size_t getClusterSize();
static void setClusterSize(size_t size);
private:
static std::map<std::string, NodeStatus> _nodeStatusMap;
static std::list<std::string> _expireNodes;
static size_t clusterSize;
};
class StringUtil {
public:
static std::string& trim(std::string &str);
};
} // end of namepsace pdfs
#endif