You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by di...@apache.org on 2021/07/12 22:23:17 UTC
[airavata-mft] branch develop updated: Auto selecting target agents
when non is specified for http download
This is an automated email from the ASF dual-hosted git repository.
dimuthuupe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-mft.git
The following commit(s) were added to refs/heads/develop by this push:
new 44e8cd9 Auto selecting target agents when non is specified for http download
44e8cd9 is described below
commit 44e8cd91f5f92cddfb73bb56d080227d47d28d0f
Author: Dimuthu Wannipurage <di...@gmail.com>
AuthorDate: Mon Jul 12 18:23:03 2021 -0400
Auto selecting target agents when non is specified for http download
---
.../airavata/mft/api/handler/MFTApiHandler.java | 25 +++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/api/service/src/main/java/org/apache/airavata/mft/api/handler/MFTApiHandler.java b/api/service/src/main/java/org/apache/airavata/mft/api/handler/MFTApiHandler.java
index c3a9840..29f144b 100644
--- a/api/service/src/main/java/org/apache/airavata/mft/api/handler/MFTApiHandler.java
+++ b/api/service/src/main/java/org/apache/airavata/mft/api/handler/MFTApiHandler.java
@@ -22,6 +22,7 @@ import com.google.protobuf.util.JsonFormat;
import io.grpc.stub.StreamObserver;
import org.apache.airavata.mft.admin.MFTConsulClient;
import org.apache.airavata.mft.admin.SyncRPCClient;
+import org.apache.airavata.mft.admin.models.AgentInfo;
import org.apache.airavata.mft.admin.models.TransferState;
import org.apache.airavata.mft.admin.models.rpc.SyncRPCRequest;
import org.apache.airavata.mft.admin.models.rpc.SyncRPCResponse;
@@ -97,8 +98,13 @@ public class MFTApiHandler extends MFTApiServiceGrpc.MFTApiServiceImplBase {
public void submitHttpDownload(HttpDownloadApiRequest request, StreamObserver<HttpDownloadApiResponse> responseObserver) {
try {
// TODO : Automatically derive agent if the target agent is empty
+
+ logger.info("Processing submit http download for resource {}", request.getSourceResourceId());
+
+ String targetAgent = derriveTargetAgent(request.getTargetAgent());
+
SyncRPCRequest.SyncRPCRequestBuilder requestBuilder = SyncRPCRequest.SyncRPCRequestBuilder.builder()
- .withAgentId(request.getTargetAgent())
+ .withAgentId(targetAgent)
.withMessageId(UUID.randomUUID().toString())
.withMethod("submitHttpDownload")
.withParameter("resourceId", request.getSourceResourceId())
@@ -294,4 +300,21 @@ public class MFTApiHandler extends MFTApiServiceGrpc.MFTApiServiceImplBase {
responseObserver.onError(new Exception("Failed to fetch directory resource metadata", e));
}
}
+
+ private String derriveTargetAgent(String targetAgent) throws Exception {
+ if (targetAgent.isEmpty()) {
+ List<String> liveAgentIds = mftConsulClient.getLiveAgentIds();
+ if (liveAgentIds.isEmpty()) {
+ throw new Exception("No agent is available to perform the operation");
+ }
+ targetAgent = liveAgentIds.get(0);
+ logger.info("Using agent {} for processing the operation", targetAgent);
+ } else {
+ Optional<AgentInfo> agentInfo = mftConsulClient.getAgentInfo(targetAgent);
+ if (agentInfo.isEmpty()) {
+ throw new Exception("Target agent " + targetAgent + " is not available");
+ }
+ }
+ return targetAgent;
+ }
}