Skip to content

Commit 72e35ca

Browse files
committed
Cleanup
1 parent da1f6df commit 72e35ca

1 file changed

Lines changed: 0 additions & 163 deletions

File tree

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

Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import com.cloud.dc.ClusterDetailsDao;
2525
import com.cloud.dc.ClusterDetailsVO;
2626
import com.cloud.dc.ClusterVO;
27-
import com.cloud.dc.DataCenterVO;
28-
import com.cloud.dc.HostPodVO;
2927
import com.cloud.dc.dao.ClusterDao;
3028
import com.cloud.dc.dao.DataCenterDao;
3129
import com.cloud.dc.dao.HostPodDao;
@@ -39,7 +37,6 @@
3937
import com.cloud.host.dao.HostDao;
4038
import com.cloud.host.dao.HostTagsDao;
4139
import com.cloud.hypervisor.Hypervisor;
42-
import com.cloud.org.Cluster;
4340
import com.cloud.service.ServiceOfferingVO;
4441
import com.cloud.service.dao.ServiceOfferingDao;
4542
import com.cloud.utils.Pair;
@@ -322,171 +319,11 @@ private Set<Host> getHostsListForRollingMaintenance(ResourceType type, List<Long
322319
return hosts;
323320
}
324321

325-
/**
326-
* Invoke rolling maintenance from an entity and type
327-
*/
328-
private Pair<Boolean, String> rollingMaintenance(RollingMaintenanceEntity entity, ResourceType type, long timeout, String payload, Boolean forced) {
329-
if (entity instanceof HostPodVO && type == ResourceType.Pod) {
330-
HostPodVO podVO = (HostPodVO) entity;
331-
return rollingMaintenancePod(podVO, timeout, payload, forced);
332-
} else if (entity instanceof DataCenterVO && type == ResourceType.Zone) {
333-
DataCenterVO dataCenterVO = (DataCenterVO) entity;
334-
return rollingMaintenanceZone(dataCenterVO, timeout, payload, forced);
335-
} else if (entity instanceof ClusterVO && type == ResourceType.Cluster) {
336-
ClusterVO clusterVO = (ClusterVO) entity;
337-
return rollingMaintenanceCluster(clusterVO, timeout, payload, forced);
338-
} else if (entity instanceof HostVO && type == ResourceType.Host) {
339-
HostVO hostVO = (HostVO) entity;
340-
if (hostVO.getState() != Status.Up) {
341-
return new Pair<>(false, "Host " + hostVO.getUuid() + " is not in Up state");
342-
}
343-
return rollingMaintenanceHost(hostVO, timeout, payload);
344-
}
345-
throw new CloudRuntimeException("Unrecognized entity with type: " + type);
346-
}
347-
348-
/**
349-
* Retrieve an entity from its type and ID
350-
*/
351-
private RollingMaintenanceEntity getEntity(ResourceType type, Long entityId) {
352-
s_logger.debug("Searching for entity with ID: " + entityId + " and type: " + type);
353-
RollingMaintenanceEntity entity = null;
354-
if (type == ResourceType.Pod) {
355-
entity = podDao.findById(entityId);
356-
} else if (type == ResourceType.Cluster) {
357-
entity = clusterDao.findById(entityId);
358-
} else if (type == ResourceType.Zone) {
359-
entity = dataCenterDao.findById(entityId);
360-
} else if (type == ResourceType.Host) {
361-
entity = hostDao.findById(entityId);
362-
} else {
363-
throw new CloudRuntimeException("Unknown resource type: " + type);
364-
}
365-
if (entity == null) {
366-
throw new CloudRuntimeException("Could not find " + type + " with ID: " + entityId);
367-
}
368-
return entity;
369-
}
370-
371322
@Override
372323
public Pair<ResourceType, List<Long>> getResourceTypeIdPair(StartRollingMaintenanceCmd cmd) {
373324
return getResourceTypeAndIdPair(cmd.getPodIds(), cmd.getClusterIds(), cmd.getZoneIds(), cmd.getHostIds());
374325
}
375326

