You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2014/07/23 18:48:23 UTC

[09/20] git commit: introducing workflow engine cpi

introducing workflow engine cpi


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

Branch: refs/heads/master
Commit: 0095c915145ff26a0d1a39c2059c09687098e602
Parents: a8974b7
Author: Saminda Wijeratne <sa...@gmail.com>
Authored: Fri Jul 11 22:31:17 2014 -0400
Committer: Saminda Wijeratne <sa...@gmail.com>
Committed: Fri Jul 11 22:31:17 2014 -0400

----------------------------------------------------------------------
 .../catalog/WorkflowCatalogFactory.java         |  2 +-
 .../workflow/engine/WorkflowEngine.java         | 26 +++++++
 .../engine/WorkflowEngineException.java         | 17 +++++
 .../workflow/engine/WorkflowEngineFactory.java  | 33 +++++++++
 .../workflow/engine/WorkflowEngineImpl.java     | 77 ++++++++++++++++++++
 5 files changed, 154 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/0095c915/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/catalog/WorkflowCatalogFactory.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/catalog/WorkflowCatalogFactory.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/catalog/WorkflowCatalogFactory.java
index 9156282..3b4e747 100644
--- a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/catalog/WorkflowCatalogFactory.java
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/catalog/WorkflowCatalogFactory.java
@@ -22,7 +22,7 @@
 package org.apache.airavata.workflow.catalog;
 
 public class WorkflowCatalogFactory {
-	private static WorkflowCatalogImpl workflowCatalog;
+	private static WorkflowCatalog workflowCatalog;
 	
 	public static WorkflowCatalog getWorkflowCatalog(){
 		if (workflowCatalog==null) {

http://git-wip-us.apache.org/repos/asf/airavata/blob/0095c915/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngine.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngine.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngine.java
new file mode 100644
index 0000000..3d17378
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngine.java
@@ -0,0 +1,26 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.engine;
+
+public interface WorkflowEngine {
+	public void launchExperiment(String experimentId, String token) throws WorkflowEngineException;
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/0095c915/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineException.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineException.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineException.java
new file mode 100644
index 0000000..1ef965d
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineException.java
@@ -0,0 +1,17 @@
+package org.apache.airavata.workflow.engine;
+
+public class WorkflowEngineException extends Exception{
+    private static final long serialVersionUID = -2849422320139467602L;
+
+    public WorkflowEngineException(Throwable e) {
+        super(e);
+    }
+
+    public WorkflowEngineException(String message) {
+        super(message, null);
+    }
+
+    public WorkflowEngineException(String message, Throwable e) {
+        super(message, e);
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/0095c915/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineFactory.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineFactory.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineFactory.java
new file mode 100644
index 0000000..272d11a
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineFactory.java
@@ -0,0 +1,33 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.engine;
+
+public class WorkflowEngineFactory {
+	private static WorkflowEngine workflowCatalog;
+	
+	public static WorkflowEngine getWorkflowEngine(){
+		if (workflowCatalog==null) {
+			workflowCatalog = new WorkflowEngineImpl();
+		}
+		return workflowCatalog;
+	}
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/0095c915/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineImpl.java
----------------------------------------------------------------------
diff --git a/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineImpl.java b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineImpl.java
new file mode 100644
index 0000000..84045ab
--- /dev/null
+++ b/modules/workflow-model/workflow-engine/src/main/java/org/apache/airavata/workflow/engine/WorkflowEngineImpl.java
@@ -0,0 +1,77 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.engine;
+
+import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.model.workspace.experiment.Experiment;
+import org.apache.airavata.orchestrator.client.OrchestratorClientFactory;
+import org.apache.airavata.orchestrator.cpi.OrchestratorService;
+import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory;
+import org.apache.airavata.registry.cpi.Registry;
+import org.apache.airavata.registry.cpi.RegistryException;
+import org.apache.airavata.registry.cpi.RegistryModelType;
+import org.apache.airavata.workflow.catalog.WorkflowCatalog;
+import org.apache.airavata.workflow.catalog.WorkflowCatalogFactory;
+import org.apache.airavata.workflow.engine.interpretor.WorkflowInterpreter;
+import org.apache.airavata.workflow.engine.interpretor.WorkflowInterpreterConfiguration;
+import org.apache.airavata.workflow.model.exceptions.WorkflowException;
+import org.apache.airavata.workflow.model.wf.Workflow;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class WorkflowEngineImpl implements WorkflowEngine {
+    private static final Logger logger = LoggerFactory.getLogger(WorkflowEngineImpl.class);
+
+	@Override
+	public void launchExperiment(String experimentId, String token)
+			throws WorkflowEngineException {
+		try {
+            Registry registry = RegistryFactory.getDefaultRegistry();
+            Experiment experiment = (Experiment)registry.get(RegistryModelType.EXPERIMENT, experimentId);
+            WorkflowCatalog workflowCatalog = WorkflowCatalogFactory.getWorkflowCatalog();
+			WorkflowInterpreterConfiguration config = new WorkflowInterpreterConfiguration(new Workflow(workflowCatalog.getWorkflow(experiment.getApplicationId()).getGraph()));
+			final WorkflowInterpreter workflowInterpreter = new WorkflowInterpreter(experiment, token, config , getOrchestratorClient());
+			new Thread(){
+				public void run() {
+					try {
+						workflowInterpreter.scheduleDynamically();
+					} catch (WorkflowException e) {
+						e.printStackTrace();
+					} catch (RegistryException e) {
+						e.printStackTrace();
+					}
+				};
+			}.start();
+        } catch (Exception e) {
+            logger.error("Error while retrieving the experiment", e);
+            WorkflowEngineException exception = new WorkflowEngineException("Error while launching the workflow experiment. More info : " + e.getMessage());
+            throw exception;
+        }
+
+	}
+
+	private OrchestratorService.Client getOrchestratorClient() {
+		final int serverPort = Integer.parseInt(ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ORCHESTRATOR_SERVER_PORT,"8940"));
+        final String serverHost = ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.ORCHESTRATOR_SERVER_HOST, null);
+        return OrchestratorClientFactory.createOrchestratorClient(serverHost, serverPort);
+	}
+}