Skip to content

Commit b564c50

Browse files
author
Nicole Schmidt
committed
Add API command remove management server
1 parent 98f5663 commit b564c50

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
@@ -785,6 +785,9 @@ public class EventTypes {
785785
public static final String EVENT_SHAREDFS_EXPUNGE = "SHAREDFS.EXPUNGE";
786786
public static final String EVENT_SHAREDFS_RECOVER = "SHAREDFS.RECOVER";
787787

788+
// Management Server
789+
public static final String EVENT_MANAGEMENT_SERVER_REMOVE = "MANAGEMENT.SERVER.REMOVE";
790+
788791
static {
789792

790793
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
@@ -1273,6 +1276,9 @@ public class EventTypes {
12731276
entityEventDetails.put(EVENT_SHAREDFS_DESTROY, SharedFS.class);
12741277
entityEventDetails.put(EVENT_SHAREDFS_EXPUNGE, SharedFS.class);
12751278
entityEventDetails.put(EVENT_SHAREDFS_RECOVER, SharedFS.class);
1279+
1280+
// Management Server
1281+
entityEventDetails.put(EVENT_MANAGEMENT_SERVER_REMOVE, "ManagementServer");
12761282
}
12771283

12781284
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
@@ -45,6 +45,8 @@
4545
import javax.naming.ConfigurationException;
4646

4747
import com.cloud.utils.security.CertificateHelper;
48+
import com.cloud.api.query.dao.ManagementServerJoinDao;
49+
import com.cloud.api.query.vo.ManagementServerJoinVO;
4850
import org.apache.cloudstack.acl.ControlledEntity;
4951
import org.apache.cloudstack.acl.SecurityChecker;
5052
import org.apache.cloudstack.affinity.AffinityGroupProcessor;
@@ -126,6 +128,7 @@
126128
import org.apache.cloudstack.api.command.admin.iso.RegisterIsoCmdByAdmin;
127129
import org.apache.cloudstack.api.command.admin.loadbalancer.ListLoadBalancerRuleInstancesCmdByAdmin;
128130
import org.apache.cloudstack.api.command.admin.management.ListMgmtsCmd;
131+
import org.apache.cloudstack.api.command.admin.management.RemoveMgmtCmd;
129132
import org.apache.cloudstack.api.command.admin.network.AddNetworkDeviceCmd;
130133
import org.apache.cloudstack.api.command.admin.network.AddNetworkServiceProviderCmd;
131134
import org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
@@ -626,6 +629,7 @@
626629
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
627630
import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
628631
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
632+
import org.apache.cloudstack.management.ManagementServerHost;
629633
import org.apache.cloudstack.query.QueryService;
630634
import org.apache.cloudstack.resourcedetail.dao.GuestOsDetailsDao;
631635
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);
@@ -5495,4 +5502,24 @@ public void setLockControllerListener(final LockControllerListener lockControlle
54955502
_lockControllerListener = lockControllerListener;
54965503
}
54975504

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

0 commit comments

Comments
 (0)