Skip to content
Open
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
92 changes: 49 additions & 43 deletions compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4860,49 +4860,49 @@ public void handle(ErrorCode errCode, Map data) {
}).start();
}

private void handle(final APIRecoverVmInstanceMsg msg) {
thdf.chainSubmit(new ChainTask(msg) {
@Override
public String getSyncSignature() {
return syncThreadName;
}

@Override
public void run(final SyncTaskChain chain) {
final APIRecoverVmInstanceEvent evt = new APIRecoverVmInstanceEvent(msg.getId());
refreshVO();

ErrorCode error = validateOperationByState(msg, self.getState(), SysErrors.OPERATION_ERROR);
if (error != null) {
evt.setError(error);
bus.publish(evt);
chain.next();
return;
}

recoverVm(new Completion(msg, chain) {
@Override
public void success() {
evt.setInventory(getSelfInventory());
bus.publish(evt);
chain.next();
}

@Override
public void fail(ErrorCode errorCode) {
evt.setError(errorCode);
bus.publish(evt);
chain.next();
}
});
}

@Override
public String getName() {
return "recover-vm";
}
});
}
// private void handle(final APIRecoverVmInstanceMsg msg) {
// thdf.chainSubmit(new ChainTask(msg) {
// @Override
// public String getSyncSignature() {
// return syncThreadName;
// }
//
// @Override
// public void run(final SyncTaskChain chain) {
// final APIRecoverVmInstanceEvent evt = new APIRecoverVmInstanceEvent(msg.getId());
// refreshVO();
//
// ErrorCode error = validateOperationByState(msg, self.getState(), SysErrors.OPERATION_ERROR);
// if (error != null) {
// evt.setError(error);
// bus.publish(evt);
// chain.next();
// return;
// }
//
// recoverVm(new Completion(msg, chain) {
// @Override
// public void success() {
// evt.setInventory(getSelfInventory());
// bus.publish(evt);
// chain.next();
// }
//
// @Override
// public void fail(ErrorCode errorCode) {
// evt.setError(errorCode);
// bus.publish(evt);
// chain.next();
// }
// });
// }
//
// @Override
// public String getName() {
// return "recover-vm";
// }
// });
// }
Comment on lines +4863 to +4905
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

恢复 APIRecoverVmInstanceMsg 的实际执行路径,避免当前“注释实现”造成的功能回归与误导

这里把原实现整段注释掉,但 handleApiMessage() 仍然会把 APIRecoverVmInstanceMsg 路由到该 handler;结合下方新增的空实现(Line 9373-9377),当前 API recover 语义等同于被禁用,且从代码阅读角度非常容易误判“只是临时注释”。
建议:要么恢复实现(见下方建议 diff),要么明确删除路由/直接返回错误事件(避免 silent no-op)。

🤖 Prompt for AI Agents
In @compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java around lines
4863 - 4905, The handler for APIRecoverVmInstanceMsg has been fully commented
out while handleApiMessage still routes messages to it, causing a silent no-op;
either restore the original implementation in
VmInstanceBase.handle(APIRecoverVmInstanceMsg) (reintroduce the thdf.chainSubmit
ChainTask that calls validateOperationByState, refreshVO, recoverVm with the
Completion that publishes APIRecoverVmInstanceEvent via bus and uses
getSelfInventory on success), or explicitly remove the routing in
handleApiMessage and return/publish a clear error event immediately so callers
don’t get a silent success; ensure references to APIRecoverVmInstanceMsg,
APIRecoverVmInstanceEvent, validateOperationByState, recoverVm,
getSelfInventory, and thdf.chainSubmit are updated accordingly.


private void handle(final APIExpungeVmInstanceMsg msg) {
final APIExpungeVmInstanceEvent evt = new APIExpungeVmInstanceEvent(msg.getId());
Expand Down Expand Up @@ -9369,5 +9369,11 @@ public void run(MessageReply reply) {
}
});
}

private void handle(final APIRecoverVmInstanceMsg msg) {
//


}
Comment on lines +9373 to +9377
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

阻断级问题:APIRecoverVmInstanceMsg handler 为空,可能导致 API 调用无事件返回/超时

当前方法体为空,且没有发布 APIRecoverVmInstanceEvent,调用侧很可能等不到事件。建议直接恢复原逻辑(或至少 publish error/success event)。

建议修复(恢复为可工作的 handler)
 private void handle(final APIRecoverVmInstanceMsg msg) {
-    //
+    thdf.chainSubmit(new ChainTask(msg) {
+        @Override
+        public String getSyncSignature() {
+            return syncThreadName;
+        }
+
+        @Override
+        public void run(final SyncTaskChain chain) {
+            final APIRecoverVmInstanceEvent evt = new APIRecoverVmInstanceEvent(msg.getId());
+            refreshVO();
+
+            ErrorCode error = validateOperationByState(msg, self.getState(), SysErrors.OPERATION_ERROR);
+            if (error != null) {
+                evt.setError(error);
+                bus.publish(evt);
+                chain.next();
+                return;
+            }
+
+            recoverVm(new Completion(msg, chain) {
+                @Override
+                public void success() {
+                    evt.setInventory(getSelfInventory());
+                    bus.publish(evt);
+                    chain.next();
+                }
+
+                @Override
+                public void fail(ErrorCode errorCode) {
+                    evt.setError(errorCode);
+                    bus.publish(evt);
+                    chain.next();
+                }
+            });
+        }
+
+        @Override
+        public String getName() {
+            return "recover-vm";
+        }
+    });
 }
🤖 Prompt for AI Agents
In @compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java around lines
9373 - 9377, The handler method VmInstanceBase.handle(APIRecoverVmInstanceMsg
msg) is empty and must publish an APIRecoverVmInstanceEvent so callers get a
response; restore the original recovery flow: create an
APIRecoverVmInstanceEvent for msg.getId(), attempt the VM recovery logic (reuse
the existing recovery code path or invoke the recovery helper used elsewhere),
on success set event.setInventory(...) and publish the event via
bus.publish(event), and on failure catch the exception, log it and publish an
event with error code/event.setError(errCode) or throw a CloudRuntimeException
as your pattern requires; ensure you reference APIRecoverVmInstanceMsg,
APIRecoverVmInstanceEvent and the VmInstanceBase.handle(...) method when
implementing the fix.

}