Skip to content

Commit e1dd07a

Browse files
authored
Ability to put a server in Down state to maintenance (#4363)
1 parent 25dd7aa commit e1dd07a

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
415415
"Maximum IOPS read burst duration (seconds). If '0' (zero) then does not check for maximum burst length.", true, ConfigKey.Scope.Global, null);
416416
public final static ConfigKey<Long> IOPS_MAX_WRITE_LENGTH = new ConfigKey<Long>(Long.class, "vm.disk.iops.maximum.write.length", "Advanced", "0",
417417
"Maximum IOPS write burst duration (seconds). If '0' (zero) then does not check for maximum burst length.", true, ConfigKey.Scope.Global, null);
418-
419418
public static final ConfigKey<Boolean> ADD_HOST_ON_SERVICE_RESTART_KVM = new ConfigKey<Boolean>(Boolean.class, "add.host.on.service.restart.kvm", "Advanced", "true",
420419
"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",
421420
true, ConfigKey.Scope.Global, null);
421+
public static final ConfigKey<Boolean> SET_HOST_DOWN_TO_MAINTENANCE = new ConfigKey<Boolean>(Boolean.class, "set.host.down.to.maintenance", "Advanced", "false",
422+
"Indicates whether the host in down state can be put into maintenance state so thats its not enabled after it comes back.",
423+
true, ConfigKey.Scope.Zone, null);
422424

423425
private static final String IOPS_READ_RATE = "IOPS Read";
424426
private static final String IOPS_WRITE_RATE = "IOPS Write";
@@ -6437,6 +6439,6 @@ public String getConfigComponentName() {
64376439
@Override
64386440
public ConfigKey<?>[] getConfigKeys() {
64396441
return new ConfigKey<?>[] {SystemVMUseLocalStorage, IOPS_MAX_READ_LENGTH, IOPS_MAX_WRITE_LENGTH,
6440-
BYTES_MAX_READ_LENGTH, BYTES_MAX_WRITE_LENGTH, ADD_HOST_ON_SERVICE_RESTART_KVM};
6442+
BYTES_MAX_READ_LENGTH, BYTES_MAX_WRITE_LENGTH, ADD_HOST_ON_SERVICE_RESTART_KVM, SET_HOST_DOWN_TO_MAINTENANCE};
64416443
}
64426444
}

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@
180180
import com.cloud.vm.dao.VMInstanceDao;
181181
import com.google.gson.Gson;
182182

183+
184+
import static com.cloud.configuration.ConfigurationManagerImpl.SET_HOST_DOWN_TO_MAINTENANCE;
185+
183186
@Component
184187
public class ResourceManagerImpl extends ManagerBase implements ResourceManager, ResourceService, Manager {
185188
private static final Logger s_logger = Logger.getLogger(ResourceManagerImpl.class);
@@ -1302,6 +1305,17 @@ public Host maintain(final PrepareForMaintenanceCmd cmd) {
13021305
throw new CloudRuntimeException("Host is already in state " + host.getResourceState() + ". Cannot recall for maintenance until resolved.");
13031306
}
13041307

1308+
if (SET_HOST_DOWN_TO_MAINTENANCE.valueIn(host.getDataCenterId()) && (host.getStatus() == Status.Down)) {
1309+
if (host.getResourceState() == ResourceState.Enabled) {
1310+
_hostDao.updateResourceState(ResourceState.Enabled, ResourceState.Event.AdminAskMaintenance, ResourceState.PrepareForMaintenance, host);
1311+
_hostDao.updateResourceState(ResourceState.PrepareForMaintenance, ResourceState.Event.InternalEnterMaintenance, ResourceState.Maintenance, host);
1312+
return _hostDao.findById(hostId);
1313+
} else if (host.getResourceState() == ResourceState.ErrorInMaintenance) {
1314+
_hostDao.updateResourceState(ResourceState.ErrorInMaintenance, ResourceState.Event.InternalEnterMaintenance, ResourceState.Maintenance, host);
1315+
return _hostDao.findById(hostId);
1316+
}
1317+
}
1318+
13051319
if (_hostDao.countBy(host.getClusterId(), ResourceState.PrepareForMaintenance, ResourceState.ErrorInPrepareForMaintenance) > 0) {
13061320
throw new CloudRuntimeException("There are other servers attempting migrations for maintenance. " +
13071321
"Found hosts in PrepareForMaintenance OR ErrorInPrepareForMaintenance STATUS in cluster " + host.getClusterId());

0 commit comments

Comments
 (0)