mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Refactor cloud-agent module logs for Log4j2 (#8714)
* Refactor cloud-agent module logs for Log4j2 * better log4j2 logs for cloud-agent module * erasing commented lines * erasing unused import * fixing mistakes * more log refactor * fixing log refactor lambdas * adding suggestions to log refactor * Apply suggestions from code review Co-authored-by: João Jandre <48719461+JoaoJandre@users.noreply.github.com> * Update Agent.java revert a lambda expression because log4j2 does not support a non lambda + lambda as parameters * Update Agent.java fixing little mistake --------- Co-authored-by: klaus.freitas.scclouds <klaus.freitas@scclouds.com.br> Co-authored-by: João Jandre <48719461+JoaoJandre@users.noreply.github.com>
This commit is contained in:
parent
88d250487c
commit
a0b642cdb8
@ -55,6 +55,7 @@ import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
|
||||
import org.apache.cloudstack.utils.security.KeyStoreUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -182,7 +183,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
|
||||
final String value = _shell.getPersistentProperty(getResourceName(), "id");
|
||||
_id = value != null ? Long.parseLong(value) : null;
|
||||
logger.info("id is " + (_id != null ? _id : ""));
|
||||
logger.info("id is {}", ObjectUtils.defaultIfNull(_id, ""));
|
||||
|
||||
final Map<String, Object> params = new HashMap<>();
|
||||
|
||||
@ -211,8 +212,8 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
new ThreadPoolExecutor(_shell.getWorkers(), 5 * _shell.getWorkers(), 1, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory(
|
||||
"agentRequest-Handler"));
|
||||
|
||||
logger.info("Agent [id = " + (_id != null ? _id : "new") + " : type = " + getResourceName() + " : zone = " + _shell.getZone() + " : pod = " + _shell.getPod() +
|
||||
" : workers = " + _shell.getWorkers() + " : host = " + host + " : port = " + _shell.getPort());
|
||||
logger.info("Agent [id = {} : type = {} : zone = {} : pod = {} : workers = {} : host = {} : port = {}", ObjectUtils.defaultIfNull(_id, "new"), getResourceName(),
|
||||
_shell.getZone(), _shell.getPod(), _shell.getWorkers(), host, _shell.getPort());
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
@ -269,7 +270,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
|
||||
public void start() {
|
||||
if (!_resource.start()) {
|
||||
logger.error("Unable to start the resource: " + _resource.getName());
|
||||
logger.error("Unable to start the resource: {}", _resource.getName());
|
||||
throw new CloudRuntimeException("Unable to start the resource: " + _resource.getName());
|
||||
}
|
||||
|
||||
@ -286,14 +287,13 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
try {
|
||||
_connection.start();
|
||||
} catch (final NioConnectionException e) {
|
||||
logger.warn("NIO Connection Exception " + e);
|
||||
logger.info("Attempted to connect to the server, but received an unexpected exception, trying again...");
|
||||
logger.warn("Attempt to connect to server generated NIO Connection Exception {}, trying again", e.getLocalizedMessage());
|
||||
}
|
||||
while (!_connection.isStartup()) {
|
||||
final String host = _shell.getNextHost();
|
||||
_shell.getBackoffAlgorithm().waitBeforeRetry();
|
||||
_connection = new NioClient("Agent", host, _shell.getPort(), _shell.getWorkers(), this);
|
||||
logger.info("Connecting to host:" + host);
|
||||
logger.info("Connecting to host:{}", host);
|
||||
try {
|
||||
_connection.start();
|
||||
} catch (final NioConnectionException e) {
|
||||
@ -301,7 +301,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
try {
|
||||
_connection.cleanUp();
|
||||
} catch (final IOException ex) {
|
||||
logger.warn("Fail to clean up old connection. " + ex);
|
||||
logger.warn("Fail to clean up old connection. {}", ex);
|
||||
}
|
||||
logger.info("Attempted to connect to the server, but received an unexpected exception, trying again...", e);
|
||||
}
|
||||
@ -312,7 +312,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
}
|
||||
|
||||
public void stop(final String reason, final String detail) {
|
||||
logger.info("Stopping the agent: Reason = " + reason + (detail != null ? ": Detail = " + detail : ""));
|
||||
logger.info("Stopping the agent: Reason = {} {}", reason, ": Detail = " + ObjectUtils.defaultIfNull(detail, ""));
|
||||
_reconnectAllowed = false;
|
||||
if (_connection != null) {
|
||||
final ShutdownCommand cmd = new ShutdownCommand(reason, detail);
|
||||
@ -322,9 +322,9 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
_link.send(req.toBytes());
|
||||
}
|
||||
} catch (final ClosedChannelException e) {
|
||||
logger.warn("Unable to send: " + cmd.toString());
|
||||
logger.warn("Unable to send: {}", cmd.toString());
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Unable to send: " + cmd.toString() + " due to exception: ", e);
|
||||
logger.warn("Unable to send: {} due to exception: {}", cmd.toString(), e);
|
||||
}
|
||||
logger.debug("Sending shutdown to management server");
|
||||
try {
|
||||
@ -377,7 +377,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
}
|
||||
|
||||
public void setId(final Long id) {
|
||||
logger.info("Set agent id " + id);
|
||||
logger.debug("Set agent id {}", id);
|
||||
_id = id;
|
||||
_shell.setPersistentProperty(getResourceName(), "id", Long.toString(id));
|
||||
}
|
||||
@ -396,7 +396,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
hostLBTimer.cancel();
|
||||
}
|
||||
if (checkInterval > 0L) {
|
||||
logger.info("Scheduling preferred host timer task with host.lb.interval=" + checkInterval + "ms");
|
||||
logger.info("Scheduling preferred host timer task with host.lb.interval={}ms", checkInterval);
|
||||
hostLBTimer = new Timer("Host LB Timer");
|
||||
hostLBTimer.scheduleAtFixedRate(new PreferredHostCheckerTask(), checkInterval, checkInterval);
|
||||
}
|
||||
@ -404,9 +404,8 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
|
||||
public void scheduleWatch(final Link link, final Request request, final long delay, final long period) {
|
||||
synchronized (_watchList) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Adding a watch list");
|
||||
}
|
||||
logger.debug("Adding task with request: {} to watch list", request.toString());
|
||||
|
||||
final WatchTask task = new WatchTask(link, request, this);
|
||||
_timer.schedule(task, 0, period);
|
||||
_watchList.add(task);
|
||||
@ -423,7 +422,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
try {
|
||||
_link.send(request.toBytes());
|
||||
} catch (final ClosedChannelException e) {
|
||||
logger.warn("Unable to send ping update: " + request.toString());
|
||||
logger.warn("Unable to send ping update: {}", request.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,9 +431,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
for (final WatchTask task : _watchList) {
|
||||
task.cancel();
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Clearing watch list: " + _watchList.size());
|
||||
}
|
||||
logger.debug("Clearing {} tasks of watch list", _watchList.size());
|
||||
_watchList.clear();
|
||||
}
|
||||
}
|
||||
@ -470,14 +467,12 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
final Request request = new Request(_id != null ? _id : -1, -1, commands, false, false);
|
||||
request.setSequence(getNextSequence());
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Sending Startup: " + request.toString());
|
||||
}
|
||||
logger.debug("Sending Startup: {}", request.toString());
|
||||
lockStartupTask(link);
|
||||
try {
|
||||
link.send(request.toBytes());
|
||||
} catch (final ClosedChannelException e) {
|
||||
logger.warn("Unable to send request: " + request.toString());
|
||||
logger.warn("Unable to send request: {}", request.toString());
|
||||
}
|
||||
|
||||
if (_resource instanceof ResourceStatusUpdater) {
|
||||
@ -537,14 +532,14 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
|
||||
_resource.disconnected();
|
||||
|
||||
logger.info("Lost connection to host: " + _shell.getConnectedHost() + ". Attempting reconnection while we still have " + _inProgress.get() + " commands in progress.");
|
||||
logger.info("Lost connection to host: {}. Attempting reconnection while we still have {} commands in progress.", _shell.getConnectedHost(), _inProgress.get());
|
||||
|
||||
_connection.stop();
|
||||
|
||||
try {
|
||||
_connection.cleanUp();
|
||||
} catch (final IOException e) {
|
||||
logger.warn("Fail to clean up old connection. " + e);
|
||||
logger.warn("Fail to clean up old connection. {}", e);
|
||||
}
|
||||
|
||||
while (_connection.isStartup()) {
|
||||
@ -554,7 +549,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
do {
|
||||
final String host = _shell.getNextHost();
|
||||
_connection = new NioClient("Agent", host, _shell.getPort(), _shell.getWorkers(), this);
|
||||
logger.info("Reconnecting to host:" + host);
|
||||
logger.info("Reconnecting to host:{}", host);
|
||||
try {
|
||||
_connection.start();
|
||||
} catch (final NioConnectionException e) {
|
||||
@ -563,13 +558,13 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
try {
|
||||
_connection.cleanUp();
|
||||
} catch (final IOException ex) {
|
||||
logger.warn("Fail to clean up old connection. " + ex);
|
||||
logger.warn("Fail to clean up old connection. {}", ex);
|
||||
}
|
||||
}
|
||||
_shell.getBackoffAlgorithm().waitBeforeRetry();
|
||||
} while (!_connection.isStartup());
|
||||
_shell.updateConnectedHost();
|
||||
logger.info("Connected to the host: " + _shell.getConnectedHost());
|
||||
logger.info("Connected to the host: {}", _shell.getConnectedHost());
|
||||
}
|
||||
|
||||
public void processStartupAnswer(final Answer answer, final Response response, final Link link) {
|
||||
@ -584,7 +579,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
}
|
||||
final StartupAnswer startup = (StartupAnswer)answer;
|
||||
if (!startup.getResult()) {
|
||||
logger.error("Not allowed to connect to the server: " + answer.getDetails());
|
||||
logger.error("Not allowed to connect to the server: {}", answer.getDetails());
|
||||
System.exit(1);
|
||||
}
|
||||
if (cancelled) {
|
||||
@ -592,7 +587,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Process agent startup answer, agent id = " + startup.getHostId());
|
||||
logger.info("Process agent startup answer, agent id = {}", startup.getHostId());
|
||||
|
||||
setId(startup.getHostId());
|
||||
_pingInterval = (long)startup.getPingInterval() * 1000; // change to ms.
|
||||
@ -602,7 +597,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
|
||||
_ugentTaskPool.setKeepAliveTime(2 * _pingInterval, TimeUnit.MILLISECONDS);
|
||||
|
||||
logger.info("Startup Response Received: agent id = " + getId());
|
||||
logger.info("Startup Response Received: agent id = {}", getId());
|
||||
}
|
||||
|
||||
protected void processRequest(final Request request, final Link link) {
|
||||
@ -624,11 +619,11 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
{
|
||||
final String requestMsg = request.toString();
|
||||
if (requestMsg != null) {
|
||||
logger.debug("Request:" + requestMsg);
|
||||
logger.debug("Request:{}",requestMsg);
|
||||
}
|
||||
requestLogged = true;
|
||||
}
|
||||
logger.debug("Processing command: " + cmd.toString());
|
||||
logger.debug("Processing command: {}", cmd.toString());
|
||||
}
|
||||
|
||||
if (cmd instanceof CronCommand) {
|
||||
@ -637,7 +632,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
answer = new Answer(cmd, true, null);
|
||||
} else if (cmd instanceof ShutdownCommand) {
|
||||
final ShutdownCommand shutdown = (ShutdownCommand)cmd;
|
||||
logger.debug("Received shutdownCommand, due to: " + shutdown.getReason());
|
||||
logger.debug("Received shutdownCommand, due to: {}", shutdown.getReason());
|
||||
cancelTasks();
|
||||
if (shutdown.isRemoveHost()) {
|
||||
cleanupAgentZoneProperties();
|
||||
@ -645,7 +640,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
_reconnectAllowed = false;
|
||||
answer = new Answer(cmd, true, null);
|
||||
} else if (cmd instanceof ReadyCommand && ((ReadyCommand)cmd).getDetails() != null) {
|
||||
logger.debug("Not ready to connect to mgt server: " + ((ReadyCommand)cmd).getDetails());
|
||||
logger.debug("Not ready to connect to mgt server: {}", ((ReadyCommand)cmd).getDetails());
|
||||
System.exit(1);
|
||||
return;
|
||||
} else if (cmd instanceof MaintainCommand) {
|
||||
@ -663,7 +658,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
}
|
||||
|
||||
if (answer == null) {
|
||||
logger.warn("No handler found to process cmd: " + cmd.toString());
|
||||
logger.warn("No handler found to process cmd: {}", cmd.toString());
|
||||
answer = new AgentControlAnswer(cmd);
|
||||
}
|
||||
} else if (cmd instanceof SetupKeyStoreCommand && ((SetupKeyStoreCommand) cmd).isHandleByAgent()) {
|
||||
@ -686,7 +681,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
_inProgress.decrementAndGet();
|
||||
}
|
||||
if (answer == null) {
|
||||
logger.debug("Response: unsupported command" + cmd.toString());
|
||||
logger.debug("Response: unsupported command {}", cmd.toString());
|
||||
answer = Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
}
|
||||
@ -718,7 +713,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
try {
|
||||
link.send(response.toBytes());
|
||||
} catch (final ClosedChannelException e) {
|
||||
logger.warn("Unable to send response: " + response.toString());
|
||||
logger.warn("Unable to send response: {}", response.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -782,7 +777,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
try {
|
||||
FileUtils.writeStringToFile(new File(certFile), certificate, Charset.defaultCharset());
|
||||
FileUtils.writeStringToFile(new File(caCertFile), caCertificates, Charset.defaultCharset());
|
||||
logger.debug("Saved received client certificate to: " + certFile);
|
||||
logger.debug("Saved received client certificate to: {}", certFile);
|
||||
} catch (IOException e) {
|
||||
throw new CloudRuntimeException("Unable to save received agent client and ca certificates", e);
|
||||
}
|
||||
@ -813,7 +808,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
_shell.setPersistentProperty(null, "host", newMSHosts);
|
||||
_shell.setHosts(newMSHosts);
|
||||
_shell.resetHostCounter();
|
||||
logger.info("Processed new management server list: " + newMSHosts);
|
||||
logger.info("Processed new management server list: {}", newMSHosts);
|
||||
} catch (final Exception e) {
|
||||
throw new CloudRuntimeException("Could not persist received management servers list", e);
|
||||
}
|
||||
@ -832,9 +827,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
|
||||
public void processResponse(final Response response, final Link link) {
|
||||
final Answer answer = response.getAnswer();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Received response: " + response.toString());
|
||||
}
|
||||
logger.debug("Received response: {}", response.toString());
|
||||
if (answer instanceof StartupAnswer) {
|
||||
processStartupAnswer(answer, response, link);
|
||||
} else if (answer instanceof AgentControlAnswer) {
|
||||
@ -860,37 +853,35 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
NumbersUtil.enableHumanReadableSizes = humanReadable;
|
||||
}
|
||||
|
||||
logger.info("Processing agent ready command, agent id = " + ready.getHostId());
|
||||
logger.info("Processing agent ready command, agent id = {}", ready.getHostId());
|
||||
if (ready.getHostId() != null) {
|
||||
setId(ready.getHostId());
|
||||
}
|
||||
|
||||
processManagementServerList(ready.getMsHostList(), ready.getLbAlgorithm(), ready.getLbCheckInterval());
|
||||
|
||||
logger.info("Ready command is processed for agent id = " + getId());
|
||||
logger.info("Ready command is processed for agent id = {}", getId());
|
||||
}
|
||||
|
||||
public void processOtherTask(final Task task) {
|
||||
final Object obj = task.get();
|
||||
if (obj instanceof Response) {
|
||||
if (System.currentTimeMillis() - _lastPingResponseTime > _pingInterval * _shell.getPingRetries()) {
|
||||
logger.error("Ping Interval has gone past " + _pingInterval * _shell.getPingRetries() + ". Won't reconnect to mgt server, as connection is still alive");
|
||||
logger.error("Ping Interval has gone past {}. Won't reconnect to mgt server, as connection is still alive", _pingInterval * _shell.getPingRetries());
|
||||
return;
|
||||
}
|
||||
|
||||
final PingCommand ping = _resource.getCurrentStatus(getId());
|
||||
final Request request = new Request(_id, -1, ping, false);
|
||||
request.setSequence(getNextSequence());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Sending ping: " + request.toString());
|
||||
}
|
||||
logger.debug("Sending ping: {}", request.toString());
|
||||
|
||||
try {
|
||||
task.getLink().send(request.toBytes());
|
||||
//if i can send pingcommand out, means the link is ok
|
||||
setLastPingResponseTime();
|
||||
} catch (final ClosedChannelException e) {
|
||||
logger.warn("Unable to send request: " + request.toString());
|
||||
logger.warn("Unable to send request: {}", request.toString());
|
||||
}
|
||||
|
||||
} else if (obj instanceof Request) {
|
||||
@ -909,13 +900,11 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
if (answer != null) {
|
||||
final Response response = new Response(req, answer);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Watch Sent: " + response.toString());
|
||||
}
|
||||
logger.debug("Watch Sent: {}", response.toString());
|
||||
try {
|
||||
task.getLink().send(response.toBytes());
|
||||
} catch (final ClosedChannelException e) {
|
||||
logger.warn("Unable to send response: " + response.toString());
|
||||
logger.warn("Unable to send response: {}", response.toString());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -981,7 +970,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
try {
|
||||
_link.send(request.toBytes());
|
||||
} catch (final ClosedChannelException e) {
|
||||
logger.warn("Unable to post agent control request: " + request.toString());
|
||||
logger.warn("Unable to post agent control request: {}", request.toString());
|
||||
throw new AgentControlChannelException("Unable to post agent control request due to " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
@ -1045,9 +1034,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
|
||||
@Override
|
||||
protected void runInContext() {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Scheduling " + (_request instanceof Response ? "Ping" : "Watch Task"));
|
||||
}
|
||||
logger.trace("Scheduling {}", (_request instanceof Response ? "Ping" : "Watch Task"));
|
||||
try {
|
||||
if (_request instanceof Response) {
|
||||
_ugentTaskPool.submit(new ServerHandler(Task.Type.OTHER, _link, _request));
|
||||
@ -1084,9 +1071,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
@Override
|
||||
protected synchronized void runInContext() {
|
||||
if (!cancelled) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("The startup command is now cancelled");
|
||||
}
|
||||
cancelled = true;
|
||||
_startup = null;
|
||||
_startupWait = _startupWaitDefault * 2;
|
||||
@ -1192,9 +1177,8 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
shell.launchNewAgent(resource);
|
||||
return;
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.debug("Other tasks are in progress, will retry post certificate renewal command after few seconds");
|
||||
}
|
||||
|
||||
Thread.sleep(5000);
|
||||
} catch (final Exception e) {
|
||||
logger.warn("Failed to execute post certificate renewal command:", e);
|
||||
@ -1215,23 +1199,20 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater
|
||||
}
|
||||
final String preferredHost = msList[0];
|
||||
final String connectedHost = _shell.getConnectedHost();
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Running preferred host checker task, connected host=" + connectedHost + ", preferred host=" + preferredHost);
|
||||
}
|
||||
logger.trace("Running preferred host checker task, connected host={}, preferred host={}", connectedHost, preferredHost);
|
||||
|
||||
if (preferredHost != null && !preferredHost.equals(connectedHost) && _link != null) {
|
||||
boolean isHostUp = true;
|
||||
try (final Socket socket = new Socket()) {
|
||||
socket.connect(new InetSocketAddress(preferredHost, _shell.getPort()), 5000);
|
||||
} catch (final IOException e) {
|
||||
isHostUp = false;
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Host: " + preferredHost + " is not reachable");
|
||||
}
|
||||
logger.trace("Host: {} is not reachable", preferredHost);
|
||||
|
||||
}
|
||||
if (isHostUp && _link != null && _inProgress.get() == 0) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Preferred host " + preferredHost + " is found to be reachable, trying to reconnect");
|
||||
}
|
||||
logger.debug("Preferred host {} is found to be reachable, trying to reconnect", preferredHost);
|
||||
|
||||
_shell.resetHostCounter();
|
||||
reconnect(_link);
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ public class AgentShell implements IAgentShell, Daemon {
|
||||
throw new ConfigurationException("Unable to find agent.properties.");
|
||||
}
|
||||
|
||||
LOGGER.info("agent.properties found at " + file.getAbsolutePath());
|
||||
LOGGER.info("agent.properties found at {}", file.getAbsolutePath());
|
||||
|
||||
try {
|
||||
PropertiesUtil.loadFromFile(_properties, file);
|
||||
@ -382,7 +382,7 @@ public class AgentShell implements IAgentShell, Daemon {
|
||||
if (_version == null) {
|
||||
throw new CloudRuntimeException("Unable to find the implementation version of this agent");
|
||||
}
|
||||
LOGGER.info("Implementation Version is " + _version);
|
||||
LOGGER.info("Implementation Version is {}", _version);
|
||||
|
||||
loadProperties();
|
||||
parseCommand(args);
|
||||
@ -390,7 +390,7 @@ public class AgentShell implements IAgentShell, Daemon {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
List<String> properties = Collections.list((Enumeration<String>)_properties.propertyNames());
|
||||
for (String property : properties) {
|
||||
LOGGER.debug("Found property: " + property);
|
||||
LOGGER.debug("Found property: {}", property);
|
||||
}
|
||||
}
|
||||
|
||||
@ -411,7 +411,7 @@ public class AgentShell implements IAgentShell, Daemon {
|
||||
|
||||
private void launchAgent() throws ConfigurationException {
|
||||
String resourceClassNames = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.RESOURCE);
|
||||
LOGGER.trace("resource=" + resourceClassNames);
|
||||
LOGGER.trace("resource={}", resourceClassNames);
|
||||
if (resourceClassNames != null) {
|
||||
launchAgentFromClassInfo(resourceClassNames);
|
||||
return;
|
||||
@ -444,7 +444,7 @@ public class AgentShell implements IAgentShell, Daemon {
|
||||
LOGGER.error("Unable to retrieve the type");
|
||||
throw new ConfigurationException("Unable to retrieve the type of this agent.");
|
||||
}
|
||||
LOGGER.trace("Launching agent based on type=" + typeInfo);
|
||||
LOGGER.trace("Launching agent based on type={}", typeInfo);
|
||||
}
|
||||
|
||||
public void launchNewAgent(ServerResource resource) throws ConfigurationException {
|
||||
@ -506,7 +506,7 @@ public class AgentShell implements IAgentShell, Daemon {
|
||||
String pidDir = getProperty(null, "piddir");
|
||||
|
||||
final String run = "agent." + instance + "pid";
|
||||
LOGGER.debug("Checking to see if " + run + " exists.");
|
||||
LOGGER.debug("Checking to see if {} exists.", run);
|
||||
ProcessUtil.pidCheck(pidDir, run);
|
||||
|
||||
launchAgent();
|
||||
|
||||
@ -93,14 +93,12 @@ public class PropertiesStorage implements StorageComponent {
|
||||
file = new File(path);
|
||||
try {
|
||||
if (!file.createNewFile()) {
|
||||
logger.error(String.format("Unable to create _file: %s", file.getAbsolutePath()));
|
||||
logger.error("Unable to create _file: {}", file.getAbsolutePath());
|
||||
return false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error(String.format("Unable to create file: %s", file.getAbsolutePath()));
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("IOException while trying to create file: %s", file.getAbsolutePath()), e);
|
||||
}
|
||||
logger.error("Unable to create file: {}", file.getAbsolutePath());
|
||||
logger.debug("IOException while trying to create file: {}", file.getAbsolutePath(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,8 +87,7 @@ public class MockVmMgr implements VmMgr {
|
||||
|
||||
@Override
|
||||
public String stopVM(String vmName, boolean force) {
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("Stop VM. name: " + vmName);
|
||||
logger.info("Stop VM. name: {}", vmName);
|
||||
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
@ -103,8 +102,7 @@ public class MockVmMgr implements VmMgr {
|
||||
|
||||
@Override
|
||||
public String rebootVM(String vmName) {
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("Reboot VM. name: " + vmName);
|
||||
logger.info("Reboot VM. name: {}", vmName);
|
||||
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
@ -116,8 +114,7 @@ public class MockVmMgr implements VmMgr {
|
||||
|
||||
@Override
|
||||
public boolean migrate(String vmName, String params) {
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("Migrate VM. name: " + vmName);
|
||||
logger.info("Migrate VM. name: {}", vmName);
|
||||
|
||||
synchronized (this) {
|
||||
MockVm vm = vms.get(vmName);
|
||||
|
||||
@ -48,7 +48,7 @@ public class AgentPropertiesFileHandler {
|
||||
File agentPropertiesFile = PropertiesUtil.findConfigFile(KeyStoreUtils.AGENT_PROPSFILE);
|
||||
|
||||
if (agentPropertiesFile == null) {
|
||||
LOGGER.debug(String.format("File [%s] was not found, we will use default defined values. Property [%s]: [%s].", KeyStoreUtils.AGENT_PROPSFILE, name, defaultValue));
|
||||
LOGGER.debug("File [{}] was not found, we will use default defined values. Property [{}]: [{}].", KeyStoreUtils.AGENT_PROPSFILE, name, defaultValue);
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
@ -56,7 +56,7 @@ public class AgentPropertiesFileHandler {
|
||||
try {
|
||||
String configValue = PropertiesUtil.loadFromFile(agentPropertiesFile).getProperty(name);
|
||||
if (StringUtils.isBlank(configValue)) {
|
||||
LOGGER.debug(String.format("Property [%s] has empty or null value. Using default value [%s].", name, defaultValue));
|
||||
LOGGER.debug("Property [{}] has empty or null value. Using default value [{}].", name, defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@ -68,11 +68,11 @@ public class AgentPropertiesFileHandler {
|
||||
ConvertUtils.register(new LongConverter(defaultValue), Long.class);
|
||||
}
|
||||
|
||||
LOGGER.debug(String.format("Property [%s] was altered. Now using the value [%s].", name, configValue));
|
||||
LOGGER.debug("Property [{}] was altered. Now using the value [{}].", name, configValue);
|
||||
return (T)ConvertUtils.convert(configValue, property.getTypeClass());
|
||||
|
||||
} catch (IOException ex) {
|
||||
LOGGER.debug(String.format("Failed to get property [%s]. Using default value [%s].", name, defaultValue), ex);
|
||||
LOGGER.debug("Failed to get property [{}]. Using default value [{}].", name, defaultValue, ex);
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
|
||||
@ -175,12 +175,12 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
|
||||
try {
|
||||
is.close();
|
||||
} catch (final IOException e) {
|
||||
logger.warn("Exception when closing , console proxy address : " + proxyManagementIp);
|
||||
logger.warn("Exception when closing , console proxy address : {}", proxyManagementIp);
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
logger.warn("Unable to open console proxy command port url, console proxy address : " + proxyManagementIp);
|
||||
logger.warn("Unable to open console proxy command port url, console proxy address : {}", proxyManagementIp);
|
||||
success = false;
|
||||
}
|
||||
|
||||
@ -278,20 +278,19 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
|
||||
disableRpFilter();
|
||||
}
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("Receive proxyVmId in ConsoleProxyResource configuration as " + proxyVmId);
|
||||
logger.info("Receive proxyVmId in ConsoleProxyResource configuration as {}", proxyVmId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addRouteToInternalIpOrCidr(String localgw, String eth1ip, String eth1mask, String destIpOrCidr) {
|
||||
logger.debug("addRouteToInternalIp: localgw=" + localgw + ", eth1ip=" + eth1ip + ", eth1mask=" + eth1mask + ",destIp=" + destIpOrCidr);
|
||||
logger.debug("addRouteToInternalIp: localgw={}, eth1ip={}, eth1mask={}, destIp={}", localgw, eth1ip, eth1mask, destIpOrCidr);
|
||||
if (destIpOrCidr == null) {
|
||||
logger.debug("addRouteToInternalIp: destIp is null");
|
||||
return;
|
||||
}
|
||||
if (!NetUtils.isValidIp4(destIpOrCidr) && !NetUtils.isValidIp4Cidr(destIpOrCidr)) {
|
||||
logger.warn(" destIp is not a valid ip address or cidr destIp=" + destIpOrCidr);
|
||||
logger.warn(" destIp is not a valid ip address or cidr destIp={}", destIpOrCidr);
|
||||
return;
|
||||
}
|
||||
boolean inSameSubnet = false;
|
||||
@ -299,13 +298,13 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
|
||||
if (eth1ip != null && eth1mask != null) {
|
||||
inSameSubnet = NetUtils.sameSubnet(eth1ip, destIpOrCidr, eth1mask);
|
||||
} else {
|
||||
logger.warn("addRouteToInternalIp: unable to determine same subnet: eth1ip=" + eth1ip + ", dest ip=" + destIpOrCidr + ", eth1mask=" + eth1mask);
|
||||
logger.warn("addRouteToInternalIp: unable to determine same subnet: eth1ip={}, dest ip={}, eth1mask={}", eth1ip, destIpOrCidr, eth1mask);
|
||||
}
|
||||
} else {
|
||||
inSameSubnet = NetUtils.isNetworkAWithinNetworkB(destIpOrCidr, NetUtils.ipAndNetMaskToCidr(eth1ip, eth1mask));
|
||||
}
|
||||
if (inSameSubnet) {
|
||||
logger.debug("addRouteToInternalIp: dest ip " + destIpOrCidr + " is in the same subnet as eth1 ip " + eth1ip);
|
||||
logger.debug("addRouteToInternalIp: dest ip {} is in the same subnet as eth1 ip {}", destIpOrCidr, eth1ip);
|
||||
return;
|
||||
}
|
||||
Script command = new Script("/bin/bash", logger);
|
||||
@ -317,9 +316,9 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
|
||||
command.add("ip route add " + destIpOrCidr + " via " + localgw);
|
||||
String result = command.execute();
|
||||
if (result != null) {
|
||||
logger.warn("Error in configuring route to internal ip err=" + result);
|
||||
logger.warn("Error in configuring route to internal ip err={}", result);
|
||||
} else {
|
||||
logger.debug("addRouteToInternalIp: added route to internal ip=" + destIpOrCidr + " via " + localgw);
|
||||
logger.debug("addRouteToInternalIp: added route to internal ip={} via {}", destIpOrCidr, localgw);
|
||||
}
|
||||
}
|
||||
|
||||
@ -332,7 +331,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
|
||||
final Object resource = this;
|
||||
logger.info("Building class loader for com.cloud.consoleproxy.ConsoleProxy");
|
||||
if (consoleProxyMain == null) {
|
||||
logger.info("Running com.cloud.consoleproxy.ConsoleProxy with encryptor password=" + encryptorPassword);
|
||||
logger.info("Running com.cloud.consoleproxy.ConsoleProxy with encryptor password={}", encryptorPassword);
|
||||
consoleProxyMain = new Thread(new ManagedContextRunnable() {
|
||||
@Override
|
||||
protected void runInContext() {
|
||||
@ -355,7 +354,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
|
||||
logger.error("Unable to launch console proxy due to IllegalAccessException", e);
|
||||
System.exit(ExitStatus.Error.value());
|
||||
} catch (InvocationTargetException e) {
|
||||
logger.error("Unable to launch console proxy due to InvocationTargetException " + e.getTargetException().toString(), e);
|
||||
logger.error("Unable to launch console proxy due to InvocationTargetException {}", e.getTargetException().toString(), e);
|
||||
System.exit(ExitStatus.Error.value());
|
||||
}
|
||||
} catch (final ClassNotFoundException e) {
|
||||
@ -418,10 +417,10 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
|
||||
result.setTunnelUrl(authAnswer.getTunnelUrl());
|
||||
result.setTunnelSession(authAnswer.getTunnelSession());
|
||||
} else {
|
||||
logger.error("Authentication failed for vm: " + vmId + " with sid: " + sid);
|
||||
logger.error("Authentication failed for vm: {} with sid: {}", vmId, sid);
|
||||
}
|
||||
} catch (AgentControlChannelException e) {
|
||||
logger.error("Unable to send out console access authentication request due to " + e.getMessage(), e);
|
||||
logger.error("Unable to send out console access authentication request due to {}", e.getMessage(), e);
|
||||
}
|
||||
|
||||
return new Gson().toJson(result);
|
||||
@ -431,18 +430,15 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
|
||||
ConsoleProxyLoadReportCommand cmd = new ConsoleProxyLoadReportCommand(proxyVmId, gsonLoadInfo);
|
||||
try {
|
||||
getAgentControl().postRequest(cmd);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Report proxy load info, proxy : " + proxyVmId + ", load: " + gsonLoadInfo);
|
||||
logger.debug("Report proxy load info, proxy : {}, load: {}", proxyVmId, gsonLoadInfo);
|
||||
} catch (AgentControlChannelException e) {
|
||||
logger.error("Unable to send out load info due to " + e.getMessage(), e);
|
||||
logger.error("Unable to send out load info due to {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void ensureRoute(String address) {
|
||||
if (localGateway != null) {
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Ensure route for " + address + " via " + localGateway);
|
||||
logger.debug("Ensure route for {} via {}", address, localGateway);
|
||||
|
||||
// this method won't be called in high frequency, serialize access
|
||||
// to script execution
|
||||
@ -450,7 +446,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
|
||||
try {
|
||||
addRouteToInternalIpOrCidr(localGateway, eth1Ip, eth1Mask, address);
|
||||
} catch (Throwable e) {
|
||||
logger.warn("Unexpected exception while adding internal route to " + address, e);
|
||||
logger.warn("Unexpected exception while adding internal route to {}", address, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user