Skip to content

Commit f881d39

Browse files
committed
bug 9415: deleteHost - cleanup vms running on the host to be removed
status 9415: resolved fixed
1 parent 15e14fb commit f881d39

8 files changed

Lines changed: 4023 additions & 4389 deletions

File tree

‎api/src/com/cloud/api/commands/DeleteHostCmd.java‎

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*
1717
*/
1818

19-
package com.cloud.api.commands;
20-
19+
package com.cloud.api.commands;
20+
2121
import org.apache.log4j.Logger;
2222

2323
import com.cloud.api.ApiConstants;
@@ -28,52 +28,56 @@
2828
import com.cloud.api.response.SuccessResponse;
2929
import com.cloud.user.Account;
3030

31+
@Implementation(description = "Deletes a host.", responseObject = SuccessResponse.class)
32+
public class DeleteHostCmd extends BaseCmd {
33+
public static final Logger s_logger = Logger.getLogger(DeleteHostCmd.class.getName());
34+
35+
private static final String s_name = "deletehostresponse";
3136

32-
@Implementation(description="Deletes a host.", responseObject=SuccessResponse.class)
33-
public class DeleteHostCmd extends BaseCmd {
34-
public static final Logger s_logger = Logger.getLogger(DeleteHostCmd.class.getName());
35-
36-
private static final String s_name = "deletehostresponse";
37-
38-
/////////////////////////////////////////////////////
39-
//////////////// API parameters /////////////////////
40-
/////////////////////////////////////////////////////
37+
// ///////////////////////////////////////////////////
38+
// ////////////// API parameters /////////////////////
39+
// ///////////////////////////////////////////////////
4140

42-
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the host ID")
41+
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "the host ID")
4342
private Long id;
4443

44+
@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, description = "Force delete the host. All HA enabled vms running on the host will be put to HA; HA disabled ones will be stopped")
45+
private Boolean forced;
4546

46-
/////////////////////////////////////////////////////
47-
/////////////////// Accessors ///////////////////////
48-
/////////////////////////////////////////////////////
47+
// ///////////////////////////////////////////////////
48+
// ///////////////// Accessors ///////////////////////
49+
// ///////////////////////////////////////////////////
4950

5051
public Long getId() {
5152
return id;
5253
}
5354

55+
public boolean isForced() {
56+
return (forced != null) ? forced : false;
57+
}
5458

55-
/////////////////////////////////////////////////////
56-
/////////////// API Implementation///////////////////
57-
/////////////////////////////////////////////////////
59+
// ///////////////////////////////////////////////////
60+
// ///////////// API Implementation///////////////////
61+
// ///////////////////////////////////////////////////
5862

5963
@Override
60-
public String getCommandName() {
61-
return s_name;
64+
public String getCommandName() {
65+
return s_name;
6266
}
63-
67+
6468
@Override
6569
public long getEntityOwnerId() {
6670
return Account.ACCOUNT_ID_SYSTEM;
6771
}
68-
72+
6973
@Override
70-
public void execute(){
71-
boolean result = _resourceService.deleteHost(this);
74+
public void execute() {
75+
boolean result = _resourceService.deleteHost(getId(), isForced());
7276
if (result) {
7377
SuccessResponse response = new SuccessResponse(getCommandName());
7478
this.setResponseObject(response);
7579
} else {
7680
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete host");
7781
}
78-
}
82+
}
7983
}

‎api/src/com/cloud/api/commands/StopRouterCmd.java‎

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*
1717
*/
1818

19-
package com.cloud.api.commands;
20-
19+
package com.cloud.api.commands;
20+
2121
import org.apache.log4j.Logger;
2222

2323
import com.cloud.api.ApiConstants;
@@ -34,37 +34,36 @@
3434
import com.cloud.network.router.VirtualRouter;
3535
import com.cloud.user.Account;
3636

