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 <rgo...@redhat.com> --- 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, 50 insertions(+), 35 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/47/25547/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 60aab98..a4f8817 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 @@ -156,7 +156,10 @@ GetDiskAlignment("org.ovirt.engine.core.vdsbroker.vdsbroker"), GlusterTasksList("org.ovirt.engine.core.vdsbroker.gluster"), GetGlusterVolumeRemoveBricksStatus("org.ovirt.engine.core.vdsbroker.gluster"), - SetNumberOfCpus("org.ovirt.engine.core.vdsbroker"); + SetNumberOfCpus("org.ovirt.engine.core.vdsbroker"), + 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 67a8d21..6dda8bf 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 @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -63,6 +64,7 @@ import org.ovirt.engine.core.common.vdscommands.GetVmStatsVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters; 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; @@ -80,15 +82,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; @@ -941,17 +939,21 @@ log.debug("vds::refreshVmList entered"); } - VdsBrokerCommand<VdsIdAndVdsVDSCommandParametersBase> command; + VDSReturnValue vdsReturnValue; if (!_vdsManager.getRefreshStatistics()) { - command = new ListVDSCommand<VdsIdAndVdsVDSCommandParametersBase>( - new VdsIdAndVdsVDSCommandParametersBase(_vds)); + vdsReturnValue = + getResourceManager().runVdsCommand( + VDSCommandType.List, + new VdsIdAndVdsVDSCommandParametersBase(_vds)); } else { - command = new GetAllVmStatsVDSCommand<VdsIdAndVdsVDSCommandParametersBase>( - new VdsIdAndVdsVDSCommandParametersBase(_vds)); + vdsReturnValue = + getResourceManager().runVdsCommand( + VDSCommandType.GetAllVmStats, + new VdsIdAndVdsVDSCommandParametersBase(_vds)); } - _runningVms = (Map<Guid, VmInternalData>) command.executeWithReturnValue(); + _runningVms = (Map<Guid, VmInternalData>) vdsReturnValue.getReturnValue(); - if (command.getVDSReturnValue().getSucceeded()) { + if (vdsReturnValue.getSucceeded()) { List<VM> running = checkVmsStatusChanged(); proceedWatchdogEvents(); @@ -982,20 +984,22 @@ updateLunDisks(); - } 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!", vdsReturnValue.toString()); + } } } @@ -1302,17 +1306,22 @@ VM vmToUpdate = _vmDict.get(runningVm.getId()); 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()); + || !EnumSet.of( + runningVm.getStatus(), + VMStatus.PreparingForHibernate, + VMStatus.Up + ).contains(vmToUpdate.getStatus())) { + VDSReturnValue vmStats = + getResourceManager().runVdsCommand( + VDSCommandType.GetVmStats, + new GetVmStatsVDSCommandParameters(_vds, runningVm.getId())); + if (vmStats.getSucceeded()) { + _runningVms.put( + runningVm.getId(), + (VmInternalData) vmStats.getReturnValue()); } else { - _runningVms.remove(runningVm.getId()); + log.error("failed to fetch vm stats. set to UNKNOWN to ignore it"); + _runningVms.get(runningVm.getId()).getVmDynamic().setStatus(VMStatus.Unknown); } } else { // status not changed move to next vm @@ -2183,4 +2192,7 @@ AuditLogDirector.log(auditLogable, AuditLogType.VM_STATUS_RESTORED); } + protected ResourceManager getResourceManager() { + return ResourceManager.getInstance(); + } } -- To view, visit http://gerrit.ovirt.org/25547 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I16359bf4af4968c8e9d8a650fb2af541ae0cc3fb Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Roy Golan <rgo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches