This is an automated email from the ASF dual-hosted git repository.
joao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new d5fd3ec36ea Add API command remove management server (#10325)
d5fd3ec36ea is described below
commit d5fd3ec36ea7f2c3828ae8668c1bfec22f31761e
Author: Nicole Schmidt <[email protected]>
AuthorDate: Fri Jul 4 14:49:28 2025 -0300
Add API command remove management server (#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]>
---
api/src/main/java/com/cloud/event/EventTypes.java | 6 +++
.../java/com/cloud/server/ManagementService.java | 3 ++
.../management/RemoveManagementServerCmd.java | 61 ++++++++++++++++++++++
.../cloud/api/query/vo/ManagementServerJoinVO.java | 4 ++
.../com/cloud/server/ManagementServerImpl.java | 27 ++++++++++
5 files changed, 101 insertions(+)
diff --git a/api/src/main/java/com/cloud/event/EventTypes.java
b/api/src/main/java/com/cloud/event/EventTypes.java
index 88050349bc9..c8694e076b8 100644
--- a/api/src/main/java/com/cloud/event/EventTypes.java
+++ b/api/src/main/java/com/cloud/event/EventTypes.java
@@ -801,6 +801,9 @@ public class EventTypes {
// Resource Limit
public static final String EVENT_RESOURCE_LIMIT_UPDATE =
"RESOURCE.LIMIT.UPDATE";
+ // Management Server
+ public static final String EVENT_MANAGEMENT_SERVER_REMOVE =
"MANAGEMENT.SERVER.REMOVE";
+
public static final String VM_LEASE_EXPIRED = "VM.LEASE.EXPIRED";
public static final String VM_LEASE_DISABLED = "VM.LEASE.DISABLED";
public static final String VM_LEASE_CANCELLED = "VM.LEASE.CANCELLED";
@@ -1301,6 +1304,9 @@ public class EventTypes {
entityEventDetails.put(EVENT_SHAREDFS_EXPUNGE, SharedFS.class);
entityEventDetails.put(EVENT_SHAREDFS_RECOVER, SharedFS.class);
+ // Management Server
+ entityEventDetails.put(EVENT_MANAGEMENT_SERVER_REMOVE,
"ManagementServer");
+
// VM Lease
entityEventDetails.put(VM_LEASE_EXPIRED, VirtualMachine.class);
entityEventDetails.put(VM_LEASE_EXPIRING, VirtualMachine.class);
diff --git a/api/src/main/java/com/cloud/server/ManagementService.java
b/api/src/main/java/com/cloud/server/ManagementService.java
index 032245a91ad..f7b2456ce5c 100644
--- a/api/src/main/java/com/cloud/server/ManagementService.java
+++ b/api/src/main/java/com/cloud/server/ManagementService.java
@@ -38,6 +38,7 @@ import
org.apache.cloudstack.api.command.admin.guest.UpdateGuestOsCmd;
import org.apache.cloudstack.api.command.admin.guest.UpdateGuestOsMappingCmd;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
+import
org.apache.cloudstack.api.command.admin.management.RemoveManagementServerCmd;
import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
import org.apache.cloudstack.api.command.admin.resource.ArchiveAlertsCmd;
import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd;
@@ -506,4 +507,6 @@ public interface ManagementService {
Pair<Boolean, String> patchSystemVM(PatchSystemVMCmd cmd);
+ boolean removeManagementServer(RemoveManagementServerCmd cmd);
+
}
diff --git
a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java
b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java
new file mode 100644
index 00000000000..803b95bfa9e
--- /dev/null
+++
b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java
@@ -0,0 +1,61 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.admin.management;
+
+import com.cloud.event.EventTypes;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.response.ManagementServerResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.context.CallContext;
+
+@APICommand(name = "removeManagementServer", description = "Removes a
Management Server.", responseObject = SuccessResponse.class,
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
authorized = RoleType.Admin)
+public class RemoveManagementServerCmd extends BaseCmd {
+
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType =
ManagementServerResponse.class, required = true, description = "the ID of the
Management Server")
+ private Long id;
+
+ public Long getId() {
+ return id;
+ }
+
+ @Override
+ public void execute() {
+ boolean result = _mgr.removeManagementServer(this);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed
to remove Management Server.");
+ }
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return CallContext.current().getCallingAccountId();
+ }
+
+ public String getEventType() {
+ return EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE;
+ }
+}
diff --git
a/server/src/main/java/com/cloud/api/query/vo/ManagementServerJoinVO.java
b/server/src/main/java/com/cloud/api/query/vo/ManagementServerJoinVO.java
index be1a4c6f7fb..8ce6dccbbf6 100644
--- a/server/src/main/java/com/cloud/api/query/vo/ManagementServerJoinVO.java
+++ b/server/src/main/java/com/cloud/api/query/vo/ManagementServerJoinVO.java
@@ -170,4 +170,8 @@ public class ManagementServerJoinVO {
public String getJavaVersion() {
return javaVersion;
}
+
+ public void setRemoved(Date removedDate) {
+ removed = removedDate;
+ }
}
diff --git a/server/src/main/java/com/cloud/server/ManagementServerImpl.java
b/server/src/main/java/com/cloud/server/ManagementServerImpl.java
index 3bb6f02a58e..9ac4599f30e 100644
--- a/server/src/main/java/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/main/java/com/cloud/server/ManagementServerImpl.java
@@ -44,6 +44,8 @@ import javax.crypto.spec.SecretKeySpec;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+import com.cloud.api.query.dao.ManagementServerJoinDao;
+import com.cloud.api.query.vo.ManagementServerJoinVO;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
@@ -128,6 +130,7 @@ import
org.apache.cloudstack.api.command.admin.iso.ListIsosCmdByAdmin;
import org.apache.cloudstack.api.command.admin.iso.RegisterIsoCmdByAdmin;
import
org.apache.cloudstack.api.command.admin.loadbalancer.ListLoadBalancerRuleInstancesCmdByAdmin;
import org.apache.cloudstack.api.command.admin.management.ListMgmtsCmd;
+import
org.apache.cloudstack.api.command.admin.management.RemoveManagementServerCmd;
import org.apache.cloudstack.api.command.admin.network.AddNetworkDeviceCmd;
import
org.apache.cloudstack.api.command.admin.network.AddNetworkServiceProviderCmd;
import
org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
@@ -634,6 +637,7 @@ import
org.apache.cloudstack.framework.config.impl.ConfigurationSubGroupVO;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
+import org.apache.cloudstack.management.ManagementServerHost;
import org.apache.cloudstack.query.QueryService;
import org.apache.cloudstack.resourcedetail.dao.GuestOsDetailsDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
@@ -1024,6 +1028,8 @@ public class ManagementServerImpl extends ManagerBase
implements ManagementServe
UserDataManager userDataManager;
@Inject
StoragePoolTagsDao storagePoolTagsDao;
+ @Inject
+ protected ManagementServerJoinDao managementServerJoinDao;
@Inject
private PublicIpQuarantineDao publicIpQuarantineDao;
@@ -4161,6 +4167,7 @@ public class ManagementServerImpl extends ManagerBase
implements ManagementServe
cmdList.add(ListTemplateDirectDownloadCertificatesCmd.class);
cmdList.add(ProvisionTemplateDirectDownloadCertificateCmd.class);
cmdList.add(ListMgmtsCmd.class);
+ cmdList.add(RemoveManagementServerCmd.class);
cmdList.add(GetUploadParamsForIsoCmd.class);
cmdList.add(GetRouterHealthCheckResultsCmd.class);
cmdList.add(StartRollingMaintenanceCmd.class);
@@ -5701,4 +5708,24 @@ public class ManagementServerImpl extends ManagerBase
implements ManagementServe
_lockControllerListener = lockControllerListener;
}
+ @Override
+ @DB
+ @ActionEvent(eventType = EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE,
eventDescription = "removing Management Server")
+ public boolean removeManagementServer(RemoveManagementServerCmd cmd) {
+ final Long id = cmd.getId();
+ ManagementServerJoinVO managementServer =
managementServerJoinDao.findById(id);
+
+ if (managementServer == null) {
+ throw new InvalidParameterValueException(String.format("Unable to
find a Management Server with ID equal to [%s].", managementServer.getUuid()));
+ }
+
+ if
(!ManagementServerHost.State.Down.equals(managementServer.getState())) {
+ 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()));
+ }
+
+ managementServer.setRemoved(new Date());
+ return managementServerJoinDao.update(id, managementServer);
+
+ }
+
}