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 2022/05/04 15:46:25 UTC

[airavata-mft] branch master updated: Adding command line client to insert swift endpoint

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 7b5df18  Adding command line client to insert swift endpoint
7b5df18 is described below

commit 7b5df183df3021454e3b91c2a210a82dd52d0424
Author: Dimuthu Wannipurage <di...@gmail.com>
AuthorDate: Wed May 4 11:46:14 2022 -0400

    Adding command line client to insert swift endpoint
---
 agent/src/main/resources/application.properties    |  3 +-
 .../distribution/conf/application.properties       |  3 +-
 .../airavata/mft/command/line/MainRunner.java      |  3 +-
 .../sub/s3/storage/S3StorageAddSubCommand.java     |  2 +-
 .../command/line/sub/swift/SwiftAddSubCommand.java | 83 ++++++++++++++++++++++
 .../line/sub/swift/SwiftRemoteSubCommand.java      |  7 ++
 .../command/line/sub/swift/SwiftSubCommand.java    |  8 +++
 .../proto/resourcesecretmap/StorageSecretMap.proto |  1 +
 8 files changed, 106 insertions(+), 4 deletions(-)

diff --git a/agent/src/main/resources/application.properties b/agent/src/main/resources/application.properties
index ee48ad5..ad13cb8 100644
--- a/agent/src/main/resources/application.properties
+++ b/agent/src/main/resources/application.properties
@@ -36,4 +36,5 @@ secret.service.port=7003
 agent.advertised.url=http://localhost:3333
 agent.concurrent.transfers=8
 agent.concurrent.chunked.threads=20
-agent.chunk.size=10
\ No newline at end of file
+agent.chunk.size=10
+agent.chunk.streaming.enabled=true
\ No newline at end of file
diff --git a/agent/src/main/resources/distribution/conf/application.properties b/agent/src/main/resources/distribution/conf/application.properties
index c8dc189..915c55b 100644
--- a/agent/src/main/resources/distribution/conf/application.properties
+++ b/agent/src/main/resources/distribution/conf/application.properties
@@ -35,4 +35,5 @@ secret.service.host=localhost
 secret.service.port=7003
 agent.concurrent.transfers=8
 agent.concurrent.chunked.threads=20
-agent.chunk.size=10
\ No newline at end of file
+agent.chunk.size=10
+agent.chunk.streaming.enabled=true
\ No newline at end of file
diff --git a/command-line/src/main/java/org/apache/airavata/mft/command/line/MainRunner.java b/command-line/src/main/java/org/apache/airavata/mft/command/line/MainRunner.java
index e6bda28..072c988 100644
--- a/command-line/src/main/java/org/apache/airavata/mft/command/line/MainRunner.java
+++ b/command-line/src/main/java/org/apache/airavata/mft/command/line/MainRunner.java
@@ -1,13 +1,14 @@
 package org.apache.airavata.mft.command.line;
 
 import org.apache.airavata.mft.command.line.sub.s3.S3SubCommand;
