mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Removed the remove method. Not sure why we added to VirtualMachineManager
This commit is contained in:
parent
3ae0acc26f
commit
9bc5870f01
@ -733,7 +733,8 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast
|
||||
if (gceed) {
|
||||
try {
|
||||
s_logger.info("Attempting to destroy ELB VM: " + elbVm);
|
||||
_itMgr.expunge(elbVm, user, _systemAcct);
|
||||
_itMgr.expunge(elbVm.getUuid());
|
||||
_routerDao.remove(elbVm.getId());
|
||||
} catch (ResourceUnavailableException e) {
|
||||
s_logger.warn("Unable to destroy unused ELB vm " + elbVm + " due to ", e);
|
||||
gceed = false;
|
||||
|
||||
@ -513,7 +513,9 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements
|
||||
|
||||
_accountMgr.checkAccess(caller, null, true, internalLbVm);
|
||||
|
||||
return _itMgr.expunge(internalLbVm, _accountMgr.getActiveUser(callerUserId), caller);
|
||||
_itMgr.expunge(internalLbVm.getUuid());
|
||||
_internalLbVmDao.remove(internalLbVm.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -24,13 +24,8 @@ import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
|
||||
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -38,6 +33,9 @@ import org.mockito.Mockito;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
|
||||
import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
@ -56,12 +54,12 @@ import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.router.VirtualRouter.Role;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.LoadBalancerContainer.Scheme;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.Ip;
|
||||
@ -103,6 +101,7 @@ public class InternalLBVMManagerTest extends TestCase {
|
||||
long validVmId = 1L;
|
||||
long invalidVmId = 2L;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
//mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
|
||||
@ -160,12 +159,6 @@ public class InternalLBVMManagerTest extends TestCase {
|
||||
networkOfferingVO.setConcurrentConnections(500);
|
||||
Mockito.when(_offeringDao.findById(Mockito.anyLong())).thenReturn(networkOfferingVO);
|
||||
|
||||
try {
|
||||
Mockito.when(_itMgr.expunge(Mockito.any(DomainRouterVO.class), Mockito.any(User.class), Mockito.any(Account.class))).thenReturn(true);
|
||||
} catch (ResourceUnavailableException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm);
|
||||
Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null);
|
||||
|
||||
@ -1152,17 +1152,16 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
|
||||
ConsoleProxyVO proxy = _consoleProxyDao.findById(vmId);
|
||||
try {
|
||||
//expunge the vm
|
||||
boolean result = _itMgr.expunge(proxy, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||
if (result) {
|
||||
HostVO host = _hostDao.findByTypeNameAndZoneId(proxy.getDataCenterId(), proxy.getHostName(),
|
||||
Host.Type.ConsoleProxy);
|
||||
if (host != null) {
|
||||
s_logger.debug("Removing host entry for proxy id=" + vmId);
|
||||
result = result && _hostDao.remove(host.getId());
|
||||
}
|
||||
_itMgr.expunge(proxy.getUuid());
|
||||
_consoleProxyDao.remove(vmId);
|
||||
HostVO host = _hostDao.findByTypeNameAndZoneId(proxy.getDataCenterId(), proxy.getHostName(),
|
||||
Host.Type.ConsoleProxy);
|
||||
if (host != null) {
|
||||
s_logger.debug("Removing host entry for proxy id=" + vmId);
|
||||
return _hostDao.remove(host.getId());
|
||||
}
|
||||
|
||||
return result;
|
||||
return true;
|
||||
} catch (ResourceUnavailableException e) {
|
||||
s_logger.warn("Unable to expunge " + proxy, e);
|
||||
return false;
|
||||
|
||||
@ -421,12 +421,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
|
||||
_accountMgr.checkAccess(caller, null, true, router);
|
||||
|
||||
boolean result = _itMgr.expunge(router, _accountMgr.getActiveUser(callerUserId), _accountMgr.getAccount(router.getAccountId()));
|
||||
|
||||
if (result) {
|
||||
return router;
|
||||
}
|
||||
return null;
|
||||
_itMgr.expunge(router.getUuid());
|
||||
_routerDao.remove(router.getId());
|
||||
return router;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -968,17 +968,16 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
|
||||
SecondaryStorageVmVO ssvm = _secStorageVmDao.findById(vmId);
|
||||
|
||||
try {
|
||||
boolean result = _itMgr.expunge(ssvm, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
|
||||
if (result) {
|
||||
HostVO host = _hostDao.findByTypeNameAndZoneId(ssvm.getDataCenterId(), ssvm.getHostName(),
|
||||
Host.Type.SecondaryStorageVM);
|
||||
if (host != null) {
|
||||
s_logger.debug("Removing host entry for ssvm id=" + vmId);
|
||||
result = result && _hostDao.remove(host.getId());
|
||||
}
|
||||
_itMgr.expunge(ssvm.getUuid());
|
||||
_secStorageVmDao.remove(ssvm.getId());
|
||||
HostVO host = _hostDao.findByTypeNameAndZoneId(ssvm.getDataCenterId(), ssvm.getHostName(),
|
||||
Host.Type.SecondaryStorageVM);
|
||||
if (host != null) {
|
||||
s_logger.debug("Removing host entry for ssvm id=" + vmId);
|
||||
_hostDao.remove(host.getId());
|
||||
}
|
||||
|
||||
return result;
|
||||
return true;
|
||||
} catch (ResourceUnavailableException e) {
|
||||
s_logger.warn("Unable to expunge " + ssvm, e);
|
||||
return false;
|
||||
|
||||
@ -1503,10 +1503,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
@Override
|
||||
public boolean expunge(UserVmVO vm, long callerUserId, Account caller) {
|
||||
try {
|
||||
List<VolumeVO> rootVol = _volsDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT);
|
||||
// expunge the vm
|
||||
if (!_itMgr.advanceExpunge(vm, _accountMgr.getSystemUser(), caller)) {
|
||||
s_logger.info("Did not expunge " + vm);
|
||||
return false;
|
||||
_itMgr.advanceExpunge(vm.getUuid());
|
||||
// Update Resource count
|
||||
if (vm.getAccountId() != Account.ACCOUNT_ID_SYSTEM && !rootVol.isEmpty()) {
|
||||
_resourceLimitMgr.decrementResourceCount(vm.getAccountId(), ResourceType.volume);
|
||||
_resourceLimitMgr.decrementResourceCount(vm.getAccountId(), ResourceType.primary_storage,
|
||||
new Long(rootVol.get(0).getSize()));
|
||||
}
|
||||
|
||||
// Only if vm is not expunged already, cleanup it's resources
|
||||
@ -1524,7 +1528,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
return false;
|
||||
}
|
||||
|
||||
_itMgr.remove(vm, _accountMgr.getSystemUser(), caller);
|
||||
_vmDao.remove(vm.getId());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@ -78,7 +78,7 @@ public interface VirtualMachineManager extends Manager {
|
||||
|
||||
void stop(String vmUuid) throws ResourceUnavailableException;
|
||||
|
||||
<T extends VMInstanceVO> boolean expunge(T vm, User caller, Account account) throws ResourceUnavailableException;
|
||||
void expunge(String vmUuid) throws ResourceUnavailableException;
|
||||
|
||||
void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru);
|
||||
|
||||
@ -92,9 +92,7 @@ public interface VirtualMachineManager extends Manager {
|
||||
|
||||
void advanceStop(String vmUuid, boolean cleanupEvenIfUnableToStop) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException;
|
||||
|
||||
<T extends VMInstanceVO> boolean advanceExpunge(T vm, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException;
|
||||
|
||||
<T extends VMInstanceVO> boolean remove(T vm, User caller, Account account);
|
||||
void advanceExpunge(String vmUuid) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException;
|
||||
|
||||
void destroy(String vmUuid) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException;
|
||||
|
||||
|
||||
@ -83,7 +83,6 @@ import com.cloud.alert.AlertManager;
|
||||
import com.cloud.capacity.CapacityManager;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.Resource.ResourceType;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.ClusterDetailsDao;
|
||||
import com.cloud.dc.ClusterDetailsVO;
|
||||
@ -395,16 +394,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends VMInstanceVO> boolean expunge(T vm, User caller, Account account) throws ResourceUnavailableException {
|
||||
public void expunge(String vmUuid) throws ResourceUnavailableException {
|
||||
try {
|
||||
if (advanceExpunge(vm, caller, account)) {
|
||||
// Mark vms as removed
|
||||
remove(vm, caller, account);
|
||||
return true;
|
||||
} else {
|
||||
s_logger.info("Did not expunge " + vm);
|
||||
return false;
|
||||
}
|
||||
advanceExpunge(vmUuid);
|
||||
} catch (OperationTimedoutException e) {
|
||||
throw new CloudRuntimeException("Operation timed out", e);
|
||||
} catch (ConcurrentOperationException e) {
|
||||
@ -413,12 +405,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends VMInstanceVO> boolean advanceExpunge(T vm, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException {
|
||||
public void advanceExpunge(String vmUuid) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException {
|
||||
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
|
||||
advanceExpunge(vm);
|
||||
}
|
||||
|
||||
protected void advanceExpunge(VMInstanceVO vm) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException {
|
||||
if (vm == null || vm.getRemoved() != null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Unable to find vm or vm is destroyed: " + vm);
|
||||
}
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
advanceStop(vm, false);
|
||||
@ -426,11 +423,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
try {
|
||||
if (!stateTransitTo(vm, VirtualMachine.Event.ExpungeOperation, vm.getHostId())) {
|
||||
s_logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm);
|
||||
return false;
|
||||
throw new CloudRuntimeException("Unable to destroy " + vm);
|
||||
|
||||
}
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm);
|
||||
return false;
|
||||
throw new CloudRuntimeException("Unable to destroy " + vm, e);
|
||||
}
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
@ -450,7 +448,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
_networkMgr.cleanupNics(profile);
|
||||
|
||||
// Clean up volumes based on the vm's instance id
|
||||
List<VolumeVO> rootVol = _volsDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT);
|
||||
volumeMgr.cleanupVolumes(vm.getId());
|
||||
|
||||
VirtualMachineGuru guru = getVmGuru(vm);
|
||||
@ -475,12 +472,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
_agentMgr.send(hostId, cmds);
|
||||
if(!cmds.isSuccessful()){
|
||||
for (Answer answer : cmds.getAnswers()){
|
||||
if(answer != null && !answer.getResult()){
|
||||
if (!answer.getResult()) {
|
||||
s_logger.warn("Failed to expunge vm due to: " + answer.getDetails());
|
||||
break;
|
||||
throw new CloudRuntimeException("Unable to expunge " + vm + " due to " + answer.getDetails());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -489,13 +485,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
s_logger.debug("Expunged " + vm);
|
||||
}
|
||||
|
||||
// Update Resource count
|
||||
if (vm.getAccountId() != Account.ACCOUNT_ID_SYSTEM && !rootVol.isEmpty()) {
|
||||
_resourceLimitMgr.decrementResourceCount(vm.getAccountId(), ResourceType.volume);
|
||||
_resourceLimitMgr.decrementResourceCount(vm.getAccountId(), ResourceType.primary_storage,
|
||||
new Long(rootVol.get(0).getSize()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@DB
|
||||
@ -1335,11 +1324,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
|
||||
return _stateMachine.transitTo(vm, e, new Pair<Long, Long>(vm.getHostId(), hostId), _vmDao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends VMInstanceVO> boolean remove(T vm, User user, Account caller) {
|
||||
return _vmDao.remove(vm.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(String vmUuid) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
|
||||
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user