Gilad Chaplik has uploaded a new change for review. Change subject: engine: policy unit should contain single logic ......................................................................
engine: policy unit should contain single logic Utill now policy unit could hold logic for filtering, weighing or balancing (one or more). in this patch each policy unit could hold a single logic, according to a type field (enum) added to the entity. Change-Id: Ia6f1d88c7c9bbc600dba0199a7cab27d914c68f4 Signed-off-by: Gilad Chaplik <gchap...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/PolicyUnitImpl.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/commands/ClusterPolicyCRUDCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/PolicyUnit.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/PolicyUnitType.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/scheduling/ClusterPolicyDaoImpl.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/scheduling/PolicyUnitDaoImpl.java M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PolicyUnitDaoTest.java M backend/manager/modules/dal/src/test/resources/fixtures.xml M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/configure/scheduling/ClusterPolicyListModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/configure/scheduling/NewClusterPolicyModel.java M packaging/dbscripts/cluster_policy_sp.sql A packaging/dbscripts/upgrade/03_03_0630_allow_single_logic_for_policy_unit.sql 12 files changed, 110 insertions(+), 148 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/35/17535/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/PolicyUnitImpl.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/PolicyUnitImpl.java index 2d2d2a6..3158093 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/PolicyUnitImpl.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/PolicyUnitImpl.java @@ -17,6 +17,7 @@ import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.scheduling.PolicyUnit; +import org.ovirt.engine.core.common.scheduling.PolicyUnitType; import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.utils.log.Log; @@ -111,33 +112,13 @@ } @Override - public final boolean isFilterImplemeted() { - return policyUnit.isFilterImplemeted(); + public PolicyUnitType getPolicyUnitType() { + return policyUnit.getPolicyUnitType(); } @Override - public final void setFilterImplemeted(boolean filterImplemeted) { - policyUnit.setFilterImplemeted(filterImplemeted); - } - - @Override - public final boolean isFunctionImplemeted() { - return policyUnit.isFunctionImplemeted(); - } - - @Override - public final void setFunctionImplemeted(boolean functionImplemeted) { - policyUnit.setFunctionImplemeted(functionImplemeted); - } - - @Override - public final boolean isBalanceImplemeted() { - return policyUnit.isBalanceImplemeted(); - } - - @Override - public final void setBalanceImplemeted(boolean balanceImplemeted) { - policyUnit.setBalanceImplemeted(balanceImplemeted); + public void setPolicyUnitType(PolicyUnitType policyUnitType) { + policyUnit.setPolicyUnitType(policyUnitType); } @Override diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/commands/ClusterPolicyCRUDCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/commands/ClusterPolicyCRUDCommand.java index 0e947fa..117674f 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/commands/ClusterPolicyCRUDCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/commands/ClusterPolicyCRUDCommand.java @@ -11,6 +11,7 @@ import org.ovirt.engine.core.common.VdcObjectType; import org.ovirt.engine.core.common.errors.VdcBllMessages; import org.ovirt.engine.core.common.scheduling.ClusterPolicy; +import org.ovirt.engine.core.common.scheduling.PolicyUnitType; import org.ovirt.engine.core.common.scheduling.parameters.ClusterPolicyCRUDParameters; import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.core.compat.Guid; @@ -46,7 +47,7 @@ if (policyUnitImpl == null) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT); } - if (!policyUnitImpl.isFilterImplemeted()) { + if (policyUnitImpl.getPolicyUnitType() != PolicyUnitType.Filter) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_POLICY_FILTER_NOT_IMPLEMENTED); } } @@ -78,7 +79,7 @@ if (policyUnitImpl == null) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT); } - if (!policyUnitImpl.isFunctionImplemeted()) { + if (policyUnitImpl.getPolicyUnitType() != PolicyUnitType.Weight) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_POLICY_FUNCTION_NOT_IMPLEMENTED); } if (functionPair.getSecond() < 0) { @@ -92,7 +93,7 @@ if (policyUnitImpl == null) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT); } - if (!policyUnitImpl.isBalanceImplemeted()) { + if (policyUnitImpl.getPolicyUnitType() != PolicyUnitType.LoadBalancing) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_POLICY_BALANCE_NOT_IMPLEMENTED); } } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/PolicyUnit.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/PolicyUnit.java index 796e871..f3d8ca8 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/PolicyUnit.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/PolicyUnit.java @@ -26,17 +26,9 @@ */ private boolean internal = true; /** - * specifies whether filter method implemented in loaded class + * specifies policy unit type (filter, weight or load balance) */ - private boolean filterImplemeted; - /** - * specifies whether weight function method implemented in loaded class - */ - private boolean functionImplemeted; - /** - * specifies whether load balancing method implemented in loaded class - */ - private boolean balanceImplemeted; + private PolicyUnitType policyUnitType; /** * policy unit acceptable custom parameters; format <parameterName, regex> */ @@ -73,28 +65,12 @@ this.internal = internal; } - public boolean isFilterImplemeted() { - return filterImplemeted; + public PolicyUnitType getPolicyUnitType() { + return policyUnitType; } - public void setFilterImplemeted(boolean filterImplemeted) { - this.filterImplemeted = filterImplemeted; - } - - public boolean isFunctionImplemeted() { - return functionImplemeted; - } - - public void setFunctionImplemeted(boolean functionImplemeted) { - this.functionImplemeted = functionImplemeted; - } - - public boolean isBalanceImplemeted() { - return balanceImplemeted; - } - - public void setBalanceImplemeted(boolean balanceImplemeted) { - this.balanceImplemeted = balanceImplemeted; + public void setPolicyUnitType(PolicyUnitType policyUnitType) { + this.policyUnitType = policyUnitType; } public Map<String, String> getParameterRegExMap() { @@ -109,9 +85,7 @@ public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (balanceImplemeted ? 1231 : 1237); - result = prime * result + (filterImplemeted ? 1231 : 1237); - result = prime * result + (functionImplemeted ? 1231 : 1237); + result = prime * result + ((policyUnitType == null) ? 0 : policyUnitType.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + (internal ? 1231 : 1237); result = prime * result + ((name == null) ? 0 : name.hashCode()); @@ -128,12 +102,6 @@ if (getClass() != obj.getClass()) return false; PolicyUnit other = (PolicyUnit) obj; - if (balanceImplemeted != other.balanceImplemeted) - return false; - if (filterImplemeted != other.filterImplemeted) - return false; - if (functionImplemeted != other.functionImplemeted) - return false; if (id == null) { if (other.id != null) return false; @@ -151,6 +119,8 @@ return false; } else if (!parameterRegExMap.equals(other.parameterRegExMap)) return false; + if (policyUnitType != other.policyUnitType) + return false; return true; } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/PolicyUnitType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/PolicyUnitType.java new file mode 100644 index 0000000..cef03cc --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/scheduling/PolicyUnitType.java @@ -0,0 +1,33 @@ +package org.ovirt.engine.core.common.scheduling; + +import java.util.HashMap; + +import org.ovirt.engine.core.common.businessentities.Identifiable; + +public enum PolicyUnitType implements Identifiable { + Filter(0), + Weight(1), + LoadBalancing(2); + + private int intValue; + private static java.util.HashMap<Integer, PolicyUnitType> mappings = new HashMap<Integer, PolicyUnitType>(); + + static { + for (PolicyUnitType vmType : values()) { + mappings.put(vmType.getValue(), vmType); + } + } + + private PolicyUnitType(int value) { + intValue = value; + } + + @Override + public int getValue() { + return intValue; + } + + public static PolicyUnitType forValue(int value) { + return mappings.get(value); + } +} diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/scheduling/ClusterPolicyDaoImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/scheduling/ClusterPolicyDaoImpl.java index 22c18fd..570f108 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/scheduling/ClusterPolicyDaoImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/scheduling/ClusterPolicyDaoImpl.java @@ -9,6 +9,8 @@ import java.util.Map; import org.ovirt.engine.core.common.scheduling.ClusterPolicy; +import org.ovirt.engine.core.common.scheduling.PolicyUnit; +import org.ovirt.engine.core.common.scheduling.PolicyUnitType; import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dao.DefaultGenericDaoDbFacade; @@ -17,6 +19,7 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; public class ClusterPolicyDaoImpl extends DefaultGenericDaoDbFacade<ClusterPolicy, Guid> implements ClusterPolicyDao { + private static Map<Guid, PolicyUnit> policyUnitMap = null; public ClusterPolicyDaoImpl() { super("ClusterPolicy"); @@ -78,9 +81,15 @@ } private void fillClusterPolicy(Map<Guid, ClusterPolicy> map, List<ClusterPolicyUnit> clusterPolicyUnits) { + if (policyUnitMap == null) { + policyUnitMap = new HashMap<Guid, PolicyUnit>(); + for (PolicyUnit policyUnit : dbFacade.getPolicyUnitDao().getAll()) { + policyUnitMap.put(policyUnit.getId(), policyUnit); + } + } for (ClusterPolicyUnit clusterPolicyUnit : clusterPolicyUnits) { ClusterPolicy clusterPolicy = map.get(clusterPolicyUnit.getClusterPolicyId()); - if (clusterPolicyUnit.isFilterSelected()) { + if (policyUnitMap.get(clusterPolicyUnit.getPolicyUnitId()).getPolicyUnitType() == PolicyUnitType.Filter) { if (clusterPolicy.getFilters() == null) { clusterPolicy.setFilters(new ArrayList<Guid>()); } @@ -93,14 +102,14 @@ clusterPolicyUnit.getFilterSequence()); } } - if (clusterPolicyUnit.isFunctionSelected()) { + if (policyUnitMap.get(clusterPolicyUnit.getPolicyUnitId()).getPolicyUnitType() == PolicyUnitType.Weight) { if(clusterPolicy.getFunctions() == null){ clusterPolicy.setFunctions(new ArrayList<Pair<Guid, Integer>>()); } clusterPolicy.getFunctions().add(new Pair<Guid, Integer>(clusterPolicyUnit.getPolicyUnitId(), clusterPolicyUnit.getFactor())); } - if (clusterPolicyUnit.isBalanceSelected()) { + if (policyUnitMap.get(clusterPolicyUnit.getPolicyUnitId()).getPolicyUnitType() == PolicyUnitType.LoadBalancing) { clusterPolicy.setBalance(clusterPolicyUnit.getPolicyUnitId()); } } @@ -112,7 +121,6 @@ if (entity.getFilters() != null) { for (Guid policyUnitId : entity.getFilters()) { unit = getClusterPolicyUnit(entity, policyUnitId, map); - unit.setFilterSelected(true); if (entity.getFilterPositionMap() != null) { Integer position = entity.getFilterPositionMap().get(policyUnitId); unit.setFilterSequence(position != null ? position : 0); @@ -122,13 +130,11 @@ if (entity.getFunctions() != null) { for (Pair<Guid, Integer> pair : entity.getFunctions()) { unit = getClusterPolicyUnit(entity, pair.getFirst(), map); - unit.setFunctionSelected(true); unit.setFactor(pair.getSecond()); } } if (entity.getBalance() != null) { unit = getClusterPolicyUnit(entity, entity.getBalance(), map); - unit.setBalanceSelected(true); } return new ArrayList<ClusterPolicyUnit>(map.values()); } @@ -141,11 +147,8 @@ private MapSqlParameterSource getClusterPolicyUnitParameterMap(ClusterPolicyUnit clusterPolicyUnit) { return getCustomMapSqlParameterSource().addValue("cluster_policy_id", clusterPolicyUnit.getClusterPolicyId()) .addValue("policy_unit_id", clusterPolicyUnit.getPolicyUnitId()) - .addValue("is_filter_selected", clusterPolicyUnit.isFilterSelected()) .addValue("filter_sequence", clusterPolicyUnit.getFilterSequence()) - .addValue("is_function_selected", clusterPolicyUnit.isFunctionSelected()) - .addValue("factor", clusterPolicyUnit.getFactor()) - .addValue("is_balance_selected", clusterPolicyUnit.isBalanceSelected()); + .addValue("factor", clusterPolicyUnit.getFactor()); } protected RowMapper<ClusterPolicyUnit> createClusterPolicyUnitRowMapper() { @@ -155,11 +158,8 @@ ClusterPolicyUnit unit = new ClusterPolicyUnit(); unit.setClusterPolicyId(getGuid(rs, "cluster_policy_id")); unit.setPolicyUnitId(getGuid(rs, "policy_unit_id")); - unit.setFilterSelected(rs.getBoolean("is_filter_selected")); unit.setFilterSequence(rs.getInt("filter_sequence")); - unit.setFunctionSelected(rs.getBoolean("is_function_selected")); unit.setFactor(rs.getInt("factor")); - unit.setBalanceSelected(rs.getBoolean("is_balance_selected")); return unit; } }; @@ -218,11 +218,8 @@ private static class ClusterPolicyUnit { Guid clusterPolicyId; Guid policyUnitId; - boolean filterSelected; int filterSequence; - boolean functionSelected; int factor; - boolean balanceSelected; public ClusterPolicyUnit() { } @@ -248,28 +245,12 @@ this.policyUnitId = policyUnitId; } - public boolean isFilterSelected() { - return filterSelected; - } - - public void setFilterSelected(boolean filterSelected) { - this.filterSelected = filterSelected; - } - public int getFilterSequence() { return filterSequence; } public void setFilterSequence(int filterSequence) { this.filterSequence = filterSequence; - } - - public boolean isFunctionSelected() { - return functionSelected; - } - - public void setFunctionSelected(boolean functionSelected) { - this.functionSelected = functionSelected; } public int getFactor() { @@ -280,12 +261,5 @@ this.factor = factor; } - public boolean isBalanceSelected() { - return balanceSelected; - } - - public void setBalanceSelected(boolean balanceSelected) { - this.balanceSelected = balanceSelected; - } } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/scheduling/PolicyUnitDaoImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/scheduling/PolicyUnitDaoImpl.java index 346b828..f6195e2 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/scheduling/PolicyUnitDaoImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/scheduling/PolicyUnitDaoImpl.java @@ -5,6 +5,7 @@ import java.util.LinkedHashMap; import org.ovirt.engine.core.common.scheduling.PolicyUnit; +import org.ovirt.engine.core.common.scheduling.PolicyUnitType; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dao.DefaultGenericDaoDbFacade; import org.ovirt.engine.core.utils.SerializationFactory; @@ -22,9 +23,7 @@ return createIdParameterMapper(entity.getId()) .addValue("name", entity.getName()) .addValue("is_internal", entity.isInternal()) - .addValue("has_filter", entity.isFilterImplemeted()) - .addValue("has_function", entity.isFunctionImplemeted()) - .addValue("has_balance", entity.isBalanceImplemeted()) + .addValue("type", entity.getPolicyUnitType().getValue()) .addValue("custom_properties_regex", SerializationFactory.getSerializer().serialize(entity.getParameterRegExMap())); } @@ -43,10 +42,8 @@ PolicyUnit policyUnit = new PolicyUnit(); policyUnit.setId(getGuid(rs, "id")); policyUnit.setName(rs.getString("name")); - - policyUnit.setFilterImplemeted(rs.getBoolean("has_filter")); - policyUnit.setFunctionImplemeted(rs.getBoolean("has_function")); - policyUnit.setBalanceImplemeted(rs.getBoolean("has_balance")); + policyUnit.setInternal(rs.getBoolean("is_internal")); + policyUnit.setPolicyUnitType(PolicyUnitType.forValue(rs.getInt("type"))); policyUnit.setParameterRegExMap(SerializationFactory.getDeserializer() .deserializeOrCreateNew(rs.getString("custom_properties_regex"), LinkedHashMap.class)); return policyUnit; diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PolicyUnitDaoTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PolicyUnitDaoTest.java index f99ce9e..4b83eca 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PolicyUnitDaoTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PolicyUnitDaoTest.java @@ -52,7 +52,6 @@ dummyPolicyUnit = new PolicyUnit(); dummyPolicyUnit.setId(Guid.newGuid()); dummyPolicyUnit.setName("Dummy policy unit"); - dummyPolicyUnit.setBalanceImplemeted(true); } } diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml b/backend/manager/modules/dal/src/test/resources/fixtures.xml index deaec5c..4a631fc 100644 --- a/backend/manager/modules/dal/src/test/resources/fixtures.xml +++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml @@ -529,26 +529,20 @@ <column>id</column> <column>name</column> <column>is_internal</column> - <column>has_filter</column> - <column>has_function</column> - <column>has_balance</column> + <column>type</column> <column>custom_properties_regex</column> <row> <value>84e6ddee-ab0d-42dd-82f0-c297779db5e5</value> <value>Migration</value> <value>true</value> - <value>true</value> - <value>false</value> - <value>false</value> + <value>0</value> <null/> </row> <row> <value>a267eddb-768d-45fd-9dbb-6ebcee343508</value> <value>MigrationDomain</value> <value>true</value> - <value>true</value> - <value>false</value> - <value>false</value> + <value>0</value> <null/> </row> </table> @@ -556,28 +550,19 @@ <table name="cluster_policy_units"> <column>cluster_policy_id</column> <column>policy_unit_id</column> - <column>is_filter_selected</column> <column>filter_sequence</column> - <column>is_function_selected</column> <column>factor</column> - <column>is_balance_selected</column> <row> <value>20d25257-b4bd-4589-92a6-c4c5c5d3fd1a</value> <value>84e6ddee-ab0d-42dd-82f0-c297779db5e5</value> - <value>true</value> <value>1</value> - <value>false</value> <value>0</value> - <value>false</value> </row> <row> <value>5a2b0939-7d46-4b73-a469-e9c2c7fc6a53</value> <value>a267eddb-768d-45fd-9dbb-6ebcee343508</value> - <value>true</value> <value>1</value> - <value>false</value> <value>0</value> - <value>false</value> </row> </table> diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/configure/scheduling/ClusterPolicyListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/configure/scheduling/ClusterPolicyListModel.java index 37ed7d4..9443461 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/configure/scheduling/ClusterPolicyListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/configure/scheduling/ClusterPolicyListModel.java @@ -9,6 +9,7 @@ import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.common.scheduling.ClusterPolicy; import org.ovirt.engine.core.common.scheduling.PolicyUnit; +import org.ovirt.engine.core.common.scheduling.PolicyUnitType; import org.ovirt.engine.core.common.scheduling.parameters.ClusterPolicyCRUDParameters; import org.ovirt.engine.ui.frontend.AsyncQuery; import org.ovirt.engine.ui.frontend.Frontend; @@ -48,7 +49,7 @@ public List<PolicyUnit> getBalancePolicyUnits() { ArrayList<PolicyUnit> list = new ArrayList<PolicyUnit>(); for (PolicyUnit policyUnit : getPolicyUnits()) { - if (policyUnit.isBalanceImplemeted()) { + if (policyUnit.getPolicyUnitType() == PolicyUnitType.LoadBalancing) { list.add(policyUnit); } @@ -59,7 +60,7 @@ public ArrayList<PolicyUnit> getFilterPolicyUnits() { ArrayList<PolicyUnit> list = new ArrayList<PolicyUnit>(); for (PolicyUnit policyUnit : getPolicyUnits()) { - if (policyUnit.isFilterImplemeted()) { + if (policyUnit.getPolicyUnitType() == PolicyUnitType.Filter) { list.add(policyUnit); } } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/configure/scheduling/NewClusterPolicyModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/configure/scheduling/NewClusterPolicyModel.java index d17bc4e..1be60e1 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/configure/scheduling/NewClusterPolicyModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/configure/scheduling/NewClusterPolicyModel.java @@ -9,6 +9,7 @@ import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.scheduling.ClusterPolicy; import org.ovirt.engine.core.common.scheduling.PolicyUnit; +import org.ovirt.engine.core.common.scheduling.PolicyUnitType; import org.ovirt.engine.core.common.scheduling.parameters.ClusterPolicyCRUDParameters; import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.core.compat.Guid; @@ -179,7 +180,7 @@ } ArrayList<PolicyUnit> balancePolicyUnits = new ArrayList<PolicyUnit>(); for (PolicyUnit policyUnit : list) { - if (policyUnit.isBalanceImplemeted()) { + if (policyUnit.getPolicyUnitType() == PolicyUnitType.LoadBalancing) { balancePolicyUnits.add(policyUnit); } } @@ -192,7 +193,7 @@ } ArrayList<PolicyUnit> filterPolicyUnits = new ArrayList<PolicyUnit>(); for (PolicyUnit policyUnit : list) { - if (policyUnit.isFilterImplemeted()) { + if (policyUnit.getPolicyUnitType() == PolicyUnitType.Filter) { filterPolicyUnits.add(policyUnit); } } @@ -205,7 +206,7 @@ } ArrayList<PolicyUnit> functionPolicyUnits = new ArrayList<PolicyUnit>(); for (PolicyUnit policyUnit : list) { - if (policyUnit.isFunctionImplemeted()) { + if (policyUnit.getPolicyUnitType() == PolicyUnitType.Weight) { functionPolicyUnits.add(policyUnit); } } diff --git a/packaging/dbscripts/cluster_policy_sp.sql b/packaging/dbscripts/cluster_policy_sp.sql index 74f5086..e11d361 100644 --- a/packaging/dbscripts/cluster_policy_sp.sql +++ b/packaging/dbscripts/cluster_policy_sp.sql @@ -122,30 +122,21 @@ Create or replace FUNCTION InsertClusterPolicyUnit( v_cluster_policy_id UUID, v_policy_unit_id UUID, - v_is_filter_selected BOOLEAN, v_filter_sequence int, - v_is_function_selected BOOLEAN, - v_factor int, - v_is_balance_selected BOOLEAN) + v_factor int) RETURNS VOID AS $procedure$ BEGIN INSERT INTO cluster_policy_units( cluster_policy_id, policy_unit_id, - is_filter_selected, filter_sequence, - is_function_selected, - factor, - is_balance_selected) + factor) VALUES( v_cluster_policy_id, v_policy_unit_id, - v_is_filter_selected, v_filter_sequence, - v_is_function_selected, - v_factor, - v_is_balance_selected); + v_factor); END; $procedure$ LANGUAGE plpgsql; diff --git a/packaging/dbscripts/upgrade/03_03_0630_allow_single_logic_for_policy_unit.sql b/packaging/dbscripts/upgrade/03_03_0630_allow_single_logic_for_policy_unit.sql new file mode 100644 index 0000000..0e0134c --- /dev/null +++ b/packaging/dbscripts/upgrade/03_03_0630_allow_single_logic_for_policy_unit.sql @@ -0,0 +1,29 @@ +-- add type column (default is type = filter) +SELECT fn_db_add_column('policy_units', 'type', 'smallint default 0'); +-- update balance p.u to type = 2 +UPDATE policy_units SET type = 2 WHERE has_balance = true; +-- remove has_XXX columns (transformed into type column) +SELECT fn_db_drop_column('policy_units', 'has_filter'); +SELECT fn_db_drop_column('policy_units', 'has_function'); +SELECT fn_db_drop_column('policy_units', 'has_balance'); +-- becuase policy unit cannot contain more than one type, adding new entries for weight functions. +INSERT INTO policy_units (id, name, is_internal, custom_properties_regex, type) VALUES ('38440000-8cf0-14bd-c43e-10b96e4ef00b', 'None', true, NULL, 1); +INSERT INTO policy_units (id, name, is_internal, custom_properties_regex, type) VALUES ('736999d0-1023-46a4-9a75-1316ed50e15b', 'PowerSaving', true, NULL, 1); +INSERT INTO policy_units (id, name, is_internal, custom_properties_regex, type) VALUES ('7db4ab05-81ab-42e8-868a-aee2df483edb', 'EvenDistribution', true, NULL, 1); +-- cluster_policy_units: adding entries for new weight functions +INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) +SELECT cluster_policy_id, '38440000-8cf0-14bd-c43e-10b96e4ef00b', is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected +FROM cluster_policy_units +WHERE policy_unit_id = '38440000-8cf0-14bd-c43e-10b96e4ef00a'; +INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) +SELECT cluster_policy_id, '736999d0-1023-46a4-9a75-1316ed50e15b', is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected +FROM cluster_policy_units +WHERE policy_unit_id = '736999d0-1023-46a4-9a75-1316ed50e151'; +INSERT INTO cluster_policy_units (cluster_policy_id, policy_unit_id, is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected) +SELECT cluster_policy_id, '7db4ab05-81ab-42e8-868a-aee2df483edb', is_filter_selected, filter_sequence, is_function_selected, factor, is_balance_selected +FROM cluster_policy_units +WHERE policy_unit_id = '7db4ab05-81ab-42e8-868a-aee2df483ed2'; +-- cluster_policy_units: removing is_XXX_selected (since policy unit contain only a single entry) +SELECT fn_db_drop_column('cluster_policy_units', 'is_filter_selected'); +SELECT fn_db_drop_column('cluster_policy_units', 'is_function_selected'); +SELECT fn_db_drop_column('cluster_policy_units', 'is_balance_selected'); -- To view, visit http://gerrit.ovirt.org/17535 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia6f1d88c7c9bbc600dba0199a7cab27d914c68f4 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