Damans227 commented on code in PR #13788:
URL: https://github.com/apache/cloudstack/pull/13788#discussion_r4696637368
##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -460,8 +460,13 @@ private AgentControlAnswer handleControlCommand(final
AgentAttache attache, fina
public void handleCommands(final AgentAttache attache, final long
sequence, final Command[] cmds) {
for (final Pair<Integer, Listener> listener : _cmdMonitors) {
- final boolean processed =
listener.second().processCommands(attache.getId(), sequence, cmds);
- logger.trace("SeqA {}-{}: {} by {}", attache.getId(), sequence,
(processed ? "processed" : "not processed"), listener.getClass());
+ try {
+ final boolean processed =
listener.second().processCommands(attache.getId(), sequence, cmds);
+ logger.trace("SeqA {}-{}: {} by {}", attache.getId(),
sequence, (processed ? "processed" : "not processed"),
listener.second().getClass());
+ } catch (final Exception e) {
+ logger.warn("Listener {} threw an exception processing
commands for agent {} seq {}; continuing to next listener",
+ listener.second().getClass().getName(),
attache.getId(), sequence, e);
+ }
Review Comment:
processCommands doesnt declare any checked exception, so an
InterruptedException cant reach this catch. a separate catch for it wouldnt
compile.
##########
engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java:
##########
@@ -210,6 +210,53 @@ public void
testUpdatePowerStateNoChangeMaxUpdatesInvalidStateVmRunning() {
assertTrue(result);
}
+ /*
+ * Mirrors testUpdatePowerStateNoChangeMaxUpdatesInvalidStateVmStopped but
with a null
+ * hostId (the default from setUp), which is what happens when the row was
loaded through
+ * a partial-select projection that doesn't include hostId.
isPowerStateInSyncWithInstanceState
+ * must not NPE on the null hostId, and must still detect the state is
out-of-sync.
Review Comment:
updated the comment. its the vm's own host id thats null, the argument and
the power host id are both set.
##########
engine/orchestration/src/test/java/com/cloud/agent/manager/AgentManagerImplTest.java:
##########
@@ -172,4 +173,84 @@ public void testGetHostSshPortWithKVMHostCustomPort() {
int hostSshPort = mgr.getHostSshPort(host);
Assert.assertEquals(3922, hostSshPort);
}
+
+ /*
+ * When the first registered listener throws a RuntimeException,
+ * handleCommands must catch it, log a warning, and continue so that
+ * the second listener still runs.
+ */
+ @Test
+ public void testHandleCommandsListenerExceptionDoesNotAbortLoop() throws
Exception {
+ Listener throwingListener = Mockito.mock(Listener.class);
+ Mockito.when(throwingListener.processCommands(Mockito.anyLong(),
Mockito.anyLong(), Mockito.any()))
+ .thenThrow(new RuntimeException("simulated NPE from
power-state sync"));
+
+ Listener goodListener = Mockito.mock(Listener.class);
+ Mockito.when(goodListener.processCommands(Mockito.anyLong(),
Mockito.anyLong(), Mockito.any()))
Review Comment:
done, switched all of them to Mockito.any(Command[].class)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]