Skip to content

Commit 2286c8d

Browse files
committed
Merge remote-tracking branch 'origin/4.14' into 4.15
2 parents dc91a1f + e2183ed commit 2286c8d

5 files changed

Lines changed: 33 additions & 31 deletions

File tree

api/src/main/java/com/cloud/resource/ResourceState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public static boolean canAttemptMaintenance(ResourceState state) {
114114
s_fsm.addTransition(ResourceState.Enabled, Event.Disable, ResourceState.Disabled);
115115
s_fsm.addTransition(ResourceState.Enabled, Event.AdminAskMaintenance, ResourceState.PrepareForMaintenance);
116116
s_fsm.addTransition(ResourceState.Enabled, Event.InternalEnterMaintenance, ResourceState.Maintenance);
117+
s_fsm.addTransition(ResourceState.Enabled, Event.DeleteHost, ResourceState.Disabled);
117118
s_fsm.addTransition(ResourceState.Disabled, Event.Enable, ResourceState.Enabled);
118119
s_fsm.addTransition(ResourceState.Disabled, Event.Disable, ResourceState.Disabled);
119120
s_fsm.addTransition(ResourceState.Disabled, Event.InternalCreated, ResourceState.Disabled);

engine/components-api/src/main/java/com/cloud/ha/HighAvailabilityManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
public interface HighAvailabilityManager extends Manager {
3434

35-
ConfigKey<Boolean> ForceHA = new ConfigKey<>("Advanced", Boolean.class, "force.ha", "false",
35+
public ConfigKey<Boolean> ForceHA = new ConfigKey<>("Advanced", Boolean.class, "force.ha", "false",
3636
"Force High-Availability to happen even if the VM says no.", true, Cluster);
3737

3838
ConfigKey<Integer> HAWorkers = new ConfigKey<>("Advanced", Integer.class, "ha.workers", "5",

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4695,7 +4695,7 @@ private void handlePowerOffReportWithNoPendingJobsOnVM(final VMInstanceVO vm) {
46954695
String.format("VM %s is at %s and we received a %s report while there is no pending jobs on it"
46964696
, vm.getInstanceName(), vm.getState(), vm.getPowerState()));
46974697
}
4698-
if(vm.isHaEnabled() && vm.getState() == State.Running
4698+
if((HighAvailabilityManager.ForceHA.value() || vm.isHaEnabled()) && vm.getState() == State.Running
46994699
&& HaVmRestartHostUp.value()
47004700
&& vm.getHypervisorType() != HypervisorType.VMware
47014701
&& vm.getHypervisorType() != HypervisorType.Hyperv) {

server/src/main/java/com/cloud/ha/HighAvailabilityManagerImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ public void setHaPlanners(List<HAPlanner> haPlanners) {
202202
int _maxRetries;
203203
long _timeBetweenFailures;
204204
long _timeBetweenCleanups;
205-
boolean _forceHA;
206205
String _haTag = null;
207206

208207
protected HighAvailabilityManagerImpl() {
@@ -369,7 +368,7 @@ public void scheduleRestart(VMInstanceVO vm, boolean investigate) {
369368
alertType = AlertManager.AlertType.ALERT_TYPE_SSVM;
370369
}
371370

372-
if (!(_forceHA || vm.isHaEnabled())) {
371+
if (!(ForceHA.value() || vm.isHaEnabled())) {
373372
String hostDesc = "id:" + vm.getHostId() + ", availability zone id:" + vm.getDataCenterId() + ", pod id:" + vm.getPodIdToDeployIn();
374373
_alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodIdToDeployIn(), "VM (name: " + vm.getHostName() + ", id: " + vm.getId() +
375374
") stopped unexpectedly on host " + hostDesc, "Virtual Machine " + vm.getHostName() + " (id: " + vm.getId() + ") running on host [" + vm.getHostId() +
@@ -574,7 +573,7 @@ protected Long restart(final HaWorkVO work) {
574573

575574
vm = _itMgr.findById(vm.getId());
576575

577-
if (!_forceHA && !vm.isHaEnabled()) {
576+
if (!ForceHA.value() && !vm.isHaEnabled()) {
578577
if (s_logger.isDebugEnabled()) {
579578
s_logger.debug("VM is not HA enabled so we're done.");
580579
}
@@ -885,7 +884,6 @@ public boolean configure(final String name, final Map<String, Object> xmlParams)
885884
_workers[i] = new WorkerThread("HA-Worker-" + i);
886885
}
887886

888-
_forceHA = ForceHA.value();
889887
_timeToSleep = TimeToSleep.value() * SECONDS_TO_MILLISECONDS_FACTOR;
890888
_maxRetries = MigrationMaxRetries.value();
891889
_timeBetweenFailures = TimeBetweenFailures.value() * SECONDS_TO_MILLISECONDS_FACTOR;

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

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,34 +2370,32 @@ public void deleteRoutingHost(final HostVO host, final boolean isForced, final b
23702370
s_logger.debug("Deleting Host: " + host.getId() + " Guid:" + host.getGuid());
23712371
}
23722372

2373-
if (forceDestroyStorage) {
2373+
final StoragePoolVO storagePool = _storageMgr.findLocalStorageOnHost(host.getId());
2374+
if (forceDestroyStorage && storagePool != null) {
23742375
// put local storage into mainenance mode, will set all the VMs on
23752376
// this local storage into stopped state
2376-
final StoragePoolVO storagePool = _storageMgr.findLocalStorageOnHost(host.getId());
2377-
if (storagePool != null) {
2378-
if (storagePool.getStatus() == StoragePoolStatus.Up || storagePool.getStatus() == StoragePoolStatus.ErrorInMaintenance) {
2379-
try {
2380-
final StoragePool pool = _storageSvr.preparePrimaryStorageForMaintenance(storagePool.getId());
2381-
if (pool == null) {
2382-
s_logger.debug("Failed to set primary storage into maintenance mode");
2377+
if (storagePool.getStatus() == StoragePoolStatus.Up || storagePool.getStatus() == StoragePoolStatus.ErrorInMaintenance) {
2378+
try {
2379+
final StoragePool pool = _storageSvr.preparePrimaryStorageForMaintenance(storagePool.getId());
2380+
if (pool == null) {
2381+
s_logger.debug("Failed to set primary storage into maintenance mode");
23832382

2384-
throw new UnableDeleteHostException("Failed to set primary storage into maintenance mode");
2385-
}
2386-
} catch (final Exception e) {
2387-
s_logger.debug("Failed to set primary storage into maintenance mode, due to: " + e.toString());
2388-
throw new UnableDeleteHostException("Failed to set primary storage into maintenance mode, due to: " + e.toString());
2383+
throw new UnableDeleteHostException("Failed to set primary storage into maintenance mode");
23892384
}
2385+
} catch (final Exception e) {
2386+
s_logger.debug("Failed to set primary storage into maintenance mode, due to: " + e.toString());
2387+
throw new UnableDeleteHostException("Failed to set primary storage into maintenance mode, due to: " + e.toString());
23902388
}
2389+
}
23912390

2392-
final List<VMInstanceVO> vmsOnLocalStorage = _storageMgr.listByStoragePool(storagePool.getId());
2393-
for (final VMInstanceVO vm : vmsOnLocalStorage) {
2394-
try {
2395-
_vmMgr.destroy(vm.getUuid(), false);
2396-
} catch (final Exception e) {
2397-
final String errorMsg = "There was an error Destory the vm: " + vm + " as a part of hostDelete id=" + host.getId();
2398-
s_logger.debug(errorMsg, e);
2399-
throw new UnableDeleteHostException(errorMsg + "," + e.getMessage());
2400-
}
2391+
final List<VMInstanceVO> vmsOnLocalStorage = _storageMgr.listByStoragePool(storagePool.getId());
2392+
for (final VMInstanceVO vm : vmsOnLocalStorage) {
2393+
try {
2394+
_vmMgr.destroy(vm.getUuid(), false);
2395+
} catch (final Exception e) {
2396+
final String errorMsg = "There was an error Destory the vm: " + vm + " as a part of hostDelete id=" + host.getId();
2397+
s_logger.debug(errorMsg, e);
2398+
throw new UnableDeleteHostException(errorMsg + "," + e.getMessage());
24012399
}
24022400
}
24032401
} else {
@@ -2407,17 +2405,22 @@ public void deleteRoutingHost(final HostVO host, final boolean isForced, final b
24072405
if (isForced) {
24082406
// Stop HA disabled vms and HA enabled vms in Stopping state
24092407
// Restart HA enabled vms
2408+
try {
2409+
resourceStateTransitTo(host, ResourceState.Event.DeleteHost, host.getId());
2410+
} catch (final NoTransitionException e) {
2411+
s_logger.debug("Cannot transmit host " + host.getId() + " to Disabled state", e);
2412+
}
24102413
for (final VMInstanceVO vm : vms) {
2411-
if (!vm.isHaEnabled() || vm.getState() == State.Stopping) {
2414+
if ((! HighAvailabilityManager.ForceHA.value() && !vm.isHaEnabled()) || vm.getState() == State.Stopping) {
24122415
s_logger.debug("Stopping vm: " + vm + " as a part of deleteHost id=" + host.getId());
24132416
try {
2414-
_vmMgr.advanceStop(vm.getUuid(), false);
2417+
_haMgr.scheduleStop(vm, host.getId(), WorkType.Stop);
24152418
} catch (final Exception e) {
24162419
final String errorMsg = "There was an error stopping the vm: " + vm + " as a part of hostDelete id=" + host.getId();
24172420
s_logger.debug(errorMsg, e);
24182421
throw new UnableDeleteHostException(errorMsg + "," + e.getMessage());
24192422
}
2420-
} else if (vm.isHaEnabled() && (vm.getState() == State.Running || vm.getState() == State.Starting)) {
2423+
} else if ((HighAvailabilityManager.ForceHA.value() || vm.isHaEnabled()) && (vm.getState() == State.Running || vm.getState() == State.Starting)) {
24212424
s_logger.debug("Scheduling restart for vm: " + vm + " " + vm.getState() + " on the host id=" + host.getId());
24222425
_haMgr.scheduleRestart(vm, false);
24232426
}

0 commit comments

Comments
 (0)