Skip to content

Commit 1145c3a

Browse files
author
Nicole Schmidt
committed
Add API command remove management server
1 parent 7632814 commit 1145c3a

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
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
@@ -796,6 +796,9 @@ public class EventTypes {
796796
// Resource Limit
797797
public static final String EVENT_RESOURCE_LIMIT_UPDATE = "RESOURCE.LIMIT.UPDATE";
798798

799+
// Management Server
800+
public static final String EVENT_MANAGEMENT_SERVER_REMOVE = "MANAGEMENT.SERVER.REMOVE";
801+
799802
public static final String VM_LEASE_EXPIRED = "VM.LEASE.EXPIRED";
800803
public static final String VM_LEASE_DISABLED = "VM.LEASE.DISABLED";
801804
public static final String VM_LEASE_CANCELLED = "VM.LEASE.CANCELLED";
@@ -1296,6 +1299,9 @@ public class EventTypes {
12961299
entityEventDetails.put(EVENT_SHAREDFS_EXPUNGE, SharedFS.class);
12971300
entityEventDetails.put(EVENT_SHAREDFS_RECOVER, SharedFS.class);
12981301

1302+
// Management Server
1303+
entityEventDetails.put(EVENT_MANAGEMENT_SERVER_REMOVE, "ManagementServer");
1304+
12991305
// VM Lease
13001306
entityEventDetails.put(VM_LEASE_EXPIRED, VirtualMachine.class);
13011307
entityEventDetails.put(VM_LEASE_EXPIRING, VirtualMachine.class);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.cloudstack.api.command.admin.guest.UpdateGuestOsMappingCmd;
3636
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
3737
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
38+
import org.apache.cloudstack.api.command.admin.management.RemoveMgmtCmd;
3839
import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
3940
import org.apache.cloudstack.api.command.admin.resource.ArchiveAlertsCmd;
4041
import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd;
@@ -481,4 +482,6 @@ VirtualMachine upgradeSystemVM(ScaleSystemVMCmd cmd) throws ResourceUnavailableE
481482

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

485+
boolean removeManagementServer(RemoveMgmtCmd cmd);
486+
484487
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
import com.cloud.exception.ConcurrentOperationException;
32+
import com.cloud.exception.NetworkRuleConflictException;
33+
import com.cloud.exception.InsufficientCapacityException;
34+
import com.cloud.exception.ResourceAllocationException;
35+
import com.cloud.exception.ResourceUnavailableException;
36+
37+
@APICommand(name = "removeManagementServer", description = "Removes a management server.", responseObject = SuccessResponse.class,
38+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = RoleType.Admin)
39+
public class RemoveMgmtCmd extends BaseCmd {
40+
41+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ManagementServerResponse.class, required = true, description = "the id of the management server")
42+
private Long id;
43+
44+
public Long getId() {
45+
return id;
46+
}
47+
48+
@Override
49+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
50+
boolean result = _mgr.removeManagementServer(this);
51+
if (result) {
52+
SuccessResponse response = new SuccessResponse(getCommandName());
53+
this.setResponseObject(response);
54+
} else {
55+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove management server");
56+
}
57+
}
58+
59+
@Override
60+
public long getEntityOwnerId() {
61+
return CallContext.current().getCallingAccountId();
62+
}
63+
64+
public String getEventType() {
65+
return EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE;
66+
}
67+
}

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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import javax.inject.Inject;
4545
import javax.naming.ConfigurationException;
4646

47+
import com.cloud.api.query.dao.ManagementServerJoinDao;
48+
import com.cloud.api.query.vo.ManagementServerJoinVO;
4749
import org.apache.cloudstack.acl.ControlledEntity;
4850
import org.apache.cloudstack.acl.SecurityChecker;
4951
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
@@ -125,6 +127,7 @@
125127
import org.apache.cloudstack.api.command.admin.iso.RegisterIsoCmdByAdmin;
126128
import org.apache.cloudstack.api.command.admin.loadbalancer.ListLoadBalancerRuleInstancesCmdByAdmin;
127129
import org.apache.cloudstack.api.command.admin.management.ListMgmtsCmd;
130+
import org.apache.cloudstack.api.command.admin.management.RemoveMgmtCmd;
128131
import org.apache.cloudstack.api.command.admin.network.AddNetworkDeviceCmd;
129132
import org.apache.cloudstack.api.command.admin.network.AddNetworkServiceProviderCmd;
130133
import org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
@@ -627,6 +630,7 @@
627630
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
628631
import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
629632
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
633+
import org.apache.cloudstack.management.ManagementServerHost;
630634
import org.apache.cloudstack.query.QueryService;
631635
import org.apache.cloudstack.resourcedetail.dao.GuestOsDetailsDao;
632636
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
@@ -1015,6 +1019,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
10151019
UserDataManager userDataManager;
10161020
@Inject
10171021
StoragePoolTagsDao storagePoolTagsDao;
1022+
@Inject
1023+
protected ManagementServerJoinDao _managementServerJoinDao;
10181024

10191025
@Inject
10201026
private PublicIpQuarantineDao publicIpQuarantineDao;
@@ -4041,6 +4047,7 @@ public List<Class<?>> getCommands() {
40414047
cmdList.add(ListTemplateDirectDownloadCertificatesCmd.class);
40424048
cmdList.add(ProvisionTemplateDirectDownloadCertificateCmd.class);
40434049
cmdList.add(ListMgmtsCmd.class);
4050+
cmdList.add(RemoveMgmtCmd.class);
40444051
cmdList.add(GetUploadParamsForIsoCmd.class);
40454052
cmdList.add(GetRouterHealthCheckResultsCmd.class);
40464053
cmdList.add(StartRollingMaintenanceCmd.class);
@@ -5552,4 +5559,24 @@ public void setLockControllerListener(final LockControllerListener lockControlle
55525559
_lockControllerListener = lockControllerListener;
55535560
}
55545561

5562+
@Override
5563+
@DB
5564+
@ActionEvent(eventType = EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE, eventDescription = "removing management server")
5565+
public boolean removeManagementServer(RemoveMgmtCmd cmd) {
5566+
final Long id = cmd.getId();
5567+
ManagementServerJoinVO managementServer = _managementServerJoinDao.findById(id);
5568+
5569+
if (managementServer == null) {
5570+
throw new InvalidParameterValueException(String.format("Unable to find the management server for specified id [%s]", managementServer.getUuid()));
5571+
}
5572+
5573+
if (ManagementServerHost.State.Up.equals(managementServer.getState())) {
5574+
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()));
5575+
}
5576+
5577+
managementServer.setRemoved(new Date());
5578+
return _managementServerJoinDao.update(id, managementServer);
5579+
5580+
}
5581+
55555582
}

0 commit comments

Comments
 (0)