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 2023/02/21 05:12:09 UTC

[airavata-mft] branch master updated: Refactoring API

This is an automated email from the ASF dual-hosted git repository.

dimuthuupe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-mft.git


The following commit(s) were added to refs/heads/master by this push:
     new 58570dc  Refactoring API
58570dc is described below

commit 58570dcab36ef0965749ff3b2e48d3289dbb095f
Author: DImuthuUpe <di...@gmail.com>
AuthorDate: Tue Feb 21 00:09:05 2023 -0500

    Refactoring API
---
 agent/stub/src/main/proto/MFTAgentStubs.proto      |  1 -
 .../airavata/mft/api/handler/MFTApiHandler.java    | 67 ++++------------------
 api/stub/src/main/proto/MFTTransferApi.proto       | 30 ----------
 3 files changed, 10 insertions(+), 88 deletions(-)

diff --git a/agent/stub/src/main/proto/MFTAgentStubs.proto b/agent/stub/src/main/proto/MFTAgentStubs.proto
index 451722b..121a2ad 100644
--- a/agent/stub/src/main/proto/MFTAgentStubs.proto
+++ b/agent/stub/src/main/proto/MFTAgentStubs.proto
@@ -120,6 +120,5 @@ message GetResourceMetadataRequest {
     StorageWrapper storage = 2;
     SecretWrapper secret = 3;
     bool recursiveSearch = 4;
-    string targetAgent = 5;
 }
 
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 9574eb1..e595281 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
@@ -131,59 +131,6 @@ public class MFTApiHandler extends MFTTransferServiceGrpc.MFTTransferServiceImpl
         }
     }
 
-    @Override
-    public void submitHttpUpload(HttpUploadApiRequest request, StreamObserver<HttpUploadApiResponse> responseObserver) {
-        super.submitHttpUpload(request, responseObserver);
-    }
-
-    @Override
-    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 path {}", request.getResourcePath());
-
-            String targetAgent = derriveTargetAgent(request.getTargetAgent());
-
-            SyncRPCRequest.SyncRPCRequestBuilder requestBuilder = SyncRPCRequest.SyncRPCRequestBuilder.builder()
-                    .withAgentId(targetAgent)
-                    .withMessageId(UUID.randomUUID().toString())
-                    .withMethod("submitHttpDownload")
-                    .withParameter("resourcePath", request.getResourcePath())
-                    .withParameter("sourceStorageId", request.getSourceStorageId())
-                    .withParameter("sourceToken", request.getSourceSecretId())
-                    .withParameter("mftAuthorizationToken", JsonFormat.printer().print(request.getMftAuthorizationToken()));
-
-            SyncRPCResponse rpcResponse = agentRPCClient.sendSyncRequest(requestBuilder.build());
-
-            switch (rpcResponse.getResponseStatus()) {
-                case SUCCESS:
-                    String url = rpcResponse.getResponseAsStr();
-                    HttpDownloadApiResponse downloadResponse = HttpDownloadApiResponse.newBuilder()
-                            .setUrl(url)
-                            .setTargetAgent(request.getTargetAgent()).build();
-                    responseObserver.onNext(downloadResponse);
-                    responseObserver.onCompleted();
-                    return;
-                case FAIL:
-                    logger.error("Errored while processing the download request to resource path {}. Error msg : {}",
-                            request.getResourcePath(), rpcResponse.getErrorAsStr());
-
-                    responseObserver.onError(Status.INTERNAL
-                            .withDescription("Errored while processing the the fetch file metadata response. Error msg : " +
-                                    rpcResponse.getErrorAsStr())
-                            .asException());
-            }
-
-        } catch (Exception e) {
-            logger.error("Error while submitting http download request to resource path {}",
-                                                request.getResourcePath() , e);
-            responseObserver.onError(Status.INTERNAL
-                    .withDescription("Failed to submit http download request. " + e.getMessage())
-                    .asException());
-        }
-    }
-
     @Override
     public void getAllTransferStates(TransferStateApiRequest request, StreamObserver<TransferStateResponse> responseObserver) {
         try {
@@ -328,7 +275,6 @@ public class MFTApiHandler extends MFTTransferServiceGrpc.MFTTransferServiceImpl
                 directReqBuilder
                         .setStorage(StorageWrapper.newBuilder().setLocal(localStorage).build());
 
-                directReqBuilder.setTargetAgent(localStorage.getAgentId());
                 break;
             case BOX:
                 BoxStorage boxStorage = storageClient.box()
@@ -430,7 +376,7 @@ public class MFTApiHandler extends MFTTransferServiceGrpc.MFTTransferServiceImpl
                 directRequest = deriveDirectRequest(request.getIdRequest());
             }
 
-            String targetAgent = derriveTargetAgent(directRequest.getTargetAgent());
+            String targetAgent = derriveTargetAgent(directRequest);
             SyncRPCRequest.SyncRPCRequestBuilder requestBuilder = SyncRPCRequest.SyncRPCRequestBuilder.builder()
                     .withAgentId(targetAgent)
                     .withMessageId(UUID.randomUUID().toString())
@@ -475,7 +421,7 @@ public class MFTApiHandler extends MFTTransferServiceGrpc.MFTTransferServiceImpl
                 directRequest = deriveDirectRequest(request.getIdRequest());
             }
 
