Skip to content

Commit c4b7bec

Browse files
DaanHooglanddhslove
authored andcommitted
deal with NPE during host reconnect (apache#10158)
* log to see what command is being processed * exception names
1 parent a4ae988 commit c4b7bec

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
5555
import org.apache.cloudstack.utils.identity.ManagementServerNode;
5656
import org.apache.commons.collections.MapUtils;
57+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
5758
import org.apache.commons.lang3.BooleanUtils;
5859

5960
import com.cloud.agent.AgentManager;
@@ -618,30 +619,27 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
618619
logger.debug("Sending Connect to listener: {}", monitor.second().getClass().getSimpleName());
619620
for (int i = 0; i < cmd.length; i++) {
620621
try {
622+
if (logger.isDebugEnabled()) {
623+
logger.debug("process connection to issue " + ReflectionToStringBuilderUtils.reflectCollection(cmd[i]) + " forRebalance == " + forRebalance);
624+
}
621625
monitor.second().processConnect(host, cmd[i], forRebalance);
622-
} catch (final Exception e) {
623-
if (e instanceof ConnectionException) {
624-
final ConnectionException ce = (ConnectionException)e;
625-
if (ce.isSetupError()) {
626-
logger.warn("Monitor {} says there is an error in the connect process for {} due to {}",
627-
monitor.second().getClass().getSimpleName(), host, e.getMessage());
628-
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
629-
throw ce;
630-
} else {
631-
logger.info("Monitor {} says not to continue the connect process for {} due to {}",
632-
monitor.second().getClass().getSimpleName(), host, e.getMessage());
633-
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
634-
return attache;
635-
}
636-
} else if (e instanceof HypervisorVersionChangedException) {
637-
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
638-
throw new CloudRuntimeException(String.format("Unable to connect %s", attache), e);
639-
} else {
640-
logger.error("Monitor {} says there is an error in the connect process for {} due to {}",
641-
monitor.second().getClass().getSimpleName(), host, e.getMessage(), e);
626+
} catch (final ConnectionException ce) {
627+
if (ce.isSetupError()) {
628+
logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + ce.getMessage());
642629
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
643-
throw new CloudRuntimeException(String.format("Unable to connect %s", attache), e);
630+
throw ce;
631+
} else {
632+
logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + ce.getMessage());
633+
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
634+
return attache;
644635
}
636+
} catch (final HypervisorVersionChangedException hvce) {
637+
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
638+
throw new CloudRuntimeException("Unable to connect " + attache.getId(), hvce);
639+
} catch (final Exception e) {
640+
logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e);
641+
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
642+
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
645643
}
646644
}
647645
}

0 commit comments

Comments
 (0)