use of org.apache.airavata.datalake.drms.storage.ssh.SSHStorage in project airavata-data-lake by apache.
the class AnyStorageDeserializer method deriveStorageFromMap.
public static AnyStorage deriveStorageFromMap(Map<String, Object> fixedMap) throws Exception {
Map<String, Object> asMap = new HashMap<>(fixedMap);
AnyStorage.Builder anyStorageBuilder = AnyStorage.newBuilder();
String type = (String) asMap.get(StorageConstants.STORAGE_TYPE_LABEL);
asMap.remove(StorageConstants.STORAGE_TYPE_LABEL);
switch(type) {
case StorageConstants.SSH_STORAGE_TYPE_LABEL:
SSHStorage.Builder builder = SSHStorage.newBuilder();
setObjectFieldsUsingMap(builder, asMap);
SSHStorage sshStorage = builder.build();
anyStorageBuilder.setSshStorage(sshStorage);
break;
case StorageConstants.S3_STORAGE_TYPE_LABEL:
S3Storage.Builder s3Builder = S3Storage.newBuilder();
setObjectFieldsUsingMap(s3Builder, asMap);
anyStorageBuilder.setS3Storage(s3Builder.build());
break;
default:
throw new Exception("Unsupported storage type for deserializing : " + type);
}
return anyStorageBuilder.build();
}
use of org.apache.airavata.datalake.drms.storage.ssh.SSHStorage in project airavata-mft by apache.
the class DatalakeResourceBackend method getGenericResource.
@Override
public Optional<GenericResource> getGenericResource(GenericResourceGetRequest request) throws Exception {
AuthToken authzToken = request.getAuthzToken();
DRMSServiceAuthToken drmsServiceAuthToken = getDrmsToken(authzToken);
if (drmsServiceAuthToken == null) {
logger.error("DRMS Service auth token can not be null. Invalid token type {} specified", authzToken.getAuthMechanismCase());
throw new Exception("DRMS Service auth token can not be null. Invalid token type specified");
}
ResourceServiceGrpc.ResourceServiceBlockingStub datalakeResourceStub = ResourceServiceGrpc.newBlockingStub(channel);
ResourceFetchResponse resourceFetchResponse = datalakeResourceStub.fetchResource(ResourceFetchRequest.newBuilder().setAuthToken(drmsServiceAuthToken).setResourceId(request.getResourceId()).build());
if (resourceFetchResponse.getResource().getResourceId().isEmpty()) {
return Optional.empty();
}
org.apache.airavata.datalake.drms.resource.GenericResource resource = resourceFetchResponse.getResource();
GenericResource.Builder resourceBuilder = GenericResource.newBuilder().setResourceId(resource.getResourceId());
switch(resource.getType()) {
case "FILE":
resourceBuilder.setFile(FileResource.newBuilder().setResourcePath(resource.getResourcePath()).build());
break;
case "COLLECTION":
resourceBuilder.setDirectory(DirectoryResource.newBuilder().setResourcePath(resource.getResourcePath()).build());
break;
}
switch(resource.getStorageCase()) {
case SSH_STORAGE:
SSHStorage storage = resource.getSshStorage();
resourceBuilder.setScpStorage(SCPStorage.newBuilder().setStorageId(storage.getStorageId()).setHost(storage.getHostName()).setPort(storage.getPort()).build());
break;
case S3_STORAGE:
org.apache.airavata.datalake.drms.storage.s3.S3Storage s3Storage = resource.getS3Storage();
resourceBuilder.setS3Storage(S3Storage.newBuilder().setStorageId(s3Storage.getStorageId()).setBucketName(s3Storage.getBucketName()).setRegion(s3Storage.getRegion()).build());
break;
case STORAGE_NOT_SET:
logger.error("No preference registered for the resource {}", request.getResourceId());
throw new Exception("No preference registered for the resource " + request.getResourceId());
}
return Optional.of(resourceBuilder.build());
}
use of org.apache.airavata.datalake.drms.storage.ssh.SSHStorage in project airavata-data-lake by apache.
the class AnyStorageSerializer method serializeToMap.
public static Map<String, Object> serializeToMap(AnyStorage anyStorage) {
Map<String, Object> fields = new HashMap<>();
Map<Descriptors.FieldDescriptor, Object> allFields = null;
switch(anyStorage.getStorageCase()) {
case SSH_STORAGE:
SSHStorage sshStorage = anyStorage.getSshStorage();
allFields = sshStorage.getAllFields();
fields.put(StorageConstants.STORAGE_TYPE_LABEL, StorageConstants.SSH_STORAGE_TYPE_LABEL);
break;
case S3_STORAGE:
S3Storage s3Storage = anyStorage.getS3Storage();
allFields = s3Storage.getAllFields();
fields.put(StorageConstants.STORAGE_TYPE_LABEL, StorageConstants.S3_STORAGE_TYPE_LABEL);
break;
case STORAGE_NOT_SET:
break;
}
if (allFields != null) {
allFields.forEach((descriptor, value) -> {
String fieldName = descriptor.getJsonName();
fields.put(fieldName, value);
});
}
return fields;
}
Aggregations