From d100ad4f139dfab0c0bf7a749107890cb0a10b29 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Thu, 2 Sep 2021 14:43:10 +0200 Subject: [PATCH 1/7] moved to version 2.6.1-SNAPSHOT. see 21411 --- .classpath | 1 + .settings/org.eclipse.wst.common.component | 20 ++++++++++++++++++- ....eclipse.wst.common.project.facet.core.xml | 2 +- CHANGELOG.md | 5 +++++ pom.xml | 4 ++-- .../resolver/services/StorageIDResolver.java | 4 ++-- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.classpath b/.classpath index 045159b..c3a4e8b 100644 --- a/.classpath +++ b/.classpath @@ -27,6 +27,7 @@ + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index cfa6374..2a94e7d 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,10 +1,28 @@ - + + + + + + + + uses + + + uses + + + uses + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index 8461581..e9d8776 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -2,7 +2,7 @@ - + diff --git a/CHANGELOG.md b/CHANGELOG.md index 7227e26..4f58699 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v2-6-1-SNAPSHOT] - 2021-09-02 + +**New features** + +[#21411] add forceClose method: closing mongodb connections for old https urls (by storage-manager) ## [v2-5-1-SNAPSHOT] - 2021-06-04 diff --git a/pom.xml b/pom.xml index 2f4a736..be4fa8e 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.data.transfer uri-resolver - 2.5.1-SNAPSHOT + 2.6.1-SNAPSHOT war The URI Resolver is an HTTP URI resolver implemented as an REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications. @@ -58,7 +58,7 @@ org.gcube.contentmanagement storage-manager-wrapper - [2.0.0, 3.0.0-SNAPSHOT) + [2.6.1-SNAPSHOT, 3.0.0-SNAPSHOT) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java index ccc76cf..05e61e8 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java @@ -187,7 +187,7 @@ public class StorageIDResolver { // if (contentType!= null) // response.header("Content-Type",contentType); - + iClient.forceClose(); return response.build(); } @@ -328,7 +328,7 @@ public class StorageIDResolver { .header("Content-Type", contentType) .header(ConstantsResolver.CONTENT_LENGTH, size) .header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename=\""+fileName+"\""); - + iClient.forceClose(); return response.build(); } -- 2.17.1 From 5fbf3e30917368a2cbd6072d20b730ca423ac57e Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Thu, 2 Sep 2021 15:29:58 +0200 Subject: [PATCH 2/7] force memoryType to persistent when it is not initialized --- .../datatransfer/resolver/services/StorageIDResolver.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java index 05e61e8..0d77782 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java @@ -350,11 +350,9 @@ public class StorageIDResolver { } StorageClient client; - if(memory==null) - client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC); - else - client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory); - + if(memory==null) + memory=MemoryType.PERSISTENT; + client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory); return new StorageClientInstance(client, memory, storageId); } -- 2.17.1 From 4e9354930cc7c5ee528546ca47310077b02e4194 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Thu, 2 Sep 2021 15:44:35 +0200 Subject: [PATCH 3/7] initialized storage-manager-client with backendType option --- .../datatransfer/resolver/services/StorageIDResolver.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java index 0d77782..8a4d4ab 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java @@ -20,6 +20,7 @@ import org.apache.http.HttpStatus; import org.gcube.contentmanagement.blobstorage.resource.MyFile; import org.gcube.contentmanagement.blobstorage.service.IClient; import org.gcube.contentmanager.storageclient.wrapper.AccessType; +import org.gcube.contentmanager.storageclient.wrapper.BackendType; import org.gcube.contentmanager.storageclient.wrapper.MemoryType; import org.gcube.contentmanager.storageclient.wrapper.StorageClient; import org.gcube.datatransfer.resolver.ConstantsResolver; @@ -352,7 +353,7 @@ public class StorageIDResolver { StorageClient client; if(memory==null) memory=MemoryType.PERSISTENT; - client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory); + client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory, BackendType.MongoDB); return new StorageClientInstance(client, memory, storageId); } -- 2.17.1 From 9d128ce1a0e0a92e4c5c2301565963f786153f1b Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Fri, 3 Sep 2021 10:39:38 +0200 Subject: [PATCH 4/7] replace buildStorageClientInstance method, with getStorageClientInstance method --- .../resolver/services/StorageIDResolver.java | 108 +++++++++++++----- 1 file changed, 82 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java index 8a4d4ab..73a9492 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java @@ -2,6 +2,7 @@ package org.gcube.datatransfer.resolver.services; import java.io.IOException; import java.io.InputStream; +import java.util.Objects; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; @@ -54,6 +55,7 @@ public class StorageIDResolver { private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver"; + protected static IClient storageManagerClient; /** * Gets the storage id. @@ -124,20 +126,35 @@ public class StorageIDResolver { LOG.error("storageId not found"); throw ExceptionManager.badRequestException(httpRequest, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help); } - - StorageClientInstance scInstance = buildStorageClientInstance(storageId); +/** START PATCH 2.6.1-SNAPSHOT **/ +// StorageClientInstance scInstance = buildStorageClientInstance(storageId); +// String toSEID = null; +// IClient iClient = null; +// storageId = scInstance.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT' +// LOG.info("I'm using the storageId {}",storageId); +// try{ +// iClient = scInstance.getStorageClient().getClient(); +// toSEID = iClient.getId(storageId); //to Storage Encrypted ID +// LOG.info("Decoded ID"+" = "+ toSEID); +// }catch(Exception e){ +// LOG.error("Storage Client Exception when getting file from storage: ", e); +// throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); +// } + + + IClient iClient = getStorageClientInstance(storageId); String toSEID = null; - IClient iClient = null; - storageId = scInstance.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT' LOG.info("I'm using the storageId {}",storageId); try{ - iClient = scInstance.getStorageClient().getClient(); toSEID = iClient.getId(storageId); //to Storage Encrypted ID LOG.info("Decoded ID"+" = "+ toSEID); }catch(Exception e){ LOG.error("Storage Client Exception when getting file from storage: ", e); throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); } + +/** END PATCH 2.6.1-SNAPSHOT **/ + if(toSEID==null || toSEID.isEmpty()){ LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!"); @@ -188,7 +205,7 @@ public class StorageIDResolver { // if (contentType!= null) // response.header("Content-Type",contentType); - iClient.forceClose(); + return response.build(); } @@ -255,20 +272,34 @@ public class StorageIDResolver { LOG.warn("storageId not found"); throw ExceptionManager.badRequestException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, this.getClass(), help); } - StorageClientInstance client = buildStorageClientInstance(storageId); - String toSEID = null; - IClient iClient = null; - storageId = client.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT' - LOG.info("I'm using the storageId {}",storageId); +/** START PATCH 2.6.1-SNAPSHOT **/ +// StorageClientInstance scInstance = buildStorageClientInstance(storageId); +// String toSEID = null; +// IClient iClient = null; +// storageId = scInstance.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT' +// LOG.info("I'm using the storageId {}",storageId); +// try{ +// iClient = scInstance.getStorageClient().getClient(); +// toSEID = iClient.getId(storageId); //to Storage Encrypted ID +// LOG.info("Decoded ID"+" = "+ toSEID); +// }catch(Exception e){ +// LOG.error("Storage Client Exception when getting file from storage: ", e); +// throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); +// } + + IClient iClient = getStorageClientInstance(storageId); + String toSEID = null; + LOG.info("I'm using the storageId {}",storageId); try{ - iClient = client.getStorageClient().getClient(); toSEID = iClient.getId(storageId); //to Storage Encrypted ID - LOG.debug("Decoded ID"+" = "+ toSEID); + LOG.info("Decoded ID"+" = "+ toSEID); }catch(Exception e){ LOG.error("Storage Client Exception when getting file from storage: ", e); - throw ExceptionManager.internalErrorException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); + throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); } + +/** END PATCH 2.6.1-SNAPSHOT **/ if(toSEID==null || toSEID.isEmpty()){ LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!"); @@ -335,30 +366,55 @@ public class StorageIDResolver { } +// /** +// * Builds the storage client instance. +// * +// * @param storageId the storage id +// * @return the storage client instance +// * @throws Exception the exception +// */ +// protected static StorageClientInstance buildStorageClientInstance(String storageId) throws Exception{ +// +// MemoryType memory=null; +// if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){ +// memory=MemoryType.VOLATILE; +// storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, ""); +// } +// +// StorageClient client; +// if(memory==null) +// memory=MemoryType.PERSISTENT; +// client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory, BackendType.MongoDB); +// return new StorageClientInstance(client, memory, storageId); +// } + /** - * Builds the storage client instance. + * Get a storage client instance. * * @param storageId the storage id * @return the storage client instance - * @throws Exception the exception */ - protected static StorageClientInstance buildStorageClientInstance(String storageId) throws Exception{ - + protected static IClient getStorageClientInstance(String storageId) { MemoryType memory=null; if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){ memory=MemoryType.VOLATILE; storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, ""); - } - - StorageClient client; - if(memory==null) + }else { memory=MemoryType.PERSISTENT; - client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory, BackendType.MongoDB); - return new StorageClientInstance(client, memory, storageId); + } + if ((!Objects.isNull(storageManagerClient)) && (storageManagerClient.getGcubeMemoryType().equals(memory))) + return storageManagerClient; + else { + if(!Objects.isNull(storageManagerClient)) { + LOG.debug("going to close an old storage-client instance"); + storageManagerClient.forceClose(); + } + LOG.debug("initializing a new storage-client instance"); + storageManagerClient=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory, BackendType.MongoDB).getClient(); + return storageManagerClient; + } } - - /** * Gets the storage metadata file. * -- 2.17.1 From b64bb2fe4598f94dbc8a78d77d55fd5eea4d9f2b Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Fri, 3 Sep 2021 11:13:41 +0200 Subject: [PATCH 5/7] add identifyId private method --- .../resolver/services/StorageIDResolver.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java index 73a9492..2e132d6 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java @@ -56,6 +56,7 @@ public class StorageIDResolver { private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver"; protected static IClient storageManagerClient; + private static MemoryType memory; /** * Gets the storage id. @@ -140,9 +141,8 @@ public class StorageIDResolver { // LOG.error("Storage Client Exception when getting file from storage: ", e); // throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); // } - - - IClient iClient = getStorageClientInstance(storageId); + storageId = identifyIdAndMemory(storageId); + IClient iClient = getStorageClientInstance(memory); String toSEID = null; LOG.info("I'm using the storageId {}",storageId); try{ @@ -209,6 +209,9 @@ public class StorageIDResolver { return response.build(); } + + + /** @@ -288,7 +291,8 @@ public class StorageIDResolver { // } - IClient iClient = getStorageClientInstance(storageId); + storageId = identifyIdAndMemory(storageId); + IClient iClient = getStorageClientInstance(memory); String toSEID = null; LOG.info("I'm using the storageId {}",storageId); try{ @@ -394,14 +398,7 @@ public class StorageIDResolver { * @param storageId the storage id * @return the storage client instance */ - protected static IClient getStorageClientInstance(String storageId) { - MemoryType memory=null; - if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){ - memory=MemoryType.VOLATILE; - storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, ""); - }else { - memory=MemoryType.PERSISTENT; - } + protected static IClient getStorageClientInstance(MemoryType memory) { if ((!Objects.isNull(storageManagerClient)) && (storageManagerClient.getGcubeMemoryType().equals(memory))) return storageManagerClient; else { @@ -415,6 +412,17 @@ public class StorageIDResolver { } } + private static String identifyIdAndMemory(String storageId) { + if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){ + LOG.info("identificated a VOLATILE url"); + memory=MemoryType.VOLATILE; + storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, ""); + }else { + memory=MemoryType.PERSISTENT; + } + return storageId; + } + /** * Gets the storage metadata file. * -- 2.17.1 From 3ec3a05cfcb2aa9bd1dcbb96bba7cde0001d5c28 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Fri, 3 Sep 2021 15:43:47 +0200 Subject: [PATCH 6/7] add some costants and comments to the code --- .../resolver/services/StorageIDResolver.java | 78 +++---------------- 1 file changed, 12 insertions(+), 66 deletions(-) diff --git a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java index 2e132d6..cac6917 100644 --- a/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java +++ b/src/main/java/org/gcube/datatransfer/resolver/services/StorageIDResolver.java @@ -50,7 +50,8 @@ public class StorageIDResolver { */ protected static final String STORAGEID_RESOLVER = "storageid-resolver"; private static final String STORAGE_ID = "storage-id"; - + private static final AccessType STORAGE_ACCESS_TYPE=AccessType.PUBLIC; + private static final BackendType STORAGE_BACKEND_TYPE=BackendType.MongoDB; private static final Logger LOG = LoggerFactory.getLogger(StorageIDResolver.class); private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver"; @@ -127,20 +128,6 @@ public class StorageIDResolver { LOG.error("storageId not found"); throw ExceptionManager.badRequestException(httpRequest, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help); } -/** START PATCH 2.6.1-SNAPSHOT **/ -// StorageClientInstance scInstance = buildStorageClientInstance(storageId); -// String toSEID = null; -// IClient iClient = null; -// storageId = scInstance.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT' -// LOG.info("I'm using the storageId {}",storageId); -// try{ -// iClient = scInstance.getStorageClient().getClient(); -// toSEID = iClient.getId(storageId); //to Storage Encrypted ID -// LOG.info("Decoded ID"+" = "+ toSEID); -// }catch(Exception e){ -// LOG.error("Storage Client Exception when getting file from storage: ", e); -// throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); -// } storageId = identifyIdAndMemory(storageId); IClient iClient = getStorageClientInstance(memory); String toSEID = null; @@ -152,10 +139,6 @@ public class StorageIDResolver { LOG.error("Storage Client Exception when getting file from storage: ", e); throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); } - -/** END PATCH 2.6.1-SNAPSHOT **/ - - if(toSEID==null || toSEID.isEmpty()){ LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!"); throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help); @@ -274,23 +257,7 @@ public class StorageIDResolver { if (storageId == null || storageId.isEmpty()) { LOG.warn("storageId not found"); throw ExceptionManager.badRequestException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, this.getClass(), help); - } -/** START PATCH 2.6.1-SNAPSHOT **/ -// StorageClientInstance scInstance = buildStorageClientInstance(storageId); -// String toSEID = null; -// IClient iClient = null; -// storageId = scInstance.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT' -// LOG.info("I'm using the storageId {}",storageId); -// try{ -// iClient = scInstance.getStorageClient().getClient(); -// toSEID = iClient.getId(storageId); //to Storage Encrypted ID -// LOG.info("Decoded ID"+" = "+ toSEID); -// }catch(Exception e){ -// LOG.error("Storage Client Exception when getting file from storage: ", e); -// throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); -// } - - + } storageId = identifyIdAndMemory(storageId); IClient iClient = getStorageClientInstance(memory); String toSEID = null; @@ -302,14 +269,10 @@ public class StorageIDResolver { LOG.error("Storage Client Exception when getting file from storage: ", e); throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help); } - -/** END PATCH 2.6.1-SNAPSHOT **/ - if(toSEID==null || toSEID.isEmpty()){ LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!"); throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help); } - //SETTING DEFAULT METADATA String fileName = ConstantsResolver.DEFAULT_FILENAME_FROM_STORAGE_MANAGER; String contentType = ConstantsResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN; @@ -368,34 +331,12 @@ public class StorageIDResolver { return response.build(); } - - -// /** -// * Builds the storage client instance. -// * -// * @param storageId the storage id -// * @return the storage client instance -// * @throws Exception the exception -// */ -// protected static StorageClientInstance buildStorageClientInstance(String storageId) throws Exception{ -// -// MemoryType memory=null; -// if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){ -// memory=MemoryType.VOLATILE; -// storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, ""); -// } -// -// StorageClient client; -// if(memory==null) -// memory=MemoryType.PERSISTENT; -// client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory, BackendType.MongoDB); -// return new StorageClientInstance(client, memory, storageId); -// } /** - * Get a storage client instance. + * Get a storage-manager client instance. A new storage instance will be instantied only if the memory type is not the same of the previous one. + * In this case the old connection will be closed. * - * @param storageId the storage id + * @param memoryType indicates the memory type (Persistent, Volatile or whatever) * @return the storage client instance */ protected static IClient getStorageClientInstance(MemoryType memory) { @@ -407,11 +348,16 @@ public class StorageIDResolver { storageManagerClient.forceClose(); } LOG.debug("initializing a new storage-client instance"); - storageManagerClient=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory, BackendType.MongoDB).getClient(); + storageManagerClient=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, STORAGE_ACCESS_TYPE, memory, STORAGE_BACKEND_TYPE).getClient(); return storageManagerClient; } } + /** + * Set the right memory type extrapolated from the storageid + * @param storageId storageid with backend type specification (if present) + * @return storageId without backend type specification + */ private static String identifyIdAndMemory(String storageId) { if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){ LOG.info("identificated a VOLATILE url"); -- 2.17.1 From 261dbbe2780cea6557b4dfd2f25eeb1d7971c6af Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Fri, 3 Sep 2021 15:48:42 +0200 Subject: [PATCH 7/7] update changelog description --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f58699..15d1787 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm **New features** -[#21411] add forceClose method: closing mongodb connections for old https urls (by storage-manager) +[#21411] add forceClose method from storage-manager, used for closing mongodb connections related to the old https urls (managed by storage-manager) ## [v2-5-1-SNAPSHOT] - 2021-06-04 -- 2.17.1