Skip to content

Commit bb42373

Browse files
committed
Bug 11522 - New agent manager
refine reconnectHost logic
1 parent 95dbf2a commit bb42373

7 files changed

Lines changed: 40 additions & 67 deletions

File tree

‎api/src/com/cloud/api/commands/ReconnectHostCmd.java‎

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void execute(){
107107
} else {
108108
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to reconnect host");
109109
}
110-
} catch (AgentUnavailableException ex) {
110+
} catch (Exception ex) {
111111
s_logger.warn("Exception: ", ex);
112112
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
113113
}

‎api/src/com/cloud/resource/ResourceService.java‎

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public interface ResourceService {
4646

4747
Host cancelMaintenance(CancelMaintenanceCmd cmd);
4848

49-
Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException;
49+
Host reconnectHost(ReconnectHostCmd cmd);
5050

5151
/**
5252
* We will automatically create a cloud.com cluster to attach to the external cluster and return a hyper host to perform

‎server/src/com/cloud/agent/AgentManager.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ public enum TapAgentsAction {
189189

190190
public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException;
191191

192-
public boolean reconnect(final long hostId) throws AgentUnavailableException;
193-
194192
boolean isHostNativeHAEnabled(long hostId);
195193

196194
Answer sendTo(Long dcId, HypervisorType type, Command cmd);
@@ -219,4 +217,6 @@ public enum TapAgentsAction {
219217
public boolean disconnectAgent(HostVO host, Status.Event e, long msId);
220218

221219
public void pullAgentToMaintenance(long hostId);
220+
221+
boolean reconnect(long hostId);
222222
}

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

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,6 @@ public void removeAgent(AgentAttache attache, Status nextState) {
718718
public void updateStatus(HostVO host, Status.Event event) {
719719
_hostDao.updateStatus(host, event, _nodeId);
720720
}
721-
public void disconnect(AgentAttache attache, final Status.Event event, final boolean investigate) {
722-
_executor.submit(new DisconnectTask(attache, event, investigate));
723-
}
724721

725722
protected AgentAttache notifyMonitorsOfConnection(AgentAttache attache, final StartupCommand[] cmd, boolean forRebalance) throws ConnectionException {
726723
long hostId = attache.getId();
@@ -737,19 +734,19 @@ protected AgentAttache notifyMonitorsOfConnection(AgentAttache attache, final St
737734
ConnectionException ce = (ConnectionException)e;
738735
if (ce.isSetupError()) {
739736
s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage());
740-
handleDisconnect(attache, Event.AgentDisconnected);
737+
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected);
741738
throw ce;
742739
} else {
743740
s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage());
744-
handleDisconnect(attache, Event.ShutdownRequested);
741+
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested);
745742
return attache;
746743
}
747744
} else if (e instanceof HypervisorVersionChangedException) {
748-
handleDisconnect(attache, Event.HypervisorVersionChanged);
745+
handleDisconnectWithoutInvestigation(attache, Event.HypervisorVersionChanged);
749746
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
750747
} else {
751748
s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e);
752-
handleDisconnect(attache, Event.AgentDisconnected);
749+
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected);
753750
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
754751
}
755752
}
@@ -763,7 +760,7 @@ protected AgentAttache notifyMonitorsOfConnection(AgentAttache attache, final St
763760
// this is tricky part for secondary storage
764761
// make it as disconnected, wait for secondary storage VM to be up
765762
// return the attache instead of null, even it is disconnectede
766-
handleDisconnect(attache, Event.AgentDisconnected);
763+
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected);
767764
}
768765

769766
_hostDao.updateStatus(host, Event.Ready, _nodeId);
@@ -1010,7 +1007,7 @@ public String getName() {
10101007
return _name;
10111008
}
10121009

1013-
protected boolean handleDisconnect(AgentAttache attache, Status.Event event) {
1010+
protected boolean handleDisconnectWithoutInvestigation(AgentAttache attache, Status.Event event) {
10141011
long hostId = attache.getId();
10151012

10161013
s_logger.info("Host " + hostId + " is disconnecting with event " + event);
@@ -1128,7 +1125,7 @@ protected boolean handleDisconnectWithInvestigation(AgentAttache attache, Status
11281125
}
11291126
}
11301127

1131-
handleDisconnect(attache, event);
1128+
handleDisconnectWithoutInvestigation(attache, event);
11321129
/*TODO: call HA manager in monitors
11331130
* host = _hostDao.findById(host.getId());
11341131
if (!event.equals(Event.PrepareUnmanaged) && !event.equals(Event.HypervisorVersionChanged) && (host.getStatus() == Status.Alert || host.getStatus() == Status.Down)) {
@@ -1155,7 +1152,7 @@ public void run() {
11551152
if (_investigate == true) {
11561153
handleDisconnectWithInvestigation(_attache, _event);
11571154
} else {
1158-
handleDisconnect(_attache, _event);
1155+
handleDisconnectWithoutInvestigation(_attache, _event);
11591156
}
11601157
} catch (final Exception e) {
11611158
s_logger.error("Exception caught while handling disconnect: ", e);
@@ -1216,7 +1213,7 @@ public Answer[] send(final Long hostId, Commands cmds) throws AgentUnavailableEx
12161213
}
12171214

12181215
@Override
1219-
public boolean reconnect(final long hostId) throws AgentUnavailableException {
1216+
public boolean reconnect(final long hostId) {
12201217
HostVO host;
12211218

12221219
host = _hostDao.findById(hostId);
@@ -1236,46 +1233,25 @@ public boolean reconnect(final long hostId) throws AgentUnavailableException {
12361233
return false;
12371234
}
12381235

1239-
disconnect(attache, Event.ShutdownRequested, false);
1236+
disconnectWithoutInvestigation(attache, Event.ShutdownRequested);
12401237
return true;
12411238
}
12421239

12431240
@Override
12441241
public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException {
1245-
if (event == Event.MaintenanceRequested) {
1246-
return maintain(hostId);
1247-
} else if (event == Event.ResetRequested) {
1248-
return cancelMaintenance(hostId);
1249-
} else if (event == Event.PrepareUnmanaged) {
1250-
return disconnect(hostId);
1251-
} else if (event == Event.Remove) {
1252-
User caller = _accountMgr.getActiveUser(User.UID_SYSTEM);
1253-
return deleteHost(hostId, false, false, caller);
1254-
} else if (event == Event.AgentDisconnected) {
1242+
if (event == Event.AgentDisconnected) {
12551243
if (s_logger.isDebugEnabled()) {
12561244
s_logger.debug("Received agent disconnect event for host " + hostId);
12571245
}
12581246
AgentAttache attache = null;
12591247
attache = findAttache(hostId);
12601248
if (attache != null) {
1261-
handleDisconnect(attache, Event.AgentDisconnected, false);
1249+
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected);
12621250
}
12631251
return true;
12641252
} else if (event == Event.ShutdownRequested) {
12651253
return reconnect(hostId);
12661254
}
1267-
else if (event == Event.UpdatePassword) {
1268-
AgentAttache attache = findAttache(hostId);
1269-
if (attache != null) {
1270-
DetailVO nv = _detailsDao.findDetail(hostId, ApiConstants.USERNAME);
1271-
String username = nv.getValue();
1272-
nv = _detailsDao.findDetail(hostId, ApiConstants.PASSWORD);
1273-
String password = nv.getValue();
1274-
UpdateHostPasswordCommand cmd = new UpdateHostPasswordCommand(username, password);
1275-
attache.updatePassword(cmd);
1276-
return true;
1277-
}
1278-
}
12791255
return false;
12801256
}
12811257

@@ -1900,9 +1876,9 @@ protected void processRequest(final Link link, final Request request) {
19001876
final String reason = shutdown.getReason();
19011877
s_logger.info("Host " + attache.getId() + " has informed us that it is shutting down with reason " + reason + " and detail " + shutdown.getDetail());
19021878
if (reason.equals(ShutdownCommand.Update)) {
1903-
disconnect(attache, Event.UpdateNeeded, false);
1879+
disconnectWithoutInvestigation(attache, Event.UpdateNeeded);
19041880
} else if (reason.equals(ShutdownCommand.Requested)) {
1905-
disconnect(attache, Event.ShutdownRequested, false);
1881+
disconnectWithoutInvestigation(attache, Event.ShutdownRequested);
19061882
}
19071883
return;
19081884
} else if (cmd instanceof AgentControlCommand) {
@@ -1999,7 +1975,7 @@ protected void doTask(final Task task) throws Exception {
19991975
final Link link = task.getLink();
20001976
final AgentAttache attache = (AgentAttache) link.attachment();
20011977
if (attache != null) {
2002-
disconnect(attache, Event.AgentDisconnected, true);
1978+
disconnectWithInvestigation(attache, Event.AgentDisconnected);
20031979
} else {
20041980
s_logger.info("Connection from " + link.getIpAddress() + " closed but no cleanup was done.");
20051981
link.close();

‎server/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ protected AgentAttache createAttacheForDirectConnect(HostVO host, ServerResource
255255
}
256256

257257
@Override
258-
protected boolean handleDisconnect(AgentAttache attache, Status.Event event) {
258+
protected boolean handleDisconnectWithoutInvestigation(AgentAttache attache, Status.Event event) {
259259
return handleDisconnect(attache, event, false, true);
260260
}
261261

@@ -265,19 +265,17 @@ protected boolean handleDisconnectWithInvestigation(AgentAttache attache, Status
265265
}
266266

267267
protected boolean handleDisconnect(AgentAttache agent, Status.Event event, boolean investigate, boolean broadcast) {
268-
if (agent == null) {
269-
return true;
270-
}
271-
272268
boolean res;
273269
if (!investigate) {
274-
res = super.handleDisconnect(agent, event);
270+
res = super.handleDisconnectWithoutInvestigation(agent, event);
275271
} else {
276272
res = super.handleDisconnectWithInvestigation(agent, event);
277273
}
278274

279-
if (res && broadcast) {
280-
notifyNodesInCluster(agent);
275+
if (res) {
276+
if (broadcast) {
277+
notifyNodesInCluster(agent);
278+
}
281279
return true;
282280
} else {
283281
return false;
@@ -302,12 +300,18 @@ public boolean executeUserRequest(long hostId, Event event) throws AgentUnavaila
302300
}
303301

304302
@Override
305-
public boolean reconnect(final long hostId) throws AgentUnavailableException {
306-
Boolean result = _clusterMgr.propagateAgentEvent(hostId, Event.ShutdownRequested);
307-
if (result != null) {
308-
return result;
303+
public boolean reconnect(final long hostId) {
304+
Boolean result;
305+
try {
306+
result = _clusterMgr.propagateAgentEvent(hostId, Event.ShutdownRequested);
307+
if (result != null) {
308+
return result;
309+
}
310+
} catch (AgentUnavailableException e) {
311+
s_logger.debug("cannot propagate agent reconnect because agent is not available", e);
312+
return false;
309313
}
310-
314+
311315
return super.reconnect(hostId);
312316
}
313317

‎server/src/com/cloud/agent/manager/DirectAgentAttache.java‎

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public synchronized void run() {
143143
PingCommand cmd = resource.getCurrentStatus(_id);
144144
if (cmd == null) {
145145
s_logger.warn("Unable to get current status on " + _id);
146-
_mgr.disconnect(DirectAgentAttache.this, Event.AgentDisconnected, true);
146+
_mgr.disconnectWithInvestigation(DirectAgentAttache.this, Event.AgentDisconnected);
147147
return;
148148
}
149149
if (s_logger.isDebugEnabled()) {

‎server/src/com/cloud/resource/ResourceManagerImpl.java‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -955,19 +955,15 @@ public Host cancelMaintenance(CancelMaintenanceCmd cmd) {
955955
}
956956

957957
@Override
958-
public Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException {
958+
public Host reconnectHost(ReconnectHostCmd cmd) {
959959
Long hostId = cmd.getId();
960960

961961
HostVO host = _hostDao.findById(hostId);
962962
if (host == null) {
963963
throw new InvalidParameterValueException("Host with id " + hostId.toString() + " doesn't exist");
964964
}
965965

966-
boolean result = _agentMgr.reconnect(hostId);
967-
if (result) {
968-
return host;
969-
}
970-
throw new CloudRuntimeException("Failed to reconnect host with id " + hostId.toString() + ", internal error.");
966+
return (_agentMgr.reconnect(hostId) ? host : null);
971967
}
972968

973969
@Override
@@ -1657,8 +1653,6 @@ private boolean cancelMaintenance(long hostId) {
16571653
public boolean executeUserRequest(long hostId, ResourceState.Event event) throws AgentUnavailableException {
16581654
if (event == ResourceState.Event.AdminAskMaintenace) {
16591655
return doMaintain(hostId);
1660-
} else if (event == ResourceState.Event.AdminAskReconnect) {
1661-
return doReconncetHost(hostId);
16621656
} else if (event == ResourceState.Event.AdminCancelMaintenance) {
16631657
return doCancelMaintenance(hostId);
16641658
} else if (event == ResourceState.Event.DeleteHost) {
@@ -1740,6 +1734,5 @@ public boolean updateHostPassword(UpdateHostPasswordCmd cmd) {
17401734

17411735
return true;
17421736
}
1743-
}
1744-
1737+
}
17451738
}

0 commit comments

Comments
 (0)