airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [airavata] 01/02: AIRAVATA-2821 Set STATUS_ID on TaskState in TaskRepository
Date Mon, 11 Jun 2018 16:39:42 GMT
This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch group-based-auth
in repository https://gitbox.apache.org/repos/asf/airavata.git

commit 0d3e2872619530107a5d3942ed5298b41a0214c1
Author: Marcus Christie <machristie@apache.org>
AuthorDate: Mon Jun 11 11:53:55 2018 -0400

    AIRAVATA-2821 Set STATUS_ID on TaskState in TaskRepository
---
 .../core/repositories/expcatalog/TaskRepository.java     |  7 ++++++-
 .../repositories/expcatalog/TaskStatusRepository.java    |  2 +-
 .../core/repositories/expcatalog/TaskRepositoryTest.java | 16 +++++++++++++---
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskRepository.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskRepository.java
index 737ffe0..c117da7 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskRepository.java
@@ -57,7 +57,12 @@ public class TaskRepository extends ExpCatAbstractRepository<TaskModel,
TaskEnti
 
         if (taskEntity.getTaskStatuses() != null) {
             logger.debug("Populating the Primary Key of TaskStatus objects for the Task");
-            taskEntity.getTaskStatuses().forEach(taskStatusEntity -> taskStatusEntity.setTaskId(taskId));
+            taskEntity.getTaskStatuses().forEach(taskStatusEntity -> {
+                if (taskStatusEntity.getStatusId() == null) {
+                    taskStatusEntity.setStatusId(ExpCatalogUtils.getID("TASK_STATE"));
+                }
+                taskStatusEntity.setTaskId(taskId);
+            });
         }
 
         if (taskEntity.getTaskErrors() != null) {
diff --git a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskStatusRepository.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskStatusRepository.java
index fe5f1ad..b045e4d 100644
--- a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskStatusRepository.java
+++ b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskStatusRepository.java
@@ -37,7 +37,7 @@ public class TaskStatusRepository extends ExpCatAbstractRepository<TaskStatus,
T
 
         if (taskStatus.getStatusId() == null) {
             logger.debug("Setting the TaskStatus's StatusId");
-            taskStatus.setStatusId(ExpCatalogUtils.getID("STATUS"));
+            taskStatus.setStatusId(ExpCatalogUtils.getID("TASK_STATE"));
         }
 
         return saveTaskStatus(taskStatus, taskId);
diff --git a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskRepositoryTest.java
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskRepositoryTest.java
index 8b8d746..4da9ee1 100644
--- a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskRepositoryTest.java
+++ b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/TaskRepositoryTest.java
@@ -20,9 +20,12 @@
 */
 package org.apache.airavata.registry.core.repositories.expcatalog;
 
+import org.apache.airavata.common.utils.AiravataUtils;
 import org.apache.airavata.model.experiment.ExperimentModel;
 import org.apache.airavata.model.experiment.ExperimentType;
 import org.apache.airavata.model.process.ProcessModel;
+import org.apache.airavata.model.status.TaskState;
+import org.apache.airavata.model.status.TaskStatus;
 import org.apache.airavata.model.task.TaskModel;
 import org.apache.airavata.model.task.TaskTypes;
 import org.apache.airavata.model.workspace.Gateway;
@@ -104,15 +107,22 @@ public class TaskRepositoryTest {
         taskModel.setParentProcessId(processId);
         taskModel.setSubTaskModel("subtask model".getBytes(StandardCharsets.UTF_8));
 
+        TaskStatus taskStatus = new TaskStatus(TaskState.CREATED);
+        taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
+        taskModel.addToTaskStatuses(taskStatus);
+
         String taskId = taskRepository.addTask(taskModel, processId);
         assertTrue(taskId != null);
+        // Retrieve task to get its automatically populated status id
+        final TaskModel retrievedTask = taskRepository.getTask(taskId);
         assertTrue(processRepository.getProcess(processId).getTasks().size() == 1);
 
-        taskModel.setTaskType(TaskTypes.MONITORING);
-        taskRepository.updateTask(taskModel, taskId);
-        final TaskModel retrievedTask = taskRepository.getTask(taskId);
+        retrievedTask.setTaskType(TaskTypes.MONITORING);
+        taskRepository.updateTask(retrievedTask, taskId);
         assertEquals(TaskTypes.MONITORING, retrievedTask.getTaskType());
         assertArrayEquals("subtask model".getBytes(StandardCharsets.UTF_8), retrievedTask.getSubTaskModel());
+        assertEquals(1, retrievedTask.getTaskStatusesSize());
+        assertEquals(TaskState.CREATED, retrievedTask.getTaskStatuses().get(0).getState());
 
 
         List<String> taskIdList = taskRepository.getTaskIds(DBConstants.Task.PARENT_PROCESS_ID,
processId);

-- 
To stop receiving notification emails like this one, please contact
machristie@apache.org.

Mime
View raw message