mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
Removed useless methods
This commit is contained in:
parent
f97a5e78cb
commit
ca22308d7d
@ -478,49 +478,50 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager {
|
||||
while (retry-- != 0) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
if (stateTransitTo(vm, Event.StartRequested, null, work.getId())) {
|
||||
|
||||
Journal journal = new Journal.LogJournal("Creating " + vm, s_logger);
|
||||
work = _workDao.persist(work);
|
||||
ReservationContextImpl context = new ReservationContextImpl(work.getId(), journal, caller, account);
|
||||
try {
|
||||
if (stateTransitTo(vm, Event.StartRequested, null, work.getId())) {
|
||||
|
||||
Journal journal = new Journal.LogJournal("Creating " + vm, s_logger);
|
||||
work = _workDao.persist(work);
|
||||
ReservationContextImpl context = new ReservationContextImpl(work.getId(), journal, caller, account);
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Successfully transitioned to start state for " + vm + " reservation id = " + work.getId());
|
||||
}
|
||||
return new Ternary<T, ReservationContext, ItWorkVO>(vmGuru.findById(vmId), context, work);
|
||||
}
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Successfully transitioned to start state for " + vm + " reservation id = " + work.getId());
|
||||
s_logger.debug("Determining why we're unable to update the state to Starting for " + vm);
|
||||
}
|
||||
|
||||
VMInstanceVO instance = _vmDao.lockRow(vmId, true);
|
||||
if (instance == null) {
|
||||
throw new ConcurrentOperationException("Unable to acquire lock on " + vm);
|
||||
}
|
||||
txn.commit();
|
||||
return new Ternary<T, ReservationContext, ItWorkVO>(vmGuru.findById(vmId), context, work);
|
||||
}
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Determining why we're unable to update the state to Starting for " + vm);
|
||||
}
|
||||
|
||||
VMInstanceVO instance = _vmDao.lockRow(vmId, true);
|
||||
if (instance == null) {
|
||||
throw new ConcurrentOperationException("Unable to acquire lock on " + vm);
|
||||
}
|
||||
|
||||
State state = instance.getState();
|
||||
if (state == State.Running) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("VM is already started: " + vm);
|
||||
|
||||
State state = instance.getState();
|
||||
if (state == State.Running) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("VM is already started: " + vm);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
txn.commit();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (state.isTransitional()) {
|
||||
if (!checkWorkItems(vm, state)) {
|
||||
throw new ConcurrentOperationException("There are concurrent operations on the VM " + vm);
|
||||
} else {
|
||||
continue;
|
||||
|
||||
if (state.isTransitional()) {
|
||||
if (!checkWorkItems(vm, state)) {
|
||||
throw new ConcurrentOperationException("There are concurrent operations on the VM " + vm);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state != State.Stopped) {
|
||||
s_logger.debug("VM " + vm + " is not in a state to be started: " + state);
|
||||
|
||||
if (state != State.Stopped) {
|
||||
s_logger.debug("VM " + vm + " is not in a state to be started: " + state);
|
||||
return null;
|
||||
}
|
||||
} finally {
|
||||
txn.commit();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -898,17 +899,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager {
|
||||
|
||||
protected boolean stateTransitTo(VMInstanceVO vm, VirtualMachine.Event e, Long hostId, String reservationId) {
|
||||
vm.setReservationId(reservationId);
|
||||
if (vm instanceof UserVmVO) {
|
||||
return _stateMachine.transitTo(vm, e, hostId, _userVmDao);
|
||||
} else if (vm instanceof ConsoleProxyVO) {
|
||||
return _stateMachine.transitTo(vm, e, hostId, _consoleDao);
|
||||
} else if (vm instanceof SecondaryStorageVmVO) {
|
||||
return _stateMachine.transitTo(vm, e, hostId, _secondaryDao);
|
||||
} else if (vm instanceof DomainRouterVO) {
|
||||
return _stateMachine.transitTo(vm, e, hostId, _routerDao);
|
||||
} else {
|
||||
return _stateMachine.transitTo(vm, e, hostId, _vmDao);
|
||||
}
|
||||
return _stateMachine.transitTo(vm, e, hostId, _vmDao);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -24,13 +24,10 @@ import java.util.List;
|
||||
import com.cloud.info.ConsoleProxyLoadInfo;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.fsm.StateDao;
|
||||
import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
public interface ConsoleProxyDao extends GenericDao<ConsoleProxyVO, Long>, StateDao<State, VirtualMachine.Event, VMInstanceVO> {
|
||||
public interface ConsoleProxyDao extends GenericDao<ConsoleProxyVO, Long> {
|
||||
|
||||
public void update(long id, int activeSession, Date updateTime, byte[] sessionDetails);
|
||||
|
||||
@ -49,6 +46,4 @@ public interface ConsoleProxyDao extends GenericDao<ConsoleProxyVO, Long>, State
|
||||
public int getProxyStaticLoad(long proxyVmId);
|
||||
public int getProxyActiveLoad(long proxyVmId);
|
||||
public List<Long> getRunningProxyListByMsid(long msid);
|
||||
|
||||
public boolean updateIf(ConsoleProxyVO vm, VirtualMachine.Event event, Long hostId);
|
||||
}
|
||||
|
||||
@ -38,9 +38,6 @@ import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.Event;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
@Local(value={ConsoleProxyDao.class})
|
||||
@ -153,59 +150,6 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase<ConsoleProxyVO, Long> im
|
||||
assert _updateTimeAttr != null : "Couldn't get this updateTime attribute";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateIf(ConsoleProxyVO vm, VirtualMachine.Event event, Long hostId) {
|
||||
State oldState = vm.getState();
|
||||
State newState = oldState.getNextState(event);
|
||||
|
||||
Long oldHostId = vm.getHostId();
|
||||
long oldDate = vm.getUpdated();
|
||||
|
||||
if (newState == null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SearchCriteria<ConsoleProxyVO> sc = StateChangeSearch.create();
|
||||
sc.setParameters("id", vm.getId());
|
||||
sc.setParameters("states", oldState);
|
||||
sc.setParameters("host", vm.getHostId());
|
||||
sc.setParameters("update", vm.getUpdated());
|
||||
|
||||
vm.incrUpdated();
|
||||
UpdateBuilder ub = getUpdateBuilder(vm);
|
||||
|
||||
if(newState == State.Running) {
|
||||
// save current running host id
|
||||
ub.set(vm, "lastHostId", vm.getHostId());
|
||||
}
|
||||
|
||||
ub.set(vm, _updateTimeAttr, new Date());
|
||||
ub.set(vm, "state", newState);
|
||||
ub.set(vm, "hostId", hostId);
|
||||
|
||||
if (newState == State.Stopped) {
|
||||
vm.setActiveSession(0);
|
||||
ub.set(vm, "hostId", null);
|
||||
}
|
||||
|
||||
int result = update(vm, sc);
|
||||
|
||||
if (result == 0 && s_logger.isDebugEnabled()) {
|
||||
ConsoleProxyVO vo = findById(vm.getId());
|
||||
StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
|
||||
str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated());
|
||||
str.append("} New Data: {Host=").append(vm.getHostId()).append("; State=").append(vm.getState().toString()).append("; updated=").append(vm.getUpdated());
|
||||
str.append("} Stale Data: {Host=").append(oldHostId).append("; State=").append(oldState.toString()).append("; updated=").append(oldDate).append("}");
|
||||
s_logger.debug(str.toString());
|
||||
}
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(long id, int activeSession, Date updateTime, byte[] sessionDetails) {
|
||||
ConsoleProxyVO ub = createForUpdate();
|
||||
@ -399,41 +343,6 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase<ConsoleProxyVO, Long> im
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState(State oldState, Event event,
|
||||
State newState, VMInstanceVO vm, Long hostId) {
|
||||
if (newState == null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ConsoleProxyVO consoleVM = (ConsoleProxyVO)vm;
|
||||
|
||||
SearchCriteria<ConsoleProxyVO> sc = StateChangeSearch.create();
|
||||
sc.setParameters("id", consoleVM.getId());
|
||||
sc.setParameters("states", oldState);
|
||||
sc.setParameters("host", consoleVM.getHostId());
|
||||
sc.setParameters("update", consoleVM.getUpdated());
|
||||
|
||||
vm.incrUpdated();
|
||||
UpdateBuilder ub = getUpdateBuilder(consoleVM);
|
||||
ub.set(consoleVM, "state", newState);
|
||||
ub.set(consoleVM, "hostId", hostId);
|
||||
ub.set(consoleVM, _updateTimeAttr, new Date());
|
||||
|
||||
int result = update(consoleVM, sc);
|
||||
if (result == 0 && s_logger.isDebugEnabled()) {
|
||||
ConsoleProxyVO vo = findById(consoleVM.getId());
|
||||
StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
|
||||
str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated());
|
||||
str.append("} Stale Data: {Host=").append(consoleVM.getHostId()).append("; State=").append(consoleVM.getState().toString()).append("; updated=").append(consoleVM.getUpdated()).append("}");
|
||||
s_logger.debug(str.toString());
|
||||
}
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConsoleProxyVO> listByLastHostId(long hostId) {
|
||||
SearchCriteria<ConsoleProxyVO> sc = LastHostSearch.create();
|
||||
|
||||
@ -20,13 +20,10 @@ package com.cloud.vm.dao;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.fsm.StateDao;
|
||||
import com.cloud.vm.SecondaryStorageVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
public interface SecondaryStorageVmDao extends GenericDao<SecondaryStorageVmVO, Long>, StateDao<State, VirtualMachine.Event, VMInstanceVO> {
|
||||
public interface SecondaryStorageVmDao extends GenericDao<SecondaryStorageVmVO, Long> {
|
||||
|
||||
public List<SecondaryStorageVmVO> getSecStorageVmListInStates(long dataCenterId, State... states);
|
||||
public List<SecondaryStorageVmVO> getSecStorageVmListInStates(State... states);
|
||||
@ -40,6 +37,4 @@ public interface SecondaryStorageVmDao extends GenericDao<SecondaryStorageVmVO,
|
||||
|
||||
|
||||
public List<Long> getRunningSecStorageVmListByMsid(long msid);
|
||||
|
||||
public boolean updateIf(SecondaryStorageVmVO vm, VirtualMachine.Event event, Long hostId);
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Local;
|
||||
@ -35,9 +34,6 @@ import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
import com.cloud.vm.SecondaryStorageVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.Event;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
@Local(value={SecondaryStorageVmDao.class})
|
||||
@ -93,56 +89,6 @@ public class SecondaryStorageVmDaoImpl extends GenericDaoBase<SecondaryStorageVm
|
||||
assert _updateTimeAttr != null : "Couldn't get this updateTime attribute";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateIf(SecondaryStorageVmVO vm, VirtualMachine.Event event, Long hostId) {
|
||||
State oldState = vm.getState();
|
||||
State newState = oldState.getNextState(event);
|
||||
|
||||
Long oldHostId = vm.getHostId();
|
||||
long oldDate = vm.getUpdated();
|
||||
|
||||
if (newState == null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SearchCriteria<SecondaryStorageVmVO> sc = StateChangeSearch.create();
|
||||
sc.setParameters("id", vm.getId());
|
||||
sc.setParameters("states", oldState);
|
||||
sc.setParameters("host", vm.getHostId());
|
||||
sc.setParameters("update", vm.getUpdated());
|
||||
|
||||
vm.incrUpdated();
|
||||
UpdateBuilder ub = getUpdateBuilder(vm);
|
||||
if(newState == State.Running) {
|
||||
// save current running host id
|
||||
ub.set(vm, "lastHostId", vm.getHostId());
|
||||
}
|
||||
|
||||
ub.set(vm, _updateTimeAttr, new Date());
|
||||
ub.set(vm, "state", newState);
|
||||
ub.set(vm, "hostId", hostId);
|
||||
if (newState == State.Stopped) {
|
||||
ub.set(vm, "hostId", null);
|
||||
}
|
||||
|
||||
int result = update(vm, sc);
|
||||
|
||||
if (result == 0 && s_logger.isDebugEnabled()) {
|
||||
SecondaryStorageVmVO vo = findById(vm.getId());
|
||||
StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
|
||||
str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated());
|
||||
str.append("} New Data: {Host=").append(vm.getHostId()).append("; State=").append(vm.getState().toString()).append("; updated=").append(vm.getUpdated());
|
||||
str.append("} Stale Data: {Host=").append(oldHostId).append("; State=").append(oldState.toString()).append("; updated=").append(oldDate).append("}");
|
||||
s_logger.debug(str.toString());
|
||||
}
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean remove(Long id) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
@ -219,41 +165,6 @@ public class SecondaryStorageVmDaoImpl extends GenericDaoBase<SecondaryStorageVm
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState(State oldState, Event event,
|
||||
State newState, VMInstanceVO vm, Long hostId) {
|
||||
if (newState == null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SecondaryStorageVmVO secondaryVM = (SecondaryStorageVmVO)vm;
|
||||
|
||||
SearchCriteria<SecondaryStorageVmVO> sc = StateChangeSearch.create();
|
||||
sc.setParameters("id", secondaryVM.getId());
|
||||
sc.setParameters("states", oldState);
|
||||
sc.setParameters("host", secondaryVM.getHostId());
|
||||
sc.setParameters("update", secondaryVM.getUpdated());
|
||||
|
||||
vm.incrUpdated();
|
||||
UpdateBuilder ub = getUpdateBuilder(secondaryVM);
|
||||
ub.set(secondaryVM, "state", newState);
|
||||
ub.set(secondaryVM, "hostId", hostId);
|
||||
ub.set(secondaryVM, _updateTimeAttr, new Date());
|
||||
|
||||
int result = update(secondaryVM, sc);
|
||||
if (result == 0 && s_logger.isDebugEnabled()) {
|
||||
SecondaryStorageVmVO vo = findById(secondaryVM.getId());
|
||||
StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
|
||||
str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated());
|
||||
str.append("} Stale Data: {Host=").append(secondaryVM.getHostId()).append("; State=").append(secondaryVM.getState().toString()).append("; updated=").append(secondaryVM.getUpdated()).append("}");
|
||||
s_logger.debug(str.toString());
|
||||
}
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SecondaryStorageVmVO> listByLastHostId(long hostId) {
|
||||
SearchCriteria<SecondaryStorageVmVO> sc = LastHostSearch.create();
|
||||
|
||||
@ -22,13 +22,10 @@ import java.util.List;
|
||||
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.fsm.StateDao;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
public interface UserVmDao extends GenericDao<UserVmVO, Long>, StateDao<State, VirtualMachine.Event, VMInstanceVO> {
|
||||
public interface UserVmDao extends GenericDao<UserVmVO, Long> {
|
||||
List<UserVmVO> listByAccountId(long id);
|
||||
|
||||
List<UserVmVO> listByAccountAndPod(long accountId, long podId);
|
||||
@ -47,21 +44,6 @@ public interface UserVmDao extends GenericDao<UserVmVO, Long>, StateDao<State, V
|
||||
|
||||
UserVmVO findByName(String name);
|
||||
|
||||
/**
|
||||
* This method is of supreme importance in the management of VMs. It updates a uservm if and only if
|
||||
* the following condition are true. If the update is complete, all changes to the uservm entity
|
||||
* are persisted. The state is also changed to the new state.
|
||||
*
|
||||
* 1. There's a transition from the current state via the event to a new state.
|
||||
* 2. The db has not changed on the current state, update time, and host id sent.
|
||||
*
|
||||
* @param vm vm object to persist.
|
||||
* @param event
|
||||
* @param hostId
|
||||
* @return true if updated, false if not.
|
||||
*/
|
||||
boolean updateIf(UserVmVO vm, VirtualMachine.Event event, Long hostId);
|
||||
|
||||
/**
|
||||
* Updates display name and group for vm; enables/disables ha
|
||||
* @param id vm id.
|
||||
|
||||
@ -32,17 +32,13 @@ import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.JoinBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.UpdateBuilder;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.Event;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
@Local(value={UserVmDao.class})
|
||||
public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements UserVmDao {
|
||||
public static final Logger s_logger = Logger.getLogger(UserVmDaoImpl.class.getName());
|
||||
public static final Logger s_logger = Logger.getLogger(UserVmDaoImpl.class);
|
||||
|
||||
protected final SearchBuilder<UserVmVO> RouterStateSearch;
|
||||
protected final SearchBuilder<UserVmVO> RouterIdSearch;
|
||||
@ -200,57 +196,6 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
||||
return listIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateIf(UserVmVO vm, VirtualMachine.Event event, Long hostId) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("UpdateIf called " + vm.toString() + " event " + event.toString() + " host " + hostId);
|
||||
}
|
||||
|
||||
State oldState = vm.getState();
|
||||
State newState = oldState.getNextState(event);
|
||||
Long oldHostId = vm.getHostId();
|
||||
long oldDate = vm.getUpdated();
|
||||
|
||||
|
||||
if (newState == null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SearchCriteria<UserVmVO> sc = StateChangeSearch.create();
|
||||
sc.setParameters("id", vm.getId());
|
||||
sc.setParameters("states", oldState);
|
||||
sc.setParameters("host", vm.getHostId());
|
||||
sc.setParameters("update", vm.getUpdated());
|
||||
|
||||
vm.incrUpdated();
|
||||
UpdateBuilder ub = getUpdateBuilder(vm);
|
||||
if(newState == State.Running) {
|
||||
// save current running host id to last_host_id field
|
||||
ub.set(vm, "lastHostId", vm.getHostId());
|
||||
} else if(newState == State.Expunging) {
|
||||
ub.set(vm, "lastHostId", null);
|
||||
}
|
||||
|
||||
ub.set(vm, "state", newState);
|
||||
ub.set(vm, "hostId", hostId);
|
||||
ub.set(vm, _updateTimeAttr, new Date());
|
||||
|
||||
int result = update(vm, sc);
|
||||
if (result == 0 && s_logger.isDebugEnabled()) {
|
||||
UserVmVO vo = findById(vm.getId());
|
||||
StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
|
||||
str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated());
|
||||
str.append("} New Data: {Host=").append(vm.getHostId()).append("; State=").append(vm.getState().toString()).append("; updated=").append(vm.getUpdated());
|
||||
str.append("} Stale Data: {Host=").append(oldHostId).append("; State=").append(oldState.toString()).append("; updated=").append(oldDate).append("}");
|
||||
s_logger.debug(str.toString());
|
||||
}
|
||||
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserVmVO> findDestroyedVms(Date date) {
|
||||
SearchCriteria<UserVmVO> sc = DestroySearch.create();
|
||||
@ -361,41 +306,6 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState(State oldState, Event event,
|
||||
State newState, VMInstanceVO vm, Long hostId) {
|
||||
if (newState == null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
UserVmVO userVM = (UserVmVO)vm;
|
||||
|
||||
SearchCriteria<UserVmVO> sc = StateChangeSearch.create();
|
||||
sc.setParameters("id", userVM.getId());
|
||||
sc.setParameters("states", oldState);
|
||||
sc.setParameters("host", userVM.getHostId());
|
||||
sc.setParameters("update", userVM.getUpdated());
|
||||
|
||||
vm.incrUpdated();
|
||||
UpdateBuilder ub = getUpdateBuilder(userVM);
|
||||
ub.set(userVM, "state", newState);
|
||||
ub.set(userVM, "hostId", hostId);
|
||||
ub.set(userVM, _updateTimeAttr, new Date());
|
||||
|
||||
int result = update(userVM, sc);
|
||||
if (result == 0 && s_logger.isDebugEnabled()) {
|
||||
UserVmVO vo = findById(userVM.getId());
|
||||
StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
|
||||
str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated());
|
||||
str.append("} Stale Data: {Host=").append(userVM.getHostId()).append("; State=").append(userVM.getState().toString()).append("; updated=").append(userVM.getUpdated()).append("}");
|
||||
s_logger.debug(str.toString());
|
||||
}
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserVmVO> listByLastHostId(Long hostId) {
|
||||
SearchCriteria<UserVmVO> sc = LastHostSearch.create();
|
||||
|
||||
@ -53,8 +53,6 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
|
||||
*/
|
||||
public List<VMInstanceVO> listNonExpungedByZoneAndTemplate(long zoneId, long templateId);
|
||||
|
||||
boolean updateIf(VMInstanceVO vm, VirtualMachine.Event event, Long hostId, String reservationId);
|
||||
|
||||
/**
|
||||
* Find vm instance with names like.
|
||||
*
|
||||
|
||||
@ -153,44 +153,6 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateIf(VMInstanceVO vm, VirtualMachine.Event event, Long hostId, String reservationId) {
|
||||
|
||||
State oldState = vm.getState();
|
||||
State newState = oldState.getNextState(event);
|
||||
|
||||
if (newState == null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SearchCriteria<VMInstanceVO> sc = StateChangeSearch.create();
|
||||
sc.setParameters("id", vm.getId());
|
||||
sc.setParameters("states", oldState);
|
||||
sc.setParameters("host", vm.getHostId());
|
||||
sc.setParameters("update", vm.getUpdated());
|
||||
|
||||
vm.incrUpdated();
|
||||
vm.setReservationId(reservationId);
|
||||
UpdateBuilder ub = getUpdateBuilder(vm);
|
||||
ub.set(vm, "state", newState);
|
||||
ub.set(vm, "hostId", hostId);
|
||||
ub.set(vm, _updateTimeAttr, new Date());
|
||||
|
||||
|
||||
int result = update(vm, sc);
|
||||
if (result == 0 && s_logger.isDebugEnabled()) {
|
||||
VMInstanceVO vo = findById(vm.getId());
|
||||
StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString());
|
||||
str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated());
|
||||
str.append("} Stale Data: {Host=").append(vm.getHostId()).append("; State=").append(vm.getState().toString()).append("; updated=").append(vm.getUpdated()).append("}");
|
||||
s_logger.debug(str.toString());
|
||||
}
|
||||
return result > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMInstanceVO> listByHostId(long hostid) {
|
||||
SearchCriteria<VMInstanceVO> sc = HostSearch.create();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user