From d382636ef397b65efe30f31fe922d40fe7e75316 Mon Sep 17 00:00:00 2001 From: leo79901 Date: Wed, 4 Dec 2024 21:39:15 +0800 Subject: [PATCH 1/8] add check befor fencing Resolve the issur : Should not shutting down a server which is already shut. Thanks for DaanHoogland which provide code. --- .../cloudstack/kvm/ha/KVMHAProvider.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java index 81daabf59d76..f29f3d7a9d57 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java @@ -84,18 +84,24 @@ public boolean recover(Host r) throws HARecoveryException { @Override public boolean fence(Host r) throws HAFenceException { - try { - if (outOfBandManagementService.isOutOfBandManagementEnabled(r)){ - final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.OFF, null); - return resp.getSuccess(); + // host exists and is managed OOB + if (r != null && outOfBandManagementService.isOutOfBandManagementEnabled(r)) { + // check host status + if (Host.Status.DOWN.equals(r.getStatus())) { + LOG.info("Host " + r.getName() + " is already down. Returning success."); + return true; + } else { + final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.OFF, null); + return resp.getSuccess(); + } } else { - logger.warn("OOBM fence operation failed for this host " + r.getName()); + LOG.warn("OOBM fence operation failed for this host " + r.getName()); return false; } - } catch (Exception e){ - logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); - throw new HAFenceException("OBM service is not configured or enabled for this host " + r.getName() , e); + } catch (Exception e) { + LOG.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); + throw new HAFenceException("OBM service is not configured or enabled for this host " + r.getName(), e); } } From 39115147ed772085f28007f0110213fa9330ed0e Mon Sep 17 00:00:00 2001 From: leo79901 Date: Wed, 4 Dec 2024 23:03:51 +0800 Subject: [PATCH 2/8] Update KVMHAProvider.java --- .../java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java index f29f3d7a9d57..e1fd14c98229 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java @@ -89,18 +89,18 @@ public boolean fence(Host r) throws HAFenceException { if (r != null && outOfBandManagementService.isOutOfBandManagementEnabled(r)) { // check host status if (Host.Status.DOWN.equals(r.getStatus())) { - LOG.info("Host " + r.getName() + " is already down. Returning success."); + logger.info("Host " + r.getName() + " is already down. Returning success."); return true; } else { final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.OFF, null); return resp.getSuccess(); } } else { - LOG.warn("OOBM fence operation failed for this host " + r.getName()); + logger.warn("OOBM fence operation failed for this host " + r.getName()); return false; } } catch (Exception e) { - LOG.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); + logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); throw new HAFenceException("OBM service is not configured or enabled for this host " + r.getName(), e); } } From 93818f6f17e2eb07dfc7fca16f4eecc491e002d7 Mon Sep 17 00:00:00 2001 From: leo79901 Date: Wed, 4 Dec 2024 23:08:00 +0800 Subject: [PATCH 3/8] Update KVMHAProvider.java --- .../main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java index e1fd14c98229..55b5140c9781 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java @@ -99,7 +99,7 @@ public boolean fence(Host r) throws HAFenceException { logger.warn("OOBM fence operation failed for this host " + r.getName()); return false; } - } catch (Exception e) { + } catch (Exception e){ logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); throw new HAFenceException("OBM service is not configured or enabled for this host " + r.getName(), e); } From b239b6e6dd0ea5c3430780e734da15368b6980e3 Mon Sep 17 00:00:00 2001 From: leo79901 Date: Wed, 4 Dec 2024 23:10:22 +0800 Subject: [PATCH 4/8] Update KVMHAProvider.java --- .../main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java index 55b5140c9781..cb83621b3cac 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java @@ -78,7 +78,7 @@ public boolean recover(Host r) throws HARecoveryException { } } catch (Exception e){ logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); - throw new HARecoveryException(" OOBM service is not configured or enabled for this host " + r.getName(), e); + throw new HARecoveryException(" OOBM service is not configured or enabled for this host " + r.getName() , e); } } From 79472dc54effbe817fda707fc8b66fc6d8e9d8c4 Mon Sep 17 00:00:00 2001 From: leo79901 Date: Wed, 4 Dec 2024 23:11:56 +0800 Subject: [PATCH 5/8] Update KVMHAProvider.java --- .../main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java index cb83621b3cac..55b5140c9781 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java @@ -78,7 +78,7 @@ public boolean recover(Host r) throws HARecoveryException { } } catch (Exception e){ logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); - throw new HARecoveryException(" OOBM service is not configured or enabled for this host " + r.getName() , e); + throw new HARecoveryException(" OOBM service is not configured or enabled for this host " + r.getName(), e); } } From 3e8c57d8b160041b5a2ce0721455b74475993aeb Mon Sep 17 00:00:00 2001 From: leo79901 Date: Wed, 4 Dec 2024 23:13:52 +0800 Subject: [PATCH 6/8] Update KVMHAProvider.java --- .../main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java index 55b5140c9781..11f282bba66c 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java @@ -101,7 +101,7 @@ public boolean fence(Host r) throws HAFenceException { } } catch (Exception e){ logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); - throw new HAFenceException("OBM service is not configured or enabled for this host " + r.getName(), e); + throw new HAFenceException("OBM service is not configured or enabled for this host " + r.getName() , e); } } From 3a6904094da9f84264c5a80659d334a561ff92b2 Mon Sep 17 00:00:00 2001 From: leo79901 Date: Thu, 5 Dec 2024 14:38:58 +0800 Subject: [PATCH 7/8] Update KVMHAProvider.java --- .../main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java index 11f282bba66c..5d5c65dcfcec 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java @@ -35,6 +35,7 @@ import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement.PowerOperation; import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementService; import org.joda.time.DateTime; +import com.cloud.host.Status; import javax.inject.Inject; @@ -84,11 +85,12 @@ public boolean recover(Host r) throws HARecoveryException { @Override public boolean fence(Host r) throws HAFenceException { + try { // host exists and is managed OOB if (r != null && outOfBandManagementService.isOutOfBandManagementEnabled(r)) { // check host status - if (Host.Status.DOWN.equals(r.getStatus())) { + if (Status.Down.equals(r.getStatus())) { logger.info("Host " + r.getName() + " is already down. Returning success."); return true; } else { From 67e33f60146c923682d82c184c3fcd47cfd039c1 Mon Sep 17 00:00:00 2001 From: leo79901 Date: Thu, 5 Dec 2024 17:33:52 +0800 Subject: [PATCH 8/8] Update plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java Co-authored-by: dahn --- .../main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java index 5d5c65dcfcec..72d6a802b860 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java @@ -85,7 +85,6 @@ public boolean recover(Host r) throws HARecoveryException { @Override public boolean fence(Host r) throws HAFenceException { - try { // host exists and is managed OOB if (r != null && outOfBandManagementService.isOutOfBandManagementEnabled(r)) {