Skip to content

Commit 1ea620f

Browse files
nicoschmdtbernardodemarcowinterhazel
authored andcommitted
Add API command remove management server (apache#10325)
* Add API command remove management server * Apply suggestions from code review Co-authored-by: Bernardo De Marco Gonçalves <[email protected]> * Apply sugestions from code review * Update log message with current management server state Co-authored-by: Bernardo De Marco Gonçalves <[email protected]> * Apply suggestions from code review Co-authored-by: Fabricio Duarte <[email protected]> * Update api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java Co-authored-by: Fabricio Duarte <[email protected]> * Remove unused imports --------- Co-authored-by: Bernardo De Marco Gonçalves <[email protected]> Co-authored-by: Fabricio Duarte <[email protected]>
1 parent 58e4f62 commit 1ea620f

File tree

5 files changed

+104
-2
lines changed

5 files changed

+104
-2
lines changed

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,9 @@ public class EventTypes {
814814
// Resource Limit
815815
public static final String EVENT_RESOURCE_LIMIT_UPDATE = "RESOURCE.LIMIT.UPDATE";
816816

817+
// Management Server
818+
public static final String EVENT_MANAGEMENT_SERVER_REMOVE = "MANAGEMENT.SERVER.REMOVE";
819+
817820
public static final String VM_LEASE_EXPIRED = "VM.LEASE.EXPIRED";
818821
public static final String VM_LEASE_DISABLED = "VM.LEASE.DISABLED";
819822
public static final String VM_LEASE_CANCELLED = "VM.LEASE.CANCELLED";
@@ -1321,6 +1324,9 @@ public class EventTypes {
13211324
// Disaster Recovery Cluster
13221325
entityEventDetails.put(EVENT_DISASTER_RECOVERY_CLUSTER, "DisasterRecoveryCluster");
13231326

1327+
// Management Server
1328+
entityEventDetails.put(EVENT_MANAGEMENT_SERVER_REMOVE, "ManagementServer");
1329+
13241330
// VM Lease
13251331
entityEventDetails.put(VM_LEASE_EXPIRED, VirtualMachine.class);
13261332
entityEventDetails.put(VM_LEASE_EXPIRING, VirtualMachine.class);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.apache.cloudstack.api.command.admin.outofbandmanagement.UpdateHostDevicesCmd;
4646
// import org.apache.cloudstack.api.command.admin.outofbandmanagement.UpdateHostLunDevicesCmd;
4747
// import org.apache.cloudstack.api.command.admin.outofbandmanagement.UpdateHostUsbDevicesCmd;
48+
import org.apache.cloudstack.api.command.admin.management.RemoveManagementServerCmd;
4849
import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
4950
import org.apache.cloudstack.api.command.admin.resource.ArchiveAlertsCmd;
5051
import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd;
@@ -544,4 +545,7 @@ VirtualMachine upgradeSystemVM(ScaleSystemVMCmd cmd) throws ResourceUnavailableE
544545

545546
LicenseCheckerResponse checkLicense(LicenseCheckCmd cmd);
546547

547-
}
548+
549+
boolean removeManagementServer(RemoveManagementServerCmd cmd);
550+
551+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 com.cloud.event.EventTypes;
20+
import org.apache.cloudstack.acl.RoleType;
21+
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.Parameter;
23+
import org.apache.cloudstack.api.ServerApiException;
24+
import org.apache.cloudstack.api.ApiConstants;
25+
import org.apache.cloudstack.api.ApiErrorCode;
26+
import org.apache.cloudstack.api.BaseCmd;
27+
import org.apache.cloudstack.api.response.ManagementServerResponse;
28+
import org.apache.cloudstack.api.response.SuccessResponse;
29+
import org.apache.cloudstack.context.CallContext;
30+
31+
@APICommand(name = "removeManagementServer", description = "Removes a Management Server.", responseObject = SuccessResponse.class,
32+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = RoleType.Admin)
33+
public class RemoveManagementServerCmd extends BaseCmd {
34+
35+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ManagementServerResponse.class, required = true, description = "the ID of the Management Server")
36+
private Long id;
37+
38+
public Long getId() {
39+
return id;
40+
}
41+
42+
@Override
43+
public void execute() {
44+
boolean result = _mgr.removeManagementServer(this);
45+
if (result) {
46+
SuccessResponse response = new SuccessResponse(getCommandName());
47+
this.setResponseObject(response);
48+
} else {
49+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove Management Server.");
50+
}
51+
}
52+
53+
@Override
54+
public long getEntityOwnerId() {
55+
return CallContext.current().getCallingAccountId();
56+
}
57+
58+
public String getEventType() {
59+
return EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE;
60+
}
61+
}

server/src/main/java/com/cloud/api/query/vo/ManagementServerJoinVO.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,8 @@ public String getJavaName() {
170170
public String getJavaVersion() {
171171
return javaVersion;
172172
}
173+
174+
public void setRemoved(Date removedDate) {
175+
removed = removedDate;
176+
}
173177
}

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
// import javax.net.ssl.X509TrustManager;
5959
import javax.naming.ConfigurationException;
6060

61+
import com.cloud.api.query.dao.ManagementServerJoinDao;
62+
import com.cloud.api.query.vo.ManagementServerJoinVO;
6163
import org.apache.cloudstack.acl.ControlledEntity;
6264
import org.apache.cloudstack.acl.SecurityChecker;
6365
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
@@ -140,6 +142,7 @@
140142
import org.apache.cloudstack.api.command.admin.iso.RegisterIsoCmdByAdmin;
141143
import org.apache.cloudstack.api.command.admin.loadbalancer.ListLoadBalancerRuleInstancesCmdByAdmin;
142144
import org.apache.cloudstack.api.command.admin.management.ListMgmtsCmd;
145+
import org.apache.cloudstack.api.command.admin.management.RemoveManagementServerCmd;
143146
import org.apache.cloudstack.api.command.admin.network.AddNetworkDeviceCmd;
144147
import org.apache.cloudstack.api.command.admin.network.AddNetworkServiceProviderCmd;
145148
import org.apache.cloudstack.api.command.admin.network.CreateNetworkCmdByAdmin;
@@ -659,6 +662,7 @@
659662
import org.apache.cloudstack.ha.HAResource;
660663
import org.apache.cloudstack.ha.dao.HAConfigDao;
661664
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
665+
import org.apache.cloudstack.management.ManagementServerHost;
662666
import org.apache.cloudstack.query.QueryService;
663667
import org.apache.cloudstack.resourcedetail.dao.GuestOsDetailsDao;
664668
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
@@ -1063,6 +1067,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
10631067
UserDataManager userDataManager;
10641068
@Inject
10651069
StoragePoolTagsDao storagePoolTagsDao;
1070+
@Inject
1071+
protected ManagementServerJoinDao managementServerJoinDao;
10661072

10671073
@Inject
10681074
private PublicIpQuarantineDao publicIpQuarantineDao;
@@ -4506,6 +4512,7 @@ public List<Class<?>> getCommands() {
45064512
cmdList.add(ListTemplateDirectDownloadCertificatesCmd.class);
45074513
cmdList.add(ProvisionTemplateDirectDownloadCertificateCmd.class);
45084514
cmdList.add(ListMgmtsCmd.class);
4515+
cmdList.add(RemoveManagementServerCmd.class);
45094516
cmdList.add(GetUploadParamsForIsoCmd.class);
45104517
cmdList.add(GetRouterHealthCheckResultsCmd.class);
45114518
cmdList.add(StartRollingMaintenanceCmd.class);
@@ -6286,4 +6293,24 @@ private boolean handleExpiredLicense(HostVO host) {
62866293

62876294
return licenseHostValue;
62886295
}
6289-
}
6296+
6297+
@DB
6298+
@ActionEvent(eventType = EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE, eventDescription = "removing Management Server")
6299+
public boolean removeManagementServer(RemoveManagementServerCmd cmd) {
6300+
final Long id = cmd.getId();
6301+
ManagementServerJoinVO managementServer = managementServerJoinDao.findById(id);
6302+
6303+
if (managementServer == null) {
6304+
throw new InvalidParameterValueException(String.format("Unable to find a Management Server with ID equal to [%s].", managementServer.getUuid()));
6305+
}
6306+
6307+
if (!ManagementServerHost.State.Down.equals(managementServer.getState())) {
6308+
throw new InvalidParameterValueException(String.format("Unable to remove Management Server with ID [%s]. It can only be removed when it is in the [%s] state, however currently it is in the [%s] state.", managementServer.getUuid(), ManagementServerHost.State.Down.name(), managementServer.getState().name()));
6309+
}
6310+
6311+
managementServer.setRemoved(new Date());
6312+
return managementServerJoinDao.update(id, managementServer);
6313+
6314+
}
6315+
6316+
}

0 commit comments

Comments
 (0)