|
20 | 20 | import java.net.URISyntaxException; |
21 | 21 | import java.net.URLDecoder; |
22 | 22 | import java.util.ArrayList; |
23 | | -import java.util.Arrays; |
24 | 23 | import java.util.Collections; |
25 | 24 | import java.util.HashMap; |
26 | 25 | import java.util.Iterator; |
@@ -1216,7 +1215,7 @@ private boolean doMaintain(final long hostId) { |
1216 | 1215 | final HostVO host = _hostDao.findById(hostId); |
1217 | 1216 | s_logger.info("Maintenance: attempting maintenance of host " + host.getUuid()); |
1218 | 1217 | ResourceState hostState = host.getResourceState(); |
1219 | | - if (ResourceState.isMaintenanceState(hostState)) { |
| 1218 | + if (!ResourceState.canAttemptMaintenance(hostState)) { |
1220 | 1219 | throw new CloudRuntimeException("Cannot perform maintain when resource state is " + hostState + ", hostId = " + hostId); |
1221 | 1220 | } |
1222 | 1221 |
|
@@ -1284,7 +1283,7 @@ public Host maintain(final PrepareForMaintenanceCmd cmd) { |
1284 | 1283 | s_logger.debug("Unable to find host " + hostId); |
1285 | 1284 | throw new InvalidParameterValueException("Unable to find host with ID: " + hostId + ". Please specify a valid host ID."); |
1286 | 1285 | } |
1287 | | - if (Arrays.asList(ResourceState.Maintenance, ResourceState.PrepareForMaintenance, ResourceState.ErrorInPrepareForMaintenance).contains(host.getResourceState())) { |
| 1286 | + if (!ResourceState.canAttemptMaintenance(host.getResourceState())) { |
1288 | 1287 | throw new CloudRuntimeException("Host is already in state " + host.getResourceState() + ". Cannot recall for maintenance until resolved."); |
1289 | 1288 | } |
1290 | 1289 |
|
@@ -2398,10 +2397,7 @@ private boolean doCancelMaintenance(final long hostId) { |
2398 | 2397 | * TODO: think twice about returning true or throwing out exception, I |
2399 | 2398 | * really prefer to exception that always exposes bugs |
2400 | 2399 | */ |
2401 | | - if (host.getResourceState() != ResourceState.PrepareForMaintenance && |
2402 | | - host.getResourceState() != ResourceState.ErrorInPrepareForMaintenance && |
2403 | | - host.getResourceState() != ResourceState.Maintenance && |
2404 | | - host.getResourceState() != ResourceState.ErrorInMaintenance) { |
| 2400 | + if (!ResourceState.isMaintenanceState(host.getResourceState())) { |
2405 | 2401 | throw new CloudRuntimeException("Cannot perform cancelMaintenance when resource state is " + host.getResourceState() + ", hostId = " + hostId); |
2406 | 2402 | } |
2407 | 2403 |
|
|
0 commit comments