airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adham...@apache.org
Subject [5/7] airavata git commit: Moving task implementation class load patch to messaging
Date Wed, 10 May 2017 16:13:14 GMT
Moving task implementation class load patch to messaging


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/2180f05f
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/2180f05f
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/2180f05f

Branch: refs/heads/feature-workload-mgmt
Commit: 2180f05fec67eca5a82143d1e83925f568307bb7
Parents: 2df27e6
Author: Ajinkya Dhamnaskar <adhamnas@apache.org>
Authored: Wed May 10 12:11:44 2017 -0400
Committer: Ajinkya Dhamnaskar <adhamnas@apache.org>
Committed: Wed May 10 12:11:44 2017 -0400

----------------------------------------------------------------------
 .../messaging/utils/WorkerMessagingFactory.java | 36 ++++++++++++++++++++
 1 file changed, 36 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/2180f05f/modules/worker/worker-messaging/src/main/java/org/apache/airavata/worker/messaging/utils/WorkerMessagingFactory.java
----------------------------------------------------------------------
diff --git a/modules/worker/worker-messaging/src/main/java/org/apache/airavata/worker/messaging/utils/WorkerMessagingFactory.java
b/modules/worker/worker-messaging/src/main/java/org/apache/airavata/worker/messaging/utils/WorkerMessagingFactory.java
index d33bc8b..aae0490 100644
--- a/modules/worker/worker-messaging/src/main/java/org/apache/airavata/worker/messaging/utils/WorkerMessagingFactory.java
+++ b/modules/worker/worker-messaging/src/main/java/org/apache/airavata/worker/messaging/utils/WorkerMessagingFactory.java
@@ -1,15 +1,27 @@
 package org.apache.airavata.worker.messaging.utils;
 
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.RemovalListener;
+import com.jcraft.jsch.Session;
 import org.apache.airavata.common.exception.AiravataException;
+import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.airavata.messaging.core.MessagingFactory;
 import org.apache.airavata.messaging.core.Subscriber;
+import org.apache.airavata.model.task.TaskTypes;
+import org.apache.airavata.worker.core.config.ResourceConfig;
+import org.apache.airavata.worker.core.config.TaskImplementationConfig;
+import org.apache.airavata.worker.core.config.WorkerYamlConfigruation;
+import org.apache.airavata.worker.core.exceptions.WorkerException;
+import org.apache.airavata.worker.core.task.Task;
 import org.apache.airavata.worker.messaging.handler.WorkerMessageHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.lang.reflect.Constructor;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 /**
  * Created by Ajinkya on 5/2/17.
@@ -18,11 +30,35 @@ public class WorkerMessagingFactory {
 
     private final static Logger log = LoggerFactory.getLogger(WorkerMessagingFactory.class);
     private final static Map<String, Subscriber> SUBSCRIBER_MAP;
+    private static boolean isWorkerConfigurationLoaded = false;
+    private static Map<TaskTypes, Task> taskImplementations = new HashMap<>();
 
     static{
         SUBSCRIBER_MAP = new HashMap<>();
     }
 
+    public static void loadConfiguration() throws WorkerException {
+        if (!isWorkerConfigurationLoaded) {
+            WorkerYamlConfigruation config = new WorkerYamlConfigruation();
+            try {
+                for (TaskImplementationConfig taskImplementationConfig : config.getTaskImplementations())
{
+                    String taskClass = taskImplementationConfig.getImplementationClass();
+                    Class<?> aClass = Class.forName(taskClass);
+                    Constructor<?> constructor = aClass.getConstructor();
+                    Task task = (Task) constructor.newInstance();
+                    taskImplementations.put(taskImplementationConfig.getTaskType(), task);
+                }
+            }catch (Exception e) {
+                throw new WorkerException("Worker config issue", e);
+            }
+            isWorkerConfigurationLoaded =  true;
+        }
+    }
+
+    public static Task getTaskImplementation(TaskTypes taskType) {
+        return taskImplementations.get(taskType);
+    }
+
     public static Map<String, Subscriber> getSubscriberMap(){
         return SUBSCRIBER_MAP;
     }


Mime
View raw message