This is an automated email from the ASF dual-hosted git repository.
dimuthuupe pushed a commit to branch airavata-v2-refactoring
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/airavata-v2-refactoring by
this push:
new 682948e8c1 Supporting serialization of protobuf objects in task
parameters
682948e8c1 is described below
commit 682948e8c14ab54af33d61a7b561138f38128cf2
Author: DImuthuUpe <[email protected]>
AuthorDate: Wed Jun 21 10:39:30 2023 -0400
Supporting serialization of protobuf objects in task parameters
---
modules/airavata-apis/airavata-apis-server/pom.xml | 24 ++++++++++++++++++++++
.../apis/scheduling/ExperimentLauncher.java | 7 +++++++
.../apis/workflow/task/common/TaskUtil.java | 12 +++++++++--
.../workflow/task/ec2/CreateEC2InstanceTask.java | 15 +++++++++++++-
pom.xml | 2 +-
5 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/modules/airavata-apis/airavata-apis-server/pom.xml
b/modules/airavata-apis/airavata-apis-server/pom.xml
index 8660d06d2d..eff620301e 100644
--- a/modules/airavata-apis/airavata-apis-server/pom.xml
+++ b/modules/airavata-apis/airavata-apis-server/pom.xml
@@ -15,11 +15,23 @@
<groupId>org.apache.airavata</groupId>
<artifactId>mft-secret-service-server</artifactId>
<version>0.01-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-java</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.airavata</groupId>
<artifactId>mft-resource-service-server</artifactId>
<version>0.01-SNAPSHOT</version>
+ <exclusions>
+ <exclusion>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-java</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.airavata</groupId>
@@ -103,6 +115,18 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId> com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
</exclusions>
</dependency>
</dependencies>
diff --git
a/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/scheduling/ExperimentLauncher.java
b/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/scheduling/ExperimentLauncher.java
index b1fd6d5846..1d77d6ab56 100644
---
a/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/scheduling/ExperimentLauncher.java
+++
b/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/scheduling/ExperimentLauncher.java
@@ -1,6 +1,7 @@
package org.apache.airavata.apis.scheduling;
import org.apache.airavata.api.execution.ExperimentLaunchRequest;
+import org.apache.airavata.api.execution.stubs.EC2Backend;
import org.apache.airavata.api.execution.stubs.Experiment;
import org.apache.airavata.apis.service.ExecutionService;
import org.apache.airavata.apis.workflow.task.common.BaseTask;
@@ -54,8 +55,14 @@ public class ExperimentLauncher {
taskMap.put(dataMovementTask.getTaskId(), dataMovementTask);
+ EC2Backend ec2Backend = EC2Backend.newBuilder()
+ .setAwsCredentialId("SomeCred")
+ .setFlavor("m2")
+ .setRegion("us-west").build();
+
CreateEC2InstanceTask ec2InstanceTask = new CreateEC2InstanceTask();
ec2InstanceTask.setTaskId(UUID.randomUUID().toString());
+ ec2InstanceTask.setEc2Backend(ec2Backend);
taskMap.put(ec2InstanceTask.getTaskId(), ec2InstanceTask);
dataMovementTask.addOutPort(new
OutPort().setNextTaskId(ec2InstanceTask.getTaskId()));
diff --git
a/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/workflow/task/common/TaskUtil.java
b/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/workflow/task/common/TaskUtil.java
index 7aa23b7c5e..654c0b6156 100644
---
a/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/workflow/task/common/TaskUtil.java
+++
b/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/workflow/task/common/TaskUtil.java
@@ -1,5 +1,7 @@
package org.apache.airavata.apis.workflow.task.common;
+import com.google.protobuf.AbstractMessage;
+import com.google.protobuf.GeneratedMessageV3;
import org.apache.airavata.apis.workflow.task.common.annotation.TaskParam;
import org.apache.commons.beanutils.PropertyUtils;
import org.slf4j.Logger;
@@ -42,7 +44,11 @@ public class TaskUtil {
Class<?>[] methodParamType =
writeMethod.getParameterTypes();
Class<?> writeParameterType = methodParamType[0];
- if (writeParameterType.isAssignableFrom(String.class)) {
+ if
(GeneratedMessageV3.class.isAssignableFrom(writeParameterType)) { // Parsing
protobuf messages
+ Method parseMethod =
writeParameterType.getDeclaredMethod("parseFrom", byte[].class);
+ Object obj = parseMethod.invoke(null,
params.get(param.name()).getBytes()); // Calling static method
+ writeMethod.invoke(instance, obj);
+ } else if
(writeParameterType.isAssignableFrom(String.class)) {
writeMethod.invoke(instance, params.get(param.name()));
} else if
(writeParameterType.isAssignableFrom(Integer.class) ||
writeParameterType.isAssignableFrom(Integer.TYPE))
{
@@ -74,7 +80,9 @@ public class TaskUtil {
try {
if (parm != null) {
Object propertyValue = PropertyUtils.getProperty(data,
classField.getName());
- if (propertyValue instanceof TaskParamType) {
+ if (propertyValue instanceof GeneratedMessageV3) {
+ result.put(parm.name(), new
String(GeneratedMessageV3.class.cast(propertyValue).toByteArray()));
+ } else if (propertyValue instanceof TaskParamType) {
result.put(parm.name(),
TaskParamType.class.cast(propertyValue).serialize());
} else {
result.put(parm.name(), propertyValue.toString());
diff --git
a/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/workflow/task/ec2/CreateEC2InstanceTask.java
b/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/workflow/task/ec2/CreateEC2InstanceTask.java
index 537323bd70..95454e1d4f 100644
---
a/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/workflow/task/ec2/CreateEC2InstanceTask.java
+++
b/modules/airavata-apis/airavata-apis-server/src/main/java/org/apache/airavata/apis/workflow/task/ec2/CreateEC2InstanceTask.java
@@ -1,7 +1,9 @@
package org.apache.airavata.apis.workflow.task.ec2;
+import org.apache.airavata.api.execution.stubs.EC2Backend;
import org.apache.airavata.apis.workflow.task.common.BaseTask;
import org.apache.airavata.apis.workflow.task.common.annotation.TaskDef;
+import org.apache.airavata.apis.workflow.task.common.annotation.TaskParam;
import org.apache.helix.task.TaskResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -11,10 +13,13 @@ public class CreateEC2InstanceTask extends BaseTask {
private final static Logger logger =
LoggerFactory.getLogger(CreateEC2InstanceTask.class);
+ @TaskParam(name = "ec2Backend")
+ private ThreadLocal<EC2Backend> ec2Backend = new ThreadLocal<>();
+
@Override
public TaskResult onRun() throws Exception {
logger.info("Starting Create EC2 Instance Task {}", getTaskId());
-
+ logger.info("EC2 Backend {}", getEc2Backend().toString());
return new TaskResult(TaskResult.Status.COMPLETED, "Completed");
}
@@ -22,4 +27,12 @@ public class CreateEC2InstanceTask extends BaseTask {
public void onCancel() throws Exception {
}
+
+ public EC2Backend getEc2Backend() {
+ return ec2Backend.get();
+ }
+
+ public void setEc2Backend(EC2Backend ec2Backend) {
+ this.ec2Backend.set(ec2Backend);
+ }
}
diff --git a/pom.xml b/pom.xml
index 626f0ff48a..83687db300 100644
--- a/pom.xml
+++ b/pom.xml
@@ -86,7 +86,7 @@
<properties>
<protobuf.maven.plugin>0.5.1</protobuf.maven.plugin>
<os.maven.plugin>1.5.0.Final</os.maven.plugin>
- <protobuf.java>3.21.11</protobuf.java>
+ <protobuf.java>3.22.5</protobuf.java>
<!-- This needs to match the grpc version used by grpc.spring.boot -->
<!-- see
https://github.com/LogNet/grpc-spring-boot-starter/blob/master/ReleaseNotes.md
-->
<grpc.version>1.47.0</grpc.version>