Skip to content

Commit 0e41964

Browse files
committed
bug 7811: Start domR/Dhcp if it's not running when do userVmReboot
status 7811: resolved fixed Other fixes: * vmExpunge: cleanup LB/PF rules after vm was marked as Expunging in the DB to avoid the situation when user recovers a vm in the middle of expunge job.
1 parent 2466589 commit 0e41964

13 files changed

Lines changed: 153 additions & 48 deletions

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import com.cloud.api.response.UserVmResponse;
2929
import com.cloud.async.AsyncJob;
3030
import com.cloud.event.EventTypes;
31+
import com.cloud.exception.InsufficientCapacityException;
32+
import com.cloud.exception.ResourceUnavailableException;
3133
import com.cloud.user.Account;
3234
import com.cloud.uservm.UserVm;
3335

@@ -89,7 +91,7 @@ public Long getInstanceId() {
8991
}
9092

9193
@Override
92-
public void execute(){
94+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException{
9395
UserVm result = _userVmService.rebootVirtualMachine(this);
9496
if (result !=null){
9597
UserVmResponse response = _responseGenerator.createUserVmResponse(result);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import com.cloud.api.response.UserVmResponse;
3131
import com.cloud.async.AsyncJob;
3232
import com.cloud.event.EventTypes;
33+
import com.cloud.exception.InsufficientCapacityException;
34+
import com.cloud.exception.ResourceUnavailableException;
3335
import com.cloud.user.Account;
3436
import com.cloud.uservm.UserVm;
3537

@@ -107,7 +109,7 @@ public Long getInstanceId() {
107109

108110
Random _rand = new Random(System.currentTimeMillis());
109111
@Override
110-
public void execute(){
112+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException{
111113
password = Long.toHexString(_rand.nextLong());
112114
UserVm result = _userVmService.resetVMPassword(this, password);
113115
if (result != null){

‎api/src/com/cloud/vm/UserVmService.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public interface UserVmService {
7373
* @param cmd - the command specifying vmId, password
7474
* @return the VM if reset worked successfully, null otherwise
7575
*/
76-
UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password);
76+
UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password) throws ResourceUnavailableException, InsufficientCapacityException;
7777

7878
/**
7979
* Attaches the specified volume to the specified VM
@@ -93,7 +93,7 @@ public interface UserVmService {
9393

9494
UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, ExecutionException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
9595
UserVm stopVirtualMachine(StopVMCmd cmd) throws ServerApiException, ConcurrentOperationException;
96-
UserVm rebootVirtualMachine(RebootVMCmd cmd);
96+
UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException;
9797
UserVm updateVirtualMachine(UpdateVMCmd cmd);
9898
UserVm recoverVirtualMachine(RecoverVMCmd cmd) throws ResourceAllocationException;
9999

‎server/src/com/cloud/configuration/ConfigurationManager.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.List;
2121

22+
import com.cloud.dc.ClusterVO;
2223
import com.cloud.dc.DataCenter;
2324
import com.cloud.dc.DataCenter.NetworkType;
2425
import com.cloud.dc.DataCenterVO;
@@ -175,5 +176,9 @@ void checkDiskOfferingAccess(Account caller, DiskOffering dof)
175176

176177
DataCenterVO getZone(long id);
177178

179+
HostPodVO getPod(long id);
180+
181+
ClusterVO getCluster(long id);
182+
178183
boolean deleteAccountSpecificVirtualRanges(long accountId);
179184
}

‎server/src/com/cloud/configuration/ConfigurationManagerImpl.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import com.cloud.configuration.ResourceCount.ResourceType;
5959
import com.cloud.configuration.dao.ConfigurationDao;
6060
import com.cloud.dc.AccountVlanMapVO;
61+
import com.cloud.dc.ClusterVO;
6162
import com.cloud.dc.DataCenter;
6263
import com.cloud.dc.DataCenter.NetworkType;
6364
import com.cloud.dc.DataCenterIpAddressVO;
@@ -69,6 +70,7 @@
6970
import com.cloud.dc.Vlan.VlanType;
7071
import com.cloud.dc.VlanVO;
7172
import com.cloud.dc.dao.AccountVlanMapDao;
73+
import com.cloud.dc.dao.ClusterDao;
7274
import com.cloud.dc.dao.DataCenterDao;
7375
import com.cloud.dc.dao.DataCenterIpAddressDao;
7476
import com.cloud.dc.dao.DataCenterLinkLocalIpAddressDaoImpl;
@@ -158,6 +160,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
158160
@Inject SecondaryStorageVmDao _secStorageDao;
159161
@Inject AccountManager _accountMgr;
160162
@Inject NetworkManager _networkMgr;
163+
@Inject ClusterDao _clusterDao;
161164
@Inject(adapter=SecurityChecker.class)
162165
Adapters<SecurityChecker> _secChecker;
163166

@@ -2707,4 +2710,14 @@ public boolean deleteAccountSpecificVirtualRanges(long accountId) {
27072710
}
27082711
return result;
27092712
}
2713+
2714+
@Override
2715+
public HostPodVO getPod(long id) {
2716+
return _podDao.findById(id);
2717+
}
2718+
2719+
@Override
2720+
public ClusterVO getCluster(long id) {
2721+
return _clusterDao.findById(id);
2722+
}
27102723
}

‎server/src/com/cloud/network/NetworkManager.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public interface NetworkManager extends NetworkService {
109109

110110
void cleanupNics(VirtualMachineProfile<? extends VMInstanceVO> vm);
111111

112+
void expungeNics(VirtualMachineProfile<? extends VMInstanceVO> vm);
113+
112114
List<? extends Nic> getNics(VirtualMachine vm);
113115

114116
List<AccountVO> getAccountsUsingNetwork(long configurationId);

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,14 @@ public void cleanupNics(VirtualMachineProfile<? extends VMInstanceVO> vm) {
12591259
}
12601260
}
12611261

1262+
@Override
1263+
public void expungeNics(VirtualMachineProfile<? extends VMInstanceVO> vm) {
1264+
List<NicVO> nics = _nicDao.listIncludingRemovedBy(vm.getId());
1265+
for (NicVO nic : nics) {
1266+
_nicDao.expunge(nic.getId());
1267+
}
1268+
}
1269+
12621270
@Override
12631271
public Network createNetwork(CreateNetworkCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
12641272
Long networkOfferingId = cmd.getNetworkOfferingId();

‎server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,15 @@ public boolean removeFromLoadBalancer(long loadBalancerId, List<Long> instanceId
208208
_lb2VmMapDao.persist(map);
209209
s_logger.debug("Set load balancer rule for revoke: rule id " + loadBalancerId + ", vmId " + instanceId);
210210
}
211-
212-
applyLoadBalancerConfig(loadBalancerId);
213-
_lb2VmMapDao.remove(loadBalancerId, instanceIds, null);
214-
s_logger.debug("Load balancer rule id " + loadBalancerId + " is removed for vms " + instanceIds);
211+
212+
if (applyLoadBalancerConfig(loadBalancerId)) {
213+
_lb2VmMapDao.remove(loadBalancerId, instanceIds, null);
214+
s_logger.debug("Load balancer rule id " + loadBalancerId + " is removed for vms " + instanceIds);
215+
} else {
216+
s_logger.warn("Failed to remove load balancer rule id " + loadBalancerId + " for vms " + instanceIds);
217+
throw new CloudRuntimeException("Failed to remove load balancer rule id " + loadBalancerId + " for vms " + instanceIds);
218+
}
219+
215220
} catch (ResourceUnavailableException e) {
216221
s_logger.warn("Unable to apply the load balancer config because resource is unavaliable.", e);
217222
return false;
@@ -418,7 +423,7 @@ public List<LbDestination> getExistingDestinations(long lbId) {
418423
String dstIp = null;
419424
for (LoadBalancerVMMapVO lbVmMap : lbVmMaps) {
420425
UserVm vm = _vmDao.findById(lbVmMap.getInstanceId());
421-
Nic nic = _nicDao.findByInstanceIdAndNetworkId(lb.getNetworkId(), vm.getId());
426+
Nic nic = _nicDao.findByInstanceIdAndNetworkIdIncludingRemoved(lb.getNetworkId(), vm.getId());
422427
dstIp = nic.getIp4Address();
423428
LbDestination lbDst = new LbDestination(lb.getDefaultPortStart(), lb.getDefaultPortEnd(), dstIp, lbVmMap.isRevoke());
424429
dstList.add(lbDst);

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
4545
import com.cloud.agent.api.GetVmStatsAnswer;
4646
import com.cloud.agent.api.GetVmStatsCommand;
47-
import com.cloud.agent.api.RebootAnswer;
48-
import com.cloud.agent.api.RebootCommand;
4947
import com.cloud.agent.api.SnapshotCommand;
5048
import com.cloud.agent.api.StopAnswer;
5149
import com.cloud.agent.api.StopCommand;
@@ -85,6 +83,7 @@
8583
import com.cloud.dc.DataCenterVO;
8684
import com.cloud.dc.HostPodVO;
8785
import com.cloud.dc.dao.AccountVlanMapDao;
86+
import com.cloud.dc.dao.ClusterDao;
8887
import com.cloud.dc.dao.DataCenterDao;
8988
import com.cloud.dc.dao.HostPodDao;
9089
import com.cloud.dc.dao.VlanDao;
@@ -237,6 +236,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
237236
@Inject AccountService _accountService;
238237
@Inject AsyncJobManager _asyncMgr;
239238
@Inject VlanDao _vlanDao;
239+
@Inject ClusterDao _clusterDao;
240240
@Inject AccountVlanMapDao _accountVlanMapDao;
241241
@Inject StoragePoolDao _storagePoolDao;
242242
@Inject VMTemplateHostDao _vmTemplateHostDao;
@@ -281,7 +281,7 @@ public List<? extends UserVm> getVirtualMachines(long hostId) {
281281
}
282282

283283
@Override
284-
public UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password){
284+
public UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password) throws ResourceUnavailableException, InsufficientCapacityException{
285285
Account account = UserContext.current().getCaller();
286286
Long userId = UserContext.current().getCallerUserId();
287287
Long vmId = cmd.getId();
@@ -313,7 +313,8 @@ public UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password){
313313
return userVm;
314314
}
315315

316-
private boolean resetVMPasswordInternal(ResetVMPasswordCmd cmd, String password) {
316+
private boolean resetVMPasswordInternal(ResetVMPasswordCmd cmd, String password) throws ResourceUnavailableException, InsufficientCapacityException{
317+
317318
return true;
318319
// Long vmId = cmd.getId();
319320
// Long userId = UserContext.current().getCallerUserId();
@@ -331,7 +332,7 @@ private boolean resetVMPasswordInternal(ResetVMPasswordCmd cmd, String password)
331332
// }
332333
// if (_routerMgr.savePasswordToRouter(vmInstance.getDomainRouterId(), vmInstance.getPrivateIpAddress(), password)) {
333334
// // Need to reboot the virtual machine so that the password gets redownloaded from the DomR, and reset on the VM
334-
// if (!rebootVirtualMachine(userId, vmId)) {
335+
// if (rebootVirtualMachine(userId, vmId) == null) {
335336
// if (vmInstance.getState() == State.Stopped) {
336337
// return true;
337338
// }
@@ -785,25 +786,21 @@ public boolean attachISOToVM(long vmId, long isoId, boolean attach) {
785786
}
786787

787788

788-
private boolean rebootVirtualMachine(long userId, long vmId) {
789+
private UserVm rebootVirtualMachine(long userId, long vmId) throws InsufficientCapacityException, ResourceUnavailableException{
789790
UserVmVO vm = _vmDao.findById(vmId);
791+
User caller = _accountMgr.getActiveUser(userId);
792+
Account owner = _accountMgr.getAccount(vm.getAccountId());
790793

791794
if (vm == null || vm.getState() == State.Destroyed || vm.getState() == State.Expunging || vm.getRemoved() != null) {
792-
return false;
795+
s_logger.warn("Vm id=" + vmId + " doesn't exist");
796+
return null;
793797
}
794798

795799
if (vm.getState() == State.Running && vm.getHostId() != null) {
796-
RebootCommand cmd = new RebootCommand(vm.getInstanceName());
797-
RebootAnswer answer = (RebootAnswer)_agentMgr.easySend(vm.getHostId(), cmd);
798-
799-
if (answer != null) {
800-
return true;
801-
} else {
802-
return false;
803-
}
800+
return _itMgr.reboot(vm, null, caller, owner);
804801
} else {
805802
s_logger.error("Vm id=" + vmId + " is not in Running state, failed to reboot");
806-
return false;
803+
return null;
807804
}
808805
}
809806
@Override
@@ -1142,9 +1139,17 @@ public UserVm startUserVm(long vmId) throws ConcurrentOperationException, Execut
11421139
public boolean expunge(UserVmVO vm, long callerUserId, Account caller) {
11431140
try {
11441141

1145-
//Cleanup LB/PF rules before expunging the vm
1146-
long vmId = vm.getId();
1147-
//cleanup port forwarding rules
1142+
if (!_itMgr.advanceExpunge(vm, _accountMgr.getSystemUser(), caller)) {
1143+
s_logger.info("Did not expunge " + vm);
1144+
return false;
1145+
}
1146+
1147+
_networkGroupMgr.removeInstanceFromGroups(vm.getId());
1148+
removeInstanceFromGroup(vm.getId());
1149+
1150+
//Cleanup LB/PF rules before expunging the vm
1151+
long vmId = vm.getId();
1152+
//cleanup port forwarding rules
11481153
if (_rulesMgr.revokePortForwardingRule(vmId)) {
11491154
s_logger.debug("Port forwarding rules are removed successfully as a part of vm id=" + vmId + " expunge");
11501155
} else {
@@ -1157,16 +1162,7 @@ public boolean expunge(UserVmVO vm, long callerUserId, Account caller) {
11571162
} else {
11581163
s_logger.warn("Fail to remove lb rules as a part of vm id=" + vmId + " expunge");
11591164
}
1160-
1161-
1162-
if (!_itMgr.advanceExpunge(vm, _accountMgr.getSystemUser(), caller)) {
1163-
s_logger.info("Did not expunge " + vm);
1164-
return false;
1165-
}
1166-
1167-
_networkGroupMgr.removeInstanceFromGroups(vm.getId());
1168-
removeInstanceFromGroup(vm.getId());
1169-
1165+
11701166
_itMgr.remove(vm, _accountMgr.getSystemUser(), caller);
11711167
return true;
11721168
} catch (ResourceUnavailableException e) {
@@ -1622,7 +1618,7 @@ public UserVm startVirtualMachine(StartVMCmd cmd) throws ExecutionException, Con
16221618
}
16231619

16241620
@Override
1625-
public UserVm rebootVirtualMachine(RebootVMCmd cmd) {
1621+
public UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException{
16261622
Account account = UserContext.current().getCaller();
16271623
Long userId = UserContext.current().getCallerUserId();
16281624
Long vmId = cmd.getId();
@@ -1635,14 +1631,7 @@ public UserVm rebootVirtualMachine(RebootVMCmd cmd) {
16351631

16361632
userId = accountAndUserValidation(vmId, account, userId, vmInstance);
16371633

1638-
boolean status = rebootVirtualMachine(userId, vmId);
1639-
1640-
if (status) {
1641-
return _vmDao.findById(vmId);
1642-
} else {
1643-
s_logger.warn("Failed to reboot vm with id: " + vmId);
1644-
return null;
1645-
}
1634+
return rebootVirtualMachine(userId, vmId);
16461635
}
16471636

16481637
@Override

‎server/src/com/cloud/vm/VirtualMachineManager.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,8 @@ <T extends VMInstanceVO> T allocate(T vm,
9595
boolean migrateAway(VirtualMachine.Type type, long vmid, long hostId) throws InsufficientServerCapacityException;
9696

9797
<T extends VMInstanceVO> T migrate(T vm, long srcHostId, DeployDestination dest) throws ResourceUnavailableException;
98+
99+
<T extends VMInstanceVO> T reboot(T vm, Map<String, Object> params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException;
100+
101+
<T extends VMInstanceVO> T advanceReboot(T vm, Map<String, Object> params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException;
98102
}

0 commit comments

Comments
 (0)