Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ protected VmInstanceVO changeVmStateInDb(VmInstanceStateEvent stateEvent) {
}

protected VmInstanceVO changeVmStateInDb(VmInstanceStateEvent stateEvent, Runnable runnable) {
return changeVmStateInDb(stateEvent, runnable, null);
}

protected VmInstanceVO changeVmStateInDb(VmInstanceStateEvent stateEvent, Runnable runnable, String stateChangeSource) {
VmInstanceState bs = self.getState();
final VmInstanceState state = self.getState().nextState(stateEvent);

Expand Down Expand Up @@ -374,6 +378,7 @@ protected void scripts() {
data.setVmUuid(self.getUuid());
data.setOldState(bs.toString());
data.setNewState(state.toString());
data.setStateChangeSource(stateChangeSource);
data.setInventory(getSelfInventory());
evtf.fire(VmCanonicalEvents.VM_FULL_STATE_CHANGED_PATH, data);

Expand Down Expand Up @@ -1004,16 +1009,7 @@ public void done(ErrorCodeList errorCodeList) {

logger.debug(String.format("HaStartVmJudger[%s] says the VM[uuid:%s, name:%s] is qualified for HA start, now we are starting it",
judger.getClass(), self.getUuid(), self.getName()));
UpdateQuery sql = SQL.New(VmInstanceVO.class)
.eq(VmInstanceVO_.uuid, self.getUuid())
.set(VmInstanceVO_.state, VmInstanceState.Stopped)
.set(VmInstanceVO_.hostUuid, null);

if (self.getHostUuid() != null) {
sql.set(VmInstanceVO_.lastHostUuid, self.getHostUuid());
}

sql.update();
changeVmStateInDb(VmInstanceStateEvent.stopped, null, HaStartVmInstanceMsg.class.getName());

startVm(msg, new Completion(msg, chain) {
@Override
Expand Down Expand Up @@ -8984,4 +8980,3 @@ public void run(MessageReply reply) {
});
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public static class VmStateChangedData {
private String vmUuid;
private String oldState;
private String newState;
private String stateChangeSource;
private VmInstanceInventory inventory;
private Date date = new Date();

Expand Down Expand Up @@ -197,6 +198,14 @@ public String getNewState() {
public void setNewState(String newState) {
this.newState = newState;
}

public String getStateChangeSource() {
return stateChangeSource;
}

public void setStateChangeSource(String stateChangeSource) {
this.stateChangeSource = stateChangeSource;
}
}

@NeedJsonSchema
Expand Down