From 1145c3a992da17ea351cb348d084a6e9351c2c29 Mon Sep 17 00:00:00 2001 From: Nicole Schmidt Date: Wed, 29 Jan 2025 15:15:38 -0300 Subject: [PATCH 1/7] Add API command remove management server --- .../main/java/com/cloud/event/EventTypes.java | 6 ++ .../com/cloud/server/ManagementService.java | 3 + .../admin/management/RemoveMgmtCmd.java | 67 +++++++++++++++++++ .../api/query/vo/ManagementServerJoinVO.java | 4 ++ .../cloud/server/ManagementServerImpl.java | 27 ++++++++ 5 files changed, 107 insertions(+) create mode 100644 api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveMgmtCmd.java diff --git a/api/src/main/java/com/cloud/event/EventTypes.java b/api/src/main/java/com/cloud/event/EventTypes.java index e194085a9d9e..e5d4f6909f36 100644 --- a/api/src/main/java/com/cloud/event/EventTypes.java +++ b/api/src/main/java/com/cloud/event/EventTypes.java @@ -796,6 +796,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"; @@ -1296,6 +1299,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 18f3e901cd93..95cf70466074 100644 --- a/api/src/main/java/com/cloud/server/ManagementService.java +++ b/api/src/main/java/com/cloud/server/ManagementService.java @@ -35,6 +35,7 @@ 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.RemoveMgmtCmd; 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; @@ -481,4 +482,6 @@ VirtualMachine upgradeSystemVM(ScaleSystemVMCmd cmd) throws ResourceUnavailableE Pair patchSystemVM(PatchSystemVMCmd cmd); + boolean removeManagementServer(RemoveMgmtCmd cmd); + } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveMgmtCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveMgmtCmd.java new file mode 100644 index 000000000000..69bed65ca92a --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveMgmtCmd.java @@ -0,0 +1,67 @@ +// 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; + +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.NetworkRuleConflictException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; + +@APICommand(name = "removeManagementServer", description = "Removes a management server.", responseObject = SuccessResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = RoleType.Admin) +public class RemoveMgmtCmd 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() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + 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 be1a4c6f7fbe..8ce6dccbbf6f 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 String getJavaName() { 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 de0aa286a977..92c69ea0517d 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.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; @@ -125,6 +127,7 @@ 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.RemoveMgmtCmd; 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; @@ -627,6 +630,7 @@ 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; @@ -1015,6 +1019,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe UserDataManager userDataManager; @Inject StoragePoolTagsDao storagePoolTagsDao; + @Inject + protected ManagementServerJoinDao _managementServerJoinDao; @Inject private PublicIpQuarantineDao publicIpQuarantineDao; @@ -4041,6 +4047,7 @@ public List> getCommands() { cmdList.add(ListTemplateDirectDownloadCertificatesCmd.class); cmdList.add(ProvisionTemplateDirectDownloadCertificateCmd.class); cmdList.add(ListMgmtsCmd.class); + cmdList.add(RemoveMgmtCmd.class); cmdList.add(GetUploadParamsForIsoCmd.class); cmdList.add(GetRouterHealthCheckResultsCmd.class); cmdList.add(StartRollingMaintenanceCmd.class); @@ -5552,4 +5559,24 @@ public void setLockControllerListener(final LockControllerListener lockControlle _lockControllerListener = lockControllerListener; } + @Override + @DB + @ActionEvent(eventType = EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE, eventDescription = "removing management server") + public boolean removeManagementServer(RemoveMgmtCmd cmd) { + final Long id = cmd.getId(); + ManagementServerJoinVO managementServer = _managementServerJoinDao.findById(id); + + if (managementServer == null) { + throw new InvalidParameterValueException(String.format("Unable to find the management server for specified id [%s]", managementServer.getUuid())); + } + + if (ManagementServerHost.State.Up.equals(managementServer.getState())) { + throw new InvalidParameterValueException(String.format("Unable to remove management server [%s], it is not in the right state, it can only be removed when state is [%s]", managementServer.getUuid(), ManagementServerHost.State.Down.name())); + } + + managementServer.setRemoved(new Date()); + return _managementServerJoinDao.update(id, managementServer); + + } + } From de5b6f5261660a0e396c9ea89aa9a1a9f706d418 Mon Sep 17 00:00:00 2001 From: Nicole Schmidt <45316185+nicoschmdt@users.noreply.github.com> Date: Wed, 5 Feb 2025 08:04:33 -0300 Subject: [PATCH 2/7] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bernardo De Marco Gonçalves --- .../api/command/admin/management/RemoveMgmtCmd.java | 6 +++--- .../main/java/com/cloud/server/ManagementServerImpl.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveMgmtCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveMgmtCmd.java index 69bed65ca92a..fbd09a812aa4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveMgmtCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveMgmtCmd.java @@ -34,11 +34,11 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; -@APICommand(name = "removeManagementServer", description = "Removes a management server.", responseObject = SuccessResponse.class, +@APICommand(name = "removeManagementServer", description = "Removes a Management Server.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = RoleType.Admin) public class RemoveMgmtCmd extends BaseCmd { - @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ManagementServerResponse.class, required = true, description = "the id of the management server") + @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() { @@ -52,7 +52,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove management server"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove Management Server"); } } diff --git a/server/src/main/java/com/cloud/server/ManagementServerImpl.java b/server/src/main/java/com/cloud/server/ManagementServerImpl.java index 92c69ea0517d..d12db3d1208c 100644 --- a/server/src/main/java/com/cloud/server/ManagementServerImpl.java +++ b/server/src/main/java/com/cloud/server/ManagementServerImpl.java @@ -5561,17 +5561,17 @@ public void setLockControllerListener(final LockControllerListener lockControlle @Override @DB - @ActionEvent(eventType = EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE, eventDescription = "removing management server") + @ActionEvent(eventType = EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE, eventDescription = "removing Management Server") public boolean removeManagementServer(RemoveMgmtCmd cmd) { final Long id = cmd.getId(); ManagementServerJoinVO managementServer = _managementServerJoinDao.findById(id); if (managementServer == null) { - throw new InvalidParameterValueException(String.format("Unable to find the management server for specified id [%s]", managementServer.getUuid())); + throw new InvalidParameterValueException(String.format("Unable to find a Management Server with ID equal to [%s]", managementServer.getUuid())); } if (ManagementServerHost.State.Up.equals(managementServer.getState())) { - throw new InvalidParameterValueException(String.format("Unable to remove management server [%s], it is not in the right state, it can only be removed when state is [%s]", managementServer.getUuid(), ManagementServerHost.State.Down.name())); + 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(), ManagementServerHost.State.Up.name())); } managementServer.setRemoved(new Date()); From 380d621d0bda9b07048364e25e826167b68fbb05 Mon Sep 17 00:00:00 2001 From: Nicole Schmidt Date: Mon, 10 Feb 2025 12:30:56 -0300 Subject: [PATCH 3/7] Apply sugestions from code review --- .../java/com/cloud/server/ManagementService.java | 4 ++-- ...MgmtCmd.java => RemoveManagementServerCmd.java} | 2 +- .../com/cloud/server/ManagementServerImpl.java | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) rename api/src/main/java/org/apache/cloudstack/api/command/admin/management/{RemoveMgmtCmd.java => RemoveManagementServerCmd.java} (98%) diff --git a/api/src/main/java/com/cloud/server/ManagementService.java b/api/src/main/java/com/cloud/server/ManagementService.java index 95cf70466074..21a820a35cf2 100644 --- a/api/src/main/java/com/cloud/server/ManagementService.java +++ b/api/src/main/java/com/cloud/server/ManagementService.java @@ -35,7 +35,7 @@ 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.RemoveMgmtCmd; +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; @@ -482,6 +482,6 @@ VirtualMachine upgradeSystemVM(ScaleSystemVMCmd cmd) throws ResourceUnavailableE Pair patchSystemVM(PatchSystemVMCmd cmd); - boolean removeManagementServer(RemoveMgmtCmd cmd); + boolean removeManagementServer(RemoveManagementServerCmd cmd); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveMgmtCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java similarity index 98% rename from api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveMgmtCmd.java rename to api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java index fbd09a812aa4..63aee734709b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveMgmtCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java @@ -36,7 +36,7 @@ @APICommand(name = "removeManagementServer", description = "Removes a Management Server.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = RoleType.Admin) -public class RemoveMgmtCmd extends BaseCmd { +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; diff --git a/server/src/main/java/com/cloud/server/ManagementServerImpl.java b/server/src/main/java/com/cloud/server/ManagementServerImpl.java index d12db3d1208c..60e940200c6b 100644 --- a/server/src/main/java/com/cloud/server/ManagementServerImpl.java +++ b/server/src/main/java/com/cloud/server/ManagementServerImpl.java @@ -127,7 +127,7 @@ 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.RemoveMgmtCmd; +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; @@ -1020,7 +1020,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe @Inject StoragePoolTagsDao storagePoolTagsDao; @Inject - protected ManagementServerJoinDao _managementServerJoinDao; + protected ManagementServerJoinDao managementServerJoinDao; @Inject private PublicIpQuarantineDao publicIpQuarantineDao; @@ -4047,7 +4047,7 @@ public List> getCommands() { cmdList.add(ListTemplateDirectDownloadCertificatesCmd.class); cmdList.add(ProvisionTemplateDirectDownloadCertificateCmd.class); cmdList.add(ListMgmtsCmd.class); - cmdList.add(RemoveMgmtCmd.class); + cmdList.add(RemoveManagementServerCmd.class); cmdList.add(GetUploadParamsForIsoCmd.class); cmdList.add(GetRouterHealthCheckResultsCmd.class); cmdList.add(StartRollingMaintenanceCmd.class); @@ -5562,20 +5562,20 @@ public void setLockControllerListener(final LockControllerListener lockControlle @Override @DB @ActionEvent(eventType = EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE, eventDescription = "removing Management Server") - public boolean removeManagementServer(RemoveMgmtCmd cmd) { + public boolean removeManagementServer(RemoveManagementServerCmd cmd) { final Long id = cmd.getId(); - ManagementServerJoinVO managementServer = _managementServerJoinDao.findById(id); + 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.Up.equals(managementServer.getState())) { + 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(), ManagementServerHost.State.Up.name())); } managementServer.setRemoved(new Date()); - return _managementServerJoinDao.update(id, managementServer); + return managementServerJoinDao.update(id, managementServer); } From 16c4ababec7d3b8f0bd8850ac7c7eb5db8e3cb78 Mon Sep 17 00:00:00 2001 From: Nicole Schmidt <45316185+nicoschmdt@users.noreply.github.com> Date: Thu, 13 Feb 2025 10:00:50 -0300 Subject: [PATCH 4/7] Update log message with current management server state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bernardo De Marco Gonçalves --- server/src/main/java/com/cloud/server/ManagementServerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/server/ManagementServerImpl.java b/server/src/main/java/com/cloud/server/ManagementServerImpl.java index 60e940200c6b..e199966ad181 100644 --- a/server/src/main/java/com/cloud/server/ManagementServerImpl.java +++ b/server/src/main/java/com/cloud/server/ManagementServerImpl.java @@ -5571,7 +5571,7 @@ public boolean removeManagementServer(RemoveManagementServerCmd cmd) { } 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(), ManagementServerHost.State.Up.name())); + 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()); From b6566884a59d0b5923b9d3a48b25bae5a8024fef Mon Sep 17 00:00:00 2001 From: Nicole Schmidt <45316185+nicoschmdt@users.noreply.github.com> Date: Fri, 21 Feb 2025 09:10:44 -0300 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: Fabricio Duarte --- .../command/admin/management/RemoveManagementServerCmd.java | 2 +- .../src/main/java/com/cloud/server/ManagementServerImpl.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 index 63aee734709b..52f97d1079ac 100644 --- 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 @@ -52,7 +52,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove Management Server"); + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove Management Server."); } } diff --git a/server/src/main/java/com/cloud/server/ManagementServerImpl.java b/server/src/main/java/com/cloud/server/ManagementServerImpl.java index e199966ad181..c3feb424d13b 100644 --- a/server/src/main/java/com/cloud/server/ManagementServerImpl.java +++ b/server/src/main/java/com/cloud/server/ManagementServerImpl.java @@ -5567,11 +5567,11 @@ public boolean removeManagementServer(RemoveManagementServerCmd cmd) { 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())); + 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())); + 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()); From 4d7472c58b027686fa71fed33a3b9da68e602ecc Mon Sep 17 00:00:00 2001 From: Nicole Schmidt <45316185+nicoschmdt@users.noreply.github.com> Date: Fri, 21 Feb 2025 10:31:45 -0300 Subject: [PATCH 6/7] Update api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java Co-authored-by: Fabricio Duarte --- .../api/command/admin/management/RemoveManagementServerCmd.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 52f97d1079ac..185057f55623 100644 --- 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 @@ -46,7 +46,7 @@ public Long getId() { } @Override - public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { + public void execute() { boolean result = _mgr.removeManagementServer(this); if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); From fb3e7de18ec0acf6331ae89baf4912d348fc4ae4 Mon Sep 17 00:00:00 2001 From: Nicole Schmidt Date: Mon, 24 Feb 2025 18:19:07 -0300 Subject: [PATCH 7/7] Remove unused imports --- .../command/admin/management/RemoveManagementServerCmd.java | 6 ------ 1 file changed, 6 deletions(-) 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 index 185057f55623..803b95bfa9e2 100644 --- 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 @@ -28,12 +28,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.NetworkRuleConflictException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.ResourceAllocationException; -import com.cloud.exception.ResourceUnavailableException; - @APICommand(name = "removeManagementServer", description = "Removes a Management Server.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = RoleType.Admin) public class RemoveManagementServerCmd extends BaseCmd {