Allon Mureinik has uploaded a new change for review.

Change subject: core: Added executionIndex to async_tasks
......................................................................

core: Added executionIndex to async_tasks

Added the executionIndex property to the async_tasks entity, to
represent the fact that a task can be a part of a larger command, that
may in turn include more than one task.

This patch contains:
* Adding the member to the async_tasks java class (including a getter
  and setter and a constructor argument)
* Modified the call to new async_tasks with said constiructor add
* An upgrade script to add the execution_index column to the async_tasks
  database table
* Changes to the DAO to query, insert and update said column from the
  database
* Tests to verify that the DAO's behavior functions as expected

Change-Id: I20904de7818c60b981282817640f23b62b57a6f7
Signed-off-by: Allon Mureinik <[email protected]>
---
M backend/manager/dbscripts/async_tasks_sp.sql
A 
backend/manager/dbscripts/upgrade/03_01_1380_add_execution_index_async_tasks.sql
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskFactory.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/async_tasks.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AsyncTaskDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/AsyncTaskDAOTest.java
7 files changed, 40 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/11/7911/1

diff --git a/backend/manager/dbscripts/async_tasks_sp.sql 
b/backend/manager/dbscripts/async_tasks_sp.sql
index 97d43a4..4bafa30 100644
--- a/backend/manager/dbscripts/async_tasks_sp.sql
+++ b/backend/manager/dbscripts/async_tasks_sp.sql
@@ -9,13 +9,14 @@
        v_action_params_class varchar(256),
        v_step_id UUID,
        v_command_id UUID,
+        v_execution_index int,
         v_entity_type varchar(128),
         v_entity_ids text)
 RETURNS VOID
    AS $procedure$
 BEGIN
-INSERT INTO async_tasks(action_type, result, status, task_id, 
action_parameters,action_params_class, step_id, command_id)
-       VALUES(v_action_type, v_result, v_status, v_task_id, 
v_action_parameters,v_action_params_class, v_step_id, v_command_id);
+INSERT INTO async_tasks(action_type, result, status, task_id, 
action_parameters,action_params_class, step_id, command_id, execution_index)
+       VALUES(v_action_type, v_result, v_status, v_task_id, 
v_action_parameters,v_action_params_class, v_step_id, v_command_id, 
v_execution_index);
 INSERT INTO async_tasks_entities (async_task_id,entity_id,entity_type)
        SELECT v_task_id,id,v_entity_type from fnsplitteruuid(v_entity_ids);
 END; $procedure$
@@ -29,7 +30,8 @@
        v_action_parameters text,
        v_action_params_class varchar(256),
        v_step_id UUID,
-       v_command_id UUID)
+       v_command_id UUID,
+        v_execution_index int)
 RETURNS VOID
 
        --The [async_tasks] table doesn't have a timestamp column. Optimistic 
concurrency logic cannot be generated
@@ -42,7 +44,8 @@
           action_parameters = v_action_parameters,
           action_params_class = v_action_params_class,
           step_id = v_step_id,
-          command_id = v_command_id
+          command_id = v_command_id,
+          execution_index = v_execution_index
       WHERE task_id = v_task_id;
 END; $procedure$
 LANGUAGE plpgsql;
diff --git 
a/backend/manager/dbscripts/upgrade/03_01_1380_add_execution_index_async_tasks.sql
 
b/backend/manager/dbscripts/upgrade/03_01_1380_add_execution_index_async_tasks.sql
new file mode 100644
index 0000000..0bdc66b
--- /dev/null
+++ 
b/backend/manager/dbscripts/upgrade/03_01_1380_add_execution_index_async_tasks.sql
@@ -0,0 +1 @@
+select fn_db_add_column('async_tasks', 'execution_index', 'int not null 
default 0');
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskFactory.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskFactory.java
index 3847f29..e2108d1 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskFactory.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AsyncTaskFactory.java
@@ -30,12 +30,14 @@
     public static SPMAsyncTask Construct(AsyncTaskCreationInfo creationInfo) {
         async_tasks asyncTask = 
DbFacade.getInstance().getAsyncTaskDAO().get(creationInfo.getTaskID());
         if (asyncTask == null || asyncTask.getaction_parameters() == null) {
-            asyncTask = new async_tasks(VdcActionType.Unknown, 
AsyncTaskResultEnum.success,
-                            AsyncTaskStatusEnum.running,
-                            creationInfo.getTaskID(),
-                            new VdcActionParametersBase(),
-                            creationInfo.getStepId(),
-                            asyncTask == null ? Guid.NewGuid() : 
asyncTask.getCommandId());
+            asyncTask = new async_tasks
+                    (VdcActionType.Unknown, AsyncTaskResultEnum.success,
+                     AsyncTaskStatusEnum.running,
+                     creationInfo.getTaskID(),
+                     new VdcActionParametersBase(),
+                     creationInfo.getStepId(),
+                     asyncTask == null ? Guid.NewGuid() : 
asyncTask.getCommandId(),
+                     0);
             creationInfo.setTaskType(AsyncTaskType.unknown);
         }
         AsyncTaskParameters asyncTaskParams = new 
AsyncTaskParameters(creationInfo, asyncTask);
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
index 8e3aa79..ae1aa9c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
@@ -1115,7 +1115,8 @@
                         asyncTaskCreationInfo.getTaskID(),
                         parametersForTask,
                         asyncTaskCreationInfo.getStepId(),
-                        getCommandId()));
+                        getCommandId(),
+                        0));
         p.setEntityId(getParameters().getEntityId());
         return AsyncTaskManager.getInstance().CreateTask(getTaskType(), p);
     }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/async_tasks.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/async_tasks.java
