|
35 | 35 | import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementService; |
36 | 36 | import org.apache.log4j.Logger; |
37 | 37 | import org.joda.time.DateTime; |
| 38 | +import com.cloud.host.Status; |
38 | 39 |
|
39 | 40 | import javax.inject.Inject; |
40 | 41 | import java.security.InvalidParameterException; |
@@ -86,17 +87,23 @@ public boolean recover(Host r) throws HARecoveryException { |
86 | 87 |
|
87 | 88 | @Override |
88 | 89 | public boolean fence(Host r) throws HAFenceException { |
89 | | - |
90 | 90 | 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 | + } |
94 | 101 | } 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()); |
96 | 103 | return false; |
97 | 104 | } |
98 | 105 | } 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()); |
100 | 107 | throw new HAFenceException("OBM service is not configured or enabled for this host " + r.getName() , e); |
101 | 108 | } |
102 | 109 | } |
|
0 commit comments