replace buildStorageClientInstance method, with getStorageClientInstance method
This commit is contained in:
parent
4e9354930c
commit
9d128ce1a0
|
@ -2,6 +2,7 @@ package org.gcube.datatransfer.resolver.services;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.GET;
|
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";
|
private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver";
|
||||||
|
|
||||||
|
protected static IClient storageManagerClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the storage id.
|
* Gets the storage id.
|
||||||
|
@ -124,20 +126,35 @@ public class StorageIDResolver {
|
||||||
LOG.error("storageId not found");
|
LOG.error("storageId not found");
|
||||||
throw ExceptionManager.badRequestException(httpRequest, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help);
|
throw ExceptionManager.badRequestException(httpRequest, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
|
/** START PATCH 2.6.1-SNAPSHOT **/
|
||||||
StorageClientInstance scInstance = buildStorageClientInstance(storageId);
|
// 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;
|
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);
|
LOG.info("I'm using the storageId {}",storageId);
|
||||||
try{
|
try{
|
||||||
iClient = scInstance.getStorageClient().getClient();
|
|
||||||
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
||||||
LOG.info("Decoded ID"+" = "+ toSEID);
|
LOG.info("Decoded ID"+" = "+ toSEID);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
LOG.error("Storage Client Exception when getting file from storage: ", 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);
|
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()){
|
if(toSEID==null || toSEID.isEmpty()){
|
||||||
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
||||||
|
@ -188,7 +205,7 @@ public class StorageIDResolver {
|
||||||
|
|
||||||
// if (contentType!= null)
|
// if (contentType!= null)
|
||||||
// response.header("Content-Type",contentType);
|
// response.header("Content-Type",contentType);
|
||||||
iClient.forceClose();
|
|
||||||
return response.build();
|
return response.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -255,20 +272,34 @@ public class StorageIDResolver {
|
||||||
LOG.warn("storageId not found");
|
LOG.warn("storageId not found");
|
||||||
throw ExceptionManager.badRequestException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, this.getClass(), help);
|
throw ExceptionManager.badRequestException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, this.getClass(), help);
|
||||||
}
|
}
|
||||||
StorageClientInstance client = buildStorageClientInstance(storageId);
|
/** START PATCH 2.6.1-SNAPSHOT **/
|
||||||
String toSEID = null;
|
// StorageClientInstance scInstance = buildStorageClientInstance(storageId);
|
||||||
IClient iClient = null;
|
// String toSEID = null;
|
||||||
storageId = client.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT'
|
// IClient iClient = null;
|
||||||
LOG.info("I'm using the storageId {}",storageId);
|
// 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{
|
try{
|
||||||
iClient = client.getStorageClient().getClient();
|
|
||||||
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
||||||
LOG.debug("Decoded ID"+" = "+ toSEID);
|
LOG.info("Decoded ID"+" = "+ toSEID);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
LOG.error("Storage Client Exception when getting file from storage: ", 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()){
|
if(toSEID==null || toSEID.isEmpty()){
|
||||||
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
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
|
* @param storageId the storage id
|
||||||
* @return the storage client instance
|
* @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;
|
MemoryType memory=null;
|
||||||
if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){
|
if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){
|
||||||
memory=MemoryType.VOLATILE;
|
memory=MemoryType.VOLATILE;
|
||||||
storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, "");
|
storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, "");
|
||||||
}
|
}else {
|
||||||
|
|
||||||
StorageClient client;
|
|
||||||
if(memory==null)
|
|
||||||
memory=MemoryType.PERSISTENT;
|
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.
|
* Gets the storage metadata file.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue