Allon Mureinik has uploaded a new change for review. Change subject: core: Remove GetVdsHooksById2Query ......................................................................
core: Remove GetVdsHooksById2Query GetVdsHooksByIdQuery and GetVdsHooksById2Query are completely identical except for the usage of different APIs of VdsHooksParser. Since GetVdsHooksById is not used anywhere, it is removed, and GetVdsHooksById2 loses it "2" and get a name the better suits conventions (not to mention common sense). This patch includes: 1. Removing the old GetVdsHooksByIdQuery class and renaming GetVdsHooksById2Query to take its place. 2. Removing the old GetVdsHooksById constant in the VdsQueryTye enum, and renaming GetVdsHooksById2 to take its place. 3. Clearing up the VdsHooksParser class from methods with "2" in their name - either by removing unused methods, or by renaming them to a more sensible name. 4. Removing the TestVdsHooks class, as it only tested the removed methods. Change-Id: I1890f429a12cbf7e42727b7360a85ebb1b07b5b0 Signed-off-by: Allon Mureinik <[email protected]> --- D backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsHooksById2Query.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsHooksByIdQuery.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java M backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostHooksResource.java M backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostHooksResourceTest.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/vdshooks/VdsHooksParser.java D backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/vdshooks/TestVdsHooks.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostHooksListModel.java 8 files changed, 8 insertions(+), 173 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/07/13607/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsHooksById2Query.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsHooksById2Query.java deleted file mode 100644 index 2cf701d..0000000 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsHooksById2Query.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * - */ -package org.ovirt.engine.core.bll; - -import java.util.HashMap; -import java.util.Map; - -import org.ovirt.engine.core.common.businessentities.VDS; -import org.ovirt.engine.core.common.queries.GetVdsHooksByIdParameters; -import org.ovirt.engine.core.dal.dbbroker.DbFacade; -import org.ovirt.engine.core.utils.vdshooks.VdsHooksParser; - -/** - * Query for returning VDS hooks by vds ID The returned object is a map of - * folder/event names to an inner map of script names to an inner map of - * property names and values - */ -public class GetVdsHooksById2Query<P extends GetVdsHooksByIdParameters> extends QueriesCommandBase<P> { - - public GetVdsHooksById2Query(P parameters) { - super(parameters); - } - - @Override - protected void executeQueryCommand() { - - VDS vds = DbFacade.getInstance().getVdsDao().get(getParameters().getVdsId()); - Map<String, Object> result = new HashMap<String, Object>(); - if (vds != null) { - result = VdsHooksParser.parseHooks2(vds.getHooksStr()); - } - getQueryReturnValue().setReturnValue(result); - } -} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsHooksByIdQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsHooksByIdQuery.java index c91af7a..da6110c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsHooksByIdQuery.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsHooksByIdQuery.java @@ -3,9 +3,11 @@ */ package org.ovirt.engine.core.bll; +import java.util.HashMap; +import java.util.Map; + import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.queries.GetVdsHooksByIdParameters; -import org.ovirt.engine.core.common.queries.ValueObjectMap; import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.utils.vdshooks.VdsHooksParser; @@ -24,7 +26,7 @@ protected void executeQueryCommand() { VDS vds = DbFacade.getInstance().getVdsDao().get(getParameters().getVdsId()); - ValueObjectMap result = new ValueObjectMap(); + Map<String, Object> result = new HashMap<String, Object>(); if (vds != null) { result = VdsHooksParser.parseHooks(vds.getHooksStr()); } 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 7e3bbee..a82ca0e 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 @@ -28,7 +28,6 @@ GetAllSiblingVlanInterfaces, GetVlanParent, GetVdsHooksById, - GetVdsHooksById2, GetAllHosts, GetHostsByClusterId(VdcQueryAuthType.User), IsDisplayAddressConsistentInCluster, diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostHooksResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostHooksResource.java index 0ac732b..e2e224d 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostHooksResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendHostHooksResource.java @@ -27,7 +27,7 @@ public Hooks list() { @SuppressWarnings("unchecked") HashMap<String, HashMap<String, HashMap<String, String>>> hooksMap = - getEntity(HashMap.class, VdcQueryType.GetVdsHooksById2, + getEntity(HashMap.class, VdcQueryType.GetVdsHooksById, new GetVdsHooksByIdParameters(asGuid(hostId)), null); return mapCollection(hooksMap); } diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostHooksResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostHooksResourceTest.java index 57a3981..84d42d7 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostHooksResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendHostHooksResourceTest.java @@ -53,7 +53,7 @@ @Test public void testList() throws Exception { resource.setUriInfo(setUpBasicUriExpectations()); - setUpGetEntityExpectations(VdcQueryType.GetVdsHooksById2, + setUpGetEntityExpectations(VdcQueryType.GetVdsHooksById, GetVdsHooksByIdParameters.class, new String[] { "VdsId" }, new Object[] { GUIDS[0] }, getEntity(0)); diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/vdshooks/VdsHooksParser.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/vdshooks/VdsHooksParser.java index fc23299..2124c21 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/vdshooks/VdsHooksParser.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/vdshooks/VdsHooksParser.java @@ -3,9 +3,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.commons.lang.StringUtils; -import org.ovirt.engine.core.common.queries.ValueObjectMap; - /** * Parsers a hooks string to a ValueObjectMap of script directories/events to a ValueObjectMap of script names to a * ValueObjectMap of script properties The string is in format of a "toString" invocation on java.util.map object - for @@ -144,35 +141,10 @@ keyBuilder.append(current); } - /** - * Method to parse a given hooks string and return a hooks data structure - * - * @param hooksStr - * hooks string to parse - * @return hooks data structure - */ - public static ValueObjectMap parseHooks(String hooksStr) { - ValueObjectMap result = new ValueObjectMap(); - // If the hooks string is null or empty an empty data structure will be returned - if (StringUtils.isNotEmpty(hooksStr)) { - char[] chars = new char[hooksStr.length()]; - hooksStr.getChars(0, hooksStr.length(), chars, 0); - ParsingResult parsingResult = parseMap(chars, 0); - return convertParsingResultToValueObjectMap(parsingResult); - } - return result; - } - - public static Map<String, Object> parseHooks2(String hooksStr) { + public static Map<String, Object> parseHooks(String hooksStr) { char[] chars = new char[hooksStr.length()]; hooksStr.getChars(0, hooksStr.length(), chars, 0); ParsingResult parsingResult = parseMap(chars, 0); return parsingResult.getMap(); - } - - private static ValueObjectMap convertParsingResultToValueObjectMap(ParsingResult parsingResult) { - Map<String, Object> map = parsingResult.getMap(); - ValueObjectMap result = new ValueObjectMap(map, true); - return result; } } diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/vdshooks/TestVdsHooks.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/vdshooks/TestVdsHooks.java deleted file mode 100644 index 1f19169..0000000 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/vdshooks/TestVdsHooks.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.ovirt.engine.core.utils.vdshooks; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.Test; - -import org.ovirt.engine.core.common.queries.ValueObjectMap; -import org.ovirt.engine.core.common.queries.ValueObjectPair; -import static org.junit.Assert.*; - -public class TestVdsHooks { - - private Set<String> events; - private Map<String, Map<String, String>> scriptsForBeforeVmHibernate; - private Map<String, Map<String, String>> scriptsForAfterVmMigrateDestination; - private Map<String, Map<String, String>> scriptsForAfterVmCont; - private Map<String, Map<String, Map<String, String>>> eventsToScriptsMap; - - private void init() { - // Prepare a map from events to scripts information - events = - new HashSet<String>(Arrays.asList("before_vm_hibernate", - "after_vm_migrate_destination", - "after_vm_cont")); - scriptsForBeforeVmHibernate = new HashMap<String, Map<String, String>>(); - scriptsForAfterVmMigrateDestination = new HashMap<String, Map<String, String>>(); - scriptsForAfterVmCont = new HashMap<String, Map<String, String>>(); - Map<String, String> properties = new HashMap<String, String>(); - properties.put("md5", "5d9c4609cd936e80bac8c9ef7b27ea73"); - scriptsForBeforeVmHibernate.put("myscript.sh", properties); - properties = new HashMap<String, String>(); - properties.put("md5", "f388923356e84c2b4149572a44fde2b4"); - scriptsForBeforeVmHibernate.put("01_log", properties); - properties = new HashMap<String, String>(); - properties.put("md5", "677da3bdd8fbd16d4b8917a9fe0f6f89"); - scriptsForAfterVmMigrateDestination.put("myscript.sh", properties); - properties = new HashMap<String, String>(); - properties.put("md5", "f388923356e84c2b4149572a44fde2b4"); - - scriptsForAfterVmCont.put("01_log", properties); - /* - * scriptsForBeforeVmHibernate = new HashSet<String>(Arrays.asList("myscript.sh","01_log")); - * scriptsForAfterVmMigrateDestination = new HashSet<String>(Arrays.asList("myscript.sh")); - * scriptsForAfterVmCont = new HashSet<String>(Arrays.asList("01_log")); - */ - eventsToScriptsMap = new HashMap<String, Map<String, Map<String, String>>>(); - eventsToScriptsMap.put("before_vm_hibernate", scriptsForBeforeVmHibernate); - eventsToScriptsMap.put("after_vm_migrate_destination", scriptsForAfterVmMigrateDestination); - eventsToScriptsMap.put("after_vm_cont", scriptsForAfterVmCont); - } - - @Test - public void testVdsHooks() { - init(); - String hooksStr = - "{before_vm_hibernate={myscript.sh={md5=5d9c4609cd936e80bac8c9ef7b27ea73}, 01_log={md5=f388923356e84c2b4149572a44fde2b4}}, after_vm_migrate_destination={myscript.sh={md5=677da3bdd8fbd16d4b8917a9fe0f6f89}}, after_vm_cont={01_log={md5=f388923356e84c2b4149572a44fde2b4}}}"; - // Prepare data structures for testing the internal data of the value objects map - - ValueObjectMap result = VdsHooksParser.parseHooks(hooksStr); - ArrayList<ValueObjectPair> eventsValuePairs = result.getValuePairs(); - assertEquals(3, eventsValuePairs.size()); - - for (ValueObjectPair eventsValuePair : eventsValuePairs) { - String event = (String) eventsValuePair.getKey(); - ValueObjectMap scriptsObjectValuePairs = (ValueObjectMap) eventsValuePair.getValue(); - assertTrue(events.contains(event)); - testEvent(event, scriptsObjectValuePairs); - } - } - - private void testEvent(String event, ValueObjectMap scriptsObjectValueMap) { - Map<String, Map<String, String>> scriptsMap = eventsToScriptsMap.get(event); - for (ValueObjectPair scriptValueObjectPair : scriptsObjectValueMap.getValuePairs()) { - String key = (String) scriptValueObjectPair.getKey(); - assertTrue(scriptsMap.keySet().contains(key)); - ValueObjectMap properties = (ValueObjectMap) scriptValueObjectPair.getValue(); - Map<String, String> expectedProperties = scriptsMap.get(key); - testProperties(properties, expectedProperties); - } - - } - - private void testProperties(ValueObjectMap properties, Map<String, String> expectedProperties) { - ArrayList<ValueObjectPair> valuePairs = properties.getValuePairs(); - for (ValueObjectPair pair : valuePairs) { - String key = (String) pair.getKey(); - String value = (String) pair.getValue(); - String expectedValue = expectedProperties.get(key); - assertEquals(expectedValue, value); - } - // TODO Auto-generated method stub - - } - -} diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostHooksListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostHooksListModel.java index 0a54fee..66afa4a 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostHooksListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostHooksListModel.java @@ -118,7 +118,7 @@ GetVdsHooksByIdParameters tempVar = new GetVdsHooksByIdParameters(); tempVar.setVdsId(getEntity().getId()); tempVar.setRefresh(getIsQueryFirstTime()); - Frontend.RunQuery(VdcQueryType.GetVdsHooksById2, tempVar, _asyncQuery); + Frontend.RunQuery(VdcQueryType.GetVdsHooksById, tempVar, _asyncQuery); } -- To view, visit http://gerrit.ovirt.org/13607 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1890f429a12cbf7e42727b7360a85ebb1b07b5b0 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Allon Mureinik <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
