Skip to content

Add API command remove management server #10325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/src/main/java/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions api/src/main/java/com/cloud/server/ManagementService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.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;
Expand Down Expand Up @@ -481,4 +482,6 @@ VirtualMachine upgradeSystemVM(ScaleSystemVMCmd cmd) throws ResourceUnavailableE

Pair<Boolean, String> patchSystemVM(PatchSystemVMCmd cmd);

boolean removeManagementServer(RemoveManagementServerCmd cmd);

}
Original file line number Diff line number Diff line change
@@ -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;
}

Check warning on line 40 in api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java#L38-L40

Added lines #L38 - L40 were not covered by tests

@Override
public void execute() {
boolean result = _mgr.removeManagementServer(this);

Check warning on line 44 in api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java#L43-L44

Added lines #L43 - L44 were not covered by tests
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove Management Server.");

Check warning on line 49 in api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java#L46-L49

Added lines #L46 - L49 were not covered by tests
}
}

Check warning on line 51 in api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java#L51

Added line #L51 was not covered by tests

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccountId();
}

Check warning on line 56 in api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java#L54-L56

Added lines #L54 - L56 were not covered by tests

public String getEventType() {
return EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE;
}

Check warning on line 60 in api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java#L58-L60

Added lines #L58 - L60 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,8 @@
public String getJavaVersion() {
return javaVersion;
}

public void setRemoved(Date removedDate) {
removed = removedDate;
}

Check warning on line 176 in server/src/main/java/com/cloud/api/query/vo/ManagementServerJoinVO.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/query/vo/ManagementServerJoinVO.java#L174-L176

Added lines #L174 - L176 were not covered by tests
}
27 changes: 27 additions & 0 deletions server/src/main/java/com/cloud/server/ManagementServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1015,6 +1019,8 @@
UserDataManager userDataManager;
@Inject
StoragePoolTagsDao storagePoolTagsDao;
@Inject
protected ManagementServerJoinDao managementServerJoinDao;

@Inject
private PublicIpQuarantineDao publicIpQuarantineDao;
Expand Down Expand Up @@ -4041,6 +4047,7 @@
cmdList.add(ListTemplateDirectDownloadCertificatesCmd.class);
cmdList.add(ProvisionTemplateDirectDownloadCertificateCmd.class);
cmdList.add(ListMgmtsCmd.class);
cmdList.add(RemoveManagementServerCmd.class);

Check warning on line 4050 in server/src/main/java/com/cloud/server/ManagementServerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L4050 was not covered by tests
cmdList.add(GetUploadParamsForIsoCmd.class);
cmdList.add(GetRouterHealthCheckResultsCmd.class);
cmdList.add(StartRollingMaintenanceCmd.class);
Expand Down Expand Up @@ -5552,4 +5559,24 @@
_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);

Check warning on line 5567 in server/src/main/java/com/cloud/server/ManagementServerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/server/ManagementServerImpl.java#L5564-L5567

Added lines #L5564 - L5567 were not covered by tests

if (managementServer == null) {
throw new InvalidParameterValueException(String.format("Unable to find a Management Server with ID equal to [%s].", managementServer.getUuid()));

Check warning on line 5570 in server/src/main/java/com/cloud/server/ManagementServerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L5570 was not covered by tests
}

Check warning on line 5572 in server/src/main/java/com/cloud/server/ManagementServerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L5572 was not covered by tests
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()));

Check warning on line 5574 in server/src/main/java/com/cloud/server/ManagementServerImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L5574 was not covered by tests
}

managementServer.setRemoved(new Date());
return managementServerJoinDao.update(id, managementServer);

Check warning on line 5578 in server/src/main/java/com/cloud/server/ManagementServerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/server/ManagementServerImpl.java#L5577-L5578

Added lines #L5577 - L5578 were not covered by tests

}

Check warning on line 5581 in server/src/main/java/com/cloud/server/ManagementServerImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/server/ManagementServerImpl.java#L5580-L5581

Added lines #L5580 - L5581 were not covered by tests
}
Loading