use of com.cloud.agent.api.MaintainAnswer in project cloudstack by apache.
the class ResourceManagerImpl method doMaintain.
private boolean doMaintain(final long hostId) {
final HostVO host = _hostDao.findById(hostId);
s_logger.info("Maintenance: attempting maintenance of host " + host.getUuid());
ResourceState hostState = host.getResourceState();
if (!ResourceState.canAttemptMaintenance(hostState)) {
throw new CloudRuntimeException("Cannot perform maintain when resource state is " + hostState + ", hostId = " + hostId);
}
final MaintainAnswer answer = (MaintainAnswer) _agentMgr.easySend(hostId, new MaintainCommand());
if (answer == null || !answer.getResult()) {
s_logger.warn("Unable to send MaintainCommand to host: " + hostId);
return false;
}
try {
resourceStateTransitTo(host, ResourceState.Event.AdminAskMaintenance, _nodeId);
} catch (final NoTransitionException e) {
final String err = String.format("Cannot transit resource state of %s to %s", host, ResourceState.Maintenance);
s_logger.debug(err, e);
throw new CloudRuntimeException(err + e.getMessage());
}
ActionEventUtils.onStartedActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(), EventTypes.EVENT_MAINTENANCE_PREPARE, "starting maintenance for host " + hostId, true, 0);
_agentMgr.pullAgentToMaintenance(hostId);
/* TODO: move below to listener */
if (host.getType() == Host.Type.Routing) {
final List<VMInstanceVO> vms = _vmDao.listByHostId(hostId);
if (vms.size() == 0) {
return true;
}
List<HostVO> hosts = listAllUpAndEnabledHosts(Host.Type.Routing, host.getClusterId(), host.getPodId(), host.getDataCenterId());
if (CollectionUtils.isEmpty(hosts)) {
s_logger.warn("Unable to find a host for vm migration in cluster: " + host.getClusterId());
if (!isClusterWideMigrationPossible(host, vms, hosts)) {
return false;
}
}
for (final VMInstanceVO vm : vms) {
if (hosts == null || hosts.isEmpty() || !answer.getMigrate() || _serviceOfferingDetailsDao.findDetail(vm.getServiceOfferingId(), GPU.Keys.vgpuType.toString()) != null) {
handleVmForLastHostOrWithVGpu(host, vm);
} else if (HypervisorType.LXC.equals(host.getHypervisorType()) && VirtualMachine.Type.User.equals(vm.getType())) {
// Migration is not supported for LXC Vms. Schedule restart instead.
_haMgr.scheduleRestart(vm, false);
} else if (userVmManager.isVMUsingLocalStorage(vm)) {
if (isMaintenanceLocalStrategyForceStop()) {
_haMgr.scheduleStop(vm, hostId, WorkType.ForceStop);
} else if (isMaintenanceLocalStrategyMigrate()) {
migrateAwayVmWithVolumes(host, vm);
} else if (!isMaintenanceLocalStrategyDefault()) {
String logMessage = String.format("Unsupported host.maintenance.local.storage.strategy: %s. Please set a strategy according to the global settings description: " + "'Error', 'Migration', or 'ForceStop'.", HOST_MAINTENANCE_LOCAL_STRATEGY.value().toString());
s_logger.error(logMessage);
throw new CloudRuntimeException("There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage.");
}
} else {
s_logger.info("Maintenance: scheduling migration of VM " + vm.getUuid() + " from host " + host.getUuid());
_haMgr.scheduleMigration(vm);
}
}
}
return true;
}
use of com.cloud.agent.api.MaintainAnswer in project cloudstack by apache.
the class CitrixMaintainCommandWrapper method execute.
@Override
public Answer execute(final MaintainCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
try {
final XsHost xsHost = citrixResourceBase.getHost();
final String uuid = xsHost.getUuid();
final Host host = Host.getByUuid(conn, uuid);
// remove all tags cloud stack
final Host.Record hr = host.getRecord(conn);
// Adding this check because could not get the mock to work. Will push the code and fix it afterwards.
if (hr == null) {
s_logger.warn("Host.Record is null.");
return new MaintainAnswer(command, false, "Host.Record is null");
}
final Iterator<String> it = hr.tags.iterator();
while (it.hasNext()) {
final String tag = it.next();
if (tag.contains("cloud")) {
it.remove();
}
}
host.setTags(conn, hr.tags);
return new MaintainAnswer(command);
} catch (final XenAPIException e) {
s_logger.warn("Unable to put server in maintainence mode", e);
return new MaintainAnswer(command, false, e.getMessage());
} catch (final XmlRpcException e) {
s_logger.warn("Unable to put server in maintainence mode", e);
return new MaintainAnswer(command, false, e.getMessage());
}
}
Aggregations