diff --git a/.classpath b/.classpath index 8374d7b..a28ec26 100644 --- a/.classpath +++ b/.classpath @@ -6,24 +6,21 @@ - - - - - + + - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 6249222..8445b6b 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,13 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.compliance=1.8 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.source=1.7 +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/CHANGELOG.md b/CHANGELOG.md index f0f16e9..0d1db47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,10 +12,14 @@ * fix JUnitTests * upgrade JUnit to 4.12 -## [v2.6.0-SNAPSHOT] 2020-11-12 - +## [v3.0.0] 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 +* moved from 2.6.1 to 3.0.0-SNAPSHOT ## [v2.5.3] 2019-03-20 * Added wrapper for HomeLibrary configuration related to the new preproduction infrastructure diff --git a/pom.xml b/pom.xml index 196225d..a3f7be1 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ org.gcube.distribution gcube-bom - 1.4.0 + 2.0.1 pom import @@ -62,6 +62,10 @@ 4.12 test + + org.slf4j + slf4j-api + org.slf4j slf4j-api diff --git a/src/main/java/org/gcube/contentmanager/storageclient/wrapper/Configuration.java b/src/main/java/org/gcube/contentmanager/storageclient/wrapper/Configuration.java index e5d955e..bb0d588 100644 --- a/src/main/java/org/gcube/contentmanager/storageclient/wrapper/Configuration.java +++ b/src/main/java/org/gcube/contentmanager/storageclient/wrapper/Configuration.java @@ -58,8 +58,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 diff --git a/src/main/java/org/gcube/contentmanager/storageclient/wrapper/ISClientConnector.java b/src/main/java/org/gcube/contentmanager/storageclient/wrapper/ISClientConnector.java index e3154d1..9a0750f 100644 --- a/src/main/java/org/gcube/contentmanager/storageclient/wrapper/ISClientConnector.java +++ b/src/main/java/org/gcube/contentmanager/storageclient/wrapper/ISClientConnector.java @@ -102,6 +102,7 @@ public class ISClientConnector { private String[] fillConnectionFields(ServiceEndpoint resource) { logger.debug("fillConnectionsFields method "); if(resource!=null){ +<<<<<<< HEAD logger.debug("checking resource "+resource.id()); ArrayList server=new ArrayList ();//new String[resource.profile().accessPoints().size()]; if(!(getBackendType().equals(BackendType.MongoDB.name()))) { @@ -133,6 +134,25 @@ public class ISClientConnector { // TODO Auto-generated catch block e.printStackTrace(); } +======= + ArrayList srvs=new ArrayList (); +// 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()); + // if presents, try to get user and password + setUsername(ap.username()); + // set password default value to empty string + setPassword(""); + if(getUsername() != null && getUsername().length() > 0){ + try { + setPassword(StringEncrypter.getEncrypter().decrypt(ap.password())); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); +>>>>>>> master } i++; } @@ -140,7 +160,13 @@ public class ISClientConnector { logger.info("credentials Mongodb: "+getUsername()+" "+getPassword()); // setBackendType(retrievePropertyValue(resource, "type")); } +<<<<<<< HEAD +======= + String [] server=new String[srvs.size()]; + server = srvs.toArray(server); + setBackendType(retrievePropertyValue(resource, "type")); +>>>>>>> master String [] volatileHost= new String [1]; volatileHost[0]=retrievePropertyValue(resource, "volatile"); setVolatileHost(volatileHost); @@ -303,4 +329,4 @@ public class ISClientConnector { } -} \ No newline at end of file +} diff --git a/src/test/java/org/gcube/contentmanager/storageclient/test/DownloadsTest.java b/src/test/java/org/gcube/contentmanager/storageclient/test/DownloadsTest.java index d8c4c4a..a818b51 100644 --- a/src/test/java/org/gcube/contentmanager/storageclient/test/DownloadsTest.java +++ b/src/test/java/org/gcube/contentmanager/storageclient/test/DownloadsTest.java @@ -39,8 +39,13 @@ public class DownloadsTest { private static String id1; private String encryptedId="OE5tOCtuTUt5eXVNd3JkRDlnRFpDY1h1MVVWaTg0cUtHbWJQNStIS0N6Yz0";//"SG1EN2JFNXIELzZ1czdsSkRIa0Evd3VzcGFHU3J6L2RHbWJQNStIS0N6Yz0";//"OE5tOCtuTUt5eXVNd3JkRDlnRFpDY1h1MVVWaTg0cUtHbWJQNStIS0N6Yz0";//"SThtL0xRU281M2UzY29ldE44SkhkbzVkMlBWVmM4aEJHbWJQNStIS0N6Yz0";//"dExaYzNKelNyQVZMemxpcXplVXYzZGN4OGZTQ2w4aU5HbWJQNStIS0N6Yz0";//"Mm9nc0tZbXR1TVI2cVRxL3pVUElrRXJkbk9vVDY2eEJHbWJQNStIS0N6Yz0";//"FemRmUEFtRGVZMnozcEdBekVHU3E4Skt5dkh2OXJObHFHbWJQNStIS0N6Yz0";//"L0p3OGJjUHhFaEJoTmppdjlsK0l0Z0h1b3VpVlloUzVHbWJQNStIS0N6Yz0";//"NWJTRFdxQkQxclJHV05FbExrRDJjL0g4QTBwSnV1TVdHbWJQNStIS0N6Yz0";//"M2JIM2hqNUNyRkxBdG00cnRaWDBpUGxRTmtVQmtEdXBHbWJQNStIS0N6Yz0";//"lfV6BqnBWUbN5dUiQ6xpkMgI69wEwcm6Ygh60bFzaL3h2Run5e9uZMoTix+ykL5H";//"huivj74/QCHnj376YGe/FicgYHSHcwph7SoMty7FBmAh+80AzGQtOdanne6zJBd5";//"lfV6BqnBWUbN5dUiQ6xpkMgI69wEwcm6Ygh60bFzaL3h2Run5e9uZMoTix+ykL5H";//"bksxMGVWTlZ3WjM5Z1ZXYXlUOUtMZzVSNlBhZXFGb05HbWJQNStIS0N6Yz0";//"bEVydmtsOHhCclZMZGd4cEtnTVQzZXQ5UVNxWHZURGJHbWJQNStIS0N6Yz0";//"bEVydmtsOHhCclZMZGd4cEtnTVQz";//"cHEvek1sbjdBaWJkc0s4SzZpSUJpU0c2ZEgyOEVyUGJHbWJQNStIS0N6Yz0";//"RnpoMy9ZaVRoRkZjbk8ybGx0QnlRR";//"L1pWTlV3ZWxPbHRyMloxZ0JnWUVHdHYvUnZDVHJiMTBHbWJQNStIS0N6Yz0"; +<<<<<<< HEAD @BeforeClass public static void getClient() throws RemoteBackendException{ +======= + @Before + public void getClient() throws RemoteBackendException{ +>>>>>>> master ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING); // ScopeProvider.instance.set(scope); try { @@ -61,7 +66,7 @@ public class DownloadsTest { } - @Test +// @Test public void getId(){ String id= client.getId(encryptedId); System.out.println("id decrypted: "+id); diff --git a/src/test/java/org/gcube/contentmanager/storageclient/test/ForceCloseTest.java b/src/test/java/org/gcube/contentmanager/storageclient/test/ForceCloseTest.java new file mode 100644 index 0000000..8e21926 --- /dev/null +++ b/src/test/java/org/gcube/contentmanager/storageclient/test/ForceCloseTest.java @@ -0,0 +1,125 @@ +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 list = printDir(remoteDirPath); + client.remove().RFile(remotePath); + list = printDir(remoteDirPath); + assertTrue(list.isEmpty()); + } + + private List printDir(String dir) { + List 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(); + } + + + +} diff --git a/src/test/java/org/gcube/contentmanager/storageclient/test/HLcheckTest.java b/src/test/java/org/gcube/contentmanager/storageclient/test/HLcheckTest.java index daf087b..f97a0b7 100644 --- a/src/test/java/org/gcube/contentmanager/storageclient/test/HLcheckTest.java +++ b/src/test/java/org/gcube/contentmanager/storageclient/test/HLcheckTest.java @@ -39,10 +39,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, scope, false).getClient(); + client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_SCOPE_STRING, false).getClient(); assertNotNull(client); } catch (Exception e) { // TODO Auto-generated catch block @@ -88,13 +88,19 @@ public class HLcheckTest { @Test public void downloadBySpecificIdOnlyForTest() throws RemoteBackendException{ +<<<<<<< HEAD // 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 file="/Users/roberto/VivianaOtero/detailed_simulation_4327.csv"; String idReturned=client.get().LFile(file).RFile("60830489d56b08199c3407c6"); +======= + 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"); +>>>>>>> master 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(); diff --git a/src/test/java/org/gcube/contentmanager/storageclient/test/LockTest.java b/src/test/java/org/gcube/contentmanager/storageclient/test/LockTest.java index a2cbbaf..12b9c7f 100644 --- a/src/test/java/org/gcube/contentmanager/storageclient/test/LockTest.java +++ b/src/test/java/org/gcube/contentmanager/storageclient/test/LockTest.java @@ -52,7 +52,7 @@ public class LockTest { assertNotNull(id); } - @Test +// @Test public void lockTest(){ //download & lock String idLock=client.lock().LFile(absoluteLocalPathDownload).RFile(remotePath); diff --git a/src/test/java/org/gcube/contentmanager/storageclient/test/UrlResolverTest.java b/src/test/java/org/gcube/contentmanager/storageclient/test/UrlResolverTest.java index 192cd36..8745e33 100644 --- a/src/test/java/org/gcube/contentmanager/storageclient/test/UrlResolverTest.java +++ b/src/test/java/org/gcube/contentmanager/storageclient/test/UrlResolverTest.java @@ -50,8 +50,8 @@ public class UrlResolverTest { } @Test - public void getHttpUrl() throws RemoteBackendException { - String url=client.getHttpUrl().RFile(remotePath); + public void getHttpsUrl() throws RemoteBackendException { + String url=client.getHttpsUrl().RFile(remotePath); System.out.println("HttpUrl generated: "+url); } diff --git a/src/test/resources/download.png b/src/test/resources/download.png index 7a0428e..26bfd6f 100644 Binary files a/src/test/resources/download.png and b/src/test/resources/download.png differ