Compare commits

..

5 Commits

17 changed files with 54 additions and 254 deletions

View File

@ -6,21 +6,24 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target/

View File

@ -1,13 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -1,12 +1,9 @@
# Changelog for storage-manager-wrapper
## [v2.6.1] 2021-09-10
* bug fix #20505
* update gcub-bom version
* Change serviceEndpoint Category from DataStorage to Storage
* bugfix #20505
* adding new constructor with the backendType as input parameter
* retrieving specific backend credentials if a specific backend si specified as input parameter
## [v2.5.4] 2022-07-07
* remove latest from bom
* replace slf4j-log4j dep with slf4j api
## [v2.5.3] 2019-03-20
* Added wrapper for HomeLibrary configuration related to the new preproduction infrastructure

View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<version>2.6.1</version>
<version>2.5.4</version>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
@ -22,7 +22,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>2.0.1</version>
<version>1.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -32,7 +32,7 @@
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
<version>[2.13.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<version>[2.9.0, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -0,0 +1,15 @@
log4j.rootLogger=DEBUG, A1, stdout
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=log.txt
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
# ***** Max file size is set to 100KB
log4j.appender.A1.MaxFileSize=100MB
# ***** Keep one backup file
log4j.appender.A1.MaxBackupIndex=1
#CONSOLE
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%t] %-5p %c %d{dd MMM yyyy ;HH:mm:ss.SSS} - %m%n

View File

@ -1,5 +0,0 @@
package org.gcube.contentmanager.storageclient.wrapper;
public enum BackendType {
MongoDB, S3
}

View File

@ -51,8 +51,8 @@ public class Configuration {
private static final String HL_CONTEXT = "/d4science.research-infrastructures.eu";
private static final String HL_CONTEXT_DEV = "/gcube";
private static final String HL_CONTEXT_PRE = "/pred4s";
protected static final String STORAGE_SERVICEENDPOINT_NAME="StorageManager";
protected static final String STORAGE_SERVICEENDPOINT_CATEGORY="Storage";
/**
* Loads all the configuration parameters in a java object
* @param sc: service class of the remote resource
@ -73,29 +73,6 @@ public class Configuration {
setScopeString(scopeString);
}
/**
* Loads all the configuration parameters in a java object for a specific backend
*
* @param sc: service class of the remote resource
* @param sn service name of the remote resource
* @param scopeString string that identifies the scope
* @param owner user of the client library
* @param clientID
* @param accessType indicates the type of access to the storage
* @param memory indicates the type of memory used by the storage: Persistent or Volatile
*
*/
public Configuration(String sc, String sn, String scopeString, String owner, String clientID, String accessType, String memory, BackendType backend){
this.sc=sc;
this.sn=sn;
this.owner=owner;
this.clientID=clientID;
this.typeAccess=accessType;
this.memoryType=memory;
setScopeString(scopeString);
setBackendType(backend.toString());
}
/**
* Retrieve a valid configuration from IS for instantiating the engine
*/

View File

@ -63,7 +63,7 @@ public class ISClientConnector {
ScopeProvider.instance.set(scope);
}
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq '"+Configuration.STORAGE_SERVICEENDPOINT_CATEGORY+"' and $resource/Profile/Name eq '"+Configuration.STORAGE_SERVICEENDPOINT_NAME+"' ");
query.addCondition("$resource/Profile/Category/text() eq 'DataStorage' and $resource/Profile/Name eq 'StorageManager' ");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
if(scope!=null){
@ -85,13 +85,11 @@ public class ISClientConnector {
private String[] fillConnectionFields(ServiceEndpoint resource) {
if(resource!=null){
ArrayList<String> srvs=new ArrayList <String>();
// String [] server=new String[resource.profile().accessPoints().size()];
String [] server=new String[resource.profile().accessPoints().size()];
int i=0;
for (AccessPoint ap:resource.profile().accessPoints()) {
if (ap.name().equals("server"+(i+1))) {
// server[i] = ap.address();
srvs.add(ap.address());
server[i] = ap.address();
// if presents, try to get user and password
setUsername(ap.username());
// set password default value to empty string
@ -107,8 +105,6 @@ public class ISClientConnector {
i++;
}
}
String [] server=new String[srvs.size()];
server = srvs.toArray(server);
setBackendType(retrievePropertyValue(resource, "type"));
String [] volatileHost= new String [1];
volatileHost[0]=retrievePropertyValue(resource, "volatile");

View File

@ -1,6 +1,6 @@
package org.gcube.contentmanager.storageclient.wrapper;
import org.gcube.contentmanager.storageclient.wrapper.BackendType;
//import org.gcube.contentmanagement.blobstorage.resource.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
//import org.gcube.contentmanagement.blobstorage.resource.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
@ -96,34 +96,6 @@ public class StorageClient {
}
/**
* New constructor with another optional argument created for gcube infrastructure internal use.
* Available in v1.6.0
* It's possible to specify a specific backend.
* @param ServiceClass
* @param ServiceName
* @param owner
* @param typeAccess
* @param scope
*/
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, BackendType backend){
checkScopeProvider();
String id=owner;
this.owner=owner;
this.scopeString=ScopeProvider.instance.get();
if(accessType!=null)
this.typeAccess=accessType;
else throw new RuntimeException("AccessType parameter must be not null");
this.memoryType=MemoryType.BOTH;
this.serviceClass=serviceClass;
this.serviceName=serviceName;
this.setBackendType(backend.toString());
setClientId(serviceClass, serviceName, id);
}
/**
* Constructor created for external use
* @param owner
@ -200,35 +172,6 @@ public class StorageClient {
}
/**
* Available in v1.6.0
* It's possible to specify a specific backend.
* @param ServiceClass
* @param ServiceName
* @param owner
* @param typeAccess
* @param backend: specify mongodb (default) or s3
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
* @param scope
*/
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, MemoryType memory, BackendType backend){
checkScopeProvider();
String id=owner;
this.owner=owner;
this.scopeString=ScopeProvider.instance.get();
if(accessType!=null)
this.typeAccess=accessType;
else throw new RuntimeException("AccessType parameter must be not null");
if(memory!=null)
this.memoryType=memory;
else throw new RuntimeException("MemoryType parameter must be not null");
this.serviceClass=serviceClass;
this.serviceName=serviceName;
setClientId(serviceClass, serviceName, id);
this.setBackendType(backend.toString());
}
/**
* Constructor with optional arguments server and memory
@ -427,7 +370,6 @@ public class StorageClient {
public String getBackendType() {
logger.debug("backend type returned is "+backendType);
return backendType;
}

View File

@ -29,7 +29,7 @@ public class DownloadsTest {
private String absoluteLocalPath;
private String newFilePath="src/test/resources";
private IClient client;
// private String scope="/d4science.research-infrastructures.eu"; //"/gcube";//"/gcube";//"/d4science.research-infrastructures.eu"; //"/gcube/devsec";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";// //"/CNR.it";// ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private String scope="/d4science.research-infrastructures.eu"; //"/gcube";//"/gcube";//"/d4science.research-infrastructures.eu"; //"/gcube/devsec";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";// //"/CNR.it";// ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private String serviceClass="JUnitTest";
private String serviceName="StorageManager";
private String NotExistingId="5a5c7d1d1b9b060285bbe2bd";
@ -39,8 +39,8 @@ public class DownloadsTest {
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
// ScopeProvider.instance.set(scope);
// ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
ScopeProvider.instance.set(scope);
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);
@ -58,7 +58,7 @@ public class DownloadsTest {
}
// @Test
@Test
public void getId(){
String id= client.getId(encryptedId);
System.out.println("id decrypted: "+id);

View File

@ -1,125 +0,0 @@
package org.gcube.contentmanager.storageclient.test;
import static org.junit.Assert.*;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ForceCloseTest {
private String owner="rcirillo";
private String localPath="src/test/resources/CostaRica.jpg";
private String localPath2="src/test/resources/dog.jpg";
private String localPathDownload="src/test/resources/download.png";
private String remotePath="/test/test-resources/CostaRica1.jpg";
private String absoluteLocalPath;
private String absoluteLocalPath2;
private String absoluteLocalPathDownload;
private String newFilePath="src/test/resources";
private String remoteDirPath= "test/test-forceclose";
private IClient client;
private String serviceClass="JUnitTest-ForceCloseTest";
private String serviceName="StorageManager";
private static final Logger logger = LoggerFactory.getLogger(ForceCloseTest.class);
@Before
public void getClient(){
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setLocalResources();
//upload costaRica
String id=client.put(true).LFile(absoluteLocalPath).RFile(remotePath);
System.out.println("UploadByPath id: "+id);
assertNotNull(id);
}
@Test
public void forceCloseTest(){
// try {
// Thread.sleep(10000);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
client.forceClose();
//download
try {
client.get().LFile(absoluteLocalPathDownload).RFile(remotePath);
}catch(Exception e ) {
assertNotNull(e);
}
// try {
// client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
// assertNotNull(client);
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// delete
removeRemoteFile();
client.forceClose();
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@After
public void removeLocalFile(){
File f=new File(newFilePath);
f.delete();
assertFalse(f.exists());
}
private void removeRemoteFile() throws RemoteBackendException{
List<StorageObject> list = printDir(remoteDirPath);
client.remove().RFile(remotePath);
list = printDir(remoteDirPath);
assertTrue(list.isEmpty());
}
private List<StorageObject> printDir(String dir) {
List<StorageObject> list=client.showDir().RDir(dir);
for(StorageObject obj : list){
System.out.println("found "+obj.getName()+" and id " +obj.getId());
}
return list;
}
private void setLocalResources() {
absoluteLocalPath=new File(localPath).getAbsolutePath();
String dir=new File(absoluteLocalPath).getParent();
newFilePath=dir+"/testJunit.jpg";
absoluteLocalPath=new File(localPath).getAbsolutePath();
absoluteLocalPath2=new File(localPath2).getAbsolutePath();
absoluteLocalPathDownload=new File(localPathDownload).getAbsolutePath();
}
}

View File

@ -30,7 +30,7 @@ public class HLcheckTest {
private String absoluteLocalPath;
private String newFilePath="src/test/resources";
private IClient client;
// private String scope="/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//Costants.DEFAULT_SCOPE_STRING;//"/gcube/devsec";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";// //"/CNR.it";// ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private String scope="/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//Costants.DEFAULT_SCOPE_STRING;//"/gcube/devsec";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";// //"/CNR.it";// ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private String serviceClass="org.gcube.portlets.user";//"JUnitTest";
private String serviceName="home-library";//"test-home-library";//"StorageManager";
private String id;
@ -38,10 +38,10 @@ public class HLcheckTest {
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
// ScopeProvider.instance.set(scope);
// ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
ScopeProvider.instance.set(scope);
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_SCOPE_STRING, false).getClient();
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, scope, false).getClient();
assertNotNull(client);
} catch (Exception e) {
// TODO Auto-generated catch block
@ -87,12 +87,12 @@ public class HLcheckTest {
@Test
public void downloadBySpecificIdOnlyForTest() throws RemoteBackendException{
String idReturned=client.get().LFile(newFilePath).RFileById(id);
// String file="/home/rcirillo-pc/Downloads/ce1159aa-a87f-4074-a3f9-36fe26d62f87-d4science.research-infrastructures.eu-gCubeApps-DESCRAMBLE.zip";
// String idReturned=client.get().LFile(absoluteLocalPath).RFile("5f6a1f405b0bde3544cbd3be");
// String idReturned=client.get().LFile(newFilePath).RFileById(id);
String file="/home/rcirillo-pc/Downloads/ce1159aa-a87f-4074-a3f9-36fe26d62f87-d4science.research-infrastructures.eu-gCubeApps-DESCRAMBLE.zip";
String idReturned=client.get().LFile(file).RFile("5f6a1f405b0bde3544cbd3be");
System.out.println("downloadById id: "+idReturned);
File f =new File(newFilePath);
// File f =new File(file);
// File f =new File(newFilePath);
File f =new File(file);
System.out.println("path new File downloaded: "+f.getAbsolutePath());
assertTrue(f.exists());
removeLocalFile();

View File

@ -52,7 +52,7 @@ public class LockTest {
assertNotNull(id);
}
// @Test
@Test
public void lockTest(){
//download & lock
String idLock=client.lock().LFile(absoluteLocalPathDownload).RFile(remotePath);

View File

@ -26,7 +26,7 @@ public class PropertiesTest {
private String absoluteLocalPath;
private String newFilePath="src/test/resources";
private IClient client;
// private String scope="/gcube/devsec"; //"/d4science.research-infrastructures.eu"; ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private String scope="/gcube/devsec"; //"/d4science.research-infrastructures.eu"; ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private String serviceClass="JUnitTest";
private String serviceName="StorageManager";
private String id;

View File

@ -14,7 +14,7 @@ import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
public final class Costants {
public static final MemoryType DEFAULT_MEMORY_TYPE = MemoryType.PERSISTENT;
public static final String DEFAULT_SCOPE_STRING="/gcube";
public static final String DEFAULT_SCOPE_STRING="/gcube/devsec";
public static final String DEFAULT_PASS_PHRASE="this is a phrasethis is a phrase";
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 346 KiB

After

Width:  |  Height:  |  Size: 220 KiB