Skip to content
Permalink
Browse files
Refactoring storage and resource interfaces for database backend
  • Loading branch information
DImuthuUpe committed Mar 9, 2022
1 parent a2566f6 commit b777c440a4b277d83a07d578fd241c14efd8eedf
Show file tree
Hide file tree
Showing 33 changed files with 457 additions and 319 deletions.
@@ -38,6 +38,16 @@
<artifactId>mft-api-stub</artifactId>
<version>0.01-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.airavata</groupId>
<artifactId>mft-resource-service-client</artifactId>
<version>0.01-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.airavata</groupId>
<artifactId>mft-secret-service-client</artifactId>
<version>0.01-SNAPSHOT</version>
</dependency>
</dependencies>

</project>
@@ -20,6 +20,13 @@
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.apache.airavata.mft.api.service.*;
import org.apache.airavata.mft.resource.client.ResourceServiceClient;
import org.apache.airavata.mft.resource.client.ResourceServiceClientBuilder;
import org.apache.airavata.mft.resource.client.StorageServiceClient;
import org.apache.airavata.mft.resource.client.StorageServiceClientBuilder;
import org.apache.airavata.mft.resource.stubs.common.GenericResourceServiceGrpc;
import org.apache.airavata.mft.secret.client.SecretServiceClient;
import org.apache.airavata.mft.secret.client.SecretServiceClientBuilder;

import java.io.Closeable;
import java.io.IOException;
@@ -29,14 +36,41 @@

