Gilad Chaplik has uploaded a new change for review. Change subject: engine: fix clutser policy bugs ......................................................................
engine: fix clutser policy bugs which were discovered while verifying RESTful implementation for scheduling feature. Change-Id: I136e42882c1642380eb641689fc39f3a72d1f789 Signed-off-by: Gilad Chaplik <gchap...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/commands/AddClusterPolicyCommand.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/errors/VdcBllMessages.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties A packaging/dbscripts/upgrade/03_05_0510_lowercase_default_cluster_policies_names.sql 7 files changed, 25 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/61/28161/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/commands/AddClusterPolicyCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/commands/AddClusterPolicyCommand.java index 7680047..1d8db2f 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/commands/AddClusterPolicyCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/commands/AddClusterPolicyCommand.java @@ -21,6 +21,7 @@ protected void executeCommand() { getClusterPolicy().setId(Guid.newGuid()); SchedulingManager.getInstance().addClusterPolicy(getClusterPolicy()); + getReturnValue().setActionReturnValue(getClusterPolicy().getId()); setSucceeded(true); } 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 266babf..0da5f55 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 @@ -1,8 +1,10 @@ package org.ovirt.engine.core.bll.scheduling.commands; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.ovirt.engine.core.bll.CommandBase; import org.ovirt.engine.core.bll.scheduling.PolicyUnitImpl; @@ -40,9 +42,13 @@ } } Map<Guid, PolicyUnitImpl> map = SchedulingManager.getInstance().getPolicyUnitsMap(); + Set<Guid> existingPolicyUnits = new HashSet<>(); // check filter policy units if (getClusterPolicy().getFilters() != null) { for (Guid filterId : getClusterPolicy().getFilters()) { + if(isPolicyUnitExist(filterId, existingPolicyUnits)) { + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT); + } PolicyUnitImpl policyUnitImpl = map.get(filterId); if (policyUnitImpl == null) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT); @@ -75,6 +81,9 @@ // check function policy units if (getClusterPolicy().getFunctions() != null) { for (Pair<Guid, Integer> functionPair : getClusterPolicy().getFunctions()) { + if (isPolicyUnitExist(functionPair.getFirst(), existingPolicyUnits)) { + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT); + } PolicyUnitImpl policyUnitImpl = map.get(functionPair.getFirst()); if (policyUnitImpl == null) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT); @@ -110,6 +119,10 @@ return true; } + private boolean isPolicyUnitExist(Guid policyUnitId, Set<Guid> existingPolicyUnits) { + return !existingPolicyUnits.add(policyUnitId); + } + protected boolean checkRemoveEditValidations() { Guid clusterPolicyId = getParameters().getClusterPolicyId(); if (clusterPolicyId == null) { diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java index 4d118e4..8e06e54 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java @@ -805,6 +805,7 @@ ACTION_TYPE_FAILED_VDS_HA_NOT_CONFIGURED(ErrorType.BAD_PARAMETERS), // Cluster Policy messages ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID(ErrorType.BAD_PARAMETERS), + ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_CLUSTER_POLICY_NAME_INUSE(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_CLUSTER_POLICY_LOCKED(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_CLUSTER_POLICY_INUSE(ErrorType.BAD_PARAMETERS), diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties index 4819b7c..8e8c778 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -1110,6 +1110,7 @@ # cluster policy errors ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID=Cannot ${action} ${type}. Parameters are invalid. +ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT=Cannot ${action} ${type}. policy unit already exists in cluster policy. ACTION_TYPE_FAILED_CLUSTER_POLICY_NAME_INUSE=Cannot ${action} ${type}. Name is in use. ACTION_TYPE_FAILED_CLUSTER_POLICY_LOCKED=Cannot ${action} ${type}. Cluster Policy is locked, and cannot be editable. ACTION_TYPE_FAILED_CLUSTER_POLICY_INUSE=Cannot ${action} ${type}. Cluster Policy is attached to cluster(s), please assign these cluster(s) to other policy. diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java index da57788..fd22c06 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java @@ -3030,6 +3030,9 @@ @DefaultStringValue("Cannot ${action} ${type}. Parameters are invalid.") String ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID(); + @DefaultStringValue("Cannot ${action} ${type}. policy unit already exists in cluster policy.") + String ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT(); + @DefaultStringValue("Cannot ${action} ${type}. Name is in use.") String ACTION_TYPE_FAILED_CLUSTER_POLICY_NAME_INUSE(); diff --git a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 72c678b..b4a9831 100644 --- a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -1087,6 +1087,7 @@ # cluster policy errors ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID=Cannot ${action} ${type}. Parameters are invalid. +ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT=Cannot ${action} ${type}. policy unit already exists in cluster policy. ACTION_TYPE_FAILED_CLUSTER_POLICY_NAME_INUSE=Cannot ${action} ${type}. Name is in use. ACTION_TYPE_FAILED_CLUSTER_POLICY_LOCKED=Cannot ${action} ${type}. Cluster Policy is locked, and cannot be editable. ACTION_TYPE_FAILED_CLUSTER_POLICY_INUSE=Cannot ${action} ${type}. Cluster Policy is attached to cluster(s), please assign these cluster(s) to other policy. diff --git a/packaging/dbscripts/upgrade/03_05_0510_lowercase_default_cluster_policies_names.sql b/packaging/dbscripts/upgrade/03_05_0510_lowercase_default_cluster_policies_names.sql new file mode 100644 index 0000000..9ee5251 --- /dev/null +++ b/packaging/dbscripts/upgrade/03_05_0510_lowercase_default_cluster_policies_names.sql @@ -0,0 +1,5 @@ +-- Avoid lower and upper case mixture, to match RESTful API enum backward compatibility +UPDATE cluster_policies SET name = 'evenly_distributed' WHERE name = 'Evenly_Distributed'; +UPDATE cluster_policies SET name = 'power_saving' WHERE name = 'Power_Saving'; +UPDATE cluster_policies SET name = 'none' WHERE name = 'None'; +UPDATE cluster_policies SET name = 'vm_evenly_distributed' WHERE name = 'VM_Evenly_Distributed'; -- To view, visit http://gerrit.ovirt.org/28161 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I136e42882c1642380eb641689fc39f3a72d1f789 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