Skip to content
824 changes: 557 additions & 267 deletions agent/src/main/java/com/cloud/agent/Agent.java

Large diffs are not rendered by default.

33 changes: 24 additions & 9 deletions agent/src/main/java/com/cloud/agent/AgentShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import javax.naming.ConfigurationException;

import com.cloud.utils.backoff.BackoffFactory;
import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext;
import org.apache.commons.daemon.DaemonInitException;
Expand All @@ -52,7 +53,6 @@
import com.cloud.utils.ProcessUtil;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.backoff.BackoffAlgorithm;
import com.cloud.utils.backoff.impl.ConstantTimeBackoff;
import com.cloud.utils.exception.CloudRuntimeException;

public class AgentShell implements IAgentShell, Daemon {
Expand Down Expand Up @@ -95,6 +95,16 @@ public BackoffAlgorithm getBackoffAlgorithm() {
return _backoff;
}

@Override
public void setBackoffAlgorithm(BackoffAlgorithm backoffAlgorithm) {
this._backoff = backoffAlgorithm;
try {
backoffAlgorithm.getConfiguration().forEach((key, value) -> setPersistentProperty(null, key, value));
} catch (RuntimeException e) {
LOGGER.warn("Failed to persist backoff properties");
}
}

@Override
public int getPingRetries() {
return _pingRetries;
Expand Down Expand Up @@ -400,7 +410,7 @@ public void init(String[] args) throws ConfigurationException {
final Class<?> c = this.getClass();
_version = c.getPackage().getImplementationVersion();
if (_version == null) {
throw new CloudRuntimeException("Unable to find the implementation version of this agent");
_version = "unknown";
}
LOGGER.info("Implementation Version is {}", _version);

Expand All @@ -410,7 +420,7 @@ public void init(String[] args) throws ConfigurationException {
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: {}, value: {}", property, _properties.getProperty(property));
}
}

Expand All @@ -424,11 +434,15 @@ public void init(String[] args) throws ConfigurationException {
_properties.put(cmdLineProp.getKey(), cmdLineProp.getValue());
}

LOGGER.info("Defaulting to the constant time backoff algorithm");
_backoff = new ConstantTimeBackoff();
Map<String, Object> map = new HashMap<>();
map.put("seconds", _properties.getProperty("backoff.seconds"));
_backoff.configure("ConstantTimeBackoff", map);
try {
LOGGER.info("Creating backoff delay algorithm implementation");
setBackoffAlgorithm(BackoffFactory.create(_properties));
LOGGER.info("Created {} delay algorithm implementation", getBackoffAlgorithm().getClass().getName());
} catch (RuntimeException e) {
String msg = String.format("Failed to create backoff with provided properties %s, failing back to default", _properties);
LOGGER.warn(msg, e);
setBackoffAlgorithm(BackoffFactory.createDefault(_properties));
}
}

private void launchAgent() throws ConfigurationException {
Expand Down Expand Up @@ -546,7 +560,7 @@ public void start() {
}

} catch (final Exception e) {
LOGGER.error("Unable to start agent: ", e);
LOGGER.error("Unable to start agent: {}", e.getLocalizedMessage(), e);
System.exit(ExitStatus.Error.value());
}
}
Expand All @@ -568,6 +582,7 @@ public static void main(String[] args) {
shell.init(args);
shell.start();
} catch (ConfigurationException e) {
LOGGER.fatal(e.getMessage(), e);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this now logs the same message twice, LOGGER.fatal here followed by System.out.println right below with the same e.getMessage().

System.out.println(e.getMessage());
}
}
Expand Down
Loading
Loading