-            String targetAgent = derriveTargetAgent(directRequest.getTargetAgent());
+            String targetAgent = derriveTargetAgent(directRequest);
             SyncRPCRequest.SyncRPCRequestBuilder requestBuilder = SyncRPCRequest.SyncRPCRequestBuilder.builder()
                     .withAgentId(targetAgent)
                     .withMessageId(UUID.randomUUID().toString())
@@ -508,7 +454,14 @@ public class MFTApiHandler extends MFTTransferServiceGrpc.MFTTransferServiceImpl
         }
     }
 
-    private String derriveTargetAgent(String targetAgent) throws Exception {
+    private String derriveTargetAgent(GetResourceMetadataRequest directRequest) throws Exception {
+
+        String targetAgent = "";
+
+        if (directRequest.getStorage().getStorageCase() == StorageWrapper.StorageCase.LOCAL) {
+            targetAgent = directRequest.getStorage().getLocal().getAgentId();
+        }
+
         if (targetAgent.isEmpty()) {
             List<String> liveAgentIds = mftConsulClient.getLiveAgentIds();
             if (liveAgentIds.isEmpty()) {
diff --git a/api/stub/src/main/proto/MFTTransferApi.proto b/api/stub/src/main/proto/MFTTransferApi.proto
index 0301696..3629a08 100644
--- a/api/stub/src/main/proto/MFTTransferApi.proto
+++ b/api/stub/src/main/proto/MFTTransferApi.proto
@@ -53,32 +53,6 @@ message TransferApiResponse {
     string transferId = 1;
 }
 
-message HttpUploadApiRequest {
-    string destinationStorageId = 1;
-    string resourcePath = 2;
-    string destinationSecretId = 3;
-    string targetAgent = 5;
-    org.apache.airavata.mft.common.AuthToken mftAuthorizationToken = 6;
-}
-
-message HttpUploadApiResponse {
-    string url = 1;
-    string targetAgent = 2;
-}
-
-message HttpDownloadApiRequest {
-    string resourcePath = 1;
-    string sourceStorageId = 2;
-    string sourceSecretId = 3;
-    string targetAgent = 5;
-    org.apache.airavata.mft.common.AuthToken mftAuthorizationToken = 6;
-}
-
-message HttpDownloadApiResponse {
-    string url = 1;
-    string targetAgent = 2;
-}
-
 message TransferStateApiRequest {
     string transferId = 1;
     org.apache.airavata.mft.common.AuthToken mftAuthorizationToken = 2;
@@ -124,10 +98,6 @@ service  MFTTransferService {
 
     rpc submitTransfer(TransferApiRequest) returns (TransferApiResponse);
 
-    rpc submitHttpUpload(HttpUploadApiRequest) returns (HttpUploadApiResponse);
-
-    rpc submitHttpDownload(HttpDownloadApiRequest) returns (HttpDownloadApiResponse);
-
     rpc getAllTransferStates(TransferStateApiRequest) returns (stream TransferStateResponse);
 
     rpc getTransferStateSummary(TransferStateApiRequest) returns (TransferStateSummaryResponse);