Lior Vernia has uploaded a new change for review. Change subject: webadmin: Replace VM properties query ......................................................................
webadmin: Replace VM properties query It was no longer necessary, since the config values are cached in the frontend and VmPropertiesUtils is now useable by the frontend. Change-Id: Ib335cd69f8d992682fccecdbbb79e105ddc1a3e4 Signed-off-by: Lior Vernia <[email protected]> --- D backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmCustomPropertiesQuery.java D backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetVmCustomPropertiesQueryTest.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java 4 files changed, 17 insertions(+), 126 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/81/28181/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmCustomPropertiesQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmCustomPropertiesQuery.java deleted file mode 100644 index 85f8145..0000000 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVmCustomPropertiesQuery.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.ovirt.engine.core.bll; - -import org.ovirt.engine.core.common.config.Config; -import org.ovirt.engine.core.common.config.ConfigValues; -import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; -import org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils; -import org.ovirt.engine.core.compat.Version; - -public class GetVmCustomPropertiesQuery<P extends VdcQueryParametersBase> extends QueriesCommandBase<P> { - - private static final String Version3_0 = "3.0"; - - public GetVmCustomPropertiesQuery(P parameters) { - super(parameters); - } - - @Override - protected void executeQueryCommand() { - getQueryReturnValue().setReturnValue(VmPropertiesUtils.getInstance().getAllVmProperties()); - } - - /** - * @return The predefined VM properties. - */ - protected String getPredefinedVMProperties() { - return Config.<String> getValue(ConfigValues.PredefinedVMProperties, Version3_0); - } - - /** - * @return The user-defined VM properties. - */ - protected String getUserDefinedVMProperties() { - return Config.<String> getValue(ConfigValues.UserDefinedVMProperties, Version3_0); - } - - /** - * @return The other method version - */ - protected Version getVersion() { - return new Version(Version3_0); - } - -} diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetVmCustomPropertiesQueryTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetVmCustomPropertiesQueryTest.java deleted file mode 100644 index 8252019..0000000 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/GetVmCustomPropertiesQueryTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.ovirt.engine.core.bll; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; - -import java.util.Map; - -import org.junit.Ignore; -import org.junit.Test; -import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; -import org.ovirt.engine.core.compat.Version; -import org.ovirt.engine.core.utils.RandomUtils; - -public class GetVmCustomPropertiesQueryTest extends AbstractUserQueryTest<VdcQueryParametersBase, GetVmCustomPropertiesQuery<VdcQueryParametersBase>> { - - /** Tests the query if both predefined and user properties exist */ - @Ignore - @Test - public void testExecuteQueryCommandPredefinedAndUserDefinedProperties() { - String predefinedProperties = RandomUtils.instance().nextString(10); - String userProperties = RandomUtils.instance().nextString(10); - - String expectedResult = predefinedProperties + ";" + userProperties; - - assertExecuteQueryCommand(predefinedProperties, userProperties, expectedResult); - } - - @Ignore - @Test - public void testExecuteQueryCommandPredefinedPropertiesOnly() { - String predefinedProperties = RandomUtils.instance().nextString(10); - assertExecuteQueryCommand(predefinedProperties, "", predefinedProperties); - } - - @Ignore - @Test - public void testExecuteQueryCommandUserDefinedPropertiesOnly() { - String userDefinedProperties = RandomUtils.instance().nextString(10); - assertExecuteQueryCommand("", userDefinedProperties, userDefinedProperties); - } - - @Ignore - @Test - public void testExecuteQueryCommandUserNoProperties() { - assertExecuteQueryCommand("", "", ""); - } - - /** - * Asserts that the query returns the correct properties string - * - * @param predefinedProperties The predefined VM properties to be spied - * @param userProperties The user defined VM properties to be spied - * @param expectedResult The expected result of the query - */ - private void assertExecuteQueryCommand(String predefinedProperties, String userProperties, String expectedResult) { - // Spy the configuration - doReturn(predefinedProperties).when(getQuery()).getPredefinedVMProperties(); - doReturn(userProperties).when(getQuery()).getUserDefinedVMProperties(); - - getQuery().executeQueryCommand(); - - assertEquals("Wrong properties string", - expectedResult, - ((Map<Version, String>)getQuery().getQueryReturnValue().getReturnValue()).get(doReturn(userProperties).when(getQuery()).getVersion())); - } -} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java index 2502926..e1f4940 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java @@ -11,7 +11,6 @@ GetVmsRunningOnOrMigratingToVds, GetVmsByStorageDomain, GetVmsByInstanceTypeId, - GetVmCustomProperties(VdcQueryAuthType.User), GetVmConfigurationBySnapshot(VdcQueryAuthType.User), GetVmFromConfiguration(VdcQueryAuthType.User), GetVmOvfByVmId(VdcQueryAuthType.User), diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java index 4f7b8fdb..ad76c11 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java @@ -131,6 +131,8 @@ import org.ovirt.engine.core.common.utils.ObjectUtils; import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; +import org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils; +import org.ovirt.engine.core.common.utils.exceptions.InitializationException; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.IntegerCompat; import org.ovirt.engine.core.compat.KeyValuePairCompat; @@ -264,25 +266,24 @@ } private static void initCustomPropertiesList() { - AsyncQuery callback = new AsyncQuery(); - callback.asyncCallback = new INewAsyncCallback() { + VmPropertiesUtils utils = new VmPropertiesUtils() { @Override - public void onSuccess(Object model, Object returnValue) { - customPropertiesList = (Map<Version, Map<String, String>>) returnValue; + public String getPredefinedVMProperties(Version version) { + return (String) getConfigValuePreConverted(ConfigurationValues.PredefinedVMProperties, + version.getValue()); + } + @Override + public String getUserdefinedVMProperties(Version version) { + return (String) getConfigValuePreConverted(ConfigurationValues.UserDefinedVMProperties, + version.getValue()); } }; - - callback.converterCallback = new IAsyncConverter() { - @Override - public Object Convert(Object source, AsyncQuery _asyncQuery) { - return (source != null) ? (Map<Version, Map<String, String>>) source - : new HashMap<Version, Map<String, String>>(); - } - - - }; - Frontend.getInstance().runQuery(VdcQueryType.GetVmCustomProperties, - new VdcQueryParametersBase().withoutRefresh(), callback); + try { + utils.init(); + customPropertiesList = utils.getAllVmProperties(); + } catch (InitializationException e) { + customPropertiesList = new HashMap<Version, Map<String, String>>(); + } } public static void initDefaultOSes() { -- To view, visit http://gerrit.ovirt.org/28181 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib335cd69f8d992682fccecdbbb79e105ddc1a3e4 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Lior Vernia <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
