Skip to content
Permalink
Browse files
Adding command line client to insert swift endpoint
  • Loading branch information
DImuthuUpe committed May 4, 2022
1 parent 5171fee commit 7b5df183df3021454e3b91c2a210a82dd52d0424
Showing 8 changed files with 106 additions and 4 deletions.
@@ -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
agent.chunk.size=10
agent.chunk.streaming.enabled=true
@@ -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
agent.chunk.size=10
agent.chunk.streaming.enabled=true
@@ -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) {
@@ -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")
@@ -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;
}
}
@@ -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 {
}
@@ -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 {
}
@@ -35,6 +35,7 @@ message StorageSecret {
DROPBOX = 5;
GCS = 6;
AZURE = 7;
SWIFT = 8;
}
StorageType type = 4;
}

0 comments on commit 7b5df18

Please sign in to comment.