Skip to content

Commit bb91ef2

Browse files
review changes
1 parent ad7a8c5 commit bb91ef2

7 files changed

Lines changed: 34 additions & 26 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
@@ -887,7 +887,7 @@ private void handleStartupAnswer(StartupAnswer startup, Response response, Link
887887
}
888888
String hostName = startup.getHostName();
889889
if (org.apache.commons.lang3.StringUtils.isNotEmpty(hostName)) {
890-
setName(hostUuid);
890+
setName(hostName);
891891
}
892892
pingInterval = startup.getPingInterval() * 1000L; // change to ms.
893893

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,7 +1768,8 @@ private AgentAttache sendReadyAndGetAttache(HostVO host, ReadyCommand ready, Lin
17681768
GlobalLock joinLock = getHostJoinLock(host.getId());
17691769
try {
17701770
long processStart = System.currentTimeMillis();
1771-
if (joinLock.lock(getTimeoutSec())) {
1771+
int timeOutSec = getTimeoutSec();
1772+
if (joinLock.lock(timeOutSec)) {
17721773
logProcessingStart(host, joinLock);
17731774
try {
17741775
updateReadyCommandWithMSList(host, ready, startup);
@@ -1778,7 +1779,7 @@ private AgentAttache sendReadyAndGetAttache(HostVO host, ReadyCommand ready, Lin
17781779
joinLock.unlock();
17791780
}
17801781
} else {
1781-
throw createLockAcquisitionException(host, joinLock, processStart);
1782+
throw createLockAcquisitionException(host, joinLock, timeOutSec, processStart);
17821783
}
17831784
} finally {
17841785
joinLock.releaseRef();
@@ -1798,14 +1799,14 @@ private void logProcessingFinish(HostVO host, GlobalLock joinLock, long processS
17981799
StringBuilder msgBuilder = getSummaryMsgBuilder("Processing Host connection finished",
17991800
EventTypes.EVENT_HOST_RECONNECT, host.getUuid(), host.getName(), joinLock.getName(), null, null,
18001801
processFinish);
1801-
logger.fatal(msgBuilder.toString());
1802+
logger.info(msgBuilder.toString());
18021803
}
18031804

18041805
private void updateReadyCommandWithMSList(HostVO host, ReadyCommand ready, StartupCommand[] startup) {
18051806
List<String> agentMSHostList = new ArrayList<>();
18061807
String lbAlgorithm = null;
18071808

1808-
if (startup != null) {
1809+
if (startup != null && startup.length > 0) {
18091810
String agentMSHosts = startup[0].getMsHostList();
18101811
if (StringUtils.isNotEmpty(agentMSHosts)) {
18111812
String[] msHosts = agentMSHosts.split("@");
@@ -1828,19 +1829,19 @@ private void setReadyCommandMSList(HostVO host, ReadyCommand ready) {
18281829
ready.setAvoidMsHostList(avoidMsList);
18291830
ready.setLbAlgorithm(indirectAgentLB.getLBAlgorithmName());
18301831
ready.setLbCheckInterval(indirectAgentLB.getLBPreferredHostCheckInterval(host.getClusterId()));
1831-
logger.debug("Agent's management server host list is not up to date, sending list update:" + newMSList);
1832+
logger.debug("Agent's management server host list is not up to date, sending list update:{}", newMSList);
18321833
}
18331834

18341835
private AgentAttache createAndNotifyAttache(HostVO host, Link link, StartupCommand[] startup) throws ConnectionException {
18351836
AgentAttache attache = createAttacheForConnect(host, link);
18361837
return notifyMonitorsOfConnection(attache, startup, false);
18371838
}
18381839

1839-
private ConnectionException createLockAcquisitionException(HostVO host, GlobalLock joinLock, long processStart) {
1840+
private ConnectionException createLockAcquisitionException(HostVO host, GlobalLock joinLock, int timeOutSec, long processStart) {
18401841
long processFinish = System.currentTimeMillis() - processStart;
18411842
String title = "Failed to connect Host";
1842-
String summary = String.format("Failure due to unable to acquire lock %s during %s seconds",
1843-
joinLock.getName(), 60);
1843+
String summary = String.format("Failure due to unable to acquire lock %s during %d seconds",
1844+
joinLock.getName(), timeOutSec);
18441845

18451846
StringBuilder msgBuilder = getSummaryMsgBuilder(title, EventTypes.EVENT_HOST_RECONNECT, host.getUuid(),
18461847
host.getName(), joinLock.getName(), summary, null, processFinish);
@@ -2023,7 +2024,7 @@ protected void connectAgent(final Link link, final Command[] cmds, final Request
20232024
answers[i] = answer;
20242025
}
20252026
}
2026-
Response response = new Response(request, answers[0], _nodeId, -1);
2027+
Response response = new Response(request, answers, _nodeId, -1);
20272028
try {
20282029
link.send(response.toBytes());
20292030
} catch (ClosedChannelException e) {

framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletImpl.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,15 @@ public boolean ping(final String callingPeer) throws RemoteException {
141141
private String executePostMethod(final CloseableHttpClient client, final HttpPost method) {
142142
String result = null;
143143
String request = null;
144-
try {
145-
request = EntityUtils.toString(method.getEntity(), Charset.defaultCharset());
146-
} catch (Exception e) {
147-
logger.warn("Failed to retrieve request entity for POST {}", serviceUrl, e);
144+
145+
if (logger.isDebugEnabled()) {
146+
try {
147+
request = EntityUtils.toString(method.getEntity(), Charset.defaultCharset());
148+
} catch (Exception e) {
149+
logger.warn("Failed to retrieve request entity for POST {}", serviceUrl, e);
150+
}
148151
}
152+
149153
try {
150154
final Profiler profiler = new Profiler();
151155
profiler.start();
@@ -155,15 +159,14 @@ private String executePostMethod(final CloseableHttpClient client, final HttpPos
155159
result = EntityUtils.toString(httpResponse.getEntity());
156160
profiler.stop();
157161
if (logger.isDebugEnabled()) {
158-
logger.debug("POST " + serviceUrl + " request: " + request + ", response :" + result + ", responding time: " + profiler.getDurationInMillis() + " ms");
162+
logger.debug("POST {} request: {}, response :{}, responding time: {} ms", serviceUrl, request, result, profiler.getDurationInMillis());
159163
}
160164
} else {
161165
profiler.stop();
162-
logger.error("Invalid response code : " + response + ", from : " + serviceUrl + " request: " + request + ", method : " + method.getParams().getParameter("method") + " responding time: " +
163-
profiler.getDurationInMillis());
166+
logger.error("Invalid response code : {}, from : {} request: {}, method : {} responding time: {}", response, serviceUrl, request, method.getParams().getParameter("method"), profiler.getDurationInMillis());
164167
}
165168
} catch (IOException e) {
166-
logger.error("Exception from : " + serviceUrl + " request: " + request + ", method : " + method.getParams().getParameter("method") + ", exception :", e);
169+
logger.error("Exception from : {} request: {}, method : {}, exception :", serviceUrl, request, method.getParams().getParameter("method"), e);
167170
} finally {
168171
method.releaseConnection();
169172
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public boolean lock(int timeoutSeconds) {
223223
synchronized (this) {
224224
if (ownerThread == Thread.currentThread()) {
225225
logger.warn("Global lock {} re-entrance detected, owner thread: {}, reference count: {}, " +
226-
"lock count: {}", getThreadName(ownerThread), name, referenceCount, lockCount);
226+
"lock count: {}", name, getThreadName(ownerThread), referenceCount, lockCount);
227227
// if it is re-entrance, then we may have more lock counts than needed?
228228
lockCount++;
229229

utils/src/main/java/com/cloud/utils/backoff/impl/ExponentialWithJitterBackoff.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ public void waitBeforeRetry() {
7474
Thread current = Thread.currentThread();
7575
try {
7676
asleep.put(current.getName(), current);
77-
logger.debug(String.format("Going to sleep for %s", DateUtil.formatMillis(waitMs)));
77+
logger.debug("Going to sleep for {}", DateUtil.formatMillis(waitMs));
7878
Thread.sleep(waitMs);
79-
logger.debug(String.format("Sleep done for %s", DateUtil.formatMillis(waitMs)));
79+
logger.debug("Sleep done for {}", DateUtil.formatMillis(waitMs));
8080
} catch (InterruptedException e) {
81-
logger.info(String.format("Thread %s interrupted while waiting for retry", current.getName()), e);
81+
interrupted = true;
82+
logger.info("Thread {} interrupted while waiting for retry", current.getName(), e);
8283
} finally {
8384
asleep.remove(current.getName());
8485
calculateNextAttempt();
@@ -154,8 +155,9 @@ private long getNextDelay() {
154155

155156
@Override
156157
public long getTimeToWait() {
157-
long delay = getNextDelay();
158-
int jitter = random.nextInt((int) delay / 2);
158+
long delay = Math.max(1L, getNextDelay());
159+
int jitterBound = (int) Math.max(1L, delay / 2);
160+
int jitter = random.nextInt(jitterBound);
159161
return delay + jitter;
160162
}
161163

utils/src/main/java/com/cloud/utils/nio/Link.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public String getIpAddress() {
386386

387387
public synchronized void terminated() {
388388
if (LOGGER.isTraceEnabled()) {
389-
LOGGER.debug("Terminating connection to {}", _addr);
389+
LOGGER.trace("Terminating connection to {}", _addr);
390390
}
391391
_key = null;
392392
}

utils/src/main/java/com/cloud/utils/nio/NioConnection.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ public void stop() {
142142
_sslHandshakeExecutor.shutdownNow();
143143
}
144144
if (_threadExecutor != null) {
145-
_futureTask.cancel(false);
145+
if (_futureTask != null) {
146+
_futureTask.cancel(false);
147+
}
146148
_threadExecutor.shutdownNow();
147149
}
148150
_isRunning = false;

0 commit comments

Comments
 (0)