Skip to content

Commit 76c7c29

Browse files
author
Nicole Schmidt
committed
Add API command remove management server
1 parent a7beaaf commit 76c7c29

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
@@ -788,6 +788,9 @@ public class EventTypes {
788788
// Resource Limit
789789
public static final String EVENT_RESOURCE_LIMIT_UPDATE = "RESOURCE.LIMIT.UPDATE";
790790

791+
// Management Server
792+
public static final String EVENT_MANAGEMENT_SERVER_REMOVE = "MANAGEMENT.SERVER.REMOVE";
793+
791794
static {
792795

793796
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
@@ -1276,6 +1279,9 @@ public class EventTypes {
12761279
entityEventDetails.put(EVENT_SHAREDFS_DESTROY, SharedFS.class);
12771280
entityEventDetails.put(EVENT_SHAREDFS_EXPUNGE, SharedFS.class);
12781281
entityEventDetails.put(EVENT_SHAREDFS_RECOVER, SharedFS.class);
1282+
1283+
// Management Server
1284+
entityEventDetails.put(EVENT_MANAGEMENT_SERVER_REMOVE, "ManagementServer");
12791285
}
12801286

12811287
public static boolean isNetworkEvent(String eventType) {

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;
@@ -625,6 +628,7 @@
625628
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
626629
import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
627630
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
631+
import org.apache.cloudstack.management.ManagementServerHost;
628632
import org.apache.cloudstack.query.QueryService;
629633
import org.apache.cloudstack.resourcedetail.dao.GuestOsDetailsDao;
630634
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
@@ -1011,6 +1015,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
10111015
UserDataManager userDataManager;
10121016
@Inject
10131017
StoragePoolTagsDao storagePoolTagsDao;
1018+
@Inject
1019+
protected ManagementServerJoinDao _managementServerJoinDao;
10141020

10151021
@Inject
10161022
private PublicIpQuarantineDao publicIpQuarantineDao;
@@ -3995,6 +4001,7 @@ public List<Class<?>> getCommands() {
39954001
cmdList.add(ListTemplateDirectDownloadCertificatesCmd.class);
39964002
cmdList.add(ProvisionTemplateDirectDownloadCertificateCmd.class);
39974003
cmdList.add(ListMgmtsCmd.class);
4004+
cmdList.add(RemoveMgmtCmd.class);
39984005
cmdList.add(GetUploadParamsForIsoCmd.class);
39994006
cmdList.add(GetRouterHealthCheckResultsCmd.class);
40004007
cmdList.add(StartRollingMaintenanceCmd.class);
@@ -5493,4 +5500,24 @@ public void setLockControllerListener(final LockControllerListener lockControlle
54935500
_lockControllerListener = lockControllerListener;
54945501
}
54955502

5503+
@Override
5504+
@DB
5505+
@ActionEvent(eventType = EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE, eventDescription = "removing management server")
5506+
public boolean removeManagementServer(RemoveMgmtCmd cmd) {
5507+
final Long id = cmd.getId();
5508+
ManagementServerJoinVO managementServer = _managementServerJoinDao.findById(id);
5509+
5510+
if (managementServer == null) {
5511+
throw new InvalidParameterValueException(String.format("Unable to find the management server for specified id [%s]", managementServer.getUuid()));
5512+
}
5513+
5514+
if (ManagementServerHost.State.Up.equals(managementServer.getState())) {
5515+
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()));
5516+
}
5517+
5518+
managementServer.setRemoved(new Date());
5519+
return _managementServerJoinDao.update(id, managementServer);
5520+
5521+
}
5522+
54965523
}

0 commit comments

Comments
 (0)