|
16 | 16 |
|
17 | 17 | @SuppressWarnings("unused") |
18 | 18 | public class PeerStatusJsonV2 { |
19 | | - private String peer_key; |
20 | | - //TODO remove after cf-engine in build > 1.1.309 |
21 | | - private String peer_old_key; |
22 | | - private String peer_host_port; |
23 | | - private String peer_ip; |
24 | | - private String user_dns_domain; |
25 | | - private Map<String, ProjectStatus> project_name_to_status = Maps.newHashMap();//Lists.newArrayList(); |
26 | | - private String host; |
27 | | - private String canonical_host; //TODO introduced in codeine 1202, can be used after cfengine is in that build |
28 | | - private int port; |
29 | | - private String version; |
30 | | - private String tar; |
31 | | - private long start_time; |
32 | | - private long update_time;//updated in directory server when first seen |
33 | | - private long update_time_from_peer; |
34 | | - private String install_dir; |
35 | | - private PeerType peer_type; |
36 | | - private transient PeerStatusString status; |
37 | | - |
38 | | - public PeerStatusJsonV2(String host, int port, String version, long start_time, String install_dir, String tar, Map<String, ProjectStatus> project_name_to_status, String peer_ip, String user_dns_domain, String canonical_host) { |
39 | | - super(); |
40 | | - this.host = host; |
41 | | - this.canonical_host = canonical_host; |
42 | | - this.port = port; |
43 | | - this.peer_ip = peer_ip; |
44 | | - this.version = version; |
45 | | - this.start_time = start_time; |
46 | | - this.install_dir = install_dir; |
47 | | - this.tar = tar; |
48 | | - this.project_name_to_status = Maps.newHashMap(project_name_to_status); |
49 | | - this.peer_old_key = host + ":" + install_dir; |
50 | | - this.peer_key = host + ":" + HttpUtils.specialEncode(install_dir); |
51 | | - this.peer_host_port = host + ":" + port; |
52 | | - this.user_dns_domain = user_dns_domain; |
53 | | - this.peer_type = PeerType.Daemon; |
54 | | - this.project_name_to_status.put(Constants.CODEINE_NODES_PROJECT_NAME, createInternalProject()); |
55 | | - this.update_time = System.currentTimeMillis(); |
56 | | - this.update_time_from_peer = System.currentTimeMillis(); |
57 | | - } |
58 | | - private ProjectStatus createInternalProject() { |
59 | | - NodeWithMonitorsInfo node_info = new NodeWithMonitorsInfo(this, this.peer_key, this.host, Constants.CODEINE_NODES_PROJECT_NAME, Maps.<String, MonitorStatusInfo>newHashMap()); |
60 | | - node_info.version(this.version); |
61 | | - node_info.tags(Lists.newArrayList(project_name_to_status.keySet())); |
62 | | - ProjectStatus ps = new ProjectStatus(Constants.CODEINE_NODES_PROJECT_NAME, node_info); |
63 | | - return ps; |
64 | | - } |
65 | | - public PeerStatusJsonV2(String peer_key, ProjectStatus projectStatus) { |
66 | | - super(); |
67 | | - this.project_name_to_status = Maps.newHashMap(); |
68 | | - this.project_name_to_status.put(projectStatus.project_name(), projectStatus); |
69 | | - this.update_time = System.currentTimeMillis(); |
70 | | - this.update_time_from_peer = System.currentTimeMillis(); |
71 | | - this.peer_key = peer_key; |
72 | | - this.peer_type = PeerType.Reporter; |
73 | | - } |
74 | | - |
75 | | - public void addProjectStatus(String name, ProjectStatus status) { |
76 | | - HashMap<String, ProjectStatus> tempList = Maps.newHashMap(project_name_to_status); |
77 | | - tempList.put(name, status); |
78 | | - project_name_to_status = tempList; |
79 | | - } |
80 | | - |
81 | | - public Map<String, ProjectStatus> project_name_to_status() { |
82 | | - return Collections.unmodifiableMap(project_name_to_status); |
83 | | - } |
84 | | - |
85 | | - public String peer_key() { |
86 | | - return peer_key; |
87 | | - } |
88 | | - |
89 | | - public String host_port() { |
90 | | - return host + ":" + port; |
91 | | - } |
92 | | - public String canonical_host_port() { |
93 | | - return canonical_host + ":" + port; |
94 | | - } |
95 | | - public String ip_port() { |
96 | | - return peer_ip + ":" + port; |
97 | | - } |
98 | | - |
99 | | - public String address_port() { |
100 | | - if (!StringUtils.isEmpty(user_dns_domain)) { |
101 | | - return host + "." + user_dns_domain + ":" + port; |
102 | | - } else if (!StringUtils.isEmpty(canonical_host)) { |
103 | | - return canonical_host_port(); |
104 | | - } else { |
105 | | - return host_port(); |
106 | | - } |
107 | | - } |
108 | | - |
109 | | - public long update_time() { |
110 | | - return update_time; |
111 | | - } |
112 | | - public long update_time_from_peer() { |
113 | | - return update_time_from_peer; |
114 | | - } |
115 | | - |
116 | | - public String key() { |
117 | | - return peer_key(); |
118 | | - } |
119 | | - |
120 | | - public String version() { |
121 | | - return version; |
122 | | - } |
123 | | - |
124 | | - public String host() { |
125 | | - return host; |
126 | | - } |
127 | | - |
128 | | - public String tar() { |
129 | | - return tar; |
130 | | - } |
131 | | - public void status(PeerStatusString status) { |
132 | | - this.status = status; |
133 | | - } |
134 | | - public PeerStatusString status() { |
135 | | - return status; |
136 | | - } |
137 | | - public void updateNodesWithPeer() { |
138 | | - for (ProjectStatus projectStatus : project_name_to_status.values()) { |
139 | | - projectStatus.updateNodesWithPeer(this); |
140 | | - } |
141 | | - } |
142 | | - public PeerType peer_type() { |
143 | | - return peer_type; |
144 | | - } |
145 | | - public String peer_old_key() { |
146 | | - return peer_old_key; |
147 | | - } |
148 | | - @Override |
149 | | - public String toString() { |
150 | | - return "PeerStatusJsonV2 [host_port()=" + host_port() + ", update_time()=" + new Date(update_time()) |
151 | | - + ", update_time_from_peer()=" + new Date(update_time_from_peer()) + ", peer_type()=" + peer_type() + "]"; |
152 | | - } |
153 | | - |
| 19 | + |
| 20 | + private String peer_key; |
| 21 | + private String peer_host_port; |
| 22 | + private String peer_ip; |
| 23 | + private String user_dns_domain; |
| 24 | + private Map<String, ProjectStatus> project_name_to_status; |
| 25 | + private String canonical_host; |
| 26 | + private int port; |
| 27 | + private String version; |
| 28 | + private String tar; |
| 29 | + private long start_time; |
| 30 | + private long update_time;//updated in directory server when first seen |
| 31 | + private long update_time_from_peer; |
| 32 | + private String install_dir; |
| 33 | + private PeerType peer_type; |
| 34 | + private transient PeerStatusString status; |
| 35 | + |
| 36 | + public PeerStatusJsonV2(int port, String version, long start_time, |
| 37 | + String install_dir, String tar, Map<String, ProjectStatus> project_name_to_status, |
| 38 | + String peer_ip, String user_dns_domain, String canonical_host) { |
| 39 | + super(); |
| 40 | + this.canonical_host = canonical_host; |
| 41 | + this.port = port; |
| 42 | + this.peer_ip = peer_ip; |
| 43 | + this.version = version; |
| 44 | + this.start_time = start_time; |
| 45 | + this.install_dir = install_dir; |
| 46 | + this.tar = tar; |
| 47 | + this.project_name_to_status = Maps.newHashMap(project_name_to_status); |
| 48 | + this.peer_key = canonical_host + ":" + HttpUtils.specialEncode(install_dir); |
| 49 | + this.peer_host_port = canonical_host + ":" + port; |
| 50 | + this.user_dns_domain = user_dns_domain; |
| 51 | + this.peer_type = PeerType.Daemon; |
| 52 | + this.project_name_to_status |
| 53 | + .put(Constants.CODEINE_NODES_PROJECT_NAME, createInternalProject()); |
| 54 | + this.update_time = System.currentTimeMillis(); |
| 55 | + this.update_time_from_peer = System.currentTimeMillis(); |
| 56 | + } |
| 57 | + |
| 58 | + private ProjectStatus createInternalProject() { |
| 59 | + NodeWithMonitorsInfo node_info = new NodeWithMonitorsInfo(this, this.peer_key, this.canonical_host, |
| 60 | + Constants.CODEINE_NODES_PROJECT_NAME, Maps.<String, MonitorStatusInfo>newHashMap()); |
| 61 | + node_info.version(this.version); |
| 62 | + node_info.tags(Lists.newArrayList(project_name_to_status.keySet())); |
| 63 | + ProjectStatus ps = new ProjectStatus(Constants.CODEINE_NODES_PROJECT_NAME, node_info); |
| 64 | + return ps; |
| 65 | + } |
| 66 | + |
| 67 | + public PeerStatusJsonV2(String peer_key, ProjectStatus projectStatus) { |
| 68 | + super(); |
| 69 | + this.project_name_to_status = Maps.newHashMap(); |
| 70 | + this.project_name_to_status.put(projectStatus.project_name(), projectStatus); |
| 71 | + this.update_time = System.currentTimeMillis(); |
| 72 | + this.update_time_from_peer = System.currentTimeMillis(); |
| 73 | + this.peer_key = peer_key; |
| 74 | + this.peer_type = PeerType.Reporter; |
| 75 | + } |
| 76 | + |
| 77 | + public void addProjectStatus(String name, ProjectStatus status) { |
| 78 | + HashMap<String, ProjectStatus> tempList = Maps.newHashMap(project_name_to_status); |
| 79 | + tempList.put(name, status); |
| 80 | + project_name_to_status = tempList; |
| 81 | + } |
| 82 | + |
| 83 | + public Map<String, ProjectStatus> project_name_to_status() { |
| 84 | + return Collections.unmodifiableMap(project_name_to_status); |
| 85 | + } |
| 86 | + |
| 87 | + public String peer_key() { |
| 88 | + return peer_key; |
| 89 | + } |
| 90 | + |
| 91 | + public String canonical_host_port() { |
| 92 | + return canonical_host + ":" + port; |
| 93 | + } |
| 94 | + |
| 95 | + public String ip_port() { |
| 96 | + return peer_ip + ":" + port; |
| 97 | + } |
| 98 | + |
| 99 | + public String address_port() { |
| 100 | + if (!StringUtils.isEmpty(user_dns_domain)) { |
| 101 | + return canonical_host + "." + user_dns_domain + ":" + port; |
| 102 | + } |
| 103 | + return canonical_host_port(); |
| 104 | + } |
| 105 | + |
| 106 | + public long update_time() { |
| 107 | + return update_time; |
| 108 | + } |
| 109 | + |
| 110 | + public long update_time_from_peer() { |
| 111 | + return update_time_from_peer; |
| 112 | + } |
| 113 | + |
| 114 | + public String key() { |
| 115 | + return peer_key(); |
| 116 | + } |
| 117 | + |
| 118 | + public String version() { |
| 119 | + return version; |
| 120 | + } |
| 121 | + |
| 122 | + public String tar() { |
| 123 | + return tar; |
| 124 | + } |
| 125 | + |
| 126 | + public void status(PeerStatusString status) { |
| 127 | + this.status = status; |
| 128 | + } |
| 129 | + |
| 130 | + public PeerStatusString status() { |
| 131 | + return status; |
| 132 | + } |
| 133 | + |
| 134 | + public void updateNodesWithPeer() { |
| 135 | + for (ProjectStatus projectStatus : project_name_to_status.values()) { |
| 136 | + projectStatus.updateNodesWithPeer(this); |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + public PeerType peer_type() { |
| 141 | + return peer_type; |
| 142 | + } |
| 143 | + |
| 144 | + public String canonical_host() { |
| 145 | + return canonical_host; |
| 146 | + } |
| 147 | + |
| 148 | + @Override |
| 149 | + public String toString() { |
| 150 | + return "PeerStatusJsonV2 [host_port()=" + canonical_host() + ", update_time()=" + new Date( |
| 151 | + update_time()) |
| 152 | + + ", update_time_from_peer()=" + new Date(update_time_from_peer()) + ", peer_type()=" |
| 153 | + + peer_type() + "]"; |
| 154 | + } |
| 155 | + |
154 | 156 | } |
0 commit comments