mirror of https://github.com/apache/cloudstack.git
bug 10260: propagate ha and deployment planner fixes
This commit is contained in:
parent
d39048faca
commit
63113661d1
|
|
@ -912,7 +912,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
@Override
|
||||
public <T extends VMInstanceVO> boolean advanceStop(T vm, boolean forced, User user, Account account) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
|
||||
long vmId = vm.getId();
|
||||
State state = vm.getState();
|
||||
if (state == State.Stopped) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
|
|
@ -927,25 +926,25 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Long hostId = vm.getHostId();
|
||||
if (hostId == null) {
|
||||
try {
|
||||
stateTransitTo(vm, Event.AgentReportStopped, null, null);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.warn(e.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
VirtualMachineGuru<T> vmGuru = getVmGuru(vm);
|
||||
|
||||
try {
|
||||
if (!stateTransitTo(vm, Event.StopRequested, vm.getHostId())) {
|
||||
if (!stateTransitTo(vm, forced ? Event.AgentReportStopped : Event.StopRequested, vm.getHostId(), null)) {
|
||||
throw new ConcurrentOperationException("VM is being operated on.");
|
||||
}
|
||||
} catch (NoTransitionException e1) {
|
||||
if (!forced) {
|
||||
throw new ConcurrentOperationException("VM is being operated on by someone else.");
|
||||
}
|
||||
|
||||
vm = vmGuru.findById(vmId);
|
||||
if (vm == null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Unable to find VM " + vmId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
throw new CloudRuntimeException("We cannot stop " + vm + " when it is in state " + vm.getState());
|
||||
}
|
||||
|
||||
VirtualMachineProfile<T> profile = new VirtualMachineProfileImpl<T>(vm);
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
SearchCriteria<VMInstanceVO> sc = HostIdUpTypesSearch.create();
|
||||
sc.setParameters("hostid", hostid);
|
||||
sc.setParameters("types", (Object[]) types);
|
||||
sc.setParameters("states", new Object[] {State.Destroyed, State.Stopped, State.Expunging});
|
||||
sc.setParameters("states", new Object[] {State.Destroyed, State.Stopped, State.Expunging});
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
|
@ -252,8 +252,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState(State oldState, Event event,
|
||||
State newState, VirtualMachine vm, Long hostId) {
|
||||
public boolean updateState(State oldState, Event event, State newState, VirtualMachine 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());
|
||||
|
|
@ -263,6 +262,8 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
|
||||
VMInstanceVO vmi = (VMInstanceVO)vm;
|
||||
Long oldHostId = vmi.getHostId();
|
||||
Long oldUpdated = vmi.getUpdated();
|
||||
Date oldUpdateDate = vmi.getUpdateTime();
|
||||
|
||||
SearchCriteria<VMInstanceVO> sc = StateChangeSearch.create();
|
||||
sc.setParameters("id", vmi.getId());
|
||||
|
|
@ -279,15 +280,11 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
|
||||
int result = update(vmi, sc);
|
||||
if (result == 0 && s_logger.isDebugEnabled()) {
|
||||
/*update builder will change the state/hostid/updated, even update is failed*/
|
||||
vmi.setState(oldState);
|
||||
vmi.setHostId(oldHostId);
|
||||
vmi.decrUpdated();
|
||||
|
||||
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(vmi.getUpdated()).append("}");
|
||||
str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated()).append("; time=").append(vo.getUpdateTime());
|
||||
str.append("} New Data: {Host=").append(vm.getHostId()).append("; State=").append(vm.getState().toString()).append("; updated=").append(vmi.getUpdated()).append("; time=").append(vo.getUpdateTime());
|
||||
str.append("} Stale Data: {Host=").append(oldHostId).append("; State=").append(oldState).append("; updated=").append(oldUpdated).append("; time=").append(oldUpdateDate).append("}");
|
||||
s_logger.debug(str.toString());
|
||||
}
|
||||
return result > 0;
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ public class UpdateBuilder implements MethodInterceptor {
|
|||
return _collectionChanges;
|
||||
}
|
||||
|
||||
protected void clear() {
|
||||
public void clear() {
|
||||
_changes.clear();
|
||||
if (_collectionChanges != null) {
|
||||
_collectionChanges.clear();
|
||||
|
|
|
|||
|
|
@ -114,12 +114,15 @@ public class StateMachine2<S, E, V extends StateObject<S>> {
|
|||
|
||||
Long oldHostId = vo.getHostId();
|
||||
transitionStatus = dao.updateState(currentState, e, nextState, vo, id);
|
||||
if (!transitionStatus) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (StateListener<S,E, V> listener : _listeners) {
|
||||
listener.postStateTransitionEvent(currentState, e, nextState, vo, transitionStatus, oldHostId);
|
||||
}
|
||||
|
||||
return transitionStatus;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean registerListener(StateListener<S,E,V> listener) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue