235 lines
8.1 KiB
Java
235 lines
8.1 KiB
Java
package org.gcube.contentmanagement.blobstorage.transport.plugin;
|
|
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.net.UnknownHostException;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
|
|
import org.gcube.contentmanagement.blobstorage.resource.MemoryType;
|
|
import org.gcube.contentmanagement.blobstorage.resource.MyFile;
|
|
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
|
|
import org.gcube.contentmanagement.blobstorage.service.operation.Copy;
|
|
import org.gcube.contentmanagement.blobstorage.service.operation.CopyDir;
|
|
import org.gcube.contentmanagement.blobstorage.service.operation.Download;
|
|
import org.gcube.contentmanagement.blobstorage.service.operation.DuplicateFile;
|
|
import org.gcube.contentmanagement.blobstorage.service.operation.Link;
|
|
import org.gcube.contentmanagement.blobstorage.service.operation.Lock;
|
|
import org.gcube.contentmanagement.blobstorage.service.operation.Move;
|
|
import org.gcube.contentmanagement.blobstorage.service.operation.MoveDir;
|
|
import org.gcube.contentmanagement.blobstorage.service.operation.Unlock;
|
|
import org.gcube.contentmanagement.blobstorage.service.operation.Upload;
|
|
import org.gcube.contentmanagement.blobstorage.transport.TransportManager;
|
|
|
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
|
import org.gcube.contentmanagement.blobstorage.transport.plugin.Utils.Utils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import java.net.URI;
|
|
|
|
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
|
|
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
|
import software.amazon.awssdk.regions.Region;
|
|
import software.amazon.awssdk.services.s3.S3Client;
|
|
|
|
|
|
import com.mongodb.MongoException;
|
|
|
|
public class S3PluginManager extends TransportManager {
|
|
|
|
Region region = Region.US_EAST_1;
|
|
final String END_POINT = "https://s3.wasabisys.com";
|
|
S3Client s3;
|
|
private Logger logger = LoggerFactory.getLogger(S3PluginManager.class);
|
|
|
|
// THE FOLLOWING FIELDS SHOULD BE RETRIEVED FROM SERVICEENDPOINT
|
|
static final String ACCESS_KEY="UXMKEBMZBDROS5K9HREG";
|
|
static final String SECRET_ACCESS_KEY="0Mqu8gmzcZ09wuqqKZwNmuS5bYC549MlZhvfgv6W";
|
|
static final String bucket="gcube-home-test-access";
|
|
|
|
|
|
@Override
|
|
public String getName() {
|
|
return "S3PluginManager";
|
|
}
|
|
|
|
public S3PluginManager() {
|
|
logger.info("S3PluginManager");
|
|
|
|
|
|
}
|
|
|
|
public S3PluginManager(String[] server, String user, String pass, MemoryType memoryType, String[] dbNames,
|
|
String writeConcern, String readConcern) {
|
|
initBackend(server,user,pass, memoryType,dbNames, writeConcern, readConcern);
|
|
}
|
|
|
|
@Override
|
|
public void initBackend(String[] server, String user, String pass, MemoryType memoryType, String[] dbNames,
|
|
String writeConcern, String readConcern) {
|
|
AwsSessionCredentials awsCreds = AwsSessionCredentials.create(ACCESS_KEY, SECRET_ACCESS_KEY, "");
|
|
|
|
s3 = S3Client.builder().credentialsProvider(
|
|
StaticCredentialsProvider.create(awsCreds))
|
|
.endpointOverride(URI.create(END_POINT)).region(region).build();
|
|
}
|
|
|
|
@Override
|
|
public Object get(Download download) throws FileNotFoundException, IOException {
|
|
return BucketOperator.getInstance(s3).getObject(bucket, Utils.convertToS3Format(download.getResource().getRemotePath()), download.getLocalPath());
|
|
}
|
|
|
|
@Override
|
|
public String put(Upload upload) throws FileNotFoundException, IOException {
|
|
logger.info("put method invoked ");
|
|
File file= new File(upload.getResource().getLocalPath());
|
|
// return BucketOperator.getInstance(s3).putObject(bucket, Utils.convertToS3Format(upload.getResource().getRemotePath()), file).toString();
|
|
int hashcode=BucketOperator.getInstance(s3).putObject(bucket, Utils.convertToS3Format(upload.getResource().getRemotePath()), file).hashCode();
|
|
return hashcode+"";
|
|
}
|
|
|
|
@Override
|
|
public Map<String, StorageObject> getValues(MyFile resource, String bucket, Class<? extends Object> type) {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public void removeRemoteFile(String bucket, MyFile resource) throws UnknownHostException {
|
|
BucketOperator.getInstance(s3).deleteObject(this.bucket, Utils.convertToS3Format(resource.getRemotePath()));
|
|
|
|
}
|
|
|
|
@Override
|
|
public void removeDir(String remoteDir, MyFile myFile) throws UnknownHostException {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
|
|
}
|
|
|
|
@Override
|
|
public long getSize(String key, MyFile file) {
|
|
logger.info("remoteObject identifier "+key);
|
|
try {
|
|
return BucketOperator.getObjectSize(bucket, Utils.convertToS3Format(file.getRemotePath()));
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
throw new RemoteBackendException("Problem during getSize Operation on s3 cloud storage");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String lock(Lock lock) throws Exception {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public String unlock(Unlock unlock) throws FileNotFoundException, UnknownHostException, MongoException, Exception {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public long getTTL(String pathServer) throws UnknownHostException {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public long renewTTL(MyFile resource) throws UnknownHostException, IllegalAccessException {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public String link(Link link) throws UnknownHostException {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public String copy(Copy copy) throws UnknownHostException {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public String move(Move move) throws UnknownHostException {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public List<String> copyDir(CopyDir copy) throws UnknownHostException {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public List<String> moveDir(MoveDir move) throws UnknownHostException {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public String getFileProperty(String remotePath, String property) {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public long getFolderTotalItems(String folderPath) {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public long getFolderTotalVolume(String folderPath) {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public String getUserTotalVolume(String user) {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public String getUserTotalItems(String user) {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidId(String id) {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public String getId(String remoteIdentifier, boolean forceCreation) {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public String getField(String remoteIdentifier, String fieldName) throws UnknownHostException {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public void close() {
|
|
s3.close();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void setFileProperty(String remotePath, String propertyField, String propertyValue) {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
|
|
}
|
|
|
|
@Override
|
|
public String getRemotePath(String bucket) throws UnknownHostException {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public boolean exist(String bucket) {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
@Override
|
|
public String duplicateFile(DuplicateFile duplicate) {
|
|
throw new RemoteBackendException("method not implemented yet on s3 plugin");
|
|
}
|
|
|
|
}
|