Skip to content
Merged
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
16 changes: 16 additions & 0 deletions agent/src/main/java/com/cloud/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,19 @@ protected void cancelTasks() {
}
}

/**
* Cleanup agent zone properties.
*
* Unset zone, cluster and pod values so that host is not added back
* when service is restarted. This will be set to proper values
* when host is added back
*/
protected void cleanupAgentZoneProperties() {
_shell.setPersistentProperty(null, "zone", "");
_shell.setPersistentProperty(null, "cluster", "");
_shell.setPersistentProperty(null, "pod", "");
}

public synchronized void lockStartupTask(final Link link) {
_startup = new StartupTask(link);
_timer.schedule(_startup, _startupWait);
Expand Down Expand Up @@ -603,6 +616,9 @@ protected void processRequest(final Request request, final Link link) {
final ShutdownCommand shutdown = (ShutdownCommand)cmd;
s_logger.debug("Received shutdownCommand, due to: " + shutdown.getReason());
cancelTasks();
if (shutdown.isRemoveHost()) {
cleanupAgentZoneProperties();
}
_reconnectAllowed = false;
answer = new Answer(cmd, true, null);
} else if (cmd instanceof ReadyCommand && ((ReadyCommand)cmd).getDetails() != null) {
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/com/cloud/agent/api/ShutdownCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ShutdownCommand extends Command {

private String reason;
private String detail;
private boolean removeHost;

protected ShutdownCommand() {
super();
Expand All @@ -41,6 +42,13 @@ public ShutdownCommand(String reason, String detail) {
this.detail = detail;
}

public ShutdownCommand(String reason, String detail, boolean removeHost) {
super();
this.reason = reason;
this.detail = detail;
this.removeHost = removeHost;
}

/**
* @return return the reason the agent shutdown. If Unknown, call getDetail() for any details.
*/
Expand All @@ -52,6 +60,10 @@ public String getDetail() {
return detail;
}

public boolean isRemoveHost() {
return removeHost;
}

@Override
public boolean executeInSequence() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
public final static ConfigKey<Long> IOPS_MAX_WRITE_LENGTH = new ConfigKey<Long>(Long.class, "vm.disk.iops.maximum.write.length", "Advanced", "0",
"Maximum IOPS write burst duration (seconds). If '0' (zero) then does not check for maximum burst length.", true, ConfigKey.Scope.Global, null);

public static final ConfigKey<Boolean> ADD_HOST_ON_SERVICE_RESTART_KVM = new ConfigKey<Boolean>(Boolean.class, "add.host.on.service.restart.kvm", "Advanced", "true",
"Indicates whether the host will be added back to cloudstack after restarting agent service on host. If false it wont be added back even after service restart",
true, ConfigKey.Scope.Global, null);

private static final String IOPS_READ_RATE = "IOPS Read";
private static final String IOPS_WRITE_RATE = "IOPS Write";
private static final String BYTES_READ_RATE = "Bytes Read";
Expand Down Expand Up @@ -6378,6 +6382,7 @@ public String getConfigComponentName() {

@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {SystemVMUseLocalStorage, IOPS_MAX_READ_LENGTH, IOPS_MAX_WRITE_LENGTH, BYTES_MAX_READ_LENGTH, BYTES_MAX_WRITE_LENGTH};
return new ConfigKey<?>[] {SystemVMUseLocalStorage, IOPS_MAX_READ_LENGTH, IOPS_MAX_WRITE_LENGTH,
BYTES_MAX_READ_LENGTH, BYTES_MAX_WRITE_LENGTH, ADD_HOST_ON_SERVICE_RESTART_KVM};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
import com.cloud.utils.ssh.SSHCmdHelper;
import com.trilead.ssh2.Connection;

import static com.cloud.configuration.ConfigurationManagerImpl.ADD_HOST_ON_SERVICE_RESTART_KVM;

public abstract class LibvirtServerDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter {
private static final Logger s_logger = Logger.getLogger(LibvirtServerDiscoverer.class);
private final int _waitTime = 5; /* wait for 5 minutes */
Expand Down Expand Up @@ -348,6 +350,7 @@ private void setupAgentSecurity(final Connection sshConnection, final String age
_hostDao.saveDetails(connectedHost);
return resources;
} catch (DiscoveredWithErrorException e) {
s_logger.error("DiscoveredWithErrorException caught and rethrowing, message: "+ e.getMessage());
throw e;
} catch (Exception e) {
String msg = " can't setup agent, due to " + e.toString() + " - " + e.getMessage();
Expand Down Expand Up @@ -474,7 +477,7 @@ public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForc

_resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
try {
ShutdownCommand cmd = new ShutdownCommand(ShutdownCommand.DeleteHost, null);
ShutdownCommand cmd = new ShutdownCommand(ShutdownCommand.DeleteHost, null, !ADD_HOST_ON_SERVICE_RESTART_KVM.value());
agentMgr.send(host.getId(), cmd);
} catch (AgentUnavailableException e) {
s_logger.warn("Sending ShutdownCommand failed: ", e);
Expand Down