Skip to content

Commit 1e29347

Browse files
direct agent transfer fixes
1 parent fffcef0 commit 1e29347

File tree

13 files changed

+90
-12
lines changed

13 files changed

+90
-12
lines changed

api/src/main/java/com/cloud/host/Status.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public static String[] toStrings(Status... states) {
127127
s_fsm.addTransition(Status.Connecting, Event.HostDown, Status.Down);
128128
s_fsm.addTransition(Status.Connecting, Event.Ping, Status.Connecting);
129129
s_fsm.addTransition(Status.Connecting, Event.ManagementServerDown, Status.Disconnected);
130+
s_fsm.addTransition(Status.Connecting, Event.StartAgentRebalance, Status.Rebalancing);
130131
s_fsm.addTransition(Status.Connecting, Event.AgentDisconnected, Status.Alert);
131132
s_fsm.addTransition(Status.Up, Event.PingTimeout, Status.Alert);
132133
s_fsm.addTransition(Status.Up, Event.AgentDisconnected, Status.Alert);

core/src/main/java/com/cloud/agent/api/TransferAgentCommand.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class TransferAgentCommand extends Command {
2525
protected long agentId;
2626
protected long futureOwner;
2727
protected long currentOwner;
28+
protected boolean isConnectionTransfer;
2829
Event event;
2930

3031
protected TransferAgentCommand() {
@@ -37,6 +38,11 @@ public TransferAgentCommand(long agentId, long currentOwner, long futureOwner, E
3738
this.event = event;
3839
}
3940

41+
public TransferAgentCommand(long agentId, long currentOwner, long futureOwner, Event event, boolean isConnectionTransfer) {
42+
this(agentId, currentOwner, futureOwner, event);
43+
this.isConnectionTransfer = isConnectionTransfer;
44+
}
45+
4046
public long getAgentId() {
4147
return agentId;
4248
}
@@ -53,6 +59,10 @@ public long getCurrentOwner() {
5359
return currentOwner;
5460
}
5561

62+
public boolean isConnectionTransfer() {
63+
return isConnectionTransfer;
64+
}
65+
5666
@Override
5767
public boolean executeInSequence() {
5868
return false;

core/src/main/java/com/cloud/resource/ServerResource.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public interface ServerResource extends Manager {
5050
*/
5151
StartupCommand[] initialize();
5252

53+
default StartupCommand[] initialize(boolean isTransferredConnection) {
54+
return initialize();
55+
}
56+
5357
/**
5458
* @param id id of the server to put in the PingCommand
5559
* @return PingCommand

engine/components-api/src/main/java/com/cloud/resource/ResourceManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public interface ResourceManager extends ResourceService, Configurable {
8585

8686
public Host createHostAndAgent(Long hostId, ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags, boolean forRebalance);
8787

88+
public Host createHostAndAgent(Long hostId, ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags, boolean forRebalance, boolean isTransferredConnection);
89+
8890
public Host addHost(long zoneId, ServerResource resource, Type hostType, Map<String, String> hostDetails);
8991

9092
public HostVO createHostVOForConnectedAgent(StartupCommand[] cmds);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@ public void rescan() {
772772
}
773773

774774
protected boolean loadDirectlyConnectedHost(final HostVO host, final boolean forRebalance) {
775+
return loadDirectlyConnectedHost(host, forRebalance, false);
776+
}
777+
778+
protected boolean loadDirectlyConnectedHost(final HostVO host, final boolean forRebalance, final boolean isTransferredConnection) {
775779
boolean initialized = false;
776780
ServerResource resource = null;
777781
try {
@@ -800,7 +804,7 @@ protected boolean loadDirectlyConnectedHost(final HostVO host, final boolean for
800804

801805
if (forRebalance) {
802806
tapLoadingAgents(host.getId(), TapAgentsAction.Add);
803-
final Host h = _resourceMgr.createHostAndAgent(host.getId(), resource, host.getDetails(), false, null, true);
807+
final Host h = _resourceMgr.createHostAndAgent(host.getId(), resource, host.getDetails(), false, null, true, isTransferredConnection);
804808
tapLoadingAgents(host.getId(), TapAgentsAction.Del);
805809

806810
return h == null ? false : true;

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,17 @@ public void removeAgent(final AgentAttache attache, final Status nextState) {
756756

757757
@Override
758758
public boolean executeRebalanceRequest(final long agentId, final long currentOwnerId, final long futureOwnerId, final Event event) throws AgentUnavailableException, OperationTimedoutException {
759+
return executeRebalanceRequest(agentId, currentOwnerId, futureOwnerId, event, false);
760+
}
761+
762+
@Override
763+
public boolean executeRebalanceRequest(final long agentId, final long currentOwnerId, final long futureOwnerId, final Event event, boolean isConnectionTransfer) throws AgentUnavailableException, OperationTimedoutException {
759764
boolean result = false;
760765
if (event == Event.RequestAgentRebalance) {
761766
return setToWaitForRebalance(agentId, currentOwnerId, futureOwnerId);
762767
} else if (event == Event.StartAgentRebalance) {
763768
try {
764-
result = rebalanceHost(agentId, currentOwnerId, futureOwnerId);
769+
result = rebalanceHost(agentId, currentOwnerId, futureOwnerId, isConnectionTransfer);
765770
} catch (final Exception e) {
766771
logger.warn("Unable to rebalance host id={}", agentId, e);
767772
}
@@ -883,7 +888,11 @@ public void startRebalanceAgents() {
883888
}
884889

885890
private Answer[] sendRebalanceCommand(final long peer, final long agentId, final long currentOwnerId, final long futureOwnerId, final Event event) {
886-
final TransferAgentCommand transfer = new TransferAgentCommand(agentId, currentOwnerId, futureOwnerId, event);
891+
return sendRebalanceCommand(peer, agentId, currentOwnerId, futureOwnerId, event, false);
892+
}
893+
894+
private Answer[] sendRebalanceCommand(final long peer, final long agentId, final long currentOwnerId, final long futureOwnerId, final Event event, final boolean isConnectionTransfer) {
895+
final TransferAgentCommand transfer = new TransferAgentCommand(agentId, currentOwnerId, futureOwnerId, event, isConnectionTransfer);
887896
final Commands commands = new Commands(Command.OnError.Stop);
888897
commands.addCommand(transfer);
889898

@@ -1016,7 +1025,10 @@ private boolean setToWaitForRebalance(final long hostId, final long currentOwner
10161025
}
10171026

10181027
protected boolean rebalanceHost(final long hostId, final long currentOwnerId, final long futureOwnerId) throws AgentUnavailableException {
1028+
return rebalanceHost(hostId, currentOwnerId, futureOwnerId, false);
1029+
}
10191030

1031+
protected boolean rebalanceHost(final long hostId, final long currentOwnerId, final long futureOwnerId, final boolean isConnectionTransfer) throws AgentUnavailableException {
10201032
boolean result = true;
10211033
if (currentOwnerId == _nodeId) {
10221034
if (!startRebalance(hostId)) {
@@ -1025,7 +1037,7 @@ protected boolean rebalanceHost(final long hostId, final long currentOwnerId, fi
10251037
return false;
10261038
}
10271039
try {
1028-
final Answer[] answer = sendRebalanceCommand(futureOwnerId, hostId, currentOwnerId, futureOwnerId, Event.StartAgentRebalance);
1040+
final Answer[] answer = sendRebalanceCommand(futureOwnerId, hostId, currentOwnerId, futureOwnerId, Event.StartAgentRebalance, isConnectionTransfer);
10291041
if (answer == null || !answer[0].getResult()) {
10301042
result = false;
10311043
}
@@ -1055,7 +1067,7 @@ protected boolean rebalanceHost(final long hostId, final long currentOwnerId, fi
10551067

10561068
if (result) {
10571069
logger.debug("Loading directly connected host {}({}) to the management server {} as a part of rebalance process", host.getId(), host.getName(), _nodeId);
1058-
result = loadDirectlyConnectedHost(host, true);
1070+
result = loadDirectlyConnectedHost(host, true, isConnectionTransfer);
10591071
} else {
10601072
logger.warn("Failed to disconnect {}({}) as a part of rebalance process without notification" + host.getId(), host.getName());
10611073
}
@@ -1260,10 +1272,10 @@ public String dispatch(final ClusterServicePdu pdu) {
12601272
} else if (cmds.length == 1 && cmds[0] instanceof TransferAgentCommand) {
12611273
final TransferAgentCommand cmd = (TransferAgentCommand)cmds[0];
12621274

1263-
logger.debug("Intercepting command for agent rebalancing: agent {} event: {}", cmd.getAgentId(), cmd.getEvent());
1275+
logger.debug("Intercepting command for agent rebalancing: agent: {}, event: {}, connection transfer: {}", cmd.getAgentId(), cmd.getEvent(), cmd.isConnectionTransfer());
12641276
boolean result = false;
12651277
try {
1266-
result = rebalanceAgent(cmd.getAgentId(), cmd.getEvent(), cmd.getCurrentOwner(), cmd.getFutureOwner());
1278+
result = rebalanceAgent(cmd.getAgentId(), cmd.getEvent(), cmd.getCurrentOwner(), cmd.getFutureOwner(), cmd.isConnectionTransfer());
12671279
logger.debug("Result is {}", result);
12681280

12691281
} catch (final AgentUnavailableException e) {
@@ -1419,7 +1431,7 @@ public boolean transferDirectAgentsFromMS(String fromMsUuid, long fromMsId, long
14191431
_mshostCounter++;
14201432

14211433
_hostTransferDao.startAgentTransfering(host.getId(), fromMsId, msHost.getMsid());
1422-
if (!rebalanceAgent(host.getId(), Event.StartAgentRebalance, fromMsId, msHost.getMsid())) {
1434+
if (!rebalanceAgent(host.getId(), Event.StartAgentRebalance, fromMsId, msHost.getMsid(), true)) {
14231435
agentTransferFailedCount++;
14241436
} else {
14251437
updateLastManagementServer(host.getId(), fromMsId);
@@ -1511,6 +1523,10 @@ public boolean rebalanceAgent(final long agentId, final Event event, final long
15111523
return executeRebalanceRequest(agentId, currentOwnerId, futureOwnerId, event);
15121524
}
15131525

1526+
public boolean rebalanceAgent(final long agentId, final Event event, final long currentOwnerId, final long futureOwnerId, boolean isConnectionTransfer) throws AgentUnavailableException, OperationTimedoutException {
1527+
return executeRebalanceRequest(agentId, currentOwnerId, futureOwnerId, event, isConnectionTransfer);
1528+
}
1529+
15141530
public boolean isAgentRebalanceEnabled() {
15151531
return EnableLB.value();
15161532
}

engine/orchestration/src/main/java/com/cloud/cluster/ClusteredAgentRebalanceService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ public interface ClusteredAgentRebalanceService {
2727

2828
boolean executeRebalanceRequest(long agentId, long currentOwnerId, long futureOwnerId, Event event) throws AgentUnavailableException, OperationTimedoutException;
2929

30+
boolean executeRebalanceRequest(long agentId, long currentOwnerId, long futureOwnerId, Event event, boolean isConnectionTransfer) throws AgentUnavailableException, OperationTimedoutException;
3031
}

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6036,6 +6036,11 @@ public Type getType() {
60366036

60376037
@Override
60386038
public StartupCommand[] initialize() {
6039+
return initialize(false);
6040+
}
6041+
6042+
@Override
6043+
public StartupCommand[] initialize(boolean isTransferredConnection) {
60396044
try {
60406045
String hostApiVersion = "4.1";
60416046
VmwareContext context = getServiceContext();
@@ -6064,6 +6069,7 @@ public StartupCommand[] initialize() {
60646069
cmd.setHypervisorType(HypervisorType.VMware);
60656070
cmd.setCluster(_cluster);
60666071
cmd.setHypervisorVersion(hostApiVersion);
6072+
cmd.setConnectionTransferred(isTransferredConnection);
60676073

60686074
List<StartupStorageCommand> storageCmds = initializeLocalStorage();
60696075
StartupCommand[] answerCmds = new StartupCommand[1 + storageCmds.size()];

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,6 +3723,11 @@ public String handleVmStartFailure(final Connection conn, final String vmName, f
37233723

37243724
@Override
37253725
public StartupCommand[] initialize() throws IllegalArgumentException {
3726+
return initialize(false);
3727+
}
3728+
3729+
@Override
3730+
public StartupCommand[] initialize(boolean isTransferredConnection) throws IllegalArgumentException {
37263731
final Connection conn = getConnection();
37273732
if (!getHostInfo(conn)) {
37283733
logger.warn("Unable to get host information for " + _host.getIp());
@@ -3733,6 +3738,7 @@ public StartupCommand[] initialize() throws IllegalArgumentException {
37333738
cmd.setHypervisorType(HypervisorType.XenServer);
37343739
cmd.setCluster(_cluster);
37353740
cmd.setPoolSync(false);
3741+
cmd.setConnectionTransferred(isTransferredConnection);
37363742

37373743
try {
37383744
final Pool pool = Pool.getByUuid(conn, _host.getPool());

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/XenServer56Resource.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ public Boolean checkHeartbeat(final String hostuuid) {
128128

129129
@Override
130130
public StartupCommand[] initialize() {
131+
return initialize(false);
132+
}
133+
134+
@Override
135+
public StartupCommand[] initialize(boolean isTransferredConnection) {
131136
pingXAPI();
132-
return super.initialize();
137+
return super.initialize(isTransferredConnection);
133138
}
134139
}

0 commit comments

Comments
 (0)