2018-10-02 12:05:43 +02:00
|
|
|
package org.gcube.contentmanagement.blobstorage.service.operation;
|
|
|
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
|
2020-12-22 17:57:44 +01:00
|
|
|
import org.gcube.contentmanagement.blobstorage.resource.RequestObject;
|
2018-10-02 12:05:43 +02:00
|
|
|
import org.gcube.contentmanagement.blobstorage.service.directoryOperation.BucketCoding;
|
|
|
|
import org.gcube.contentmanagement.blobstorage.transport.TransportManager;
|
|
|
|
import org.gcube.contentmanagement.blobstorage.transport.TransportManagerFactory;
|
|
|
|
import org.gcube.contentmanagement.blobstorage.transport.backend.MongoIOManager;
|
|
|
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
public abstract class Link extends Operation{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logger for this class
|
|
|
|
*/
|
|
|
|
// private static final GCUBELog logger = new GCUBELog(Download.class);
|
|
|
|
final Logger logger=LoggerFactory.getLogger(Download.class);
|
|
|
|
private String sourcePath;
|
|
|
|
private String destinationPath;
|
2020-12-22 17:57:44 +01:00
|
|
|
private RequestObject resource;
|
2018-10-02 12:05:43 +02:00
|
|
|
public Link(String[] server, String user, String pwd, String bucket, Monitor monitor, boolean isChunk, String backendType, String[] dbs) {
|
|
|
|
super(server, user, pwd, bucket, monitor, isChunk, backendType, dbs);
|
|
|
|
}
|
|
|
|
|
2020-12-22 17:57:44 +01:00
|
|
|
public String initOperation(RequestObject file, String remotePath,
|
2018-10-02 12:05:43 +02:00
|
|
|
String author, String[] server, String rootArea, boolean replaceOption) {
|
|
|
|
this.sourcePath=file.getLocalPath();
|
|
|
|
this.destinationPath=remotePath;
|
|
|
|
sourcePath = new BucketCoding().bucketFileCoding(file.getLocalPath(), rootArea);
|
|
|
|
destinationPath = new BucketCoding().bucketFileCoding(remotePath, rootArea);
|
|
|
|
setResource(file);
|
|
|
|
return bucket=destinationPath;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-12-22 17:57:44 +01:00
|
|
|
public String doIt(RequestObject myFile) throws RemoteBackendException{
|
2020-11-12 18:11:07 +01:00
|
|
|
// TransportManagerFactory tmf= new TransportManagerFactory(server, user, password);
|
|
|
|
// TransportManager tm=tmf.getTransport(backendType, myFile.getGcubeMemoryType(), dbNames, myFile.getWriteConcern(), myFile.getReadPreference());
|
|
|
|
TransportManager tm=getTransport(myFile);
|
2018-10-02 12:05:43 +02:00
|
|
|
String id=null;
|
|
|
|
try {
|
|
|
|
id=tm.link(this);
|
|
|
|
} catch (UnknownHostException e) {
|
|
|
|
tm.close();
|
|
|
|
logger.error("Problem in link from: "+sourcePath+" to: "+destinationPath+": "+e.getMessage());
|
|
|
|
throw new RemoteBackendException(" Error in link operation ", e.getCause());
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2020-12-22 17:57:44 +01:00
|
|
|
public String initOperation(RequestObject resource, String remotePath,
|
2018-10-02 12:05:43 +02:00
|
|
|
String author, String[] server, String rootArea) {
|
|
|
|
// For terrastore, the name of bucket is formed: path_____fileName_____author
|
|
|
|
// String bucketName=new BucketCoding().bucketFileCoding(remotePath, rootArea);
|
|
|
|
this.sourcePath=resource.getLocalPath();
|
|
|
|
this.destinationPath=resource.getRemotePath();
|
|
|
|
setResource(resource);
|
|
|
|
sourcePath = new BucketCoding().bucketFileCoding(resource.getLocalPath(), rootArea);
|
|
|
|
destinationPath = new BucketCoding().bucketFileCoding(resource.getRemotePath(), rootArea);
|
|
|
|
return bucket=destinationPath;
|
|
|
|
}
|
|
|
|
|
2020-12-22 17:57:44 +01:00
|
|
|
public abstract String execute(MongoIOManager mongoPrimaryInstance, MongoIOManager mongoSecondaryInstance, RequestObject resource, String sourcePath, String destinationPath) throws UnknownHostException;
|
2018-10-02 12:05:43 +02:00
|
|
|
|
|
|
|
public String getSourcePath() {
|
|
|
|
return sourcePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSourcePath(String sourcePath) {
|
|
|
|
this.sourcePath = sourcePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDestinationPath() {
|
|
|
|
return destinationPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDestinationPath(String destinationPath) {
|
|
|
|
this.destinationPath = destinationPath;
|
|
|
|
}
|
|
|
|
|
2020-12-22 17:57:44 +01:00
|
|
|
public RequestObject getResource() {
|
2018-10-02 12:05:43 +02:00
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
2020-12-22 17:57:44 +01:00
|
|
|
public void setResource(RequestObject resource) {
|
2018-10-02 12:05:43 +02:00
|
|
|
this.resource = resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|