accounting user retrieved by IS

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/storage-manager-trigger@179728 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
roberto.cirillo 2019-06-06 15:50:43 +00:00
parent 7d899c997b
commit a0c234ab0e
8 changed files with 84 additions and 15 deletions

View File

@ -1,4 +1,7 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.content-management.storage-manager-trigger.1-9-0" date="2019-06-06">
<Change>accounting user retrieved by IS</Change>
</Changeset>
<Changeset component="org.gcube.content-management.storage-manager-trigger.1-8-0" date="2018-10-01"> <Changeset component="org.gcube.content-management.storage-manager-trigger.1-8-0" date="2018-10-01">
<Change>enabled ssl connection to mongodb</Change> <Change>enabled ssl connection to mongodb</Change>
</Changeset> </Changeset>

View File

@ -8,7 +8,7 @@
</parent> </parent>
<groupId>org.gcube.contentmanagement</groupId> <groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-trigger</artifactId> <artifactId>storage-manager-trigger</artifactId>
<version>1.8.0-SNAPSHOT</version> <version>1.9.0-SNAPSHOT</version>
<scm> <scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/${project.artifactId}</connection> <connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/${project.artifactId}</connection>
<developerConnection>scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/${project.artifactId}</developerConnection> <developerConnection>scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/${project.artifactId}</developerConnection>

View File

@ -145,7 +145,5 @@ public class ReadingMongoOplog extends Thread{
} }
} }
} }

View File

