diff --git a/distro/changelog.xml b/distro/changelog.xml index b9d9557..5de031c 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,7 @@ + + accounting user retrieved by IS + enabled ssl connection to mongodb diff --git a/pom.xml b/pom.xml index 07cd538..aa5bf05 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ org.gcube.contentmanagement storage-manager-trigger - 1.8.0-SNAPSHOT + 1.9.0-SNAPSHOT scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/${project.artifactId} scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/${project.artifactId} diff --git a/src/main/java/org/gcube/contentmanager/storageserver/data/ReadingMongoOplog.java b/src/main/java/org/gcube/contentmanager/storageserver/data/ReadingMongoOplog.java index 6e6b24d..bfde7da 100644 --- a/src/main/java/org/gcube/contentmanager/storageserver/data/ReadingMongoOplog.java +++ b/src/main/java/org/gcube/contentmanager/storageserver/data/ReadingMongoOplog.java @@ -145,7 +145,5 @@ public class ReadingMongoOplog extends Thread{ } } - - } diff --git a/src/main/java/org/gcube/contentmanager/storageserver/startup/Configuration.java b/src/main/java/org/gcube/contentmanager/storageserver/startup/Configuration.java index ce0cffd..85d9b5e 100644 --- a/src/main/java/org/gcube/contentmanager/storageserver/startup/Configuration.java +++ b/src/main/java/org/gcube/contentmanager/storageserver/startup/Configuration.java @@ -14,6 +14,7 @@ import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Endpoint; import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; import org.gcube.common.resources.gcore.ServiceEndpoint.Property; +import org.gcube.common.resources.gcore.utils.Group; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.contentmanager.storageserver.parse.utils.ValidationUtils; import org.gcube.resources.discovery.client.api.DiscoveryClient; @@ -30,6 +31,10 @@ public class Configuration { private String backendType; private ArrayList dtsHosts; private boolean activeDTSFilter; + private static final String SE_CATEGORY="DataStorage"; + private static final String SE_NAME="StorageManager"; + private static final String ACCOUNTING_USERNAME="accounting_user"; + private static final String ACCOUNTING_PASSWORDNAME="accounting_pwd"; Logger logger= LoggerFactory.getLogger(Configuration.class); public Configuration(String scope, String user, String password, boolean dtsFilter){ @@ -49,14 +54,14 @@ public class Configuration { } - public String[] getServerAccess(){ + public String[] getServerAccess(List resources){ String savedScope=null; if(scope!=null){ savedScope=ScopeProvider.instance.get(); ScopeProvider.instance.set(scope); } logger.debug("get server from IS "); - getServerRRFws(); + getServerRRFws(resources); if(scope!=null){ ScopeProvider.instance.set(savedScope); } @@ -64,11 +69,8 @@ public class Configuration { return server; } - public String[] getServerRRFws(){ - SimpleQuery query = queryFor(ServiceEndpoint.class); - query.addCondition("$resource/Profile/Category/text() eq 'DataStorage' and $resource/Profile/Name eq 'StorageManager' "); - DiscoveryClient client = clientFor(ServiceEndpoint.class); - List resources = client.submit(query); + public String[] getServerRRFws(List resources){ +// List resources = getStorageServiceEndpoint(); if(resources.size() > 1){ logger.info("found "+resources.size()+" RR "); // take the RR with property priority setted to DEFAULT @@ -83,6 +85,57 @@ public class Configuration { throw new RuntimeException("RUNTIME RESOURCE NOT FOUND IN SCOPE: "+ScopeProvider.instance.get()); } } + + /** + * The accounting user is retrieved from the first serviceEndpoint found in the scope and the first accessPoint inside the serviceEndpoint + * @param resources the serviceEndpoint list + * @return accounting username + */ + protected String getAccountingUser(List resources){ + logger.trace("retrieving access point"); + for (AccessPoint ap:resources.get(0).profile().accessPoints()) { + Mapmap= ap.propertyMap(); + Property user=map.get(ACCOUNTING_USERNAME); + if (user!=null){ + logger.debug("accounting user found on SE"); + return user.value(); + } + } + return null; + } + + /** + * The accounting password is retrieved from the first serviceEndpoint found in the scope and the first accessPoint inside the serviceEndpoint + * @param resources the serviceEndpoint list + * @return accounting password + */ + protected String getAccountingPassword(List resources){ + for (AccessPoint ap:resources.get(0).profile().accessPoints()) { + Mapmap= ap.propertyMap(); + Property pwd=map.get(ACCOUNTING_PASSWORDNAME); + if (pwd!=null){ + logger.debug("password field found on SE"); + try { + return StringEncrypter.getEncrypter().decrypt(pwd.value()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + return null; + } + + protected List getStorageServiceEndpoint() { + logger.debug("query for serviceEndpoint ongoing..."); + SimpleQuery query = queryFor(ServiceEndpoint.class); + query.addCondition("$resource/Profile/Category/text() eq '"+SE_CATEGORY+"' and $resource/Profile/Name eq '"+SE_NAME+"' "); + DiscoveryClient client = clientFor(ServiceEndpoint.class); + List resources = client.submit(query); + if (resources.size() > 0) + logger.debug("resource found on IS"); + return resources; + } private String[] getServers(ServiceEndpoint res) { server=new String[res.profile().accessPoints().size()]; diff --git a/src/main/java/org/gcube/contentmanager/storageserver/startup/Startup.java b/src/main/java/org/gcube/contentmanager/storageserver/startup/Startup.java index 5654e63..c1456c0 100644 --- a/src/main/java/org/gcube/contentmanager/storageserver/startup/Startup.java +++ b/src/main/java/org/gcube/contentmanager/storageserver/startup/Startup.java @@ -3,6 +3,7 @@ package org.gcube.contentmanager.storageserver.startup; import java.util.Arrays; import java.util.List; +import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.contentmanager.storageserver.consumer.FolderAccountingConsumer; import org.gcube.contentmanager.storageserver.consumer.UserAccountingConsumer; import org.gcube.contentmanager.storageserver.data.CubbyHole; @@ -12,8 +13,10 @@ public class Startup { private static String user; private static String password; + private static String accountingUser; + private static String accountingPassword; private static String scope; - + private static List se; public static void main(String[] args) { @@ -35,7 +38,12 @@ public class Startup { } scope=args[0]; String oplogServer= args[1]; +// user=args[2]; +// password=args[3]; Configuration cfg=new Configuration(scope, false); + se=cfg.getStorageServiceEndpoint(); + accountingUser=cfg.getAccountingUser(se); + accountingPassword=cfg.getAccountingPassword(se); String[] server=retrieveServerConfiguration(cfg); List dtsHosts=null;//retrieveDTSConfiguration(cfg); @@ -73,8 +81,8 @@ public class Startup { private static void startProducer(String[] args, String oplogServer, String[] server, CubbyHole c1, CubbyHole c2) { ReadingMongoOplog producer=null; - if((args.length == 4 )&& (args[2]!=null) && (args[3]!= null)) - producer=new ReadingMongoOplog( Arrays.asList(oplogServer), args[2], args[3], c1, c2, 1 ); + if((user !=null) && (password!= null)) + producer=new ReadingMongoOplog( Arrays.asList(oplogServer), accountingUser, accountingPassword, c1, c2, 1 ); else //if(args.length == 2) producer=new ReadingMongoOplog( Arrays.asList(server), c1, c2, 1 ); // else{ @@ -84,7 +92,7 @@ public class Startup { } private static String[] retrieveServerConfiguration(Configuration c) { - String[] server= c.getServerAccess(); + String[] server= c.getServerAccess(se); if(user == null) user=c.getUsername(); if(password == null) diff --git a/src/main/java/org/gcube/contentmanager/storageserver/store/MongoDB.java b/src/main/java/org/gcube/contentmanager/storageserver/store/MongoDB.java index 3dcc003..abf6620 100644 --- a/src/main/java/org/gcube/contentmanager/storageserver/store/MongoDB.java +++ b/src/main/java/org/gcube/contentmanager/storageserver/store/MongoDB.java @@ -40,6 +40,7 @@ public class MongoDB { protected static final WriteConcern WRITE_TYPE=WriteConcern.REPLICAS_SAFE; public MongoDB(String[] server, int port, String user, String password){ + logger.debug("MongoDB init with "+user+" "+password); this.server=server; this.port=port; this.pwd=password; @@ -51,6 +52,7 @@ public class MongoDB { } public MongoDB(String[] server, String user, String password){ + logger.debug("MongoDB init with "+user+" "+password); this.server=server; this.pwd=password; this.user=user; @@ -124,6 +126,7 @@ public class MongoDB { if(mongo==null){ logger.debug(" open mongo connection "); MongoClientOptions options=MongoClientOptions.builder().sslEnabled(true).connectionsPerHost(10).connectTimeout(30000).readPreference(READ_PREFERENCE).build(); +// MongoClientOptions options=MongoClientOptions.builder().connectionsPerHost(10).connectTimeout(30000).readPreference(READ_PREFERENCE).build(); if(((pwd != null) && (pwd.length() >0)) && ((user != null) && (user.length() > 0))){ MongoCredential credential = MongoCredential.createMongoCRCredential(user, ACCOUNTING_DB, pwd.toCharArray()); mongo = new MongoClient(srvList, Arrays.asList(credential), options); diff --git a/src/test/java/org/gcube/contentmanager/storageserver/startup/ConfigurationTest.java b/src/test/java/org/gcube/contentmanager/storageserver/startup/ConfigurationTest.java index c517de7..3f664af 100644 --- a/src/test/java/org/gcube/contentmanager/storageserver/startup/ConfigurationTest.java +++ b/src/test/java/org/gcube/contentmanager/storageserver/startup/ConfigurationTest.java @@ -1,6 +1,8 @@ package org.gcube.contentmanager.storageserver.startup; import java.util.List; + +import org.gcube.common.resources.gcore.ServiceEndpoint; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -21,7 +23,8 @@ public class ConfigurationTest { @Test public void serverAccess() { - Assert.assertNotNull(c.getServerAccess()); + List se=c.getStorageServiceEndpoint(); + Assert.assertNotNull(c.getServerAccess(se)); } diff --git a/src/test/java/org/gcube/contentmanager/storageserver/store/MongoDBTest.java b/src/test/java/org/gcube/contentmanager/storageserver/store/MongoDBTest.java index 265cada..9bb0fb2 100644 --- a/src/test/java/org/gcube/contentmanager/storageserver/store/MongoDBTest.java +++ b/src/test/java/org/gcube/contentmanager/storageserver/store/MongoDBTest.java @@ -11,6 +11,7 @@ public class MongoDBTest { @BeforeClass public static void init(){ mongo=new MongoDB(server, "devUser", "d3v_u534"); +// mongo=new MongoDB(server, "oplogger", "0pl0gg3r_d3v"); } // @Test