+import org.apache.airavata.mft.command.line.sub.swift.SwiftSubCommand;
 import org.apache.airavata.mft.command.line.sub.transfer.TransferSubCommand;
 import picocli.CommandLine;
 import picocli.CommandLine.Command;
 
 @Command(name = "checksum", mixinStandardHelpOptions = true, version = "checksum 4.0",
         description = "Prints the checksum (SHA-256 by default) of a file to STDOUT.",
-        subcommands = {S3SubCommand.class, TransferSubCommand.class})
+        subcommands = {S3SubCommand.class, TransferSubCommand.class, SwiftSubCommand.class})
 class MainRunner {
 
     public static void main(String... args) {
diff --git a/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/s3/storage/S3StorageAddSubCommand.java b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/s3/storage/S3StorageAddSubCommand.java
index b6a2b3d..70ea658 100644
--- a/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/s3/storage/S3StorageAddSubCommand.java
+++ b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/s3/storage/S3StorageAddSubCommand.java
@@ -20,7 +20,7 @@ public class S3StorageAddSubCommand implements Callable<Integer> {
     @CommandLine.Option(names = {"-n", "--name"}, description = "Storage Name")
     private String remoteName;
 
-    @CommandLine.Option(names = {"-b", "--bucker"}, description = "Bucket Name")
+    @CommandLine.Option(names = {"-b", "--bucket"}, description = "Bucket Name")
     private String bucket;
 
     @CommandLine.Option(names = {"-r", "--region"}, description = "Region")
diff --git a/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/swift/SwiftAddSubCommand.java b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/swift/SwiftAddSubCommand.java
new file mode 100644
index 0000000..ab81ecd
--- /dev/null
+++ b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/swift/SwiftAddSubCommand.java
@@ -0,0 +1,83 @@
+package org.apache.airavata.mft.command.line.sub.swift;
+
+import org.apache.airavata.mft.api.client.MFTApiClient;
+import org.apache.airavata.mft.common.AuthToken;
+import org.apache.airavata.mft.credential.stubs.swift.SwiftPasswordSecret;
+import org.apache.airavata.mft.credential.stubs.swift.SwiftSecret;
+import org.apache.airavata.mft.credential.stubs.swift.SwiftSecretCreateRequest;
+import org.apache.airavata.mft.resource.stubs.swift.storage.SwiftStorage;
+import org.apache.airavata.mft.resource.stubs.swift.storage.SwiftStorageCreateRequest;
+import org.apache.airavata.mft.storage.stubs.storagesecret.StorageSecret;
+import org.apache.airavata.mft.storage.stubs.storagesecret.StorageSecretCreateRequest;
+import org.apache.airavata.mft.storage.stubs.storagesecret.StorageSecretServiceGrpc;
+import picocli.CommandLine;
+
+import java.util.concurrent.Callable;
+
+@CommandLine.Command(name = "add")
+public class SwiftAddSubCommand implements Callable<Integer> {
+
+    @CommandLine.Option(names = {"-n", "--name"}, description = "Storage Name")
+    private String remoteName;
+
+    @CommandLine.Option(names = {"-c", "--container"}, description = "Swift Container Name")
+    private String container;
+
+    @CommandLine.Option(names = {"-e", "--endpoint"}, description = "Endpoint Name")
+    private String endpoint;
+
+    @CommandLine.Option(names = {"-r", "--region"}, description = "Region")
+    private String region;
+
+    @CommandLine.Option(names = {"-v", "--keystoneversion"}, description = "Keystone Version")
+    private int keystoneVersion;
+
+    @CommandLine.Option(names = {"-u", "--user"}, description = "User Name (Password Credentials")
+    private String userName;
+
+    @CommandLine.Option(names = {"-p", "--password"}, description = "Password (Password Credentials")
+    private String password;
+
+    @CommandLine.Option(names = {"-p", "--projectId"}, description = "Project Id (Password Credentials")
+    private String projectId;
+
+    @CommandLine.Option(names = {"-d", "--domainId"}, description = "Domain Id (Password Credentials")
+    private String domainId;
+
+
+    @Override
+    public Integer call() throws Exception {
+        AuthToken authToken = AuthToken.newBuilder().build();
+
+        MFTApiClient mftApiClient = MFTApiClient.MFTApiClientBuilder.newBuilder().build();
+
+        SwiftSecret swiftSecret = mftApiClient.getSecretServiceClient().swift().createSwiftSecret(SwiftSecretCreateRequest.newBuilder()
+                .setAuthzToken(authToken).setPasswordSecret(SwiftPasswordSecret.newBuilder()
+                        .setUserName(userName)
+                        .setPassword(password)
+                        .setProjectId(projectId)
+                        .setDomainId(domainId).build()).build());
+
+        System.out.println("Created the swift secret " + swiftSecret.getSecretId());
+
+        SwiftStorage swiftStorage = mftApiClient.getStorageServiceClient().swift().createSwiftStorage(SwiftStorageCreateRequest.newBuilder()
+                .setName(remoteName)
+                .setContainer(container)
+                .setEndpoint(endpoint)
+                .setKeystoneVersion(keystoneVersion)
+                .setRegion(region).build());
+
+        System.out.println("Created swift storage " + swiftStorage.getStorageId());
+
+        StorageSecretServiceGrpc.StorageSecretServiceBlockingStub storageSecretClient = mftApiClient.getStorageServiceClient().storageSecret();
+
+        StorageSecret storageSecret = storageSecretClient.createStorageSecret(StorageSecretCreateRequest.newBuilder()
+                .setStorageId(swiftStorage.getStorageId())
+                .setSecretId(swiftSecret.getSecretId())
+                .setType(StorageSecret.StorageType.SWIFT).build());
+
+        System.out.println("Successfully added Swift remote endpoint");
+
+        return 0;
+    }
+}
diff --git a/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/swift/SwiftRemoteSubCommand.java b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/swift/SwiftRemoteSubCommand.java
new file mode 100644
index 0000000..f97e16b
--- /dev/null
+++ b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/swift/SwiftRemoteSubCommand.java
@@ -0,0 +1,7 @@
+package org.apache.airavata.mft.command.line.sub.swift;
+
+import picocli.CommandLine;
+
+@CommandLine.Command(name = "remote", subcommands = {SwiftAddSubCommand.class})
+public class SwiftRemoteSubCommand {
+}
diff --git a/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/swift/SwiftSubCommand.java b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/swift/SwiftSubCommand.java
new file mode 100644
index 0000000..f013c14
--- /dev/null
+++ b/command-line/src/main/java/org/apache/airavata/mft/command/line/sub/swift/SwiftSubCommand.java
@@ -0,0 +1,8 @@
+package org.apache.airavata.mft.command.line.sub.swift;
+
+import picocli.CommandLine;
+
+@CommandLine.Command(name = "swift", description = "Manage Swift resources and credentials",
+        subcommands = {SwiftRemoteSubCommand.class})
+public class SwiftSubCommand {
+}
diff --git a/services/resource-service/stub/src/main/proto/resourcesecretmap/StorageSecretMap.proto b/services/resource-service/stub/src/main/proto/resourcesecretmap/StorageSecretMap.proto
index 257a6fd..7be8ae0 100644
--- a/services/resource-service/stub/src/main/proto/resourcesecretmap/StorageSecretMap.proto
+++ b/services/resource-service/stub/src/main/proto/resourcesecretmap/StorageSecretMap.proto
@@ -35,6 +35,7 @@ message StorageSecret {
         DROPBOX = 5;
         GCS = 6;
         AZURE = 7;
+        SWIFT = 8;
     }
     StorageType type = 4;
 }