public class MFTApiClient implements Closeable {

private final ManagedChannel channel;
private ManagedChannel channel;
private ResourceServiceClient resourceServiceClient;
private StorageServiceClient storageServiceClient;
private SecretServiceClient secretServiceClient;

public MFTApiClient(String hostName, int port) {
channel = ManagedChannelBuilder.forAddress(hostName, port).usePlaintext().build();
private String transferServiceHost;
private int transferServicePort;

private String resourceServiceHost;
private int resourceServicePort;

private String secretServiceHost;
private int secretServicePort;

public void init() {
channel = ManagedChannelBuilder.forAddress(transferServiceHost, transferServicePort).usePlaintext().build();
resourceServiceClient = ResourceServiceClientBuilder.buildClient(resourceServiceHost, resourceServicePort);
storageServiceClient = StorageServiceClientBuilder.buildClient(resourceServiceHost, resourceServicePort);
secretServiceClient = SecretServiceClientBuilder.buildClient(secretServiceHost, secretServicePort);
}

public MFTTransferServiceGrpc.MFTTransferServiceBlockingStub getTransferClient() {
return MFTTransferServiceGrpc.newBlockingStub(channel);
}

public GenericResourceServiceGrpc.GenericResourceServiceBlockingStub getResourceClient() {
return resourceServiceClient.get();
}

public MFTApiServiceGrpc.MFTApiServiceBlockingStub get() {
return MFTApiServiceGrpc.newBlockingStub(channel);
public StorageServiceClient getStorageServiceClient() {
return storageServiceClient;
}

public SecretServiceClient getSecretServiceClient() {
return secretServiceClient;
}

@Override
@@ -45,4 +79,62 @@ public void close() throws IOException {
channel.shutdown();
}
}

public static final class MFTApiClientBuilder {
private String transferServiceHost = "localhost";
private int transferServicePort = 7004;
private String resourceServiceHost = "localhost";
private int resourceServicePort = 7002;
private String secretServiceHost = "localhost";
private int secretServicePort = 7003;

private MFTApiClientBuilder() {
}

public static MFTApiClientBuilder newBuilder() {
return new MFTApiClientBuilder();
}

public MFTApiClientBuilder withTransferServiceHost(String transferServiceHost) {
this.transferServiceHost = transferServiceHost;
return this;
}

public MFTApiClientBuilder withTransferServicePort(int transferServicePort) {
this.transferServicePort = transferServicePort;
return this;
}

public MFTApiClientBuilder withResourceServiceHost(String resourceServiceHost) {
this.resourceServiceHost = resourceServiceHost;
return this;
}

public MFTApiClientBuilder withResourceServicePort(int resourceServicePort) {
this.resourceServicePort = resourceServicePort;
return this;
}

public MFTApiClientBuilder withSecretServiceHost(String secretServiceHost) {
this.secretServiceHost = secretServiceHost;
return this;
}

public MFTApiClientBuilder withSecretServicePort(int secretServicePort) {
this.secretServicePort = secretServicePort;
return this;
}

public MFTApiClient build() {
MFTApiClient mFTApiClient = new MFTApiClient();
mFTApiClient.transferServicePort = this.transferServicePort;
mFTApiClient.transferServiceHost = this.transferServiceHost;
mFTApiClient.secretServicePort = this.secretServicePort;
mFTApiClient.resourceServicePort = this.resourceServicePort;
mFTApiClient.secretServiceHost = this.secretServiceHost;
mFTApiClient.resourceServiceHost = this.resourceServiceHost;
mFTApiClient.init();
return mFTApiClient;
}
}
}
@@ -1,14 +1,14 @@
package org.apache.airavata.mft.api.client.examples;

import org.apache.airavata.mft.api.client.MFTApiClient;
import org.apache.airavata.mft.api.service.FetchResourceMetadataRequest;
import org.apache.airavata.mft.api.service.MFTApiServiceGrpc;
import org.apache.airavata.mft.api.service.MFTTransferServiceGrpc;
import org.apache.airavata.mft.api.service.ResourceAvailabilityRequest;

public class Example {

public static void main(String a[]) {
MFTApiServiceGrpc.MFTApiServiceBlockingStub mftClient = new MFTApiClient("localhost", 7004).get();
MFTTransferServiceGrpc.MFTTransferServiceBlockingStub mftClient = MFTApiClient.MFTApiClientBuilder
.newBuilder().build().getTransferClient();
mftClient.getResourceAvailability(ResourceAvailabilityRequest.newBuilder()
.setResourceId("a")
.setResourceToken("b")
@@ -42,7 +42,7 @@
import java.util.UUID;

@GRpcService
public class MFTApiHandler extends MFTApiServiceGrpc.MFTApiServiceImplBase {
public class MFTApiHandler extends MFTTransferServiceGrpc.MFTTransferServiceImplBase {

private static final Logger logger = LoggerFactory.getLogger(MFTApiHandler.class);

@@ -124,7 +124,7 @@ message FetchResourceMetadataRequest {
org.apache.airavata.mft.common.AuthToken mftAuthorizationToken = 9;
}

service MFTApiService {
service MFTTransferService {

rpc submitTransfer(TransferApiRequest) returns (TransferApiResponse) {
option (google.api.http) = {
@@ -20,16 +20,17 @@
import org.apache.airavata.mft.api.client.MFTApiClient;
import org.apache.airavata.mft.api.service.HttpDownloadApiRequest;
import org.apache.airavata.mft.api.service.HttpDownloadApiResponse;
import org.apache.airavata.mft.api.service.MFTApiServiceGrpc;
import org.apache.airavata.mft.api.service.MFTTransferServiceGrpc;
import org.apache.airavata.mft.common.AuthToken;
import org.apache.airavata.mft.common.UserTokenAuth;

public class DownloadExample {
public static void main(String args[]) {
AuthToken mftAuthorizationToken = AuthToken.newBuilder().setUserTokenAuth(UserTokenAuth.newBuilder().setToken("43ff79ac-e4f2-473c-9ea1-04eee9509a53").build()).build();

MFTApiServiceGrpc.MFTApiServiceBlockingStub client = new MFTApiClient("localhost", 7004).get();
HttpDownloadApiResponse httpDownloadApiResponse = client.submitHttpDownload(HttpDownloadApiRequest.newBuilder()
MFTTransferServiceGrpc.MFTTransferServiceBlockingStub mftClient = MFTApiClient.MFTApiClientBuilder
.newBuilder().build().getTransferClient();
HttpDownloadApiResponse httpDownloadApiResponse = mftClient.submitHttpDownload(HttpDownloadApiRequest.newBuilder()
.setTargetAgent("agent0")
.setSourceResourceId("remote-ssh-resource")
.setSourceToken("local-ssh-cred")
@@ -4,11 +4,12 @@
import org.apache.airavata.mft.api.service.DirectoryMetadataResponse;
import org.apache.airavata.mft.api.service.FetchResourceMetadataRequest;
import org.apache.airavata.mft.api.service.FileMetadataResponse;
import org.apache.airavata.mft.api.service.MFTApiServiceGrpc;
import org.apache.airavata.mft.api.service.MFTTransferServiceGrpc;

public class SCPExample {
public static void main(String args[]) throws Exception {
MFTApiServiceGrpc.MFTApiServiceBlockingStub client = new MFTApiClient("localhost", 7004).get();
MFTTransferServiceGrpc.MFTTransferServiceBlockingStub client = MFTApiClient.MFTApiClientBuilder
.newBuilder().build().getTransferClient();

// File metadata
long startTime = System.currentTimeMillis();
@@ -26,7 +26,8 @@

public class LocalExample {
public static void main(String args[]) throws Exception {
MFTApiServiceGrpc.MFTApiServiceBlockingStub client = new MFTApiClient("localhost", 7004).get();
MFTTransferServiceGrpc.MFTTransferServiceBlockingStub client = MFTApiClient.MFTApiClientBuilder
.newBuilder().build().getTransferClient();

String sourceResourceId = "remote-ssh-resource";
String sourceToken = "local-ssh-cred";
@@ -26,7 +26,8 @@

public class S3Example {
public static void main(String args[]) throws Exception {
MFTApiServiceGrpc.MFTApiServiceBlockingStub client = new MFTApiClient("localhost", 7004).get();
MFTTransferServiceGrpc.MFTTransferServiceBlockingStub client = MFTApiClient.MFTApiClientBuilder
.newBuilder().build().getTransferClient();

String sourceResourceId = "remote-ssh-storage";
String sourceResourcePath = "/tmp/1mb.txt";
@@ -26,7 +26,8 @@

public class SCPExample {
public static void main(String args[]) throws Exception {
MFTApiServiceGrpc.MFTApiServiceBlockingStub client = new MFTApiClient("localhost", 7004).get();
MFTTransferServiceGrpc.MFTTransferServiceBlockingStub client = MFTApiClient.MFTApiClientBuilder
.newBuilder().build().getTransferClient();

String sourceResourceId = "remote-ssh-resource-1";
String sourceResourcePath = "/tmp/1mb.txt";
@@ -43,10 +43,10 @@
<modules>
<module>common</module>
<module>core</module>
<module>services</module>
<module>api</module>
<module>transport</module>
<module>agent</module>
<module>services</module>
<module>controller</module>
<module>examples</module>
</modules>

0 comments on commit b777c44

Please sign in to comment.