Skip to content

Commit 3a45bd7

Browse files
weizhouapacheborisstoyanov
authored andcommitted
Improvement: management server peer states (apache#9885)
* Improvement: management server peer states * Update pr9885: consider new mgmt server node which has msId=managementServerNodeId * Update pr9885: update global config description * Update pr9885: update label on UI * framework: Do not update mshost_peer when mgmt server is Up as it will be updated by status update * mgmt: Update state to Up when mgmt server writes heartbeat to db * mgmt: change Service IP to Management IP --------- Co-authored-by: Boris Stoyanov - a.k.a Bobby <[email protected]>
1 parent 6f23a65 commit 3a45bd7

File tree

23 files changed

+782
-37
lines changed

23 files changed

+782
-37
lines changed

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
@@ -384,6 +384,14 @@ public class ApiConstants {
384384
public static final String PATH = "path";
385385
public static final String PAYLOAD = "payload";
386386
public static final String PAYLOAD_URL = "payloadurl";
387+
public static final String PEERS = "peers";
388+
public static final String PEER_ID = "peerid";
389+
public static final String PEER_NAME = "peername";
390+
public static final String PEER_MSID = "peermsid";
391+
public static final String PEER_RUNID = "peerrunid";
392+
public static final String PEER_SERVICE_IP = "peerserviceip";
393+
public static final String PEER_SERVICE_PORT = "peerserviceport";
394+
public static final String PEER_STATE = "peerstate";
387395
public static final String POD_ID = "podid";
388396
public static final String POD_NAME = "podname";
389397
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

2728
@APICommand(name = "listManagementServers", description = "Lists management servers.", responseObject = ManagementServerResponse.class,
2829
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -39,6 +40,11 @@ public class ListMgmtsCmd extends BaseListCmd {
3940
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the management server")
4041
private String hostName;
4142

43+
@Parameter(name = ApiConstants.PEERS, type = CommandType.BOOLEAN,
44+
description = "Whether to return the management server peers or not. By default, the management server peers will not be returned.",
45+
since = "4.20.0.0")
46+
private Boolean peers;
47+
4248
/////////////////////////////////////////////////////
4349
/////////////////// Accessors ///////////////////////
4450
/////////////////////////////////////////////////////
@@ -51,6 +57,10 @@ public String getHostName() {
5157
return hostName;
5258
}
5359

60+
public Boolean getPeers() {
61+
return BooleanUtils.toBooleanDefaultIfNull(peers, false);
62+
}
63+
5464
/////////////////////////////////////////////////////
5565
/////////////// API Implementation///////////////////
5666
/////////////////////////////////////////////////////

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
}
@@ -171,4 +177,19 @@ public void setServiceIp(String serviceIp) {
171177
public String getKernelVersion() {
172178
return kernelVersion;
173179
}
180+
181+
public List<PeerManagementServerNodeResponse> getPeers() {
182+
return peers;
183+
}
184+
185+
public void setPeers(List<PeerManagementServerNodeResponse> peers) {
186+
this.peers = peers;
187+
}
188+
189+
public void addPeer(PeerManagementServerNodeResponse peer) {
190+
if (peers == null) {
191+
peers = new ArrayList<>();
192+
}
193+
peers.add(peer);
194+
}
174195
}
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" />
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
18+
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_FOREIGN_KEY`;
19+
20+
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_FOREIGN_KEY` (
21+
IN in_table_name VARCHAR(200)
22+
, IN in_key_name VARCHAR(200)
23+
, IN in_foreign_key VARCHAR(200)
24+
, IN in_references VARCHAR(1000)
25+
)
26+
BEGIN
27+
28+
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT_WS(' ', 'ALTER TABLE ', in_table_name, ' ADD CONSTRAINT ', in_key_name, ' FOREIGN KEY ', in_foreign_key, ' REFERENCES ', in_references, ' ON DELETE CASCADE'); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;

engine/schema/src/main/resources/META-INF/db/schema-41910to42000.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,10 @@ INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid, hypervisor_type, hypervi
423423

424424
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vm_instance', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for vm" ');
425425
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.volumes', 'delete_protection', 'boolean DEFAULT FALSE COMMENT "delete protection for volumes" ');
426+
427+
-- Modify index for mshost_peer
428+
DELETE FROM `cloud`.`mshost_peer`;
429+
CALL `cloud`.`IDEMPOTENT_DROP_FOREIGN_KEY`('cloud.mshost_peer','fk_mshost_peer__owner_mshost');
430+
CALL `cloud`.`IDEMPOTENT_DROP_INDEX`('i_mshost_peer__owner_peer_runid','mshost_peer');
431+
CALL `cloud`.`IDEMPOTENT_ADD_UNIQUE_KEY`('cloud.mshost_peer', 'i_mshost_peer__owner_peer', '(owner_mshost, peer_mshost)');
432+
CALL `cloud`.`IDEMPOTENT_ADD_FOREIGN_KEY`('cloud.mshost_peer', 'fk_mshost_peer__owner_mshost', '(owner_mshost)', '`mshost`(`id`)');
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
18+
19+
DROP VIEW IF EXISTS `cloud`.`mshost_peer_view`;
20+
21+
CREATE VIEW `cloud`.`mshost_peer_view` AS
22+
SELECT
23+
`mshost_peer`.`id` AS `id`,
24+
`mshost_peer`.`peer_state` AS `peer_state`,
25+
`mshost_peer`.`last_update` AS `last_update`,
26+
`owner_mshost`.`id` AS `owner_mshost_id`,
27+
`owner_mshost`.`msid` AS `owner_mshost_msid`,
28+
`owner_mshost`.`runid` AS `owner_mshost_runid`,
29+
`owner_mshost`.`name` AS `owner_mshost_name`,
30+
`owner_mshost`.`uuid` AS `owner_mshost_uuid`,
31+
`owner_mshost`.`state` AS `owner_mshost_state`,
32+
`owner_mshost`.`service_ip` AS `owner_mshost_service_ip`,
33+
`owner_mshost`.`service_port` AS `owner_mshost_service_port`,
34+
`peer_mshost`.`id` AS `peer_mshost_id`,
35+
`peer_mshost`.`msid` AS `peer_mshost_msid`,
36+
`peer_mshost`.`runid` AS `peer_mshost_runid`,
37+
`peer_mshost`.`name` AS `peer_mshost_name`,
38+
`peer_mshost`.`uuid` AS `peer_mshost_uuid`,
39+
`peer_mshost`.`state` AS `peer_mshost_state`,
40+
`peer_mshost`.`service_ip` AS `peer_mshost_service_ip`,
41+
`peer_mshost`.`service_port` AS `peer_mshost_service_port`
42+
FROM `cloud`.`mshost_peer`
43+
LEFT JOIN `cloud`.`mshost` AS owner_mshost on `mshost_peer`.`owner_mshost` = `owner_mshost`.`id`
44+
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)