Skip to content

Commit d5fd3ec

Browse files
nicoschmdtbernardodemarcowinterhazel
authored
Add API command remove management server (#10325)
* Add API command remove management server * Apply suggestions from code review Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com> * Apply sugestions from code review * Update log message with current management server state Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com> * Apply suggestions from code review Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com> * Update api/src/main/java/org/apache/cloudstack/api/command/admin/management/RemoveManagementServerCmd.java Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com> * Remove unused imports --------- Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com> Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com>
1 parent 3e3a0c0 commit d5fd3ec

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-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
@@ -801,6 +801,9 @@ public class EventTypes {
801801
// Resource Limit
802802
public static final String EVENT_RESOURCE_LIMIT_UPDATE = "RESOURCE.LIMIT.UPDATE";
803803

804+
// Management Server
805+
public static final String EVENT_MANAGEMENT_SERVER_REMOVE = "MANAGEMENT.SERVER.REMOVE";
806+
804807
public static final String VM_LEASE_EXPIRED = "VM.LEASE.EXPIRED";
805808
public static final String VM_LEASE_DISABLED = "VM.LEASE.DISABLED";
806809
public static final String VM_LEASE_CANCELLED = "VM.LEASE.CANCELLED";
@@ -1301,6 +1304,9 @@ public class EventTypes {
13011304
entityEventDetails.put(EVENT_SHAREDFS_EXPUNGE, SharedFS.class);
13021305
entityEventDetails.put(EVENT_SHAREDFS_RECOVER, SharedFS.class);
13031306

1307+
// Management Server
1308+
entityEventDetails.put(EVENT_MANAGEMENT_SERVER_REMOVE, "ManagementServer");
1309+
13041310
// VM Lease
13051311
entityEventDetails.put(VM_LEASE_EXPIRED, VirtualMachine.class);
13061312
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
@@ -38,6 +38,7 @@
3838
import org.apache.cloudstack.api.command.admin.guest.UpdateGuestOsMappingCmd;
3939
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
4040
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
41+
import org.apache.cloudstack.api.command.admin.management.RemoveManagementServerCmd;
4142
import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
4243
import org.apache.cloudstack.api.command.admin.resource.ArchiveAlertsCmd;
4344
import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd;
@@ -506,4 +507,6 @@ VirtualMachine upgradeSystemVM(ScaleSystemVMCmd cmd) throws ResourceUnavailableE
506507

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

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

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;
@@ -128,6 +130,7 @@
128130
import org.apache.cloudstack.api.command.admin.iso.RegisterIsoCmdByAdmin;
129131
import org.apache.cloudstack.api.command.admin.loadbalancer.ListLoadBalancerRuleInstancesCmdByAdmin;
130132
import org.apache.cloudstack.api.command.admin.management.ListMgmtsCmd;
133+
import org.apache.cloudstack.api.command.admin.management.RemoveManagementServerCmd;
131134
import org.apache.cloudstack.api.command.admin.network.AddNetworkDeviceCmd;
132135
import org.apache.cloudstack.api.command.admin.network.AddNetworkServiceProviderCmd;
133136
import org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
@@ -634,6 +637,7 @@
634637
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
635638
import org.apache.cloudstack.framework.security.keystore.KeystoreManager;
636639
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
640+
import org.apache.cloudstack.management.ManagementServerHost;
637641
import org.apache.cloudstack.query.QueryService;
638642
import org.apache.cloudstack.resourcedetail.dao.GuestOsDetailsDao;
639643
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
@@ -1024,6 +1028,8 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
10241028
UserDataManager userDataManager;
10251029
@Inject
10261030
StoragePoolTagsDao storagePoolTagsDao;
1031+
@Inject
1032+
protected ManagementServerJoinDao managementServerJoinDao;
10271033

10281034
@Inject
10291035
private PublicIpQuarantineDao publicIpQuarantineDao;
@@ -4161,6 +4167,7 @@ public List<Class<?>> getCommands() {
41614167
cmdList.add(ListTemplateDirectDownloadCertificatesCmd.class);
41624168
cmdList.add(ProvisionTemplateDirectDownloadCertificateCmd.class);
41634169
cmdList.add(ListMgmtsCmd.class);
4170+
cmdList.add(RemoveManagementServerCmd.class);
41644171
cmdList.add(GetUploadParamsForIsoCmd.class);
41654172
cmdList.add(GetRouterHealthCheckResultsCmd.class);
41664173
cmdList.add(StartRollingMaintenanceCmd.class);
@@ -5701,4 +5708,24 @@ public void setLockControllerListener(final LockControllerListener lockControlle
57015708
_lockControllerListener = lockControllerListener;
57025709
}
57035710

5711+
@Override
5712+
@DB
5713+
@ActionEvent(eventType = EventTypes.EVENT_MANAGEMENT_SERVER_REMOVE, eventDescription = "removing Management Server")
5714+
public boolean removeManagementServer(RemoveManagementServerCmd cmd) {
5715+
final Long id = cmd.getId();
5716+
ManagementServerJoinVO managementServer = managementServerJoinDao.findById(id);
5717+
5718+
if (managementServer == null) {
5719+
throw new InvalidParameterValueException(String.format("Unable to find a Management Server with ID equal to [%s].", managementServer.getUuid()));
5720+
}
5721+
5722+
if (!ManagementServerHost.State.Down.equals(managementServer.getState())) {
5723+
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()));
5724+
}
5725+
5726+
managementServer.setRemoved(new Date());
5727+
return managementServerJoinDao.update(id, managementServer);
5728+
5729+
}
5730+
57045731
}

0 commit comments

Comments
 (0)