Skip to content

Commit 58466c8

Browse files
DaanHooglandGabrielBrascher
authored andcommitted
api: add command to list management servers (#3150)
* api: add command to list management servers * api: add number of mangement servers in listInfrastructure command * ui: add block for mangement servers on infra page * api name resolution method cleanup
1 parent 00e6d59 commit 58466c8

40 files changed

Lines changed: 366 additions & 27 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ public enum ApiCommandJobType {
5252
DedicatedGuestVlanRange,
5353
GuestOs,
5454
GuestOsMapping,
55-
Network
55+
Network,
56+
Management
5657
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Map;
2323
import java.util.Set;
2424

25+
import org.apache.cloudstack.management.ManagementServerHost;
2526
import org.apache.cloudstack.affinity.AffinityGroup;
2627
import org.apache.cloudstack.affinity.AffinityGroupResponse;
2728
import org.apache.cloudstack.api.ApiConstants.HostDetails;
@@ -64,6 +65,7 @@
6465
import org.apache.cloudstack.api.response.LBStickinessResponse;
6566
import org.apache.cloudstack.api.response.ListResponse;
6667
import org.apache.cloudstack.api.response.LoadBalancerResponse;
68+
import org.apache.cloudstack.api.response.ManagementServerResponse;
6769
import org.apache.cloudstack.api.response.NetworkACLItemResponse;
6870
import org.apache.cloudstack.api.response.NetworkACLResponse;
6971
import org.apache.cloudstack.api.response.NetworkOfferingResponse;
@@ -462,4 +464,6 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
462464
ListResponse<UpgradeRouterTemplateResponse> createUpgradeRouterTemplateResponse(List<Long> jobIds);
463465

464466
SSHKeyPairResponse createSSHKeyPairResponse(SSHKeyPair sshkeyPair, boolean privatekey);
467+
468+
ManagementServerResponse createManagementResponse(ManagementServerHost mgmt);
465469
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.command.admin.management;
18+
19+
import org.apache.cloudstack.api.APICommand;
20+
import org.apache.cloudstack.api.ApiCommandJobType;
21+
import org.apache.cloudstack.api.ApiConstants;
22+
import org.apache.cloudstack.api.BaseCmd;
23+
import org.apache.cloudstack.api.BaseListCmd;
24+
import org.apache.cloudstack.api.Parameter;
25+
import org.apache.cloudstack.api.response.HostResponse;
26+
import org.apache.cloudstack.api.response.ListResponse;
27+
import org.apache.cloudstack.api.response.ManagementServerResponse;
28+
import org.apache.log4j.Logger;
29+
30+
@APICommand(name = ListMgmtsCmd.APINAME, description = "Lists management servers.", responseObject = ManagementServerResponse.class,
31+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
32+
public class ListMgmtsCmd extends BaseListCmd {
33+
public static final Logger s_logger = Logger.getLogger(ListMgmtsCmd.class.getName());
34+
35+
public static final String APINAME = "listManagementServers";
36+
37+
/////////////////////////////////////////////////////
38+
//////////////// API parameters /////////////////////
39+
/////////////////////////////////////////////////////
40+
41+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = HostResponse.class, description = "the id of the management server")
42+
private Long id;
43+
44+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the management server")
45+
private String hostName;
46+
47+
/////////////////////////////////////////////////////
48+
/////////////////// Accessors ///////////////////////
49+
/////////////////////////////////////////////////////
50+
51+
public Long getId() {
52+
return id;
53+
}
54+
55+
public String getHostName() {
56+
return hostName;
57+
}
58+
59+
/////////////////////////////////////////////////////
60+
/////////////// API Implementation///////////////////
61+
/////////////////////////////////////////////////////
62+
63+
@Override
64+
public String getCommandName() {
65+
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
66+
}
67+
68+
@Override
69+
public ApiCommandJobType getInstanceType() {
70+
return ApiCommandJobType.Host;
71+
}
72+
73+
@Override
74+
public void execute() {
75+
ListResponse<ManagementServerResponse> response = _queryService.listManagementServers(this);
76+
response.setResponseName(getCommandName());
77+
this.setResponseObject(response);
78+
}
79+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 org.apache.cloudstack.management.ManagementServerHost;
20+
import com.cloud.serializer.Param;
21+
import com.google.gson.annotations.SerializedName;
22+
import org.apache.cloudstack.api.ApiConstants;
23+
import org.apache.cloudstack.api.BaseResponse;
24+
import org.apache.cloudstack.api.EntityReference;
25+
26+
@EntityReference(value = ManagementServerHost.class)
27+
public class ManagementServerResponse extends BaseResponse {
28+
@SerializedName(ApiConstants.ID)
29+
@Param(description = "the ID of the management server")
30+
private String id;
31+
32+
@SerializedName(ApiConstants.NAME)
33+
@Param(description = "the name of the management server")
34+
private String name;
35+
36+
@SerializedName(ApiConstants.STATE)
37+
@Param(description = "the state of the management server")
38+
private ManagementServerHost.State state;
39+
40+
@SerializedName(ApiConstants.VERSION)
41+
@Param(description = "the version of the management server")
42+
private String version;
43+
44+
public void setId(String id) {
45+
this.id = id;
46+
}
47+
48+
public void setName(String name) {
49+
this.name = name;
50+
}
51+
52+
public void setState(ManagementServerHost.State state) {
53+
this.state = state;
54+
}
55+
56+
public void setVersion(String version) {
57+
this.version = version;
58+
}
59+
}

framework/cluster/src/main/java/com/cloud/cluster/ManagementServerHost.java renamed to api/src/main/java/org/apache/cloudstack/management/ManagementServerHost.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17-
package com.cloud.cluster;
17+
package org.apache.cloudstack.management;
1818

1919
public interface ManagementServerHost {
20+
enum State {
21+
Up, Down
22+
}
23+
2024
long getId();
2125

22-
public static enum State {
23-
Up, Starting, Down
24-
};
26+
String getUuid();
2527

2628
long getMsid();
2729

2830
State getState();
2931

32+
String getName();
33+
3034
String getVersion();
3135

3236
String getServiceIP();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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.management;
18+
19+
import org.apache.cloudstack.api.InternalIdentity;
20+
21+
import java.util.Date;
22+
23+
public interface ManagementServerHostPeer extends InternalIdentity {
24+
25+
long getOwnerMshost();
26+
long getPeerMshost();
27+
long getPeerRunid();
28+
ManagementServerHost.State getPeerState();
29+
Date getLastUpdateTime();
30+
}

api/src/main/java/org/apache/cloudstack/query/QueryService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
2424
import org.apache.cloudstack.api.command.admin.host.ListHostTagsCmd;
2525
import org.apache.cloudstack.api.command.admin.internallb.ListInternalLBVMsCmd;
26+
import org.apache.cloudstack.api.command.admin.management.ListMgmtsCmd;
2627
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
2728
import org.apache.cloudstack.api.command.admin.storage.ListImageStoresCmd;
2829
import org.apache.cloudstack.api.command.admin.storage.ListSecondaryStagingStoresCmd;
@@ -58,6 +59,7 @@
5859
import org.apache.cloudstack.api.response.ImageStoreResponse;
5960
import org.apache.cloudstack.api.response.InstanceGroupResponse;
6061
import org.apache.cloudstack.api.response.ListResponse;
62+
import org.apache.cloudstack.api.response.ManagementServerResponse;
6163
import org.apache.cloudstack.api.response.ProjectAccountResponse;
6264
import org.apache.cloudstack.api.response.ProjectInvitationResponse;
6365
import org.apache.cloudstack.api.response.ProjectResponse;
@@ -141,4 +143,6 @@ public interface QueryService {
141143
ListResponse<StorageTagResponse> searchForStorageTags(ListStorageTagsCmd cmd);
142144

143145
ListResponse<HostTagResponse> searchForHostTags(ListHostTagsCmd cmd);
146+
147+
ListResponse<ManagementServerResponse> listManagementServers(ListMgmtsCmd cmd);
144148
}

engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
import com.cloud.cluster.ClusterManagerListener;
7070
import com.cloud.cluster.ClusterServicePdu;
7171
import com.cloud.cluster.ClusteredAgentRebalanceService;
72-
import com.cloud.cluster.ManagementServerHost;
72+
import org.apache.cloudstack.management.ManagementServerHost;
7373
import com.cloud.cluster.ManagementServerHostVO;
7474
import com.cloud.cluster.agentlb.AgentLoadBalancerPlanner;
7575
import com.cloud.cluster.agentlb.HostTransferMapVO;

engine/orchestration/src/main/java/com/cloud/vm/ClusteredVirtualMachineManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import com.cloud.cluster.ClusterManager;
2626
import com.cloud.cluster.ClusterManagerListener;
27-
import com.cloud.cluster.ManagementServerHost;
27+
import org.apache.cloudstack.management.ManagementServerHost;
2828

2929
public class ClusteredVirtualMachineManagerImpl extends VirtualMachineManagerImpl implements ClusterManagerListener {
3030

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41200.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@
1919

2020
import java.io.InputStream;
2121
import java.sql.Connection;
22+
import java.sql.PreparedStatement;
23+
import java.sql.SQLException;
2224

2325
import com.cloud.utils.exception.CloudRuntimeException;
26+
import org.apache.log4j.Logger;
2427

2528
public class Upgrade41120to41200 implements DbUpgrade {
2629

30+
final static Logger LOG = Logger.getLogger(Upgrade41120to41200.class);
31+
2732
@Override
2833
public String[] getUpgradableVersionRange() {
2934
return new String[] {"4.11.2.0", "4.12.0.0"};
@@ -52,7 +57,15 @@ public InputStream[] getPrepareScripts() {
5257

5358
@Override
5459
public void performDataMigration(Connection conn) {
60+
updateManagementServerHostUuid(conn);
61+
}
5562

63+
private void updateManagementServerHostUuid(Connection conn) {
64+
try (final PreparedStatement updateStatement = conn.prepareStatement("UPDATE cloud.mshost SET uuid=UUID()")) {
65+
updateStatement.executeUpdate();
66+
} catch (SQLException e) {
67+
LOG.error("Failed to add an UUID to each management server.", e);
68+
}
5669
}
5770

5871
@Override

0 commit comments

Comments
 (0)