Added new constructor in order to specify the Backend as input
parameter; upgraded to version: 3.0.0-SNAPSHOT
This commit is contained in:
parent
3fc8eda0a5
commit
c6819e84a5
2
pom.xml
2
pom.xml
|
@ -8,7 +8,7 @@
|
|||
</parent>
|
||||
<groupId>org.gcube.contentmanagement</groupId>
|
||||
<artifactId>storage-manager-wrapper</artifactId>
|
||||
<version>2.6.0-SNAPSHOT</version>
|
||||
<version>3.0.0-SNAPSHOT</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>
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
package org.gcube.contentmanager.storageclient.wrapper;
|
||||
|
||||
public enum BackendType {
|
||||
MongoDB, S3
|
||||
MongoDB, S3;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch(this) {
|
||||
case MongoDB: return "MongoDB";
|
||||
case S3: return "S3";
|
||||
default: throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class Configuration {
|
|||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Configuration.class);
|
||||
private static final String DEFAULT_BACKEND_TYPE="MongoDB";
|
||||
protected static final String DEFAULT_BACKEND_TYPE="MongoDB";
|
||||
private static final String WRITE_CONCERN_PROPERTY_NAME="write_concern";
|
||||
private static final String READ_PREFERENCE_PROPERTY_NAME="read_preference";
|
||||
private static final String DB_PROPERTY_NAME="collection";
|
||||
|
@ -114,16 +114,15 @@ public class Configuration {
|
|||
RRScope=currentScope;
|
||||
}
|
||||
logger.debug("RuntimeResource scope "+RRScope);
|
||||
ServiceEndpoint resource=getISClient().getStorageEndpoint(RRScope);
|
||||
|
||||
//in this case a specific backend type is passed as input parameter
|
||||
if (!Objects.isNull(getBackendType()))
|
||||
getISClient().setBackendType(getBackendType());
|
||||
//if a specific backend is not passed as input param then take the default one
|
||||
if (Objects.isNull(getBackendType()))
|
||||
setBackendType(DEFAULT_BACKEND_TYPE);
|
||||
ServiceEndpoint resource=getISClient(getBackendType()).getStorageEndpoint(RRScope);
|
||||
if(resource ==null )
|
||||
throw new IllegalStateException("the storage resource is not present on IS in scope: "+RRScope);
|
||||
List<ServiceEndpoint> resolverResource =getISClient().getServiceEndpoint(Utils.URI_RESOLVER_RESOURCE_CATEGORY, Utils.URI_RESOLVER_RESOURCE_NAME);
|
||||
List<ServiceEndpoint> resolverResource =getISClient(getBackendType()).getServiceEndpoint(Utils.URI_RESOLVER_RESOURCE_CATEGORY, Utils.URI_RESOLVER_RESOURCE_NAME);
|
||||
if(resolverResource !=null && resolverResource.size()> 0)
|
||||
setResolverHost(getISClient().getResolverHost(resolverResource.get(0)));
|
||||
setResolverHost(getISClient(getBackendType()).getResolverHost(resolverResource.get(0)));
|
||||
else
|
||||
throw new IllegalStateException("the uri resolver resource is not present on IS in scope: "+currentScope);
|
||||
// old method for retrieve hostedOn field in storage ServiceEndpoint resource
|
||||
|
@ -131,12 +130,12 @@ public class Configuration {
|
|||
logger.debug("server not set. Try to query IS in scope: "+scopeString);
|
||||
String[] serverFound=checkVarEnvMongo();
|
||||
if(serverFound==null){
|
||||
serverFound=getISClient().retrieveConnectionInfo(resource);
|
||||
setUser(getISClient().getUsername());
|
||||
setPassword(getISClient().password);
|
||||
setRegion(getISClient().getRegion());
|
||||
if (!Objects.isNull(getBackendType()))
|
||||
setBackendType(getISClient().getBackendType(resource));
|
||||
serverFound=getISClient(getBackendType()).retrieveConnectionInfo(resource);
|
||||
setUser(getISClient(getBackendType()).getUsername());
|
||||
setPassword(getISClient(getBackendType()).password);
|
||||
setRegion(getISClient(getBackendType()).getRegion());
|
||||
if (Objects.isNull(getBackendType()))
|
||||
setBackendType(getISClient(getBackendType()).getBackendType(resource));
|
||||
}else{
|
||||
if (!Objects.isNull(getBackendType()))
|
||||
setBackendType(checkVarEnvBackendType());
|
||||
|
@ -157,7 +156,7 @@ public class Configuration {
|
|||
}else{
|
||||
setEnvironment(setAreaStorage(getSc(), getSn()));
|
||||
// if the backend is mongodb we should set a separated server for volatile area
|
||||
if(getBackendType().equals(BackendType.MongoDB)) {
|
||||
if(getBackendType().equals("MongoDB")) {
|
||||
setServerHosts(newServer, isclient, resource);
|
||||
try {
|
||||
setPassPhrase(retrieveEncryptionField(PASS_PHRASE_FIELD));
|
||||
|
@ -250,11 +249,11 @@ public class Configuration {
|
|||
String dbString=null;
|
||||
// check optional properties only if it is not a volatile storage instance
|
||||
if((getMemoryType() != null) && (!(getMemoryType().equals(MemoryType.VOLATILE.toString())))){
|
||||
write=getISClient().retrievePropertyValue(WRITE_CONCERN_PROPERTY_NAME, currentScope);
|
||||
write=getISClient(getBackendType()).retrievePropertyValue(WRITE_CONCERN_PROPERTY_NAME, currentScope);
|
||||
logger.debug("read preference: read from service endpoint");
|
||||
read=getISClient().retrievePropertyValue(READ_PREFERENCE_PROPERTY_NAME, currentScope);
|
||||
read=getISClient(getBackendType()).retrievePropertyValue(READ_PREFERENCE_PROPERTY_NAME, currentScope);
|
||||
logger.debug(" write preference: read from service endpoint");
|
||||
dbString=getISClient().retrievePropertyValue(DB_PROPERTY_NAME, currentScope);
|
||||
dbString=getISClient(getBackendType()).retrievePropertyValue(DB_PROPERTY_NAME, currentScope);
|
||||
if((write!=null) && (read!=null)){
|
||||
engine.setWriteConcern(write);
|
||||
engine.setReadConcern(read);
|
||||
|
@ -273,7 +272,7 @@ public class Configuration {
|
|||
}
|
||||
// added db check also on volatile are
|
||||
}else if((getMemoryType().equals(MemoryType.VOLATILE.toString()))){
|
||||
dbString=getISClient().retrievePropertyValue(DB_PROPERTY_NAME, currentScope);
|
||||
dbString=getISClient(getBackendType()).retrievePropertyValue(DB_PROPERTY_NAME, currentScope);
|
||||
if(dbString!=null){
|
||||
if (dbString.contains(DB_STRING_SEPARATOR)){
|
||||
logger.debug("more than one collection read from ServiceEnpoint");
|
||||
|
@ -392,7 +391,7 @@ public class Configuration {
|
|||
String encryptedKey=null;
|
||||
// ISClientConnector isclient=getISClient();
|
||||
logger.info("retrieve encryption phrase from scope "+currentScope);
|
||||
encryptedKey=getISClient().retrievePropertyValue("PassPhrase", currentScope);
|
||||
encryptedKey=getISClient(getBackendType()).retrievePropertyValue("PassPhrase", currentScope);
|
||||
logger.info("encrypted prhase is "+encryptedKey);
|
||||
String decryptString=org.gcube.common.encryption.StringEncrypter.getEncrypter().decrypt(encryptedKey);
|
||||
return decryptString;
|
||||
|
@ -404,7 +403,7 @@ public class Configuration {
|
|||
String encryptedKey=null;
|
||||
// ISClientConnector isclient=getISClient();
|
||||
logger.info("retrieve encryption phrase from scope "+currentScope);
|
||||
encryptedKey=getISClient().retrievePropertyValue(fieldName, currentScope);
|
||||
encryptedKey=getISClient(getBackendType()).retrievePropertyValue(fieldName, currentScope);
|
||||
logger.info("encrypted prhase is "+encryptedKey);
|
||||
String decryptString=(!Objects.isNull(encryptedKey))?org.gcube.common.encryption.StringEncrypter.getEncrypter().decrypt(encryptedKey):null;
|
||||
return decryptString;
|
||||
|
@ -531,10 +530,14 @@ public class Configuration {
|
|||
this.resolverHost = resolverHost;
|
||||
}
|
||||
|
||||
public ISClientConnector getISClient(){
|
||||
if (isclient == null)
|
||||
isclient=new ISClientConnector();
|
||||
return isclient;
|
||||
private ISClientConnector getISClient(String backendType){
|
||||
// if ((isclient == null) || (isclient.getBackendType().equals(backendType)))
|
||||
// isclient=new ISClientConnector(backendType);
|
||||
//
|
||||
// return isclient;
|
||||
|
||||
return isclient=((isclient == null) || (!isclient.getBackendType().equals(backendType)))?new ISClientConnector(backendType):isclient;
|
||||
|
||||
}
|
||||
|
||||
public String getSc() {
|
||||
|
|
|
@ -40,6 +40,10 @@ public class ISClientConnector {
|
|||
public String region;
|
||||
private static HashMap<String, Object> isCache;
|
||||
|
||||
public ISClientConnector(String backendType){
|
||||
setBackendType(backendType);
|
||||
}
|
||||
|
||||
public ISClientConnector(){
|
||||
}
|
||||
|
||||
|
@ -91,13 +95,13 @@ public class ISClientConnector {
|
|||
logger.debug("fillConnectionsFields method ");
|
||||
if(resource!=null){
|
||||
logger.debug("checking resource "+resource.id());
|
||||
String [] server=new String[resource.profile().accessPoints().size()];
|
||||
if(!Objects.isNull(getBackendType())) {
|
||||
ArrayList<String> server=new ArrayList<String> ();//new String[resource.profile().accessPoints().size()];
|
||||
if(!(getBackendType().equals(BackendType.MongoDB.name()))) {
|
||||
logger.info("searching backend: "+getBackendType());
|
||||
for (AccessPoint ap:resource.profile().accessPoints()) {
|
||||
if((!getBackendType().equals(BackendType.MongoDB) && (ap.name().equals(getBackendType())))){
|
||||
if( (ap.name().equals(getBackendType()))){
|
||||
//in v1.6.0 we are considering only one accessPoint for a backend except for mongodb.
|
||||
server[0] = ap.address();
|
||||
server.add( ap.address());
|
||||
// if presents, try to get user and password
|
||||
setUsername(ap.username());
|
||||
decryptPwd(ap);
|
||||
|
@ -110,21 +114,32 @@ public class ISClientConnector {
|
|||
|
||||
for (AccessPoint ap:resource.profile().accessPoints()) {
|
||||
if (ap.name().equals("server"+(i+1))) {
|
||||
// in this case, the backend type has been set in the constructor hence we want to use this one
|
||||
// if presents, try to get user and password
|
||||
setUsername(ap.username());
|
||||
decryptPwd(ap);
|
||||
|
||||
server.add(ap.address());
|
||||
setUsername(ap.username());
|
||||
setPassword("");
|
||||
if(getUsername() != null && getUsername().length() > 0){
|
||||
try {
|
||||
setPassword(StringEncrypter.getEncrypter().decrypt(ap.password()));
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
setBackendType(retrievePropertyValue(resource, "type"));
|
||||
logger.info("credentials Mongodb: "+getUsername()+" "+getPassword());
|
||||
// setBackendType(retrievePropertyValue(resource, "type"));
|
||||
}
|
||||
|
||||
String [] volatileHost= new String [1];
|
||||
volatileHost[0]=retrievePropertyValue(resource, "volatile");
|
||||
setVolatileHost(volatileHost);
|
||||
logger.info("Type of backend found in RR is "+backendType);
|
||||
return server;
|
||||
String [] servers= new String[server.size()];
|
||||
servers=server.toArray(servers);
|
||||
return servers;
|
||||
|
||||
}else{
|
||||
throw new IllegalStateException("Runtime Resource found are more than 1 but all without default priority setted");
|
||||
|
@ -234,7 +249,7 @@ public class ISClientConnector {
|
|||
return backendType;
|
||||
}
|
||||
|
||||
public void setBackendType(String backendType) {
|
||||
private void setBackendType(String backendType) {
|
||||
this.backendType = backendType;
|
||||
}
|
||||
|
||||
|
|
|
@ -437,6 +437,8 @@ public class StorageClient {
|
|||
|
||||
|
||||
public String getBackendType() {
|
||||
if(Objects.isNull(backendType))
|
||||
backendType=Configuration.DEFAULT_BACKEND_TYPE;
|
||||
logger.debug("backend type returned is "+backendType);
|
||||
return backendType;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue