Eli Mesika has uploaded a new change for review. Change subject: core : implementing AddExternalEventCommand ... ......................................................................
core : implementing AddExternalEventCommand ... implementing AddExternalEventCommand & RemoveExternalEventCommand This patch adds AddExternalEventCommand and RemoveExternalEventCommand to allow addition/removal of External Events Change-Id: I3468a3dd99616e2436caee19b42b9cf448adc005 Signed-off-by: Eli Mesika <[email protected]> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddExternalEventCommand.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveExternalEventCommand.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddExternalEventParameters.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RemoveExternalEventParameters.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties 11 files changed, 209 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/94/10094/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddExternalEventCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddExternalEventCommand.java new file mode 100644 index 0000000..79e5fbc --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddExternalEventCommand.java @@ -0,0 +1,71 @@ +package org.ovirt.engine.core.bll; + +import java.util.Collections; +import java.util.List; + +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.AddExternalEventParameters; +import org.ovirt.engine.core.common.businessentities.ActionGroup; +import org.ovirt.engine.core.common.businessentities.AuditLog; +import org.ovirt.engine.core.dal.VdcBllMessages; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AlertDirector; +import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector; +import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase; + +public class AddExternalEventCommand<T extends AddExternalEventParameters> extends CommandBase<T> { + private static final long serialVersionUID = 1L; + private final String OVIRT="oVirt"; + + public AddExternalEventCommand(T parameters) { + super(parameters); + } + + @Override + protected boolean canDoAction() { + boolean result=true; + if (getParameters().getEvent() == null || getParameters().getEvent().equals(OVIRT)){ + addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLEGAL_ORIGIN); + result = false; + } + if (!result) { + addCanDoActionMessage(VdcBllMessages.VAR__ACTION__ADD); + addCanDoActionMessage(VdcBllMessages.VAR__TYPE__EXTERNAL_EVENT); + } + return result; + } + @Override + protected void executeCommand() { + AuditLogableBase event = new AuditLogableBase(getParameters().getEvent()); + event.setExternal(true); + String message = getParameters().getEvent().getmessage(); + switch (getParameters().getEvent().getseverity()){ + case NORMAL: + AuditLogDirector.log(event, AuditLogType.EXTERNAL_EVENT_NORMAL, message); + break; + case WARNING: + AuditLogDirector.log(event, AuditLogType.EXTERNAL_EVENT_WARNING, message); + break; + case ERROR: + AuditLogDirector.log(event, AuditLogType.EXTERNAL_EVENT_ERROR, message); + break; + case ALERT: + AlertDirector.Alert(event, AuditLogType.EXTERNAL_ALERT, message); + break; + } + AuditLog auditLog = DbFacade.getInstance().getAuditLogDao().getByOriginAndCustomEventId(getParameters().getEvent().getOrigin(), getParameters().getEvent().getCustomEventId()); + if (auditLog != null) { + setActionReturnValue(auditLog.getaudit_log_id()); + setSucceeded(true); + } + } + + @Override + public List<PermissionSubject> getPermissionCheckSubjects() { + return Collections.singletonList(new PermissionSubject(MultiLevelAdministrationHandler.SYSTEM_OBJECT_ID, + VdcObjectType.System, + ActionGroup.INJECT_EXTERNAL_EVENTS)); + } +} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveExternalEventCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveExternalEventCommand.java new file mode 100644 index 0000000..284f786 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveExternalEventCommand.java @@ -0,0 +1,60 @@ +package org.ovirt.engine.core.bll; + +import java.util.Collections; +import java.util.List; + +import org.ovirt.engine.core.bll.utils.PermissionSubject; +import org.ovirt.engine.core.common.AuditLogSeverity; +import org.ovirt.engine.core.common.VdcObjectType; +import org.ovirt.engine.core.common.action.RemoveExternalEventParameters; +import org.ovirt.engine.core.common.businessentities.ActionGroup; +import org.ovirt.engine.core.common.businessentities.AuditLog; +import org.ovirt.engine.core.dal.VdcBllMessages; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; + +public class RemoveExternalEventCommand <T extends RemoveExternalEventParameters> extends CommandBase<T> { + + private static final long serialVersionUID = 1L; + private final String OVIRT="oVirt"; + + public RemoveExternalEventCommand(T parameters) { + super(parameters); + } + + @Override + protected boolean canDoAction() { + boolean result = true; + // check if such event exists + AuditLog event = DbFacade.getInstance().getAuditLogDao().get(getParameters().getId()); + if (event == null) { + addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_EXTERNAL_EVENT_NOT_FOUND); + result = false; + } + if (event.getOrigin().equalsIgnoreCase(OVIRT)) { + addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLEGAL_ORIGIN); + result = false; + } + if (!event.getseverity().equals(AuditLogSeverity.ALERT)) { + addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLRGAL_OPERATION); + result = false; + } + if (!result) { + addCanDoActionMessage(VdcBllMessages.VAR__ACTION__ADD); + addCanDoActionMessage(VdcBllMessages.VAR__TYPE__EXTERNAL_EVENT); + } + return result; + } + + @Override + protected void executeCommand() { + DbFacade.getInstance().getAuditLogDao().remove(getParameters().getId()); + setSucceeded(true); + } + + @Override + public List<PermissionSubject> getPermissionCheckSubjects() { + return Collections.singletonList(new PermissionSubject(MultiLevelAdministrationHandler.SYSTEM_OBJECT_ID, + VdcObjectType.System, + ActionGroup.INJECT_EXTERNAL_EVENTS)); + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddExternalEventParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddExternalEventParameters.java new file mode 100644 index 0000000..bb08c49 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/AddExternalEventParameters.java @@ -0,0 +1,17 @@ +package org.ovirt.engine.core.common.action; + +import org.ovirt.engine.core.common.businessentities.AuditLog; + +public class AddExternalEventParameters extends VdcActionParametersBase { + private static final long serialVersionUID = 7023971593753015624L; + private AuditLog event = null; + + public AuditLog getEvent() { + return event; + } + + public AddExternalEventParameters(AuditLog event) { + super(); + this.event = event; + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RemoveExternalEventParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RemoveExternalEventParameters.java new file mode 100644 index 0000000..8c7c718 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RemoveExternalEventParameters.java @@ -0,0 +1,19 @@ +package org.ovirt.engine.core.common.action; + +public class RemoveExternalEventParameters extends VdcActionParametersBase { + + private static final long serialVersionUID = 1L; + private long id; + + public RemoveExternalEventParameters(Long id) { + this.id = id; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } +} 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 487492d..c162c9a 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 @@ -261,7 +261,10 @@ StartGlusterVolumeProfile(1410, ActionGroup.MANIPULATE_GLUSTER_VOLUME, QuotaDependency.NONE), StopGlusterVolumeProfile(1411, ActionGroup.MANIPULATE_GLUSTER_VOLUME, QuotaDependency.NONE), RemoveGlusterServer(1412, ActionGroup.DELETE_HOST, QuotaDependency.NONE), - ; + + // External events + AddExternalEvent(1500, ActionGroup.INJECT_EXTERNAL_EVENTS, QuotaDependency.NONE), + RemoveExternalEvent(1501, ActionGroup.INJECT_EXTERNAL_EVENTS, QuotaDependency.NONE); private int intValue; private ActionGroup actionGroup; diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java index 08cb356..bc0b8a8 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java @@ -27,6 +27,9 @@ VAR__TYPE__GLUSTER_BRICK, VAR__TYPE__GLUSTER_SERVER, + // External Event + VAR__TYPE__EXTERNAL_EVENT, + VAR__ACTION__RUN, VAR__ACTION__REMOVE, VAR__ACTION__ADD, @@ -677,7 +680,12 @@ // Engine maintenance mode ENGINE_IS_RUNNING_IN_MAINTENANCE_MODE, // Engine prepare mode - ENGINE_IS_RUNNING_IN_PREPARE_MODE; + ENGINE_IS_RUNNING_IN_PREPARE_MODE, + + // External Events + ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLEGAL_ORIGIN, + ACTION_TYPE_FAILED_EXTERNAL_EVENT_NOT_FOUND, + ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLRGAL_OPERATION; public int getValue() { return this.ordinal(); 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 f3d94458..5dfedde 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -806,3 +806,8 @@ ENGINE_IS_RUNNING_IN_MAINTENANCE_MODE=Engine is running in Maintenance mode and is not accepting commands. ENGINE_IS_RUNNING_IN_PREPARE_MODE=This action is not allowed when Engine is preparing for maintenance. ACTION_TYPE_FAILED_SERVER_NAME_REQUIRED=Cannot ${action} ${type}. Server Name required. +# Exteral Events Errors Messages +VAR__TYPE__EXTERNAL_EVENT=$type Exteral Event +ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLEGAL_ORIGIN=Cannot ${action} ${type}. Illegal Origin for External Event : oVirt +ACTION_TYPE_FAILED_EXTERNAL_EVENT_NOT_FOUND=Cannot ${action} ${type}.External Event does not exist. +ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLRGAL_OPERATION=Cannot ${action} ${type}.Only Alerts can be removed. \ No newline at end of file diff --git a/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties b/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties index 2b6c92d..bb32639 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties @@ -142,3 +142,5 @@ job.UpdateStorageDomain=Editing Storage Domain ${Storage} properties job.AddEmptyStoragePool=Adding empty Data Center ${StoragePool} job.FenceVdsManualy=Fencing Host ${VDS} manually +job.AddExternalEvent=Adding an External Event +job.RemoveExternalEvent=Removing an External Event 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 44fa62b..ce90abc 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 @@ -2114,4 +2114,16 @@ @DefaultStringValue("This action is not allowed when Engine is preparing for maintenance.") String ENGINE_IS_RUNNING_IN_PREPARE_MODE(); + + @DefaultStringValue("$type Exteral Event.") + String VAR__TYPE__EXTERNAL_EVENT(); + + @DefaultStringValue(".Cannot ${action} ${type}. Illegal Origin for External Event : oVirt") + String ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLEGAL_ORIGIN(); + + @DefaultStringValue(".Cannot ${action} ${type}.External Event does not exist.") + String ACTION_TYPE_FAILED_EXTERNAL_EVENT_NOT_FOUND(); + + @DefaultStringValue("Cannot ${action} ${type}.Only Alerts can be removed.") + String ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLRGAL_OPERATION(); } diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 8a616d3..09c1ff1 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -744,3 +744,8 @@ USER_CANNOT_FORCE_RECONNECT_TO_VM=Console connection denied. Another user has already accessed the console of this VM. The VM should be rebooted to allow another user to access it, or changed by an admin to not enforce reboot between users accessing its console. ENGINE_IS_RUNNING_IN_MAINTENANCE_MODE=Engine is running in Maintenance mode and is not accepting commands. ENGINE_IS_RUNNING_IN_PREPARE_MODE=This action is not allowed when Engine is preparing for maintenance. +# Exteral Events Errors Messages +VAR__TYPE__EXTERNAL_EVENT=$type Exteral Event +ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLEGAL_ORIGIN=Cannot ${action} ${type}. Illegal Origin for External Event : oVirt +ACTION_TYPE_FAILED_EXTERNAL_EVENT_NOT_FOUND=Cannot ${action} ${type}.External Event does not exist. +ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLRGAL_OPERATION=Cannot ${action} ${type}.Only Alerts can be removed. 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 c52ffdd..ae15835 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 @@ -745,3 +745,8 @@ USER_CANNOT_FORCE_RECONNECT_TO_VM=Console connection denied. Another user has already accessed the console of this VM. The VM should be rebooted to allow another user to access it, or changed by an admin to not enforce reboot between users accessing its console. ENGINE_IS_RUNNING_IN_MAINTENANCE_MODE=Engine is running in Maintenance mode and is not accepting commands. ENGINE_IS_RUNNING_IN_PREPARE_MODE=This action is not allowed when Engine is preparing for maintenance. +# Exteral Events Errors Messages +VAR__TYPE__EXTERNAL_EVENT=$type Exteral Event +ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLEGAL_ORIGIN=Cannot ${action} ${type}. Illegal Origin for External Event : oVirt +ACTION_TYPE_FAILED_EXTERNAL_EVENT_NOT_FOUND=Cannot ${action} ${type}.External Event does not exist. +ACTION_TYPE_FAILED_EXTERNAL_EVENT_ILLRGAL_OPERATION=Cannot ${action} ${type}.Only Alerts can be removed. -- To view, visit http://gerrit.ovirt.org/10094 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3468a3dd99616e2436caee19b42b9cf448adc005 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Eli Mesika <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