index 5bf5187..8c6eb70 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/async_tasks.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/async_tasks.java
@@ -28,7 +28,7 @@
     }
 
     public async_tasks(VdcActionType action_type, AsyncTaskResultEnum result, 
AsyncTaskStatusEnum status, Guid task_id,
-            VdcActionParametersBase action_parameters, NGuid stepId, Guid 
commandId) {
+            VdcActionParametersBase action_parameters, NGuid stepId, Guid 
commandId, int executionIndex) {
         this.actionType = action_type;
         this.result = result;
         this.status = status;
@@ -36,6 +36,7 @@
         this.setaction_parameters(action_parameters);
         this.stepId = stepId;
         this.commandId = commandId;
+        this.executionIndex = executionIndex;
     }
 
     @Column(name = "action_type", nullable = false)
@@ -122,6 +123,17 @@
         this.commandId = commandId;
     }
 
+    @Column(name = "execution_index")
+    private int executionIndex = 0;
+
+    public int getExecutionIndex() {
+        return this.executionIndex;
+    }
+
+    public void setExecutionIndex(int executionIndex) {
+        this.executionIndex = executionIndex;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -133,6 +145,7 @@
         results = prime * results + ((taskId == null) ? 0 : taskId.hashCode());
         results = prime * results + ((stepId == null) ? 0 : stepId.hashCode());
         results = prime * results + ((commandId == null) ? 0 : 
commandId.hashCode());
+        results = prime * results + executionIndex;
         return results;
     }
 
@@ -175,6 +188,9 @@
         } else if (!commandId.equals(other.commandId)) {
             return false;
         }
+        if (executionIndex != other.executionIndex) {
+            return false;
+        }
 
         return true;
     }
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 c18ea50..04f0771 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
@@ -55,6 +55,7 @@
             
entity.setaction_parameters(deserializeParameters(rs.getString("action_parameters"),rs.getString("action_params_class")));
             
entity.setStepId(NGuid.createGuidFromString(rs.getString("step_id")));
             
entity.setCommandId(Guid.createGuidFromString(rs.getString("command_id")));
+            entity.setExecutionIndex(rs.getInt("execution_index"));
             return entity;
         }
 
@@ -80,6 +81,7 @@
             
addValue("action_params_class",task.getaction_parameters().getClass().getName());
             addValue("step_id", task.getStepId());
             addValue("command_id", task.getCommandId());
+            addValue("execution_index", task.getExecutionIndex());
         }
 
         private static String serializeParameters(VdcActionParametersBase 
params) {
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/AsyncTaskDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/AsyncTaskDAOTest.java
index f0183a3..ae31dab 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/AsyncTaskDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/AsyncTaskDAOTest.java
@@ -18,6 +18,7 @@
 import org.ovirt.engine.core.common.businessentities.async_tasks;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.TransactionScopeOption;
+import org.ovirt.engine.core.utils.RandomUtils;
 
 /**
  * <code>AsyncTaskDAOTest</code> performs tests against the {@link 
AsyncTaskDAO} type.
@@ -50,6 +51,7 @@
         newAsyncTask.setresult(AsyncTaskResultEnum.success);
         newAsyncTask.setaction_parameters(params);
         newAsyncTask.setCommandId(Guid.NewGuid());
+        newAsyncTask.setExecutionIndex(RandomUtils.instance().nextInt());
 
         existingAsyncTask = dao.get(FixturesTool.EXISTING_TASK);
     }
@@ -151,6 +153,7 @@
         AddDiskParameters addDiskToVmParams = new AddDiskParameters();
         addDiskToVmParams.setSessionId("SESSION_ID");
         existingAsyncTask.setaction_parameters(addDiskToVmParams);
+        existingAsyncTask.setExecutionIndex(RandomUtils.instance().nextInt());
         dao.update(existingAsyncTask);
 
         async_tasks result = dao.get(existingAsyncTask.gettask_id());


--
To view, visit http://gerrit.ovirt.org/7911
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I20904de7818c60b981282817640f23b62b57a6f7
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Allon Mureinik <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to