37+
@Implementation(description = "Stops a router.", responseObject = DomainRouterResponse.class)
38+
public class StopRouterCmd extends BaseAsyncCmd {
39+
public static final Logger s_logger = Logger.getLogger(StopRouterCmd.class.getName());
40+
private static final String s_name = "stoprouterresponse";
3741

38-
@Implementation(description="Stops a router.", responseObject=DomainRouterResponse.class)
39-
public class StopRouterCmd extends BaseAsyncCmd {
40-
public static final Logger s_logger = Logger.getLogger(StopRouterCmd.class.getName());
41-
private static final String s_name = "stoprouterresponse";
42-
43-
/////////////////////////////////////////////////////
44-
//////////////// API parameters /////////////////////
45-
/////////////////////////////////////////////////////
42+
// ///////////////////////////////////////////////////
43+
// ////////////// API parameters /////////////////////
44+
// ///////////////////////////////////////////////////
4645

47-
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the router")
46+
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, required = true, description = "the ID of the router")
4847
private Long id;
49-
50-
@Parameter(name=ApiConstants.FORCED, type=CommandType.BOOLEAN, required=false, description="Force stop the VM. The caller knows the VM is stopped.")
48+
49+
@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, required = false, description = "Force stop the VM. The caller knows the VM is stopped.")
5150
private Boolean forced;
5251

53-
/////////////////////////////////////////////////////
54-
/////////////////// Accessors ///////////////////////
55-
/////////////////////////////////////////////////////
52+
// ///////////////////////////////////////////////////
53+
// ///////////////// Accessors ///////////////////////
54+
// ///////////////////////////////////////////////////
5655

5756
public Long getId() {
5857
return id;
5958
}
6059

61-
/////////////////////////////////////////////////////
62-
/////////////// API Implementation///////////////////
63-
/////////////////////////////////////////////////////
60+
// ///////////////////////////////////////////////////
61+
// ///////////// API Implementation///////////////////
62+
// ///////////////////////////////////////////////////
6463

6564
@Override
66-
public String getCommandName() {
67-
return s_name;
65+
public String getCommandName() {
66+
return s_name;
6867
}
6968

7069
@Override
@@ -81,35 +80,35 @@ public long getEntityOwnerId() {
8180
public String getEventType() {
8281
return EventTypes.EVENT_ROUTER_STOP;
8382
}
84-
83+
8584
@Override
8685
public String getEventDescription() {
87-
return "stopping router: " + getId();
86+
return "stopping router: " + getId();
8887
}
89-
88+
9089
@Override
9190
public AsyncJob.Type getInstanceType() {
92-
return AsyncJob.Type.DomainRouter;
91+
return AsyncJob.Type.DomainRouter;
9392
}
94-
93+
9594
@Override
9695
public Long getInstanceId() {
97-
return getId();
96+
return getId();
9897
}
99-
98+
10099
public boolean isForced() {
101100
return (forced != null) ? forced : false;
102101
}
103102

104103
@Override
105-
public void execute() throws ConcurrentOperationException, ResourceUnavailableException{
104+
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
106105
VirtualRouter result = _routerService.stopRouter(getId(), isForced());
107-
if (result != null){
108-
DomainRouterResponse response =_responseGenerator.createDomainRouterResponse(result);
106+
if (result != null) {
107+
DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
109108
response.setResponseName(getCommandName());
110109
this.setResponseObject(response);
111110
} else {
112111
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to stop router");
113112
}
114-
}
115-
}
113+
}
114+
}

‎api/src/com/cloud/resource/ResourceService.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.cloud.api.commands.AddSecondaryStorageCmd;
2525
import com.cloud.api.commands.CancelMaintenanceCmd;
2626
import com.cloud.api.commands.DeleteClusterCmd;
27-
import com.cloud.api.commands.DeleteHostCmd;
2827
import com.cloud.api.commands.PrepareForMaintenanceCmd;
2928
import com.cloud.api.commands.ReconnectHostCmd;
3029
import com.cloud.api.commands.UpdateHostCmd;
@@ -66,12 +65,12 @@ public interface ResourceService {
6665
Host maintain(PrepareForMaintenanceCmd cmd) throws InvalidParameterValueException;
6766
/**
6867
* Deletes a host
68+
* @param hostId TODO
69+
* @param isForced TODO
6970
*
70-
* @param cmd - the command specifying hostId
7171
* @param true if deleted, false otherwise
72-
* @throws InvalidParameterValueException
7372
*/
74-
boolean deleteHost(DeleteHostCmd cmd) throws InvalidParameterValueException;
73+
boolean deleteHost(long hostId, boolean isForced);
7574

7675
Host getHost(long hostId);
7776

0 commit comments

Comments
 (0)