Skip to content

Commit

Permalink
Merge pull request #4 from pokearu/DropboxTransport
Browse files Browse the repository at this point in the history
Dropbox transport implementation
  • Loading branch information
aksrajvanshi authored Apr 24, 2020
2 parents 671b048 + 97b2a45 commit bad442f
Show file tree
Hide file tree
Showing 25 changed files with 751 additions and 0 deletions.
5 changes: 5 additions & 0 deletions agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<artifactId>mft-gcp-transport</artifactId>
<version>0.01-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.airavata</groupId>
<artifactId>mft-dropbox-transport</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.airavata</groupId>
<artifactId>mft-admin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ public static Optional<Connector> resolveConnector(String type, String direction
break;
}
break;
case "DROPBOX":
switch (direction) {
case "IN":
className = "org.apache.airavata.mft.transport.dropbox.DropboxReceiver";
break;
case "OUT":
className = "org.apache.airavata.mft.transport.dropbox.DropboxSender";
break;
}
break;
}

if (className != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public static Optional<MetadataCollector> resolveMetadataCollector(String type)
case "GCS":
className = "org.apache.airavata.mft.transport.gcp.GCSMetadataCollector";
break;
case "DROPBOX":
className = "org.apache.airavata.mft.transport.dropbox.DropboxMetadataCollector";
break;
}

