21411 #2

Merged
francesco.mangiacrapa merged 7 commits from 21411 into master 2021-09-21 12:39:54 +02:00
6 changed files with 75 additions and 42 deletions

View File

@ -27,6 +27,7 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

View File

@ -1,10 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="uri-resolver">
<wb-module deploy-name="uri-resolver-2.6.1-SNAPSHOT">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="storage-manager-wrapper-2.6.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/storage-manager-wrapper/storage-manager-wrapper">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="storage-manager-core-2.13.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/storage-manager-core/storage-manager-core">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="common-encryption-1.2.1.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/common-encryption/common-encryption">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="uri-resolver"/>
<property name="java-output-path" value="/uri-resolver/target/classes"/>
</wb-module>
</project-modules>

View File

@ -2,7 +2,7 @@
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.web" version="2.3"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.jaxrs" version="2.0"/>
<installed facet="jst.web" version="3.0"/>
</faceted-project>

View File

@ -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 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

View File

@ -9,7 +9,7 @@
</parent>
<groupId>org.gcube.data.transfer</groupId>
<artifactId>uri-resolver</artifactId>
<version>2.5.1-SNAPSHOT</version>
<version>2.6.1-SNAPSHOT</version>
<packaging>war</packaging>
<description>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.</description>
@ -58,7 +58,7 @@
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
<version>[2.6.1-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>

View File

@ -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;
@ -20,6 +21,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;
@ -48,11 +50,14 @@ 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";
protected static IClient storageManagerClient;
private static MemoryType memory;
/**
* Gets the storage id.
@ -123,21 +128,17 @@ 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);
storageId = identifyIdAndMemory(storageId);
IClient iClient = getStorageClientInstance(memory);
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);
}
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);
@ -187,10 +188,13 @@ public class StorageIDResolver {
// if (contentType!= null)
// response.header("Content-Type",contentType);
return response.build();
}
/**
@ -253,27 +257,22 @@ 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);
}
StorageClientInstance client = buildStorageClientInstance(storageId);
}
storageId = identifyIdAndMemory(storageId);
IClient iClient = getStorageClientInstance(memory);
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);
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);
}
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;
@ -328,37 +327,47 @@ public class StorageIDResolver {
.header("Content-Type", contentType)
.header(ConstantsResolver.CONTENT_LENGTH, size)
.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename=\""+fileName+"\"");
iClient.forceClose();
return response.build();
}
/**
* Builds the 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
* @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, "");
protected static IClient getStorageClientInstance(MemoryType memory) {
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, STORAGE_ACCESS_TYPE, memory, STORAGE_BACKEND_TYPE).getClient();
return storageManagerClient;
}
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);
return new StorageClientInstance(client, memory, storageId);
}
/**
* 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");
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.