Gilad Chaplik has uploaded a new change for review. Change subject: engine: add missing file ......................................................................
engine: add missing file fix build break Change-Id: I0993dd074a3803721daa85dcc3d00e63dfd45f72 Signed-off-by: Gilad Chaplik <gchap...@redhat.com> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceNumberOfVdssCommand.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceVdsCommand.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MaintenanceNumberOfVdssParameters.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MaintenanceVdsParameters.java 4 files changed, 634 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/02/12402/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceNumberOfVdssCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceNumberOfVdssCommand.java new file mode 100644 index 0000000..e6245a3 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceNumberOfVdssCommand.java @@ -0,0 +1,346 @@ +package org.ovirt.engine.core.bll; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.ovirt.engine.core.bll.job.ExecutionHandler; +import org.ovirt.engine.core.bll.network.cluster.NetworkClusterHelper; +import org.ovirt.engine.core.bll.utils.PermissionSubject; +import org.ovirt.engine.core.common.VdcObjectType; +import org.ovirt.engine.core.common.action.MaintenanceNumberOfVdssParameters; +import org.ovirt.engine.core.common.action.MaintenanceVdsParameters; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.action.VdcReturnValueBase; +import org.ovirt.engine.core.common.businessentities.AsyncTaskStatus; +import org.ovirt.engine.core.common.businessentities.MigrationSupport; +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.businessentities.VDSGroup; +import org.ovirt.engine.core.common.businessentities.VDSStatus; +import org.ovirt.engine.core.common.businessentities.VM; +import org.ovirt.engine.core.common.businessentities.VdsSpmStatus; +import org.ovirt.engine.core.common.businessentities.network.Network; +import org.ovirt.engine.core.common.errors.VdcBLLException; +import org.ovirt.engine.core.common.errors.VdcBllErrors; +import org.ovirt.engine.core.common.utils.Pair; +import org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters; +import org.ovirt.engine.core.common.vdscommands.VDSCommandType; +import org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.VdcBllMessages; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; + +@InternalCommandAttribute +@NonTransactiveCommandAttribute +public class MaintenanceNumberOfVdssCommand<T extends MaintenanceNumberOfVdssParameters> extends CommandBase<T> { + private static final long serialVersionUID = -5691756067222085075L; + private final HashMap<Guid, VDS> vdssToMaintenance = new HashMap<Guid, VDS>(); + private ArrayList<Guid> _vdsGroupIds; + private final List<PermissionSubject> inspectedEntitiesMap; + private Map<String, Pair<String, String>> sharedLockMap; + + public MaintenanceNumberOfVdssCommand(T parameters) { + super(parameters); + Iterable<Guid> vdsIdList = getParameters().getVdsIdList(); + inspectedEntitiesMap = new ArrayList<PermissionSubject>(); + for (Guid g : vdsIdList) { + inspectedEntitiesMap.add(new PermissionSubject(g, + VdcObjectType.VDS, + getActionType().getActionGroup())); + } + } + + private void MoveVdssToGoingToMaintenanceMode() { + List<VDS> spms = new ArrayList<VDS>(); + for (VDS vds : vdssToMaintenance.values()) { + if (vds.getSpmStatus() != VdsSpmStatus.SPM) { + setVdsStatusToPrepareForMaintaice(vds); + } else { + spms.add(vds); + } + } + for (VDS vds : spms) { + setVdsStatusToPrepareForMaintaice(vds); + } + freeLock(); + } + + private void setVdsStatusToPrepareForMaintaice(VDS vds) { + if (vds.getStatus() != VDSStatus.PreparingForMaintenance && vds.getStatus() != VDSStatus.NonResponsive + && vds.getStatus() != VDSStatus.Down) { + runVdsCommand(VDSCommandType.SetVdsStatus, + new SetVdsStatusVDSCommandParameters(vds.getId(), VDSStatus.PreparingForMaintenance)); + } + } + + private void MigrateAllVdss() { + for (Guid vdsId : getParameters().getVdsIdList()) { + // ParametersCurrentUser = CurrentUser + MaintenanceVdsParameters tempVar = new MaintenanceVdsParameters(vdsId, getParameters().getIsInternal()); + tempVar.setSessionId(getParameters().getSessionId()); + tempVar.setCorrelationId(getParameters().getCorrelationId()); + VdcReturnValueBase result = + Backend.getInstance().runInternalAction(VdcActionType.MaintenanceVds, + tempVar, + ExecutionHandler.createInternalJobContext()); + if (!result.getCanDoAction()) { + getReturnValue().getCanDoActionMessages().addAll(result.getCanDoActionMessages()); + getReturnValue().setCanDoAction(false); + } + } + } + + @Override + protected void setActionMessageParameters() { + addCanDoActionMessage(VdcBllMessages.VAR__TYPE__HOST); + addCanDoActionMessage(VdcBllMessages.VAR__ACTION__MAINTENANCE); + } + + @Override + protected void executeCommand() { + MoveVdssToGoingToMaintenanceMode(); + MigrateAllVdss(); + // set network to operational / non-operational + for (Guid id : _vdsGroupIds) { + List<Network> networks = DbFacade.getInstance().getNetworkDao().getAllForCluster(id); + for (Network net : networks) { + NetworkClusterHelper.setStatus(id, net); + } + } + setSucceeded(true); + } + + @Override + protected boolean canDoAction() { + boolean result = true; + _vdsGroupIds = new ArrayList<Guid>(); + Set<Guid> vdsWithRunningVMs = new HashSet<Guid>(); + List<String> hostNotRespondingList = new ArrayList<String>(); + List<String> hostsWithNonMigratableVms = new ArrayList<String>(); + List<String> nonMigratableVms = new ArrayList<String>(); + + for (Guid vdsId : getParameters().getVdsIdList()) { + VDS vds = DbFacade.getInstance().getVdsDao().get(vdsId); + if (vds == null) { + log.error(String.format("ResourceManager::vdsMaintenance could not find vds_id = '%1$s'", vdsId)); + addCanDoActionMessage(VdcBllMessages.VDS_INVALID_SERVER_ID); + result = false; + continue; + } + if (!vdssToMaintenance.containsKey(vdsId)) { + vdssToMaintenance.put(vdsId, vds); + if (vds.getSpmStatus() == VdsSpmStatus.SPM) { + addSharedLockEntry(vds); + } + } + } + result = result && acquireLockInternal(); + if (result) { + // check if one of the target vdss is spm, if so check that there are no + // tasks running + for (Guid vdsId : getParameters().getVdsIdList()) { + VDS vds = vdssToMaintenance.get(vdsId); + if (vds != null) { + List<VM> vms = getVmDAO().getAllRunningForVds(vdsId); + if (vms.size() > 0) { + vdsWithRunningVMs.add(vdsId); + } + _vdsGroupIds.add(vds.getVdsGroupId()); + List<String> nonMigratableVmDescriptionsToFrontEnd = new ArrayList<String>(); + for (VM vm : vms) { + if (vm.getMigrationSupport() != MigrationSupport.MIGRATABLE) { + nonMigratableVmDescriptionsToFrontEnd.add(vm.getName()); + } + } + + if (nonMigratableVmDescriptionsToFrontEnd.size() > 0) { + hostsWithNonMigratableVms.add(vds.getName()); + nonMigratableVms.addAll(nonMigratableVmDescriptionsToFrontEnd); + + // The non migratable VM names will be comma separated + log.error(String.format("VDS %1$s contains non migratable VMs", vdsId)); + result = false; + + } else if (vds.getStatus() == VDSStatus.Maintenance) { + addCanDoActionMessage(VdcBllMessages.VDS_CANNOT_MAINTENANCE_VDS_IS_IN_MAINTENANCE); + result = false; + } else if (vds.getSpmStatus() == VdsSpmStatus.Contending) { + addCanDoActionMessage(VdcBllMessages.VDS_CANNOT_MAINTENANCE_SPM_CONTENDING); + result = false; + } else if (vds.getStatus() == VDSStatus.NonResponsive && vds.getVmCount() > 0) { + result = false; + hostNotRespondingList.add(vds.getName()); + } else if (vds.getStatus() == VDSStatus.NonResponsive && vds.getSpmStatus() != VdsSpmStatus.None) { + result = false; + addCanDoActionMessage(VdcBllMessages.VDS_CANNOT_MAINTENANCE_VDS_IS_NOT_RESPONDING_AND_IS_SPM); + } else if (vds.getSpmStatus() == VdsSpmStatus.SPM && vds.getStatus() == VDSStatus.Up) { + try { + @SuppressWarnings("unchecked") + HashMap<Guid, AsyncTaskStatus> taskStatuses = + (HashMap<Guid, AsyncTaskStatus>) Backend + .getInstance() + .getResourceManager() + .RunVdsCommand(VDSCommandType.HSMGetAllTasksStatuses, + new VdsIdVDSCommandParametersBase(vdsId)).getReturnValue(); + if (taskStatuses.size() > 0) { + addCanDoActionMessage(VdcBllMessages.VDS_CANNOT_MAINTENANCE_SPM_WITH_RUNNING_TASKS); + result = false; + } + } catch (VdcBLLException e) { + if (e.getErrorCode() == VdcBllErrors.VDS_NETWORK_ERROR) { + addCanDoActionMessage(VdcBllMessages.VDS_CANNOT_MAINTENANCE_VDS_IS_NOT_RESPONDING_AND_IS_SPM); + result = false; + } else { + log.error("Error getting spm task list.", e); + } + } catch (RuntimeException exp) { + log.error("Error getting spm task list.", exp); + } + } + } + } + + // If one of the host is non responsive with running VM's, add a CanDoAction message. + handleNonResponsiveHosts(hostNotRespondingList); + + // If one of the vms is non migratable, add a CanDoAction message. + handleNonMigratableVms(hostsWithNonMigratableVms, nonMigratableVms); + + if (result) { + // Remove all redundant clusters in clusters list, by adding it to a + // set. + // For each cluster check for each host that belongs to it, if its a + // part of the parameters and + // if there are running hosts for it - if it is up and is not in the + // parameters -migration will be possible + // to be performed, and there is no point to continue the check for + // the given cluster - otherwise, + // if the host is up and in the parameters - it may be that the + // cluster is problematic (no hosts in up + // state that we will be able to migrate VMs to) + + // In the end - if the clusters list is not empty - this is an + // error, use the "problematic clusters list" to format an error to + // the client + Set<Guid> clustersAsSet = new HashSet<Guid>(); + clustersAsSet.addAll(_vdsGroupIds); + List<String> problematicClusters = new ArrayList<String>(); + List<String> allHostsWithRunningVms = new ArrayList<String>(); + for (Guid clusterID : clustersAsSet) { + List<VDS> vdsList = DbFacade.getInstance().getVdsDao().getAllForVdsGroup(clusterID); + boolean vdsForMigrationExists = + checkIfThereIsVDSToHoldMigratedVMs(getParameters().getVdsIdList(), vdsList); + + if (!vdsForMigrationExists) { + List<String> candidateHostsWithRunningVms = new ArrayList<String>(); + for (VDS vdsInCluster : vdsList) { + if (vdsWithRunningVMs.contains(vdsInCluster.getId())) { + candidateHostsWithRunningVms.add(vdsInCluster.getName()); + } + } + // Passed on all vds in cluster - if map is not empty (host found with VMs) - + // this is indeed a problematic + // cluster + if (!candidateHostsWithRunningVms.isEmpty()) { + addClusterDetails(clusterID, problematicClusters); + allHostsWithRunningVms.addAll(candidateHostsWithRunningVms); + } + } + } + // If there are problematic clusters + result = problematicClusters.isEmpty(); + if (!result) { + addCanDoActionMessage(VdcBllMessages.CANNOT_MAINTENANCE_VDS_RUN_VMS_NO_OTHER_RUNNING_VDS); + String commaDelimitedClusters = StringUtils.join(problematicClusters, ","); + getReturnValue().getCanDoActionMessages().add(String.format("$ClustersList %1$s", + commaDelimitedClusters)); + getReturnValue().getCanDoActionMessages().add(String.format("$HostsList %1$s", + StringUtils.join(allHostsWithRunningVms, ","))); + } + } + } + return result; + } + + private void addSharedLockEntry(VDS vds) { + if (sharedLockMap == null) { + sharedLockMap = new HashMap<String, Pair<String, String>>(); + } + sharedLockMap.put(vds.getStoragePoolId().toString(), LockMessagesMatchUtil.POOL); + } + + /** + * If found hosts which has non-migratable VM's on them, add the host names and Vm's to the message. + * + * @param hostNotRespondingList + * - List of non responsive hosts with running VM's on them. + */ + private void handleNonMigratableVms(List<String> hostsWithNonMigratableVms, List<String> nonMigratableVms) { + if (!hostsWithNonMigratableVms.isEmpty()) { + addCanDoActionMessage(VdcBllMessages.VDS_CANNOT_MAINTENANCE_IT_INCLUDES_NON_MIGRATABLE_VM); + getReturnValue().getCanDoActionMessages().add((String.format("$VmsList %1$s", + StringUtils.join(nonMigratableVms, " , ")))); + getReturnValue().getCanDoActionMessages().add((String.format("$HostsList %1$s", + StringUtils.join(hostsWithNonMigratableVms, " , ")))); + } + } + + private boolean checkIfThereIsVDSToHoldMigratedVMs(Iterable<Guid> vdsIDListFromParams, List<VDS> vdsInCluster) { + // Checks if the number of UP VDS in the parameters for a given cluster + // is + // less than the number of UP parameters in that cluster - if this is + // the case, we have + // a VDS to migrate to + Set<Guid> upVdsIDsInCluster = new HashSet<Guid>(); + for (VDS vds : vdsInCluster) { + if (vds.getStatus() == VDSStatus.Up) { + upVdsIDsInCluster.add(vds.getId()); + } + } + int numOfUpVDSInClusterAndParams = 0; + for (Guid vdsID : vdsIDListFromParams) { + if (upVdsIDsInCluster.contains(vdsID)) { + numOfUpVDSInClusterAndParams++; + } + } + return numOfUpVDSInClusterAndParams < upVdsIDsInCluster.size(); + } + + /** + * If found hosts which are non-responsive and has VM's on them, add the host names to the message. + * + * @param hostNotRespondingList + * - List of non responsive hosts with running VM's on them. + */ + private void handleNonResponsiveHosts(List<String> hostNotRespondingList) { + if (!hostNotRespondingList.isEmpty()) { + addCanDoActionMessage(VdcBllMessages.VDS_CANNOT_MAINTENANCE_VDS_IS_NOT_RESPONDING_WITH_VMS); + getReturnValue().getCanDoActionMessages().add(String.format("$HostNotResponding %1$s", + StringUtils.join(hostNotRespondingList, ","))); + } + } + + private void addClusterDetails(Guid vdsGroupID, List<String> clustersWithRunningVms) { + if (vdsGroupID != null && !vdsGroupID.equals(Guid.Empty)) { + VDSGroup vdsGroup = DbFacade.getInstance().getVdsGroupDao().getWithRunningVms(vdsGroupID); + if (vdsGroup != null) { + clustersWithRunningVms.add(vdsGroup.getname()); + } + } + } + + @Override + protected Map<String, Pair<String, String>> getSharedLocks() { + return sharedLockMap; + } + + @Override + public List<PermissionSubject> getPermissionCheckSubjects() { + return Collections.unmodifiableList(inspectedEntitiesMap); + } +} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceVdsCommand.java new file mode 100644 index 0000000..e3579ec --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceVdsCommand.java @@ -0,0 +1,235 @@ +package org.ovirt.engine.core.bll; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + +import org.ovirt.engine.core.bll.context.CommandContext; +import org.ovirt.engine.core.bll.job.ExecutionContext; +import org.ovirt.engine.core.bll.job.ExecutionHandler; +import org.ovirt.engine.core.common.AuditLogType; +import org.ovirt.engine.core.common.VdcObjectType; +import org.ovirt.engine.core.common.action.HostStoragePoolParametersBase; +import org.ovirt.engine.core.common.action.InternalMigrateVmParameters; +import org.ovirt.engine.core.common.action.MaintenanceVdsParameters; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.action.VdcReturnValueBase; +import org.ovirt.engine.core.common.businessentities.MigrationSupport; +import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.businessentities.VDSStatus; +import org.ovirt.engine.core.common.businessentities.VM; +import org.ovirt.engine.core.common.businessentities.VMStatus; +import org.ovirt.engine.core.common.businessentities.VmsComparer; +import org.ovirt.engine.core.common.businessentities.storage_pool; +import org.ovirt.engine.core.common.eventqueue.Event; +import org.ovirt.engine.core.common.eventqueue.EventQueue; +import org.ovirt.engine.core.common.eventqueue.EventResult; +import org.ovirt.engine.core.common.eventqueue.EventType; +import org.ovirt.engine.core.common.job.Step; +import org.ovirt.engine.core.common.job.StepEnum; +import org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters; +import org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters; +import org.ovirt.engine.core.common.vdscommands.VDSCommandType; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.VdcBllMessages; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.dal.job.ExecutionMessageDirector; +import org.ovirt.engine.core.utils.ejb.BeanProxyType; +import org.ovirt.engine.core.utils.ejb.BeanType; +import org.ovirt.engine.core.utils.ejb.EjbUtils; +import org.ovirt.engine.core.vdsbroker.irsbroker.IrsBrokerCommand; + +public class MaintenanceVdsCommand<T extends MaintenanceVdsParameters> extends VdsCommand<T> { + + private static final long serialVersionUID = -7604781532599945079L; + private final boolean _isInternal; + private List<VM> vms; + + public MaintenanceVdsCommand(T parameters) { + super(parameters); + _isInternal = parameters.getIsInternal(); + } + + @Override + protected void executeCommand() { + if (getVds().getStatus() == VDSStatus.Maintenance) { + // nothing to do + setSucceeded(true); + } else { + orderListOfRunningVmsOnVds(getVdsId()); + setSucceeded(MigrateAllVms(getExecutionContext())); + + // if non responsive move directly to maintenance + if (getVds().getStatus() == VDSStatus.NonResponsive + || getVds().getStatus() == VDSStatus.Connecting + || getVds().getStatus() == VDSStatus.Down) { + Backend.getInstance() + .getResourceManager() + .RunVdsCommand(VDSCommandType.SetVdsStatus, + new SetVdsStatusVDSCommandParameters(getVdsId(), VDSStatus.Maintenance)); + } + } + // if there's VM(s) in this VDS which is migrating, mark this command as async + // as the migration(s) is a step of this job, so this job must not be cleaned yet + if (isVmsExist()) { + ExecutionHandler.setAsyncJob(getExecutionContext(), true); + } + } + + protected boolean isVmsExist() { + return vms != null && !vms.isEmpty(); + } + + protected void orderListOfRunningVmsOnVds(Guid vdsId) { + vms = DbFacade.getInstance().getVmDao().getAllRunningForVds(vdsId); + Collections.sort(vms, Collections.reverseOrder(new VmsComparer())); + } + + /** + * Note: you must call {@link #orderListOfRunningVmsOnVds(Guid)} before calling this method + */ + protected boolean MigrateAllVms(ExecutionContext parentContext) { + return MigrateAllVms(parentContext, false); + } + + /** + * Note: you must call {@link #orderListOfRunningVmsOnVds(Guid)} before calling this method + */ + protected boolean MigrateAllVms(ExecutionContext parentContext, boolean HAOnly) { + + boolean succeeded = true; + + for (VM vm : vms) { + // if HAOnly is true check that vm is HA (auto_startup should be true) + if (vm.getStatus() != VMStatus.MigratingFrom && (!HAOnly || (HAOnly && vm.isAutoStartup()))) { + VdcReturnValueBase result = + Backend.getInstance().runInternalAction(VdcActionType.InternalMigrateVm, + new InternalMigrateVmParameters(vm.getId(), getActionType()), + createMigrateVmContext(parentContext, vm)); + if (!result.getCanDoAction() || !(((Boolean) result.getActionReturnValue()).booleanValue())) { + succeeded = false; + appendCustomValue("failedVms", vm.getName(), ","); + log.errorFormat("ResourceManager::vdsMaintenance - Failed migrating desktop '{0}'", vm.getName()); + } + } + } + return succeeded; + } + + protected CommandContext createMigrateVmContext(ExecutionContext parentContext,VM vm) { + ExecutionContext ctx = new ExecutionContext(); + try { + Map<String, String> values = new HashMap<String, String>(); + values.put(VdcObjectType.VM.name().toLowerCase(), vm.getName()); + values.put(VdcObjectType.VDS.name().toLowerCase(), vm.getRunOnVdsName()); + Step step = ExecutionHandler.addSubStep(getExecutionContext(), + parentContext.getJob().getStep(StepEnum.EXECUTING), + StepEnum.MIGRATE_VM, + ExecutionMessageDirector.resolveStepMessage(StepEnum.MIGRATE_VM, values)); + ctx.setStep(step); + ctx.setMonitored(true); + } catch (RuntimeException e) { + log.error("Failed to create ExecutionContext for MigrateVmCommand", e); + } + return new CommandContext(ctx); + } + + @Override + protected boolean canDoAction() { + return CanMaintenanceVds(getVdsId(), getReturnValue().getCanDoActionMessages()); + } + + @Override + public AuditLogType getAuditLogTypeValue() { + if (_isInternal) { + if (getSucceeded()) { + return AuditLogType.VDS_MAINTENANCE; + } else { + return AuditLogType.VDS_MAINTENANCE_FAILED; + } + } else { + if (getSucceeded()) { + return AuditLogType.USER_VDS_MAINTENANCE; + } else { + return AuditLogType.USER_VDS_MAINTENANCE_MIGRATION_FAILED; + } + } + } + + public boolean CanMaintenanceVds(Guid vdsId, java.util.ArrayList<String> reasons) { + boolean returnValue = true; + // VDS vds = ResourceManager.Instance.getVds(vdsId); + VDS vds = DbFacade.getInstance().getVdsDao().get(vdsId); + // we can get here when vds status was set already to Maintenance + if ((vds.getStatus() != VDSStatus.Maintenance) && (vds.getStatus() != VDSStatus.NonResponsive) + && (vds.getStatus() != VDSStatus.Up) && (vds.getStatus() != VDSStatus.Error) + && (vds.getStatus() != VDSStatus.PreparingForMaintenance) && (vds.getStatus() != VDSStatus.Down)) { + returnValue = false; + reasons.add(VdcBllMessages.VDS_CANNOT_MAINTENANCE_VDS_IS_NOT_OPERATIONAL.toString()); + } + + orderListOfRunningVmsOnVds(vdsId); + + for (VM vm : vms) { + if (vm.getMigrationSupport() != MigrationSupport.MIGRATABLE) { + reasons.add(VdcBllMessages.VDS_CANNOT_MAINTENANCE_IT_INCLUDES_NON_MIGRATABLE_VM.toString()); + return false; + } + } + + return returnValue; + } + + public static void ProcessStorageOnVdsInactive(final VDS vds) { + + // Clear the problematic timers since the VDS is in maintenance so it doesn't make sense to check it + // anymore. + if (!Guid.Empty.equals(vds.getStoragePoolId())) { + clearDomainCache(vds); + + storage_pool storage_pool = DbFacade.getInstance() + .getStoragePoolDao() + .get(vds.getStoragePoolId()); + if (StoragePoolStatus.Uninitialized != storage_pool + .getstatus()) { + Backend.getInstance().getResourceManager() + .RunVdsCommand( + VDSCommandType.DisconnectStoragePool, + new DisconnectStoragePoolVDSCommandParameters(vds.getId(), + vds.getStoragePoolId(), vds.getVdsSpmId())); + HostStoragePoolParametersBase params = + new HostStoragePoolParametersBase(storage_pool, vds); + Backend.getInstance().runInternalAction(VdcActionType.DisconnectHostFromStoragePoolServers, params); + } + } + } + + /** + * The following method will clear a cache for problematic domains, which were reported by vds + * @param vds + */ + private static void clearDomainCache(final VDS vds) { + ((EventQueue) EjbUtils.findBean(BeanType.EVENTQUEUE_MANAGER, BeanProxyType.LOCAL)).submitEventSync(new Event(vds.getStoragePoolId(), + null, vds.getId(), EventType.VDSCLEARCACHE), + new Callable<EventResult>() { + @Override + public EventResult call() { + IrsBrokerCommand.clearVdsFromCache(vds.getStoragePoolId(), vds.getId(), vds.getName()); + return new EventResult(true, EventType.VDSCLEARCACHE); + } + }); + } + + @Override + public Map<String, String> getJobMessageProperties() { + if (jobProperties == null) { + jobProperties = Collections.singletonMap(VdcObjectType.VDS.name().toLowerCase(), getVdsName()); + } + + return jobProperties; + } + +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MaintenanceNumberOfVdssParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MaintenanceNumberOfVdssParameters.java new file mode 100644 index 0000000..5b8cdb0 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MaintenanceNumberOfVdssParameters.java @@ -0,0 +1,33 @@ +package org.ovirt.engine.core.common.action; + +import java.util.LinkedList; + +import org.ovirt.engine.core.compat.*; + +public class MaintenanceNumberOfVdssParameters extends VdcActionParametersBase { + private static final long serialVersionUID = 8806810521151850069L; + + private java.util.List<Guid> _vdsIdList; + + private boolean _isInternal; + + public MaintenanceNumberOfVdssParameters(java.util.List<Guid> vdsIdList, boolean isInternal) { + _vdsIdList = vdsIdList; + _isInternal = isInternal; + } + + public Iterable<Guid> getVdsIdList() { + return _vdsIdList == null ? new LinkedList<Guid>() : _vdsIdList; + } + + public void setVdsIdList(java.util.List<Guid> value) { + _vdsIdList = value; + } + + public boolean getIsInternal() { + return _isInternal; + } + + public MaintenanceNumberOfVdssParameters() { + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MaintenanceVdsParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MaintenanceVdsParameters.java new file mode 100644 index 0000000..99cb37e --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/MaintenanceVdsParameters.java @@ -0,0 +1,20 @@ +package org.ovirt.engine.core.common.action; + +import org.ovirt.engine.core.compat.*; + +public class MaintenanceVdsParameters extends VdsActionParameters { + private static final long serialVersionUID = -962696566094119431L; + private boolean _isInternal; + + public MaintenanceVdsParameters(Guid vdsId, boolean isInternal) { + super(vdsId); + _isInternal = isInternal; + } + + public boolean getIsInternal() { + return _isInternal; + } + + public MaintenanceVdsParameters() { + } +} -- To view, visit http://gerrit.ovirt.org/12402 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0993dd074a3803721daa85dcc3d00e63dfd45f72 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Gilad Chaplik <gchap...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches