Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
810 changes: 544 additions & 266 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);
System.out.println(e.getMessage());
}
}
Expand Down
Loading
Loading