376-
/*
377-
Rolling maintenance for the hosts in the zone, iterating though its pods and clusters
378-
*/
379-
private Pair<Boolean, String> rollingMaintenanceZone(DataCenterVO zoneVO, long timeout, String payload, Boolean forced) {
380-
List<HostPodVO> pods = podDao.listByDataCenterId(zoneVO.getId());
381-
for (HostPodVO pod : pods) {
382-
Pair<Boolean, String> result = rollingMaintenancePod(pod, timeout, payload, forced);
383-
if (!result.first()) {
384-
s_logger.error("Error on rolling maintenance for zone " + zoneVO.getUuid() + " while processing " +
385-
"pod " + pod.getUuid());
386-
return result;
387-
}
388-
}
389-
return new Pair<> (true, "OK");
390-
}
391-
392-
/*
393-
Rolling maintenance for the hosts in a pod, iterating through its clusters
394-
*/
395-
private Pair<Boolean, String> rollingMaintenancePod(HostPodVO podVO, long timeout, String payload, Boolean forced) {
396-
List<ClusterVO> clusters = clusterDao.listByPodId(podVO.getId());
397-
for (ClusterVO cluster : clusters) {
398-
Pair<Boolean, String> result = rollingMaintenanceCluster(cluster, timeout, payload, forced);
399-
if (!result.first()) {
400-
s_logger.error("Error on rolling maintenance for pod " + podVO.getUuid() + " while processing " +
401-
"hosts from cluster " + cluster.getUuid());
402-
return result;
403-
}
404-
}
405-
return new Pair<> (true, "OK");
406-
}
407-
408-
/*
409-
Rolling maintenance for the hosts in a cluster
410-
*/
411-
protected Pair<Boolean, String> rollingMaintenanceCluster(Cluster cluster, long timeout, String payload, Boolean forced) {
412-
if (cluster.getHypervisorType() != Hypervisor.HypervisorType.KVM) {
413-
throw new CloudRuntimeException(unsopportedHypervisorErrorMsg);
414-
}
415-
List<HostVO> clusterHosts = hostDao.listByClusterAndHypervisorType(cluster.getId(), cluster.getHypervisorType());
416-
for (HostVO host: clusterHosts) {
417-
if (host.getState() != Status.Up) {
418-
s_logger.debug("Host " + host.getUuid() + " is not in Up state, skipping on rolling maintenance");
419-
continue;
420-
}
421-
Pair<Boolean, String> result = rollingMaintenanceHost(host, timeout, payload);
422-
if (!result.first()) {
423-
if (forced) {
424-
s_logger.warn("Rolling maintenance failed for host " + host.getUuid() + " but forced flag is enabled," +
425-
"continuing with the next host...");
426-
} else {
427-
return result;
428-
}
429-
}
430-
}
431-
return new Pair<> (true, "OK");
432-
}
433-
434-
/**
435-
* Rolling maintenance for a host. It is perform in 4 stages:
436-
* - Pre-flight
437-
* - Pre-maintenance
438-
* - Maintenance
439-
* - Post-maintenance
440-
*/
441-
protected Pair<Boolean, String> rollingMaintenanceHost(Host host, long timeout, String payload) {
442-
s_logger.debug("Starting rolling maintenance on host " + host.getUuid());
443-
444-
Stage stage = Stage.PreFlight;
445-
try {
446-
while (stage != null) {
447-
s_logger.debug("Performing stage " + stage + " on host " + host.getUuid());
448-
Pair<Boolean, String> result = performRollingMaintenanceStage(host, stage, timeout, payload);
449-
if (!result.first()) {
450-
String msg = "Error on rolling maintenance for host: " + host.getUuid() + ", stage: " + stage
451-
+ ", details: " + result.second();
452-
s_logger.error(msg);
453-
return new Pair<>(false, msg);
454-
}
455-
s_logger.debug("Stage " + stage + " succeeded on host " + host.getUuid());
456-
stage = stage.next();
457-
}
458-
} catch (AgentUnavailableException | CloudRuntimeException | InterruptedException e) {
459-
String msg = "Unable to perform rolling maintenance stage " + stage + " on host " + host.getUuid()
460-
+ ": " + e.getMessage();
461-
s_logger.error(msg, e);
462-
return new Pair<>(false, msg);
463-
}
464-
return new Pair<>(true, "OK");
465-
}
466-
467-
/*
468-
Perform the rolling maintenance stage for a host
469-
*/
470-
protected Pair<Boolean, String> performRollingMaintenanceStage(Host host, Stage stage, long timeout, String payload) throws AgentUnavailableException, CloudRuntimeException, InterruptedException {
471-
if (stage == Stage.Maintenance) {
472-
s_logger.debug("Trying to set the host " + host.getId() + " into maintenance");
473-
resourceManager.maintain(host.getId());
474-
waitForHostInMaintenance(host.getId());
475-
} else if (stage == Stage.PostMaintenance) {
476-
boolean success = resourceManager.cancelMaintenance(host.getId());
477-
if (!success) {
478-
s_logger.error("Could not cancel maintenance on host " + host.getUuid());
479-
}
480-
}
481-
482-
s_logger.info("Rolling maintenance for host " + host.getUuid() + " stage = " + stage);
483-
RollingMaintenanceCommand cmd = new RollingMaintenanceCommand(stage.toString());
484-
cmd.setTimeout(timeout);
485-
cmd.setPayload(payload);
486-
487-
return sendRollingMaintenanceCommandToHost(host, cmd, timeout, payload);
488-
}
489-
490327
/*
491328
Wait for to be in maintenance mode
492329
*/

0 commit comments

Comments
 (0)