if (className != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ public interface ResourceBackend {
public GCSResource createGCSResource(GCSResourceCreateRequest request) throws Exception;
public boolean updateGCSResource(GCSResourceUpdateRequest request) throws Exception;
public boolean deleteGCSResource(GCSResourceDeleteRequest request) throws Exception;

public Optional<DropboxResource> getDropboxResource(DropboxResourceGetRequest request) throws Exception;
public DropboxResource createDropboxResource(DropboxResourceCreateRequest request) throws Exception;
public boolean updateDropboxResource(DropboxResourceUpdateRequest request) throws Exception;
public boolean deleteDropboxResource(DropboxResourceDeleteRequest request) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,23 @@ public boolean updateGCSResource(GCSResourceUpdateRequest request) throws Except
public boolean deleteGCSResource(GCSResourceDeleteRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}
@Override
public Optional<DropboxResource> getDropboxResource(DropboxResourceGetRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public DropboxResource createDropboxResource(DropboxResourceCreateRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public boolean updateDropboxResource(DropboxResourceUpdateRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public boolean deleteDropboxResource(DropboxResourceDeleteRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,44 @@ public boolean updateGCSResource(GCSResourceUpdateRequest request) throws Except
public boolean deleteGCSResource(GCSResourceDeleteRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}
@Override
public Optional<DropboxResource> getDropboxResource(DropboxResourceGetRequest request) throws Exception {
JSONParser jsonParser = new JSONParser();
InputStream inputStream = FileBasedResourceBackend.class.getClassLoader().getResourceAsStream(resourceFile);

try (InputStreamReader reader = new InputStreamReader(inputStream)) {
Object obj = jsonParser.parse(reader);

JSONArray resourceList = (JSONArray) obj;

List<DropboxResource> dropboxResources = (List<DropboxResource>) resourceList.stream()
.filter(resource -> "DROPBOX".equals(((JSONObject) resource).get("type").toString()))
.map(resource -> {
JSONObject r = (JSONObject) resource;

DropboxResource dropboxResource = DropboxResource.newBuilder()
.setResourceId(r.get("resourceId").toString())
.setResourcePath(r.get("resourcePath").toString())
.build();

return dropboxResource;
}).collect(Collectors.toList());
return dropboxResources.stream().filter(r -> request.getResourceId().equals(r.getResourceId())).findFirst();
}
}

@Override
public DropboxResource createDropboxResource(DropboxResourceCreateRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public boolean updateDropboxResource(DropboxResourceUpdateRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public boolean deleteDropboxResource(DropboxResourceDeleteRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,25 @@ public boolean updateGCSResource(GCSResourceUpdateRequest request) throws Except
public boolean deleteGCSResource(GCSResourceDeleteRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public Optional<DropboxResource> getDropboxResource(DropboxResourceGetRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public DropboxResource createDropboxResource(DropboxResourceCreateRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public boolean updateDropboxResource(DropboxResourceUpdateRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public boolean deleteDropboxResource(DropboxResourceDeleteRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,69 @@ public void deleteGCSResource(GCSResourceDeleteRequest request, StreamObserver<E
.asRuntimeException());
}
}
@Override
public void getDropboxResource(DropboxResourceGetRequest request, StreamObserver<DropboxResource> responseObserver) {
try {
this.backend.getDropboxResource(request).ifPresentOrElse(resource -> {
responseObserver.onNext(resource);
responseObserver.onCompleted();
}, () -> {
responseObserver.onError(Status.INTERNAL
.withDescription("No dropbox Resource with id " + request.getResourceId())
.asRuntimeException());
});
} catch (Exception e) {
logger.error("Failed in retrieving dropbox resource with id {}", request.getResourceId(), e);

responseObserver.onError(Status.INTERNAL.withCause(e)
.withDescription("Failed in retrieving dropbox resource with id " + request.getResourceId())
.asRuntimeException());
}
}

@Override
public void createDropboxResource(DropboxResourceCreateRequest request, StreamObserver<DropboxResource> responseObserver) {
try {
responseObserver.onNext(this.backend.createDropboxResource(request));
responseObserver.onCompleted();
} catch (Exception e) {
logger.error("Failed in creating the dropbox resource", e);

responseObserver.onError(Status.INTERNAL.withCause(e)
.withDescription("Failed in creating the dropbox resource")
.asRuntimeException());
}
}

@Override
public void updateDropboxResource(DropboxResourceUpdateRequest request, StreamObserver<Empty> responseObserver) {
try {
this.backend.updateDropboxResource(request);
responseObserver.onCompleted();
} catch (Exception e) {
logger.error("Failed in updating the dropbox resource {}", request.getResourceId(), e);

responseObserver.onError(Status.INTERNAL.withCause(e)
.withDescription("Failed in updating the dropbox resource with id " + request.getResourceId())
.asRuntimeException());
}
}

@Override
public void deleteDropboxResource(DropboxResourceDeleteRequest request, StreamObserver<Empty> responseObserver) {
try {
boolean res = this.backend.deleteDropboxResource(request);
if (res) {
responseObserver.onCompleted();
} else {
responseObserver.onError(new Exception("Failed to delete dropbox Resource with id " + request.getResourceId()));
}
} catch (Exception e) {
logger.error("Failed in deleting the dropbox resource {}", request.getResourceId(), e);

responseObserver.onError(Status.INTERNAL.withCause(e)
.withDescription("Failed in deleting the dropbox resource with id " + request.getResourceId())
.asRuntimeException());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
"resourceId": "gcs-bucket",
"bucketName": "",
"resourcePath": ""
},
{
"type": "DROPBOX",
"resourceId": "",
"resourcePath": ""
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
"resourceId": "gcs-bucket",
"bucketName": "pika-pika-bucket",
"resourcePath": "PikaPikaTest.txt"
},
{
"type": "DROPBOX",
"resourceId": "dropbox-file",
"resourcePath": "/test.txt"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,30 @@ message BoxResourceDeleteRequest {
string resourceId = 1;
}

// Dropbox Resource

message DropboxResource {
string resourceId = 1;
string resourcePath = 2;
}

message DropboxResourceGetRequest {
string resourceId = 1;
}

message DropboxResourceCreateRequest {
string resourcePath = 1;
}

message DropboxResourceUpdateRequest {
string resourceId = 1;
string resourcePath = 2;
}

message DropboxResourceDeleteRequest {
string resourceId = 1;
}

service ResourceService {
// SCP Storage

Expand Down Expand Up @@ -394,4 +418,30 @@ service ResourceService {
delete: "/v1.0/resource/gcs"
};
}
// Dropbox Resource

rpc getDropboxResource (DropboxResourceGetRequest) returns (DropboxResource) {
option (google.api.http) = {
get: "/v1.0/resource/dropbox"
};
}

rpc createDropboxResource (DropboxResourceCreateRequest) returns (DropboxResource) {
option (google.api.http) = {
post: "/v1.0/resource/dropbox"
};
}

rpc updateDropboxResource (DropboxResourceUpdateRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
put: "/v1.0/resource/dropbox"
};
}

rpc deleteDropboxResource (DropboxResourceDeleteRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
delete: "/v1.0/resource/dropbox"
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public interface SecretBackend {
public GCSSecret createGCSSecret(GCSSecretCreateRequest request) throws Exception;
public boolean updateGCSSecret(GCSSecretUpdateRequest request) throws Exception;
public boolean deleteGCSSecret(GCSSecretDeleteRequest request) throws Exception;

public Optional<DropboxSecret> getDropboxSecret(DropboxSecretGetRequest request) throws Exception;
public DropboxSecret createDropboxSecret(DropboxSecretCreateRequest request) throws Exception;
public boolean updateDropboxSecret(DropboxSecretUpdateRequest request) throws Exception;
public boolean deleteDropboxSecret(DropboxSecretDeleteRequest request) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,25 @@ public boolean deleteGCSSecret(GCSSecretDeleteRequest request) throws Exception
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public Optional<DropboxSecret> getDropboxSecret(DropboxSecretGetRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public DropboxSecret createDropboxSecret(DropboxSecretCreateRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public boolean updateDropboxSecret(DropboxSecretUpdateRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public boolean deleteDropboxSecret(DropboxSecretDeleteRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,44 @@ public boolean deleteGCSSecret(GCSSecretDeleteRequest request) throws Exception
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public Optional<DropboxSecret> getDropboxSecret(DropboxSecretGetRequest request) throws Exception {
JSONParser jsonParser = new JSONParser();
InputStream inputStream = FileBasedSecretBackend.class.getClassLoader().getResourceAsStream(secretFile);

try (InputStreamReader reader = new InputStreamReader(inputStream)) {
Object obj = jsonParser.parse(reader);
JSONArray resourceList = (JSONArray) obj;

List<DropboxSecret> dbxSecrets = (List<DropboxSecret>) resourceList.stream()
.filter(resource -> "DROPBOX".equals(((JSONObject) resource).get("type").toString()))
.map(resource -> {
JSONObject r = (JSONObject) resource;

DropboxSecret dbxSecret = DropboxSecret.newBuilder()
.setSecretId(r.get("secretId").toString())
.setAccessToken(r.get("accessToken").toString()).build();
return dbxSecret;

}).collect(Collectors.toList());
return dbxSecrets.stream().filter(r -> request.getSecretId().equals(r.getSecretId())).findFirst();
}
}

@Override
public DropboxSecret createDropboxSecret(DropboxSecretCreateRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public boolean updateDropboxSecret(DropboxSecretUpdateRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}

@Override
public boolean deleteDropboxSecret(DropboxSecretDeleteRequest request) throws Exception {
throw new UnsupportedOperationException("Operation is not supported in backend");
}


}
Loading

0 comments on commit bad442f

Please sign in to comment.