Skip to content

Commit 7294ea8

Browse files
FR80: Improvement on management server heartbeat (apache#499)
1 parent 005f289 commit 7294ea8

21 files changed

Lines changed: 732 additions & 36 deletions

api/src/main/java/com/cloud/server/ManagementServerHostStats.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public interface ManagementServerHostStats {
3232

3333
String getManagementServerHostUuid();
3434

35+
long getManagementServerRunId();
36+
3537
long getSessions();
3638

3739
double getCpuUtilization();

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ public class ApiConstants {
332332
public static final String SSHKEY_ENABLED = "sshkeyenabled";
333333
public static final String PATH = "path";
334334
public static final String PAYLOAD = "payload";
335+
public static final String PEERS = "peers";
336+
public static final String PEER_ID = "peerid";
337+
public static final String PEER_NAME = "peername";
338+
public static final String PEER_MSID = "peermsid";
339+
public static final String PEER_RUNID = "peerrunid";
340+
public static final String PEER_SERVICE_IP = "peerserviceip";
341+
public static final String PEER_SERVICE_PORT = "peerserviceport";
342+
public static final String PEER_STATE = "peerstate";
335343
public static final String POD_ID = "podid";
336344
public static final String POD_NAME = "podname";
337345
public static final String POD_IDS = "podids";

api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.cloudstack.api.Parameter;
2424
import org.apache.cloudstack.api.response.ListResponse;
2525
import org.apache.cloudstack.api.response.ManagementServerResponse;
26+
import org.apache.commons.lang3.BooleanUtils;
2627
import org.apache.log4j.Logger;
2728

2829
@APICommand(name = "listManagementServers", description = "Lists management servers.", responseObject = ManagementServerResponse.class,
@@ -41,6 +42,11 @@ public class ListMgmtsCmd extends BaseListCmd {
4142
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the management server")
4243
private String hostName;
4344

45+
@Parameter(name = ApiConstants.PEERS, type = CommandType.BOOLEAN,
46+
description = "Whether to return the management server peers or not. By default, the management server peers will not be returned.",
47+
since = "4.18.1.2")
48+
private Boolean peers;
49+
4450
/////////////////////////////////////////////////////
4551
/////////////////// Accessors ///////////////////////
4652
/////////////////////////////////////////////////////
@@ -53,6 +59,10 @@ public String getHostName() {
5359
return hostName;
5460
}
5561

62+
public Boolean getPeers() {
63+
return BooleanUtils.toBooleanDefaultIfNull(peers, false);
64+
}
65+
5666
/////////////////////////////////////////////////////
5767
/////////////// API Implementation///////////////////
5868
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/response/ManagementServerResponse.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import org.apache.cloudstack.api.EntityReference;
2525
import org.apache.cloudstack.management.ManagementServerHost.State;
2626

27+
import java.util.ArrayList;
2728
import java.util.Date;
29+
import java.util.List;
2830

2931
@EntityReference(value = ManagementServerHost.class)
3032
public class ManagementServerResponse extends BaseResponse {
@@ -76,6 +78,10 @@ public class ManagementServerResponse extends BaseResponse {
7678
@Param(description = "the IP Address for this Management Server")
7779
private String serviceIp;
7880

81+
@SerializedName(ApiConstants.PEERS)
82+
@Param(description = "the Management Server Peers")
83+
private List<PeerManagementServerNodeResponse> peers;
84+
7985
public String getId() {
8086
return this.id;
8187
}
@@ -167,4 +173,19 @@ public void setKernelVersion(String kernelVersion) {
167173
public void setServiceIp(String serviceIp) {
168174
this.serviceIp = serviceIp;
169175
}
176+
177+
public List<PeerManagementServerNodeResponse> getPeers() {
178+
return peers;
179+
}
180+
181+
public void setPeers(List<PeerManagementServerNodeResponse> peers) {
182+
this.peers = peers;
183+
}
184+
185+
public void addPeer(PeerManagementServerNodeResponse peer) {
186+
if (peers == null) {
187+
peers = new ArrayList<>();
188+
}
189+
peers.add(peer);
190+
}
170191
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. 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,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.response;
18+
19+
import com.cloud.serializer.Param;
20+
import com.google.gson.annotations.SerializedName;
21+
import org.apache.cloudstack.api.ApiConstants;
22+
import org.apache.cloudstack.api.BaseResponse;
23+
import org.apache.cloudstack.management.ManagementServerHost.State;
24+
25+
import java.util.Date;
26+
27+
public class PeerManagementServerNodeResponse extends BaseResponse {
28+
29+
@SerializedName(ApiConstants.STATE)
30+
@Param(description = "the state of the management server peer")
31+
private State state;
32+
33+
@SerializedName(ApiConstants.LAST_UPDATED)
34+
@Param(description = "the last updated time of the management server peer state")
35+
private Date lastUpdated;
36+
37+
@SerializedName(ApiConstants.PEER_ID)
38+
@Param(description = "the ID of the peer management server")
39+
private String peerId;
40+
41+
@SerializedName(ApiConstants.PEER_NAME)
42+
@Param(description = "the name of the peer management server")
43+
private String peerName;
44+
45+
@SerializedName(ApiConstants.PEER_MSID)
46+
@Param(description = "the management ID of the peer management server")
47+
private String peerMsId;
48+
49+
@SerializedName(ApiConstants.PEER_RUNID)
50+
@Param(description = "the run ID of the peer management server")
51+
private String peerRunId;
52+
53+
@SerializedName(ApiConstants.PEER_STATE)
54+
@Param(description = "the state of the peer management server")
55+
private String peerState;
56+
57+
@SerializedName(ApiConstants.PEER_SERVICE_IP)
58+
@Param(description = "the IP Address for the peer Management Server")
59+
private String peerServiceIp;
60+
61+
@SerializedName(ApiConstants.PEER_SERVICE_PORT)
62+
@Param(description = "the service port for the peer Management Server")
63+
private String peerServicePort;
64+
65+
public void setState(State state) {
66+
this.state = state;
67+
}
68+
69+
public void setLastUpdated(Date lastUpdated) {
70+
this.lastUpdated = lastUpdated;
71+
}
72+
73+
public void setPeerId(String peerId) {
74+
this.peerId = peerId;
75+
}
76+
77+
public void setPeerName(String peerName) {
78+
this.peerName = peerName;
79+
}
80+
81+
public void setPeerMsId(String peerMsId) {
82+
this.peerMsId = peerMsId;
83+
}
84+
85+
public void setPeerRunId(String peerRunId) {
86+
this.peerRunId = peerRunId;
87+
}
88+
89+
public void setPeerState(String peerState) {
90+
this.peerState = peerState;
91+
}
92+
93+
public void setPeerServiceIp(String peerServiceIp) {
94+
this.peerServiceIp = peerServiceIp;
95+
}
96+
97+
public void setPeerServicePort(String peerServicePort) {
98+
this.peerServicePort = peerServicePort;
99+
}
100+
}

engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<bean id="loadBalancerCertMapDaoImpl" class="com.cloud.network.dao.LoadBalancerCertMapDaoImpl" />
118118
<bean id="managementServerHostDaoImpl" class="com.cloud.cluster.dao.ManagementServerHostDaoImpl" />
119119
<bean id="managementServerHostPeerDaoImpl" class="com.cloud.cluster.dao.ManagementServerHostPeerDaoImpl" />
120+
<bean id="managementServerHostPeerJoinDaoImpl" class="com.cloud.cluster.dao.ManagementServerHostPeerJoinDaoImpl" />
120121
<bean id="managementServerStatusDaoImpl" class="com.cloud.cluster.dao.ManagementServerStatusDaoImpl" />
121122
<bean id="networkAccountDaoImpl" class="com.cloud.network.dao.NetworkAccountDaoImpl" />
122123
<bean id="networkACLDaoImpl" class="com.cloud.network.vpc.dao.NetworkACLDaoImpl" />

engine/schema/src/main/resources/META-INF/db/schema-41800to41810.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,31 @@ ALTER TABLE `cloud`.`vpc` MODIFY `display_text` VARCHAR(255) CHARACTER SET utf8m
588588
ALTER TABLE `cloud`.`vpc_offerings` MODIFY `name` VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT 'vpc offering name';
589589
ALTER TABLE `cloud`.`vpc_offerings` MODIFY `unique_name` VARCHAR(64) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT 'unique name of the vpc offering';
590590
ALTER TABLE `cloud`.`vpc_offerings` MODIFY `display_text` VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT 'display text';
591+
592+
-- Add view for management server peers
593+
DROP VIEW IF EXISTS `cloud`.`mshost_peer_view`;
594+
595+
CREATE VIEW `cloud`.`mshost_peer_view` AS
596+
SELECT
597+
`mshost_peer`.`id` AS `id`,
598+
`mshost_peer`.`peer_state` AS `peer_state`,
599+
`mshost_peer`.`last_update` AS `last_update`,
600+
`owner_mshost`.`id` AS `owner_mshost_id`,
601+
`owner_mshost`.`msid` AS `owner_mshost_msid`,
602+
`owner_mshost`.`runid` AS `owner_mshost_runid`,
603+
`owner_mshost`.`name` AS `owner_mshost_name`,
604+
`owner_mshost`.`uuid` AS `owner_mshost_uuid`,
605+
`owner_mshost`.`state` AS `owner_mshost_state`,
606+
`owner_mshost`.`service_ip` AS `owner_mshost_service_ip`,
607+
`owner_mshost`.`service_port` AS `owner_mshost_service_port`,
608+
`peer_mshost`.`id` AS `peer_mshost_id`,
609+
`peer_mshost`.`msid` AS `peer_mshost_msid`,
610+
`peer_mshost`.`runid` AS `peer_mshost_runid`,
611+
`peer_mshost`.`name` AS `peer_mshost_name`,
612+
`peer_mshost`.`uuid` AS `peer_mshost_uuid`,
613+
`peer_mshost`.`state` AS `peer_mshost_state`,
614+
`peer_mshost`.`service_ip` AS `peer_mshost_service_ip`,
615+
`peer_mshost`.`service_port` AS `peer_mshost_service_port`
616+
FROM `cloud`.`mshost_peer`
617+
LEFT JOIN `cloud`.`mshost` AS owner_mshost on `mshost_peer`.`owner_mshost` = `owner_mshost`.`id`
618+
LEFT JOIN `cloud`.`mshost` AS peer_mshost on `mshost_peer`.`peer_mshost` = `peer_mshost`.`id`;

framework/cluster/src/main/java/com/cloud/cluster/ClusterManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
public interface ClusterManager extends Manager {
2828
static final String ALERT_SUBJECT = "cluster-alert";
2929
final ConfigKey<Integer> HeartbeatInterval = new ConfigKey<Integer>(Integer.class, "cluster.heartbeat.interval", "management-server", "1500",
30-
"Interval to check for the heart beat between management server nodes", false);
30+
"Interval (in milliseconds) to check for the heart beat between management server nodes", false);
3131
final ConfigKey<Integer> HeartbeatThreshold = new ConfigKey<Integer>(Integer.class, "cluster.heartbeat.threshold", "management-server", "150000",
32-
"Threshold before self-fence the management server", true);
32+
"Threshold (in milliseconds) before self-fence the management server. The threshold should be larger than management.server.stats.interval", true);
3333

3434
/**
3535
* Adds a new packet to the incoming queue.

0 commit comments

Comments
 (0)