added integration with gcube infra
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/content-management/storage-manager-trigger@96750 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0c14601b7d
commit
2e61305e67
26
pom.xml
26
pom.xml
|
@ -44,6 +44,32 @@
|
|||
<artifactId>common-scope</artifactId>
|
||||
<version>[1.2.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources</groupId>
|
||||
<artifactId>common-gcore-resources</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<!-- INFRA CONNECTION -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-gcore-stubs</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>ic-client</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope-maps</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -15,7 +15,7 @@ public class ValidationUtils {
|
|||
Set<String> scopeSet=new ServiceMapScannerMediator().getScopeKeySet();
|
||||
for(String scopeItem : scopeSet){
|
||||
// System.out.println("scope scanned: "+scopeItem);
|
||||
if(scope.equalsIgnoreCase(scopeItem))
|
||||
if(scope.contains(scopeItem))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
package org.gcube.contentmanager.storageserver.startup;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.encryption.StringEncrypter;
|
||||
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.scope.api.ScopeProvider;
|
||||
import org.gcube.contentmanager.storageserver.parse.utils.ValidationUtils;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
private String scope;
|
||||
private String[] server;
|
||||
private String username;
|
||||
private String password;
|
||||
private String backendType;
|
||||
Logger logger= LoggerFactory.getLogger(Configuration.class);
|
||||
|
||||
public Configuration(String scope, String user, String password){
|
||||
this.scope=scope;
|
||||
if(!ValidationUtils.validationScope(scope))
|
||||
throw new IllegalArgumentException("invalid scope exception: "+scope);
|
||||
|
||||
}
|
||||
|
||||
public String[] getServerAccess(){
|
||||
String savedScope=null;
|
||||
if(scope!=null){
|
||||
savedScope=ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope);
|
||||
}
|
||||
logger.debug("get server from IS ");
|
||||
getServerRRFws();
|
||||
if(scope!=null){
|
||||
ScopeProvider.instance.set(savedScope);
|
||||
}
|
||||
logger.info("server found {} ", server);
|
||||
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<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
List<ServiceEndpoint> resources = client.submit(query);
|
||||
if(resources.size() > 1){
|
||||
logger.info("found "+resources.size()+" RR ");
|
||||
// take the RR with property priority setted to DEFAULT
|
||||
//take servers take RR name
|
||||
return getServers(resources);
|
||||
}else if(resources.size() == 1){
|
||||
logger.info("found only one RR, take it");
|
||||
return getServers(resources.get(0));
|
||||
//take RR name
|
||||
}else{
|
||||
logger.error("RUNTIME RESOURCE NOT FOUND IN THIS SCOPE "+ScopeProvider.instance.get());
|
||||
throw new RuntimeException("RUNTIME RESOURCE NOT FOUND IN SCOPE: "+ScopeProvider.instance.get());
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getServers(ServiceEndpoint res) {
|
||||
server=new String[res.profile().accessPoints().size()];
|
||||
int i=0;
|
||||
for (AccessPoint ap:res.profile().accessPoints()) {
|
||||
if (ap.name().equals("server"+(i+1))) {
|
||||
server[i] = ap.address();
|
||||
// if presents, try to get user and password
|
||||
username = ap.username();
|
||||
if(username != null && username.length() > 0){
|
||||
try {
|
||||
password = StringEncrypter.getEncrypter().decrypt(ap.password());
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
Iterator<AccessPoint> it= res.profile().accessPoints().iterator();
|
||||
AccessPoint ap=(AccessPoint)it.next();
|
||||
Map<String, Property>map= ap.propertyMap();
|
||||
Property type=map.get("type");
|
||||
backendType=type.value();
|
||||
logger.info("Type of backend found "+backendType);
|
||||
return server;
|
||||
}
|
||||
|
||||
private String[] getServers(List<ServiceEndpoint> resources) {
|
||||
ServiceEndpoint defaultResource=null;
|
||||
logger.info("search RR with priority ");
|
||||
// search RR with property DEFAULT
|
||||
for (ServiceEndpoint res : resources){
|
||||
String priority=retrievePropertyValue(res, "priority");
|
||||
if (priority!=null){
|
||||
defaultResource=res;
|
||||
logger.info("found a RR with priority: ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(defaultResource!=null){
|
||||
server=new String[defaultResource.profile().accessPoints().size()];
|
||||
int i=0;
|
||||
for (AccessPoint ap:defaultResource.profile().accessPoints()) {
|
||||
if (ap.name().equals("server"+(i+1))) {
|
||||
server[i] = ap.address();
|
||||
// if presents, try to get user and password
|
||||
username = ap.username();
|
||||
password="";
|
||||
if(username != null && username.length() > 0){
|
||||
try {
|
||||
password = StringEncrypter.getEncrypter().decrypt(ap.password());
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
backendType=retrievePropertyValue(defaultResource, "type");
|
||||
logger.info("Type of backend found in RR is "+backendType);
|
||||
return server;
|
||||
|
||||
}else{
|
||||
throw new IllegalStateException("Runtime Resource found are more than 1 but all without default priority setted");
|
||||
}
|
||||
}
|
||||
|
||||
private String retrievePropertyValue(String name, String scope) {
|
||||
String savedScope=null;
|
||||
if(scope!=null){
|
||||
savedScope=ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(scope);
|
||||
}
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
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);
|
||||
ServiceEndpoint res=resources.get(0);
|
||||
Iterator<AccessPoint> it= res.profile().accessPoints().iterator();
|
||||
AccessPoint ap=(AccessPoint)it.next();
|
||||
Map<String, Property>map= ap.propertyMap();
|
||||
Property type=map.get(name);
|
||||
String value=type.value();
|
||||
if(scope!=null){
|
||||
ScopeProvider.instance.set(savedScope);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private String retrievePropertyValue(ServiceEndpoint res, String name) {
|
||||
Iterator<AccessPoint> it= res.profile().accessPoints().iterator();
|
||||
AccessPoint ap=(AccessPoint)it.next();
|
||||
Map<String, Property>map= ap.propertyMap();
|
||||
Property type=map.get(name);
|
||||
if (type!=null)
|
||||
return type.value();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
package org.gcube.contentmanager.storageserver.startup;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.contentmanager.storageserver.data.CubbyHole;
|
||||
import org.gcube.contentmanager.storageserver.data.ReadingMongoOplog;
|
||||
import org.gcube.contentmanager.storageserver.parse.JsonParser;
|
||||
|
@ -10,45 +13,43 @@ import java.net.URLClassLoader;
|
|||
|
||||
public class Startup {
|
||||
|
||||
private static String user;
|
||||
private static String password;
|
||||
private static String scope;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// for (int i=0; i<args.length;i++){
|
||||
// //NO show password
|
||||
// if(i==2)
|
||||
// System.out.println("param N." +i + ": *********");
|
||||
// else
|
||||
// System.out.println("param N." +i + ": " + args[i]);
|
||||
// }
|
||||
if(args.length != 1 && args.length != 3){
|
||||
System.out.println("Usage:");
|
||||
System.out.println("\tjava Startup ip user password\n\n");
|
||||
System.out.println("\tjava Startup scope user password\n\n");
|
||||
System.out.println("Example:");
|
||||
System.out.println("\tjava Startup 127.0.0.1 pippo pluT0\n");
|
||||
System.out.println("\tjava Startup /gcube/devsec pippo pluT0\n");
|
||||
System.out.println("or ");
|
||||
System.out.println("Usage:");
|
||||
System.out.println("\tjava Startup ip \n\n");
|
||||
System.out.println("\tjava Startup scope \n\n");
|
||||
System.out.println("Example:");
|
||||
System.out.println("\tjava Startup 127.0.0.1 \n\n");
|
||||
System.out.println("\tjava Startup /gcube \n\n");
|
||||
|
||||
return;
|
||||
}
|
||||
/*CLASSPATH*/
|
||||
// System.out.println("show classpath: ");
|
||||
//// ClassLoader cl = ClassLoader.getSystemClassLoader();
|
||||
//// URL[] urls = ((URLClassLoader)cl).getURLs();
|
||||
//// for(URL url: urls){
|
||||
//// System.out.println(url.getFile());
|
||||
//// }
|
||||
// String classpath = System.getProperty("java.class.path");
|
||||
// System.out.println("classpath:\n"+classpath);
|
||||
/*END CLASSPATH*/
|
||||
scope=args[0];
|
||||
user=args[1];
|
||||
password=args[2];
|
||||
String[] server=retrieveConfiguration();
|
||||
CubbyHole c = new CubbyHole();
|
||||
ReadingMongoOplog producer=null;
|
||||
if(args.length == 3)
|
||||
producer=new ReadingMongoOplog( Arrays.asList(args[0]), args[1], args[2], c, 1 );
|
||||
producer=new ReadingMongoOplog( Arrays.asList(server), args[1], args[2], c, 1 );
|
||||
else
|
||||
producer=new ReadingMongoOplog( Arrays.asList(args[0]), c, 1 );
|
||||
producer=new ReadingMongoOplog( Arrays.asList(server), c, 1 );
|
||||
JsonParser consumer=new JsonParser(c, 1);
|
||||
producer.start();
|
||||
consumer.start();
|
||||
}
|
||||
|
||||
private static String[] retrieveConfiguration() {
|
||||
Configuration c=new Configuration(scope, user, password);
|
||||
return c.getServerAccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package org.gcube.contentmanager.storageserver.startup;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ConfigurationTest {
|
||||
|
||||
String scope="/gcube/devsec";
|
||||
String user=null;
|
||||
String password=null;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Configuration c=new Configuration(scope, user, password);
|
||||
Assert.assertNotNull(c.getServerAccess());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue