ofri masad has uploaded a new change for review. Change subject: core: Add mom policy update command ......................................................................
core: Add mom policy update command Add a command to allow update of mom policy on host. Change-Id: I64350c17f182c1dd0ba1d06130e5d56019b32fc9 Signed-off-by: Ofri Masad <oma...@redhat.com> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateMomPolicyCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.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 9 files changed, 118 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/79/17379/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateMomPolicyCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateMomPolicyCommand.java new file mode 100644 index 0000000..0c5daf8 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateMomPolicyCommand.java @@ -0,0 +1,91 @@ +package org.ovirt.engine.core.bll; + + +import org.ovirt.engine.core.bll.utils.PermissionSubject; +import org.ovirt.engine.core.common.AuditLogType; +import org.ovirt.engine.core.common.VdcObjectType; +import org.ovirt.engine.core.common.action.VdsActionParameters; +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.businessentities.VDSGroup; +import org.ovirt.engine.core.common.businessentities.VDSStatus; +import org.ovirt.engine.core.common.errors.VdcBLLException; +import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.common.eventqueue.EventResult; +import org.ovirt.engine.core.common.eventqueue.EventType; +import org.ovirt.engine.core.common.vdscommands.MomPolicyVDSParameters; +import org.ovirt.engine.core.common.vdscommands.VDSCommandType; +import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector; +import org.ovirt.engine.core.dao.VdsDAO; +import org.ovirt.engine.core.dao.VdsGroupDAO; + +import java.util.Collections; +import java.util.List; + +public class UpdateMomPolicyCommand extends CommandBase<VdsActionParameters> { + + private VDS vds; + + public UpdateMomPolicyCommand(VdsActionParameters vdsActionParameters) { + super(vdsActionParameters); + } + + private EventResult runUpdateMomPolicy(final VDS vds, boolean ballooningEnabled) { + EventResult result = new EventResult(true, EventType.VDSCONNECTTOPOOL); + try { + runVdsCommand(VDSCommandType.SetMOMPolicyParameters, + new MomPolicyVDSParameters(vds, ballooningEnabled)); + } catch (VdcBLLException e) { + log.errorFormat("Could not update MoM policy on host {0}", vds.getName()); + result.setSuccess(false); + } + + return result; + } + + @Override + protected void executeCommand() { + VDSGroup vdsGroup = getVdsGroupDao().get(vds.getVdsGroupId()); + + if (vdsGroup != null) { + runUpdateMomPolicy(vds, vdsGroup.isEnableBallooning()); + } + } + + @Override + protected boolean canDoAction() { + if (getParameters().getVdsId() == null) { + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_UPDATE_MOM_POLICY_UPDATE_NULL_HOST); + } + + vds = getVdsDao().get(getParameters().getVdsId()); + + if (vds == null) { + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_UPDATE_MOM_POLICY_UPDATE_NULL_HOST); + } + + if (vds.getStatus() != VDSStatus.Up) { + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_UPDATE_MOM_POLICY_UPDATE_HOST_DOWN); + } + return true; + } + + protected VdsDAO getVdsDao() { + return getDbFacade().getVdsDao(); + } + + protected VdsGroupDAO getVdsGroupDao() { + return getDbFacade().getVdsGroupDao(); + } + + @Override + protected void endSuccessfully() { + super.endSuccessfully(); + AuditLogDirector.log(this, AuditLogType.USER_UPDATED_MOM_POLICIES); + } + + @Override + public List<PermissionSubject> getPermissionCheckSubjects() { + return Collections.singletonList(new PermissionSubject(getParameters().getVdsId(), + VdcObjectType.VDS, getActionType().getActionGroup())); + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java index d9425dd..0a38736 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java @@ -776,7 +776,10 @@ USER_REMOVED_NETWORK_QOS(10102), USER_FAILED_TO_REMOVE_NETWORK_QOS(10103), USER_UPDATED_NETWORK_QOS(10104), - USER_FAILED_TO_UPDATE_NETWORK_QOS(10105) + USER_FAILED_TO_UPDATE_NETWORK_QOS(10105), + + //mom policies + USER_UPDATED_MOM_POLICIES(10200) ; private int intValue; diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java index 6604f57..f2e416b 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java @@ -279,7 +279,9 @@ EndExternalJob(1801, ActionGroup.INJECT_EXTERNAL_TASKS, false, QuotaDependency.NONE), ClearExternalJob(1802, ActionGroup.INJECT_EXTERNAL_TASKS, false, QuotaDependency.NONE), AddExternalStep(1803, ActionGroup.INJECT_EXTERNAL_TASKS, false, QuotaDependency.NONE), - EndExternalStep(1804, ActionGroup.INJECT_EXTERNAL_TASKS, false, QuotaDependency.NONE); + EndExternalStep(1804, ActionGroup.INJECT_EXTERNAL_TASKS, false, QuotaDependency.NONE), + + UpdateMomPolicy(1900, ActionGroup.EDIT_HOST_CONFIGURATION, false, QuotaDependency.NONE); private int intValue; private ActionGroup actionGroup; 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 a4a963e..69698e0 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 @@ -764,7 +764,11 @@ ACTION_TYPE_FAILED_NETWORK_QOS_PEAK_LOWER_THAN_AVERAGE(ErrorType.BAD_PARAMETERS), // memory QOS features - QOS_BALLOON_NOT_SUPPORTED(ErrorType.BAD_PARAMETERS); + QOS_BALLOON_NOT_SUPPORTED(ErrorType.BAD_PARAMETERS), + + //mom policy + ACTION_TYPE_FAILED_UPDATE_MOM_POLICY_UPDATE_HOST_DOWN(ErrorType.CONSTRAINT_VIOLATION), + ACTION_TYPE_FAILED_UPDATE_MOM_POLICY_UPDATE_NULL_HOST(ErrorType.BAD_PARAMETERS); private ErrorType messageType; diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java index 0f3d159..8d8a17e 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java @@ -477,6 +477,10 @@ severities.put(AuditLogType.USER_FAILED_TO_UPDATE_NETWORK_QOS, AuditLogSeverity.ERROR); } + private static void initMomPoliciesSeverities() { + severities.put(AuditLogType.USER_UPDATED_MOM_POLICIES, AuditLogSeverity.NORMAL); + } + private static void initVMSeverities() { severities.put(AuditLogType.USER_ATTACH_VM_TO_AD_GROUP, AuditLogSeverity.NORMAL); severities.put(AuditLogType.USER_ATTACH_VM_TO_AD_GROUP_FAILED, AuditLogSeverity.ERROR); 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 975457a..75b773c 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -930,6 +930,8 @@ QOS_NAME_NOT_NULL=QoS name cannot be empty. QOS_NAME_INVALID=Invalid QoS name (name must be formed of "a-z0-9A-Z" or "-_ ") QOS_NAME_TOO_LONG=QoS name length must be under 255 characters. +ACTION_TYPE_FAILED_UPDATE_MOM_POLICY_UPDATE_HOST_DOWN=Cannot update host's mom policy. Host is not running. +ACTION_TYPE_FAILED_UPDATE_MOM_POLICY_UPDATE_NULL_HOST=Cannot update host's mom policy. Host is null. # cluster policy errors ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID=Cannot ${action} ${type}. Parameters are invalid. diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties index 56349a0..58bc846 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties @@ -662,3 +662,4 @@ USER_FAILED_TO_UPDATE_CLUSTER_POLICY=Failed to update Clsuter Policy: ${ClusterPolicy}. (User: ${UserName}) USER_REMOVE_CLUSTER_POLICY=Clsuter Policy ${ClusterPolicy} was removed. (User: ${UserName}) USER_FAILED_TO_REMOVE_CLUSTER_POLICY=Failed to remove Clsuter Policy: ${ClusterPolicy}. (User: ${UserName}) +USER_UPDATED_MOM_POLICIES=Mom policy was updated on host ${VdsName}. 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 04156bd..afe6e0d 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 @@ -2554,4 +2554,10 @@ @DefaultStringValue("Cannot ${action} ${type}. Function factor cannot be negative.") String ACTION_TYPE_FAILED_CLUSTER_POLICY_FUNCTION_FACTOR_NEGATIVE(); + + @DefaultStringValue("Cannot update host's mom policy. Host is not running.") + String ACTION_TYPE_FAILED_UPDATE_MOM_POLICY_UPDATE_HOST_DOWN(); + + @DefaultStringValue("Cannot update host's mom policy. Host is null.") + String ACTION_TYPE_FAILED_UPDATE_MOM_POLICY_UPDATE_NULL_HOST(); } 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 b4d3ba3..e825781 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 @@ -910,6 +910,8 @@ QOS_NAME_NOT_NULL=QoS name cannot be empty. QOS_NAME_INVALID=Invalid QoS name (name must be formed of "a-z0-9A-Z" or "-_ ") QOS_NAME_TOO_LONG=QoS name length must be under 255 characters. +ACTION_TYPE_FAILED_UPDATE_MOM_POLICY_UPDATE_HOST_DOWN=Cannot update host's mom policy. Host is not running. +ACTION_TYPE_FAILED_UPDATE_MOM_POLICY_UPDATE_NULL_HOST=Cannot update host's mom policy. Host is null. # cluster policy errors ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID=Cannot ${action} ${type}. Parameters are invalid. -- To view, visit http://gerrit.ovirt.org/17379 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I64350c17f182c1dd0ba1d06130e5d56019b32fc9 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: ofri masad <oma...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches