Skip to content

Commit 22e832c

Browse files
review
1 parent 754da64 commit 22e832c

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

agent/src/main/java/com/cloud/agent/Agent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ private boolean isReconnectStormDetected(Link link, String preferredHost, String
840840
boolean currentLinkTerminated = this.link != null && this.link.isTerminated();
841841
boolean reconnectForNewHost = this.hostname != null && this.hostname.equals(preferredHost);
842842
// if none of the above is true
843-
boolean stormDetected = ! (reconnectForCurrentLink || currentLinkTerminated || reconnectForNewHost);
843+
boolean stormDetected = !(reconnectForCurrentLink || currentLinkTerminated || reconnectForNewHost);
844844
// connection storm guard
845845
if (stormDetected) {
846846
logger.warn("Reconnect requested for the connection {} but current connection is " +

agent/src/test/java/com/cloud/agent/HostConnectProcessTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.cloud.exception.CloudException;
2020
import com.cloud.utils.nio.Link;
2121
import org.apache.logging.log4j.Logger;
22+
import org.junit.After;
2223
import org.junit.Assert;
2324
import org.junit.Before;
2425
import org.junit.Test;
@@ -50,9 +51,13 @@ public void setUp() throws ConfigurationException {
5051
ReflectionTestUtils.setField(agent, "logger", logger);
5152
}
5253

54+
@After
55+
public void tearDown() {
56+
hostConnectProcess.stop();
57+
}
58+
5359
@Test
5460
public void testScheduleConnectProcess() throws InterruptedException, CloudException {
55-
5661
hostConnectProcess.scheduleConnectProcess(link, connectionTransfer);
5762
Assert.assertTrue(hostConnectProcess.isInProgress());
5863
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,11 @@ private AgentControlAnswer handleControlCommand(final AgentAttache attache, fina
582582

583583
private AgentConnectStatusAnswer handleAgentConnectStatusCommand(AgentAttache attache, AgentConnectStatusCommand cmd) {
584584
HostVO hostVo = _hostDao.findById(attache.getId());
585+
if (hostVo == null) {
586+
String details = String.format("Unable to find Host in DB with id %s for AgentConnectStatusCommand hostId=%s guid=%s name=%s",
587+
attache.getId(), cmd.getHostId(), cmd.getHostGuid(), cmd.getHostName());
588+
return new AgentConnectStatusAnswer(cmd, false, details);
589+
}
585590
return getConnectStatusAnswer(hostVo, cmd);
586591
}
587592

@@ -592,7 +597,7 @@ private AgentConnectStatusAnswer getConnectStatusAnswer(HostVO hostVo, AgentConn
592597
Status status = hostVo.getStatus();
593598
try {
594599
boolean lockAvailable = GlobalLock.isLockAvailable(lockName);
595-
String details = String.format("Global lock %s is%s present for %s", lockName, lockAvailable ? "" : " not",
600+
String details = String.format("Global lock %s is %s present for %s", lockName, lockAvailable ? "" : " not",
596601
hostName);
597602
logger.debug(details);
598603
return getAgentConnectStatusAnswer(cmd, lockName, hostName, lockAvailable, status, details);
@@ -612,7 +617,7 @@ private AgentConnectStatusAnswer getAgentConnectStatusAnswer(AgentConnectStatusC
612617
boolean lockAvailable,
613618
Status status,
614619
String details) {
615-
logger.debug(String.format("Checking whether global lock %s is present for %s", lockName, hostName));
620+
logger.debug("Checking whether global lock {} is present for {}", lockName, hostName);
616621
AgentConnectStatusAnswer answer = new AgentConnectStatusAnswer(cmd, true, details);
617622
answer.setLockAvailable(lockAvailable);
618623
answer.setHostStatus(status);
@@ -2024,7 +2029,7 @@ protected void connectAgent(final Link link, final Command[] cmds, final Request
20242029
answers[i] = answer;
20252030
}
20262031
}
2027-
Response response = new Response(request, answers, _nodeId, -1);
2032+
Response response = new Response(request, answers[0], _nodeId, -1);
20282033
try {
20292034
link.send(response.toBytes());
20302035
} catch (ClosedChannelException e) {

framework/db/src/main/java/com/cloud/utils/db/GlobalLock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ public int releaseRef() {
138138

139139
public static boolean isLockAvailable(String name) {
140140
if (logger.isDebugEnabled()) {
141-
logger.debug("Checking lock present for {}", name);
141+
logger.debug("Checking lock availability for {}", name);
142142
}
143143
boolean result = false;
144144
try {
145145
result = DbUtil.isFreeLock(name);
146146
} finally {
147147
if (logger.isDebugEnabled()) {
148-
logger.debug("Result of checking lock present for {}: {}", name, result);
148+
logger.debug("Result of checking lock availability for {}: {}", name, result);
149149
}
150150
}
151151
return result;

0 commit comments

Comments
 (0)