Ravi Nori has uploaded a new change for review. Change subject: engine : Add User Id to async tasks table ......................................................................
engine : Add User Id to async tasks table Add user id to async tasks table, the user id will be used to determine if the user has permissions to see the tasks for which the user requested statuses When tasks are retrieved from vdsm after server restart the user id information is not available and will be set to Guid.Empty when tasks are created Change-Id: Ib5b9f3dfb38d6d56f186aa87f3ff75007a0d3997 Bug-Url: https://bugzilla.redhat.com/1153043 Signed-off-by: Ravi Nori <rn...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskFactory.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CoCoAsyncTaskHelper.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/AsyncTask.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AsyncTaskDAO.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AsyncTaskDAODbFacadeImpl.java M packaging/dbscripts/async_tasks_sp.sql A packaging/dbscripts/upgrade/03_05_1150_add_user_id_to_async_tasks.sql 7 files changed, 73 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/43/34843/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskFactory.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskFactory.java index 57791fa..fc1c0bc 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskFactory.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/AsyncTaskFactory.java @@ -30,6 +30,7 @@ if (asyncTask == null || asyncTask.getActionParameters() == null) { asyncTask = new AsyncTask(AsyncTaskResultEnum.success, AsyncTaskStatusEnum.running, + Guid.Empty, creationInfo.getVdsmTaskId(), creationInfo.getStepId(), creationInfo.getStoragePoolID(), diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CoCoAsyncTaskHelper.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CoCoAsyncTaskHelper.java index e4324b9..db39524 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CoCoAsyncTaskHelper.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/tasks/CoCoAsyncTaskHelper.java @@ -295,6 +295,7 @@ } AsyncTask asyncTask = new AsyncTask(AsyncTaskResultEnum.success, AsyncTaskStatusEnum.running, + command.getUserId(), asyncTaskCreationInfo.getVdsmTaskId(), asyncTaskCreationInfo.getStepId(), asyncTaskCreationInfo.getStoragePoolID(), diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/AsyncTask.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/AsyncTask.java index 837821d..da58284 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/AsyncTask.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/AsyncTask.java @@ -14,6 +14,7 @@ private static final long serialVersionUID = 5913365704117183118L; private AsyncTaskResultEnum result; private AsyncTaskStatusEnum status; + private Guid userId; private Guid vdsmTaskId; private Guid storagePoolId; private Guid taskId; @@ -28,6 +29,7 @@ public AsyncTask() { result = AsyncTaskResultEnum.success; status = AsyncTaskStatusEnum.unknown; + userId = Guid.Empty; vdsmTaskId = Guid.Empty; commandId = Guid.Empty; rootCommandId = Guid.Empty; @@ -37,6 +39,7 @@ public AsyncTask(AsyncTaskResultEnum result, AsyncTaskStatusEnum status, + Guid userId, Guid vdsmTaskId, Guid stepId, Guid storagePoolId, @@ -45,6 +48,7 @@ CommandEntity childCmdEntity) { this.result = result; this.status = status; + this.userId = userId; this.vdsmTaskId = vdsmTaskId; this.stepId = stepId; this.startTime = new Date(); @@ -256,4 +260,12 @@ public void setChildCmdEntity(CommandEntity childCmdEntity) { this.childCmdEntity = childCmdEntity; } + + public Guid getUserId() { + return userId; + } + + public void setUserId(Guid userId) { + this.userId = userId; + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AsyncTaskDAO.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AsyncTaskDAO.java index f8508e8..961d75f 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AsyncTaskDAO.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AsyncTaskDAO.java @@ -93,6 +93,22 @@ */ List<AsyncTask> getTasksByEntity(Guid entityId); + /** + * Gets all the async task ids that are associated with a user id + * + * @param userId + * @return + */ + public List<Guid> getAsyncTaskIdsByUser(Guid userId); + + /** + * Gets all the vdsm task ids that are associated with a user id + * + * @param userId + * @return + */ + public List<Guid> getVdsmTaskIdsByUser(Guid userId); + void insertAsyncTaskEntities(Collection<AsyncTaskEntity> asyncTaskEntities); List<AsyncTaskEntity> getAllAsyncTaskEntitiesByTaskId(Guid taskId); diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AsyncTaskDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AsyncTaskDAODbFacadeImpl.java index fdc60ee..7fa7255 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AsyncTaskDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AsyncTaskDAODbFacadeImpl.java @@ -64,6 +64,7 @@ AsyncTask entity = new AsyncTask(); entity.setresult(AsyncTaskResultEnum.forValue(rs.getInt("result"))); entity.setstatus(AsyncTaskStatusEnum.forValue(rs.getInt("status"))); + entity.setUserId(getGuidDefaultEmpty(rs, "user_id")); entity.setTaskId(getGuidDefaultEmpty(rs, "task_id")); entity.setVdsmTaskId(getGuid(rs, "vdsm_task_id")); entity.setStepId(getGuid(rs, "step_id")); @@ -94,6 +95,7 @@ addValue("result", task.getresult()); addValue("status", task.getstatus()); addValue("vdsm_task_id", task.getVdsmTaskId()); + addValue("user_id", task.getUserId()); addValue("task_id", task.getTaskId()); addValue("step_id", task.getStepId()); addValue("command_id", task.getCommandId()); @@ -207,6 +209,20 @@ } @Override + public List<Guid> getAsyncTaskIdsByUser(Guid userId) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("user_id", userId); + return getCallsHandler().executeReadList("GetAsyncTasksIdsByUserId", IdRowMapper.instance, parameterSource); + } + + @Override + public List<Guid> getVdsmTaskIdsByUser(Guid userId) { + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + .addValue("user_id", userId); + return getCallsHandler().executeReadList("GetVdsmTasksIdsByUserId", IdRowMapper.instance, parameterSource); + } + + @Override public List<Guid> getAsyncTaskIdsByStoragePoolId(Guid storagePoolId) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("storage_pool_id", storagePoolId); diff --git a/packaging/dbscripts/async_tasks_sp.sql b/packaging/dbscripts/async_tasks_sp.sql index 005b885..e966b65 100644 --- a/packaging/dbscripts/async_tasks_sp.sql +++ b/packaging/dbscripts/async_tasks_sp.sql @@ -4,6 +4,7 @@ Create or replace FUNCTION Insertasync_tasks(v_action_type INTEGER, v_result INTEGER, v_status INTEGER, + v_user_id UUID, v_vdsm_task_id UUID, v_task_id UUID, v_step_id UUID, @@ -15,8 +16,8 @@ RETURNS VOID AS $procedure$ BEGIN -INSERT INTO async_tasks(action_type, result, status, vdsm_task_id, task_id, step_id, command_id, root_command_id, started_at,storage_pool_id, task_type) - VALUES(v_action_type, v_result, v_status, v_vdsm_task_id, v_task_id, v_step_id, v_command_id, v_root_command_id, v_started_at, v_storage_pool_id, v_async_task_type); +INSERT INTO async_tasks(action_type, result, status, user_id, vdsm_task_id, task_id, step_id, command_id, root_command_id, started_at,storage_pool_id, task_type) + VALUES(v_action_type, v_result, v_status, v_user_id, v_vdsm_task_id, v_task_id, v_step_id, v_command_id, v_root_command_id, v_started_at, v_storage_pool_id, v_async_task_type); END; $procedure$ LANGUAGE plpgsql; @@ -24,6 +25,7 @@ Create or replace FUNCTION Updateasync_tasks(v_action_type INTEGER, v_result INTEGER, v_status INTEGER, + v_user_id UUID, v_vdsm_task_id UUID, v_task_id UUID, v_step_id UUID, @@ -51,6 +53,7 @@ Create or replace FUNCTION InsertOrUpdateAsyncTasks(v_action_type INTEGER, v_result INTEGER, v_status INTEGER, + v_user_id UUID, v_vdsm_task_id UUID, v_task_id UUID, v_step_id UUID, @@ -63,10 +66,10 @@ AS $procedure$ BEGIN IF NOT EXISTS (SELECT 1 from async_tasks where async_tasks.task_id = v_task_id) THEN - PERFORM Insertasync_tasks(v_action_type, v_result, v_status, v_vdsm_task_id, v_task_id, + PERFORM Insertasync_tasks(v_action_type, v_result, v_status, v_user_id, v_vdsm_task_id, v_task_id, v_step_id, v_command_id, v_root_command_id, v_started_at, v_storage_pool_id, v_async_task_type); ELSE - PERFORM Updateasync_tasks(v_action_type, v_result, v_status, v_vdsm_task_id, v_task_id, v_step_id, v_command_id, v_root_command_id, v_storage_pool_id); + PERFORM Updateasync_tasks(v_action_type, v_result, v_status, v_user_id, v_vdsm_task_id, v_task_id, v_step_id, v_command_id, v_root_command_id, v_storage_pool_id); END IF; END; $procedure$ LANGUAGE plpgsql; @@ -95,6 +98,25 @@ END; $procedure$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION GetAsyncTasksIdsByUserId(v_user_id UUID) +RETURNS SETOF idUuidType STABLE + AS $procedure$ +BEGIN + RETURN QUERY SELECT task_id from async_tasks where user_id = v_user_id; +END; $procedure$ +LANGUAGE plpgsql; + + +CREATE OR REPLACE FUNCTION GetVdsmTasksIdsByUserId(v_user_id UUID) +RETURNS SETOF idUuidType STABLE + AS $procedure$ +BEGIN + RETURN QUERY SELECT vdsm_task_id from async_tasks where user_id = v_user_id; +END; $procedure$ +LANGUAGE plpgsql; + + CREATE OR REPLACE FUNCTION GetAsyncTaskEntitiesByTaskId(v_task_id UUID) RETURNS SETOF async_tasks_entities STABLE AS $procedure$ diff --git a/packaging/dbscripts/upgrade/03_05_1150_add_user_id_to_async_tasks.sql b/packaging/dbscripts/upgrade/03_05_1150_add_user_id_to_async_tasks.sql new file mode 100644 index 0000000..bac6fdf --- /dev/null +++ b/packaging/dbscripts/upgrade/03_05_1150_add_user_id_to_async_tasks.sql @@ -0,0 +1 @@ +select fn_db_add_column('async_tasks', 'user_id', 'UUID DEFAULT NULL'); -- To view, visit http://gerrit.ovirt.org/34843 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib5b9f3dfb38d6d56f186aa87f3ff75007a0d3997 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5 Gerrit-Owner: Ravi Nori <rn...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches