Skip to content

Commit bd4661e

Browse files
committed
CLOUDSTACK-1137: force reconnect to a disconnected host throws error.
1 parent ddcad14 commit bd4661e

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

server/src/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
230230

231231
@Override
232232
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
233-
233+
234234
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
235235
_port = NumbersUtil.parseInt(configs.get("port"), 8250);
236236
final int workers = NumbersUtil.parseInt(configs.get("workers"), 5);
@@ -778,7 +778,7 @@ protected boolean loadDirectlyConnectedHost(HostVO host, boolean forRebalance) {
778778
if (host != null) {
779779
agentStatusTransitTo(host, Event.AgentDisconnected, _nodeId);
780780
}
781-
}
781+
}
782782
}
783783

784784
if (forRebalance) {
@@ -895,7 +895,7 @@ protected boolean handleDisconnectWithInvestigation(AgentAttache attache, Status
895895
} catch (NoTransitionException ne) {
896896
/* Agent may be currently in status of Down, Alert, Removed, namely there is no next status for some events.
897897
* Why this can happen? Ask God not me. I hate there was no piece of comment for code handling race condition.
898-
* God knew what race condition the code dealt with!
898+
* God knew what race condition the code dealt with!
899899
*/
900900
}
901901

@@ -1046,6 +1046,11 @@ public boolean reconnect(final long hostId) {
10461046
return false;
10471047
}
10481048

1049+
if (host.getStatus() == Status.Disconnected) {
1050+
s_logger.info("Host is already disconnected, no work to be done");
1051+
return true;
1052+
}
1053+
10491054
if (host.getStatus() != Status.Up && host.getStatus() != Status.Alert && host.getStatus() != Status.Rebalancing) {
10501055
s_logger.info("Unable to disconnect host because it is not in the correct state: host=" + hostId + "; Status=" + host.getStatus());
10511056
return false;
@@ -1197,12 +1202,12 @@ protected void connectAgent(Link link, final Command[] cmds, final Request reque
11971202
}
11981203
}
11991204
Response response = null;
1200-
response = new Response(request, answers[0], _nodeId, -1);
1205+
response = new Response(request, answers[0], _nodeId, -1);
12011206
try {
12021207
link.send(response.toBytes());
12031208
} catch (ClosedChannelException e) {
12041209
s_logger.debug("Failed to send startupanswer: " + e.toString());
1205-
}
1210+
}
12061211
_connectExecutor.execute(new HandleAgentConnectTask(link, cmds, request));
12071212
}
12081213

@@ -1405,7 +1410,7 @@ public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
14051410
} else {
14061411
throw new CloudRuntimeException("Unkonwn TapAgentsAction " + action);
14071412
}
1408-
}
1413+
}
14091414
return true;
14101415
}
14111416

@@ -1508,7 +1513,7 @@ public void pullAgentToMaintenance(long hostId) {
15081513
attache.setMaintenanceMode(true);
15091514
// Now cancel all of the commands except for the active one.
15101515
attache.cancelAllCommands(Status.Disconnected, false);
1511-
}
1516+
}
15121517
}
15131518

15141519
@Override

0 commit comments

Comments
 (0)