Roy Golan has uploaded a new change for review. Change subject: core: VURTI - use ResourceManager instead of commands ......................................................................
core: VURTI - use ResourceManager instead of commands Use ResourceManager instead of direct command invocation Add List, GetVmStats and GetAllVmsStats to the list of Command Types Clean-up the code expressions, format, indent etc Change-Id: I16359bf4af4968c8e9d8a650fb2af541ae0cc3fb Signed-off-by: Roy Golan <[email protected]> --- M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java 2 files changed, 49 insertions(+), 49 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/35/25635/1 diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java index b25e684..9b24fca 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/VDSCommandType.java @@ -151,7 +151,9 @@ GetGlusterVolumeRebalanceStatus("org.ovirt.engine.core.vdsbroker.gluster"), GetDiskAlignment("org.ovirt.engine.core.vdsbroker.vdsbroker"), GlusterTasksList("org.ovirt.engine.core.vdsbroker.gluster"), - ; + List("org.ovirt.engine.core.vdsbroker.vdsbroker"), // get a list of VMs with status only + GetVmStats("org.ovirt.engine.core.vdsbroker.vdsbroker"), // get a VM with full data and statistics + GetAllVmStats("org.ovirt.engine.core.vdsbroker.vdsbroker"); // get a list of VMs with full data and statistics String packageName; diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java index aeaa88b..3ad788d 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java @@ -55,6 +55,8 @@ import org.ovirt.engine.core.common.vdscommands.DestroyVmVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.FullListVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.GetVmStatsVDSCommandParameters; +import org.ovirt.engine.core.common.vdscommands.VDSCommandType; +import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; import org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.RefObject; @@ -72,15 +74,11 @@ import org.ovirt.engine.core.vdsbroker.irsbroker.IRSErrorException; import org.ovirt.engine.core.vdsbroker.vdsbroker.DestroyVDSCommand; import org.ovirt.engine.core.vdsbroker.vdsbroker.FullListVdsCommand; -import org.ovirt.engine.core.vdsbroker.vdsbroker.GetAllVmStatsVDSCommand; import org.ovirt.engine.core.vdsbroker.vdsbroker.GetStatsVDSCommand; -import org.ovirt.engine.core.vdsbroker.vdsbroker.GetVmStatsVDSCommand; -import org.ovirt.engine.core.vdsbroker.vdsbroker.ListVDSCommand; import org.ovirt.engine.core.vdsbroker.vdsbroker.VDSErrorException; import org.ovirt.engine.core.vdsbroker.vdsbroker.VDSNetworkException; import org.ovirt.engine.core.vdsbroker.vdsbroker.VDSProtocolException; import org.ovirt.engine.core.vdsbroker.vdsbroker.VDSRecoveringException; -import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsBrokerCommand; import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties; import org.ovirt.engine.core.vdsbroker.vdsbroker.entities.VmInternalData; @@ -904,19 +902,17 @@ if (Config.<Boolean> GetValue(ConfigValues.DebugTimerLogging)) { log.debug("vds::refreshVmList entered"); } + VDSReturnValue vdsReturnValue; + VDSCommandType commandType = + _vdsManager.getRefreshStatistics() + ? VDSCommandType.GetAllVmStats + : VDSCommandType.List; + vdsReturnValue = getResourceManager().runVdsCommand(commandType, new VdsIdAndVdsVDSCommandParametersBase(_vds)); - VdsBrokerCommand<VdsIdAndVdsVDSCommandParametersBase> command; - if (!_vdsManager.getRefreshStatistics()) { - command = new ListVDSCommand<VdsIdAndVdsVDSCommandParametersBase>( - new VdsIdAndVdsVDSCommandParametersBase(_vds)); - } else { - command = new GetAllVmStatsVDSCommand<VdsIdAndVdsVDSCommandParametersBase>( - new VdsIdAndVdsVDSCommandParametersBase(_vds)); - } - _runningVms = (Map<Guid, VmInternalData>) command.executeWithReturnValue(); + _runningVms = (Map<Guid, VmInternalData>) vdsReturnValue.getReturnValue(); - if (command.getVDSReturnValue().getSucceeded()) { - List<VM> running = checkVmsStatusChanged(); + if (vdsReturnValue.getSucceeded()) { + List<Guid> staleRunningVms = checkVmsStatusChanged(); proceedWatchdogEvents(); @@ -929,7 +925,7 @@ processExternallyManagedVms(); // update repository and check if there are any vm in cache that not // in vdsm - updateRepository(running); + updateRepository(staleRunningVms); // Going over all returned VMs and updting the data structures // accordingly @@ -944,20 +940,22 @@ prepareGuestAgentNetworkDevicesForUpdate(); - } else if (command.getVDSReturnValue().getExceptionObject() != null) { - if (command.getVDSReturnValue().getExceptionObject() instanceof VDSErrorException) { - log.errorFormat("Failed vds listing, vds = {0} : {1}, error = {2}", _vds.getId(), - _vds.getName(), command.getVDSReturnValue().getExceptionString()); - } else if (command.getVDSReturnValue().getExceptionObject() instanceof VDSNetworkException) { - _saveVdsDynamic = _vdsManager.handleNetworkException((VDSNetworkException) command.getVDSReturnValue() - .getExceptionObject(), _vds); - } else if (command.getVDSReturnValue().getExceptionObject() instanceof VDSProtocolException) { - log.errorFormat("Failed vds listing, vds = {0} : {1}, error = {2}", _vds.getId(), - _vds.getName(), command.getVDSReturnValue().getExceptionString()); - } - throw command.getVDSReturnValue().getExceptionObject(); } else { - log.error("GetCapabilitiesVDSCommand failed with no exception!"); + RuntimeException callException = vdsReturnValue.getExceptionObject(); + if (callException != null) { + if (callException instanceof VDSErrorException) { + log.errorFormat("Failed vds listing, vds = {0} : {1}, error = {2}", _vds.getId(), + _vds.getName(), vdsReturnValue.getExceptionString()); + } else if (callException instanceof VDSNetworkException) { + _saveVdsDynamic = _vdsManager.handleNetworkException((VDSNetworkException) callException, _vds); + } else if (callException instanceof VDSProtocolException) { + log.errorFormat("Failed vds listing, vds = {0} : {1}, error = {2}", _vds.getId(), + _vds.getName(), vdsReturnValue.getExceptionString()); + } + throw callException; + } else { + log.errorFormat("{0} failed with no exception!", commandType.name()); + } } } @@ -1219,8 +1217,8 @@ } // if not statistics check if status changed and add to running list - private List<VM> checkVmsStatusChanged() { - List<VM> running = new ArrayList<VM>(); + private List<Guid> checkVmsStatusChanged() { + List<Guid> staleRunningVms = new ArrayList<>(); if (!_vdsManager.getRefreshStatistics()) { List<VmDynamic> tempRunningList = new ArrayList<VmDynamic>(); for (VmInternalData runningVm : _runningVms.values()) { @@ -1232,24 +1230,22 @@ if (vmToUpdate == null || (vmToUpdate.getStatus() != runningVm.getStatus() && !(vmToUpdate.getStatus() == VMStatus.PreparingForHibernate && runningVm.getStatus() == VMStatus.Up))) { - GetVmStatsVDSCommand<GetVmStatsVDSCommandParameters> command = - new GetVmStatsVDSCommand<GetVmStatsVDSCommandParameters>(new GetVmStatsVDSCommandParameters( - _vds, runningVm.getId())); - command.execute(); - if (command.getVDSReturnValue().getSucceeded()) { - _runningVms.put(runningVm.getId(), - (VmInternalData) command.getReturnValue()); + VDSReturnValue vdsReturnValue = getResourceManager().runVdsCommand( + VDSCommandType.GetVmStats, + new GetVmStatsVDSCommandParameters(_vds, runningVm.getId())); + if (vdsReturnValue.getSucceeded()) { + _runningVms.put(runningVm.getId(), (VmInternalData) vdsReturnValue.getReturnValue()); } else { _runningVms.remove(runningVm.getId()); } } else { // status not changed move to next vm - running.add(vmToUpdate); + staleRunningVms.add(vmToUpdate.getId()); _runningVms.remove(vmToUpdate.getId()); } } } - return running; + return staleRunningVms; } private void proceedWatchdogEvents() { @@ -1592,7 +1588,7 @@ } } - private void updateRepository(List<VM> running) { + private void updateRepository(List<Guid> staleRunningVms) { for (VmInternalData vmInternalData : _runningVms.values()) { VmDynamic runningVm = vmInternalData.getVmDynamic(); VM vmToUpdate = _vmDict.get(runningVm.getId()); @@ -1683,15 +1679,15 @@ if (vmToUpdate != null) { updateVmStatistics(vmToUpdate); if (_vmDict.containsKey(runningVm.getId())) { - running.add(_vmDict.get(runningVm.getId())); + staleRunningVms.add(runningVm.getId()); if (!_vdsManager.getInitialized()) { ResourceManager.getInstance().RemoveVmFromDownVms(_vds.getId(), runningVm.getId()); } } } } else { - if (runningVm.getStatus() == VMStatus.MigratingTo && vmToUpdate != null) { - running.add(vmToUpdate); + if (runningVm.getStatus() == VMStatus.MigratingTo) { + staleRunningVms.add(runningVm.getId()); } VmDynamic vmDynamic = getDbFacade().getVmDynamicDao().get(runningVm.getId()); @@ -1701,7 +1697,7 @@ } } // compare between vm in cache and vm from vdsm - removeVmsFromCache(running); + removeVmsFromCache(staleRunningVms); } private static void logVmStatusTransition(VM vmToUpdate, VmDynamic runningVm) { @@ -1719,11 +1715,10 @@ } // del from cache all vms that not in vdsm - private void removeVmsFromCache(List<VM> running) { + private void removeVmsFromCache(List<Guid> staleRunningVms) { Guid vmGuid; for (VM vmToRemove : _vmDict.values()) { - if (running.contains(vmToRemove)) - { + if (staleRunningVms.contains(vmToRemove.getId())) { continue; } proceedVmBeforeDeletion(vmToRemove, null); @@ -2099,4 +2094,7 @@ AuditLogDirector.log(auditLogable, AuditLogType.VM_STATUS_RESTORED); } + protected ResourceManager getResourceManager() { + return ResourceManager.getInstance(); + } } -- To view, visit http://gerrit.ovirt.org/25635 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I16359bf4af4968c8e9d8a650fb2af541ae0cc3fb Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.3 Gerrit-Owner: Roy Golan <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
