Skip to content

Commit 7bb7d3f

Browse files
leo79901DaanHoogland
authored andcommitted
add check befor fencing
Resolve the issur : Should not shutting down a server which is already shut. Thanks for DaanHoogland which provide code.
1 parent 971a5b2 commit 7bb7d3f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementService;
3636
import org.apache.log4j.Logger;
3737
import org.joda.time.DateTime;
38+
import com.cloud.host.Status;
3839

3940
import javax.inject.Inject;
4041
import java.security.InvalidParameterException;
@@ -86,17 +87,23 @@ public boolean recover(Host r) throws HARecoveryException {
8687

8788
@Override
8889
public boolean fence(Host r) throws HAFenceException {
89-
9090
try {
91-
if (outOfBandManagementService.isOutOfBandManagementEnabled(r)){
92-
final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.OFF, null);
93-
return resp.getSuccess();
91+
// host exists and is managed OOB
92+
if (r != null && outOfBandManagementService.isOutOfBandManagementEnabled(r)) {
93+
// check host status
94+
if (Status.Down.equals(r.getStatus())) {
95+
logger.info("Host " + r.getName() + " is already down. Returning success.");
96+
return true;
97+
} else {
98+
final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.OFF, null);
99+
return resp.getSuccess();
100+
}
94101
} else {
95-
LOG.warn("OOBM fence operation failed for this host " + r.getName());
102+
logger.warn("OOBM fence operation failed for this host " + r.getName());
96103
return false;
97104
}
98105
} catch (Exception e){
99-
LOG.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage());
106+
logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage());
100107
throw new HAFenceException("OBM service is not configured or enabled for this host " + r.getName() , e);
101108
}
102109
}

0 commit comments

Comments
 (0)