@ -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;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Property; 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.common.scope.api.ScopeProvider;
import org.gcube.contentmanager.storageserver.parse.utils.ValidationUtils; import org.gcube.contentmanager.storageserver.parse.utils.ValidationUtils;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
@ -30,6 +31,10 @@ public class Configuration {
private String backendType; private String backendType;
private ArrayList<String> dtsHosts; private ArrayList<String> dtsHosts;
private boolean activeDTSFilter; 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); Logger logger= LoggerFactory.getLogger(Configuration.class);
public Configuration(String scope, String user, String password, boolean dtsFilter){ public Configuration(String scope, String user, String password, boolean dtsFilter){
@ -49,14 +54,14 @@ public class Configuration {
} }
public String[] getServerAccess(){ public String[] getServerAccess(List<ServiceEndpoint> resources){
String savedScope=null; String savedScope=null;
if(scope!=null){ if(scope!=null){
savedScope=ScopeProvider.instance.get(); savedScope=ScopeProvider.instance.get();
ScopeProvider.instance.set(scope); ScopeProvider.instance.set(scope);
} }
logger.debug("get server from IS "); logger.debug("get server from IS ");
getServerRRFws(); getServerRRFws(resources);
if(scope!=null){ if(scope!=null){
ScopeProvider.instance.set(savedScope); ScopeProvider.instance.set(savedScope);
} }
@ -64,11 +69,8 @@ public class Configuration {
return server; return server;
} }
public String[] getServerRRFws(){ public String[] getServerRRFws(List<ServiceEndpoint> resources){
SimpleQuery query = queryFor(ServiceEndpoint.class); // List<ServiceEndpoint> resources = getStorageServiceEndpoint();
query.addCondition("$resource/Profile/Category/text() eq 'DataStorage' and $resource/Profile/Name eq 'StorageManager' ");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
if(resources.size() > 1){ if(resources.size() > 1){
logger.info("found "+resources.size()+" RR "); logger.info("found "+resources.size()+" RR ");
// take the RR with property priority setted to DEFAULT // 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()); 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<ServiceEndpoint> resources){
logger.trace("retrieving access point");
for (AccessPoint ap:resources.get(0).profile().accessPoints()) {
Map<String, Property>map= 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<ServiceEndpoint> resources){
for (AccessPoint ap:resources.get(0).profile().accessPoints()) {
Map<String, Property>map= 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<ServiceEndpoint> 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<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
if (resources.size() > 0)
logger.debug("resource found on IS");
return resources;
}
private String[] getServers(ServiceEndpoint res) { private String[] getServers(ServiceEndpoint res) {
server=new String[res.profile().accessPoints().size()]; server=new String[res.profile().accessPoints().size()];

View File

@ -3,6 +3,7 @@ package org.gcube.contentmanager.storageserver.startup;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.contentmanager.storageserver.consumer.FolderAccountingConsumer; import org.gcube.contentmanager.storageserver.consumer.FolderAccountingConsumer;
import org.gcube.contentmanager.storageserver.consumer.UserAccountingConsumer; import org.gcube.contentmanager.storageserver.consumer.UserAccountingConsumer;
import org.gcube.contentmanager.storageserver.data.CubbyHole; import org.gcube.contentmanager.storageserver.data.CubbyHole;
@ -12,8 +13,10 @@ public class Startup {
private static String user; private static String user;
private static String password; private static String password;
private static String accountingUser;
private static String accountingPassword;
private static String scope; private static String scope;
private static List<ServiceEndpoint> se;
public static void main(String[] args) { public static void main(String[] args) {
@ -35,7 +38,12 @@ public class Startup {
} }
scope=args[0]; scope=args[0];
String oplogServer= args[1]; String oplogServer= args[1];
// user=args[2];
// password=args[3];
Configuration cfg=new Configuration(scope, false); Configuration cfg=new Configuration(scope, false);
se=cfg.getStorageServiceEndpoint();
accountingUser=cfg.getAccountingUser(se);
accountingPassword=cfg.getAccountingPassword(se);
String[] server=retrieveServerConfiguration(cfg); String[] server=retrieveServerConfiguration(cfg);
List<String> dtsHosts=null;//retrieveDTSConfiguration(cfg); List<String> dtsHosts=null;//retrieveDTSConfiguration(cfg);
@ -73,8 +81,8 @@ public class Startup {
private static void startProducer(String[] args, String oplogServer, private static void startProducer(String[] args, String oplogServer,
String[] server, CubbyHole c1, CubbyHole c2) { String[] server, CubbyHole c1, CubbyHole c2) {
ReadingMongoOplog producer=null; ReadingMongoOplog producer=null;
if((args.length == 4 )&& (args[2]!=null) && (args[3]!= null)) if((user !=null) && (password!= null))
producer=new ReadingMongoOplog( Arrays.asList(oplogServer), args[2], args[3], c1, c2, 1 ); producer=new ReadingMongoOplog( Arrays.asList(oplogServer), accountingUser, accountingPassword, c1, c2, 1 );
else //if(args.length == 2) else //if(args.length == 2)
producer=new ReadingMongoOplog( Arrays.asList(server), c1, c2, 1 ); producer=new ReadingMongoOplog( Arrays.asList(server), c1, c2, 1 );
// else{ // else{
@ -84,7 +92,7 @@ public class Startup {
} }
private static String[] retrieveServerConfiguration(Configuration c) { private static String[] retrieveServerConfiguration(Configuration c) {
String[] server= c.getServerAccess(); String[] server= c.getServerAccess(se);
if(user == null) if(user == null)
user=c.getUsername(); user=c.getUsername();
if(password == null) if(password == null)

View File

@ -40,6 +40,7 @@ public class MongoDB {
protected static final WriteConcern WRITE_TYPE=WriteConcern.REPLICAS_SAFE; protected static final WriteConcern WRITE_TYPE=WriteConcern.REPLICAS_SAFE;
public MongoDB(String[] server, int port, String user, String password){ public MongoDB(String[] server, int port, String user, String password){
logger.debug("MongoDB init with "+user+" "+password);
this.server=server; this.server=server;
this.port=port; this.port=port;
this.pwd=password; this.pwd=password;
@ -51,6 +52,7 @@ public class MongoDB {
} }
public MongoDB(String[] server, String user, String password){ public MongoDB(String[] server, String user, String password){
logger.debug("MongoDB init with "+user+" "+password);
this.server=server; this.server=server;
this.pwd=password; this.pwd=password;
this.user=user; this.user=user;
@ -124,6 +126,7 @@ public class MongoDB {
if(mongo==null){ if(mongo==null){
logger.debug(" open mongo connection "); logger.debug(" open mongo connection ");
MongoClientOptions options=MongoClientOptions.builder().sslEnabled(true).connectionsPerHost(10).connectTimeout(30000).readPreference(READ_PREFERENCE).build(); 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))){ if(((pwd != null) && (pwd.length() >0)) && ((user != null) && (user.length() > 0))){
MongoCredential credential = MongoCredential.createMongoCRCredential(user, ACCOUNTING_DB, pwd.toCharArray()); MongoCredential credential = MongoCredential.createMongoCRCredential(user, ACCOUNTING_DB, pwd.toCharArray());
mongo = new MongoClient(srvList, Arrays.asList(credential), options); mongo = new MongoClient(srvList, Arrays.asList(credential), options);

View File

@ -1,6 +1,8 @@
package org.gcube.contentmanager.storageserver.startup; package org.gcube.contentmanager.storageserver.startup;
import java.util.List; import java.util.List;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -21,7 +23,8 @@ public class ConfigurationTest {
@Test @Test
public void serverAccess() { public void serverAccess() {
Assert.assertNotNull(c.getServerAccess()); List <ServiceEndpoint> se=c.getStorageServiceEndpoint();
Assert.assertNotNull(c.getServerAccess(se));
} }

View File

@ -11,6 +11,7 @@ public class MongoDBTest {
@BeforeClass @BeforeClass
public static void init(){ public static void init(){
mongo=new MongoDB(server, "devUser", "d3v_u534"); mongo=new MongoDB(server, "devUser", "d3v_u534");
// mongo=new MongoDB(server, "oplogger", "0pl0gg3r_d3v");
} }
// @Test // @Test