This commit is contained in:
Fabio Sinibaldi 2017-04-11 16:07:58 +00:00
parent 7877a10868
commit b8bc2d00ed
28 changed files with 851 additions and 24 deletions

View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>sdi-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<name>SDI Service</name>
<description>REST Interface towards SDI facilities</description>
<packaging>war</packaging>

View File

@ -0,0 +1,61 @@
package org.gcube.spatial.data.sdi;
import java.net.URL;
import java.util.Properties;
import javax.servlet.ServletContext;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class LocalConfiguration {
final static public String GEONETWORK_CACHE_TTL="gn.cache.TTL";
final static public String GEONETWORK_SE_CATEGORY="gn.se.category";
final static public String GEONETWORK_SE_PLATFORM="gn.se.platform";
final static public String GEONETWORK_SE_PRIORITY="gn.se.priority";
final static public String GEONETWORK_SE_ENDPOINT_NAME="gn.se.endpointName";
final static public String GEOSERVER_CACHE_TTL="gs.cache.TTL";
final static public String THREDDS_CACHE_TTL="th.cache.TTL";
final static public String THREDDS_SE_CATEGORY="th.se.category";
final static public String THREDDS_SE_PLATFORM="th.se.platform";
final static public String THREDDS_GE_SERVICE_CLASS="th.ge.serviceClass";
final static public String THREDDS_GE_SERVICE_NAME="th.ge.serviceName";
static LocalConfiguration instance=null;
public static synchronized LocalConfiguration get(){
return instance;
}
public static void init(URL propertiesURL){
instance=new LocalConfiguration(propertiesURL);
}
private Properties props=new Properties();
private LocalConfiguration(URL propertiesURL) {
try{
log.debug("Loading {} ",propertiesURL);
props.load(propertiesURL.openStream());
}catch(Exception e){
throw new RuntimeException(e);
}
}
public String getProperty(String property){
return props.getProperty(property);
}
public String getProperty(String property,String defaultValue){
return props.getProperty(property, defaultValue);
}
}

View File

@ -1,5 +1,7 @@
package org.gcube.spatial.data.sdi;
import java.net.URL;
import javax.ws.rs.ApplicationPath;
import org.gcube.smartgears.ContextProvider;
@ -9,7 +11,8 @@ import org.gcube.spatial.data.sdi.rest.GeoNetwork;
import org.glassfish.jersey.server.ResourceConfig;
import io.swagger.jaxrs.config.BeanConfig;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@ApplicationPath(Constants.APPLICATION)
public class SDIService extends ResourceConfig{
@ -26,8 +29,16 @@ public class SDIService extends ResourceConfig{
String hostName=configuration.hostname();
Integer port=configuration.port();
try{
URL resourceUrl = context.application().getResource("/WEB-INF/config.properties");
LocalConfiguration.init(resourceUrl);
}catch(Throwable t){
log.debug("Listing available paths");
for(Object obj:context.application().getResourcePaths("/WEB-INF"))
log.debug("OBJ : {} ",obj);
throw new RuntimeException("Unable to load configuration properties",t);
}

View File

@ -0,0 +1,10 @@
package org.gcube.spatial.data.sdi.engine;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.service.GeoServerClusterConfiguration;
public interface GISManager {
public GeoServerClusterConfiguration getConfiguration() throws ConfigurationNotFoundException;
}

View File

@ -0,0 +1,10 @@
package org.gcube.spatial.data.sdi.engine;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.service.GeoNetworkConfiguration;
public interface GeoNetworkManager {
public GeoNetworkConfiguration getConfiguration() throws ConfigurationNotFoundException;
}

View File

@ -0,0 +1,10 @@
package org.gcube.spatial.data.sdi.engine;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.service.ThreddsConfiguration;
public interface ThreddsManager {
public ThreddsConfiguration getConfiguration() throws ConfigurationNotFoundException;
}

View File

@ -0,0 +1,27 @@
package org.gcube.spatial.data.sdi.engine.impl;
import javax.inject.Singleton;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.GISManager;
import org.gcube.spatial.data.sdi.engine.impl.cache.Cache;
import org.gcube.spatial.data.sdi.engine.impl.cache.GeoServerClusterRetriever;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.service.GeoServerClusterConfiguration;
@Singleton
public class GISManagerImpl implements GISManager {
private Cache<GeoServerClusterConfiguration> theCache=null;
public GISManagerImpl() {
theCache=Cache.getCache(new GeoServerClusterRetriever(), Long.parseLong(LocalConfiguration.get().getProperty(LocalConfiguration.GEOSERVER_CACHE_TTL)), "GeoCluster - cache");
}
@Override
public GeoServerClusterConfiguration getConfiguration() throws ConfigurationNotFoundException {
return theCache.get();
}
}

View File

@ -0,0 +1,29 @@
package org.gcube.spatial.data.sdi.engine.impl;
import javax.inject.Singleton;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.GeoNetworkManager;
import org.gcube.spatial.data.sdi.engine.impl.cache.Cache;
import org.gcube.spatial.data.sdi.engine.impl.cache.GeoNetworkRetriever;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.service.GeoNetworkConfiguration;
@Singleton
public class GeoNetworkManagerImpl implements GeoNetworkManager {
private Cache<GeoNetworkConfiguration> cache=null;
public GeoNetworkManagerImpl() {
cache=Cache.getCache(new GeoNetworkRetriever(),
Long.parseLong(LocalConfiguration.get().getProperty(LocalConfiguration.GEONETWORK_CACHE_TTL)),"GeoNetwork - cache");
}
@Override
public GeoNetworkConfiguration getConfiguration() throws ConfigurationNotFoundException {
return cache.get();
}
}

View File

@ -2,9 +2,14 @@ package org.gcube.spatial.data.sdi.engine.impl;
import java.util.Arrays;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.engine.GISManager;
import org.gcube.spatial.data.sdi.engine.GeoNetworkManager;
import org.gcube.spatial.data.sdi.engine.SDIManager;
import org.gcube.spatial.data.sdi.engine.ThreddsManager;
import org.gcube.spatial.data.sdi.model.ScopeConfiguration;
import org.gcube.spatial.data.sdi.model.credentials.AccessType;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
@ -14,26 +19,61 @@ import org.gcube.spatial.data.sdi.model.service.GeoServerConfiguration;
import org.gcube.spatial.data.sdi.model.service.ThreddsConfiguration;
import org.gcube.spatial.data.sdi.model.service.Version;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Singleton
public class SDIManagerImpl implements SDIManager {
// @Inject
GeoNetworkManager geonetworkManager;
// @Inject
ThreddsManager threddsManager;
// @Inject
GISManager gisManager;
@Inject
public SDIManagerImpl(GeoNetworkManager geonetworkManager, ThreddsManager threddsManager, GISManager gisManager) {
super();
this.geonetworkManager = geonetworkManager;
this.threddsManager = threddsManager;
this.gisManager = gisManager;
}
@Override
public ScopeConfiguration getContextConfiguration() {
GeoNetworkConfiguration gn=new GeoNetworkConfiguration(new Version(2,2,2), "http://geonetwork.d4science.org/geonetwork",
Arrays.asList(new Credentials("GNuser","pwd",AccessType.ADMIN)), "vre_group", "vre_shared", "global public access");
ThreddsConfiguration thredds=new ThreddsConfiguration(new Version(2,2,2), "http://thredds.d4sciecne.org/thredds",
Arrays.asList(new Credentials("THuser","pwd",AccessType.ADMIN)));
GeoServerConfiguration gs1=new GeoServerConfiguration(new Version(2,10,1), "http://geoserver1.d4science.org/geoserver",
Arrays.asList(new Credentials("GS1user","pwd",AccessType.ADMIN)), "context_confidential_ws", "context_only_ws", "context_ws", "public_access_ws");
// TODO filter info by user role
GeoServerConfiguration gs2=new GeoServerConfiguration(new Version(2,6,1), "http://geoserver2.d4science.org/geoserver",
Arrays.asList(new Credentials("GS1user","pwd",AccessType.ADMIN)), "context_confidential_ws", "context_only_ws", "context_ws", "public_access_ws");
ScopeConfiguration toReturn=new ScopeConfiguration();
toReturn.setContextName(ScopeUtils.getCurrentScopeName());
try{
toReturn.setGeonetworkConfiguration(geonetworkManager.getConfiguration());
}catch(Exception e){
log.warn("Scope is not well configured. Missing GeoNetwork. ",e);
}
ScopeConfiguration toReturn=new ScopeConfiguration("/some/context", gn, new GeoServerClusterConfiguration(Arrays.asList(gs1,gs2)), thredds);
try{
toReturn.setThreddsConfiguration(threddsManager.getConfiguration());
}catch(Exception e){
log.warn("THREDDS not found in current scope {} ",ScopeUtils.getCurrentScope());
}
try{
toReturn.setGeoserverClusterConfiguration(gisManager.getConfiguration());
}catch(Exception e){
log.warn("GeoServer not found in current scope {} ",ScopeUtils.getCurrentScope());
}
return toReturn;
}
}

View File

@ -0,0 +1,27 @@
package org.gcube.spatial.data.sdi.engine.impl;
import javax.inject.Singleton;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.ThreddsManager;
import org.gcube.spatial.data.sdi.engine.impl.cache.Cache;
import org.gcube.spatial.data.sdi.engine.impl.cache.ThreddsRetriever;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.service.ThreddsConfiguration;
@Singleton
public class ThreddsManagerImpl implements ThreddsManager {
private Cache<ThreddsConfiguration> cache=null;
public ThreddsManagerImpl() {
cache=Cache.getCache(new ThreddsRetriever(),
Long.parseLong(LocalConfiguration.get().getProperty(LocalConfiguration.THREDDS_CACHE_TTL)), "THREDDS - CACHE");
}
@Override
public ThreddsConfiguration getConfiguration() throws ConfigurationNotFoundException {
return cache.get();
}
}

View File

@ -0,0 +1,53 @@
package org.gcube.spatial.data.sdi.engine.impl.cache;
import java.util.concurrent.ConcurrentHashMap;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.service.GeoService;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Cache<T> {
private long objectsTTL;
private ConcurrentHashMap<String,CachedObject<T>> theCache;
private ObjectRetriever<T> retriever;
private String cacheName;
private Cache(long objectsTTL, ObjectRetriever<T> retriever, String cacheName) {
super();
this.objectsTTL = objectsTTL;
this.retriever = retriever;
this.cacheName=cacheName;
theCache=new ConcurrentHashMap<>();
}
public synchronized T get() throws ConfigurationNotFoundException{
String key=ScopeUtils.getCurrentScope();
log.info("Getting object from cache{} , key is {} ",cacheName,key);
if((!theCache.containsKey(key))||(!theCache.get(key).isValid(objectsTTL)))
theCache.put(key, new CachedObject<T>(retriever.getObject()));
return theCache.get(key).getTheObject();
}
public void invalidate(){
String key=ScopeUtils.getCurrentScope();
log.info("Invalidating cache {} under scope {} ",cacheName,key);
if(theCache.containsKey(key))theCache.get(key).invalidate();
}
public void invalidateAll(){
for(CachedObject<?> obj:theCache.values())obj.invalidate();
}
public static<T> Cache<T> getCache(ObjectRetriever<T> retriever, long objectsTTL,String cacheName){
return new Cache<T>(objectsTTL,retriever,cacheName);
}
}

View File

@ -0,0 +1,33 @@
package org.gcube.spatial.data.sdi.engine.impl.cache;
public class CachedObject<T> {
private long lastUpdate=System.currentTimeMillis();
private T theObject;
public CachedObject(T theObject) {
super();
this.theObject = theObject;
}
public T getTheObject() {
return theObject;
}
public boolean isValid(long TTL){
return System.currentTimeMillis()-lastUpdate<TTL;
}
public void invalidate(){
lastUpdate=0l;
}
}

View File

@ -0,0 +1,140 @@
package org.gcube.spatial.data.sdi.engine.impl.cache;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
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.spatial.data.geonetwork.GeoNetworkAdministration;
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.gcube.spatial.data.geonetwork.extension.ServerAccess;
import org.gcube.spatial.data.geonetwork.model.Account;
import org.gcube.spatial.data.geonetwork.model.Account.Type;
import org.gcube.spatial.data.geonetwork.model.ScopeConfiguration;
import org.gcube.spatial.data.gis.GISInterface;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.credentials.AccessType;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import org.gcube.spatial.data.sdi.model.service.GeoNetworkConfiguration;
import org.gcube.spatial.data.sdi.model.service.Version;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GeoNetworkRetriever implements ObjectRetriever<GeoNetworkConfiguration> {
@Override
public GeoNetworkConfiguration getObject() throws ConfigurationNotFoundException {
//TODO skip library
//TODO use both GCoreEndpoints and ServiceEndpoint
// log.info("Gathering geonetwork information under scope {} ",ScopeUtils.getCurrentScope());
// LocalConfiguration config=LocalConfiguration.get();
// String category=config.getProperty(LocalConfiguration.GEONETWORK_SE_CATEGORY);
// String platformName=config.getProperty(LocalConfiguration.GEONETWORK_SE_PLATFORM);
// String priorityProperty=config.getProperty(LocalConfiguration.GEONETWORK_SE_PRIORITY);
// String endpointName=config.getProperty(LocalConfiguration.GEONETWORK_SE_ENDPOINT_NAME);
// ServiceEndpoint se=getTheRightServiceEndpoint(ISUtils.queryForServiceEndpoints(category, platformName), endpointName, priorityProperty);
// AccessPoint access=getTheRightAccessPoint(se, endpointName, priorityProperty);
//
try{
//INIT LIB
GISInterface gis=GISInterface.get();
GeoNetworkAdministration gnAdmin=(GeoNetworkAdministration) gis.getGeoNewtorkPublisher();
Configuration config=gnAdmin.getConfiguration();
Version version=config.getGeoNetworkVersion().equals(ServerAccess.Version.TRE)?new Version(3,0,0):new Version(2,6,0);
String baseEndpoint=config.getGeoNetworkEndpoint();
ScopeConfiguration scopeConfig=config.getScopeConfiguration();
List<Credentials> accessibleCredentials=new ArrayList();
for(Account acc: scopeConfig.getAccounts().values()){
accessibleCredentials.add(fromGeoNetworkAccount(acc));
}
Credentials adminCredentials=fromGeoNetworkAccount(config.getAdminAccount());
// GN Lib doesn't expose ADMIN account type
adminCredentials.setAccessType(AccessType.ADMIN);
accessibleCredentials.add(adminCredentials);
return new GeoNetworkConfiguration(version, baseEndpoint, accessibleCredentials, scopeConfig.getPrivateGroup()+"", scopeConfig.getPublicGroup()+"", "3");
}catch(Exception e){
log.warn("Unable to gather geonetwork information",e);
throw new ConfigurationNotFoundException("Unable to gather information on geonetwork. Please contact administrator.",e);
}
}
protected static final Credentials fromGeoNetworkAccount(Account toTranslate){
switch(toTranslate.getType()){
case CKAN : return new Credentials(toTranslate.getUser(),toTranslate.getPassword(),AccessType.CKAN);
case SCOPE : return new Credentials(toTranslate.getUser(),toTranslate.getPassword(),AccessType.CONTEXT_USER);
default : throw new RuntimeException("Unrecognized account type "+toTranslate);
}
}
protected static final ServiceEndpoint getTheRightServiceEndpoint(List<ServiceEndpoint>resources, String endpointName,String priorityProperty){
ServiceEndpoint toReturn=null;
int priority=1000;
for(ServiceEndpoint resource: resources){
Iterator<AccessPoint> points=resource.profile().accessPoints().iterator();
while(points.hasNext()){
AccessPoint point= points.next();
log.debug(point.toString());
if(point.name().equals(endpointName)){
Map<String, Property> properties=point.propertyMap();
if(properties.containsKey(priorityProperty)){
int currentPriority=Integer.parseInt(properties.get(priorityProperty).value());
if(toReturn==null||(currentPriority<priority)){
toReturn=resource;
priority=currentPriority;
}
}
}
}
}
return toReturn;
}
/**
* look for the access point compliant with configured endpointName and maxPriority (1)
*
* @return null if not present
*/
protected static final AccessPoint getTheRightAccessPoint(ServiceEndpoint resource,String endpointName,String priorityProperty){
AccessPoint toReturn=null;
int priority=1000;
Iterator<AccessPoint> points=resource.profile().accessPoints().iterator();
while(points.hasNext()){
AccessPoint point= points.next();
log.debug(point.toString());
if(point.name().equals(endpointName)){
Map<String, Property> properties=point.propertyMap();
if(properties.containsKey(priorityProperty)){
int currentPriority=Integer.parseInt(properties.get(priorityProperty).value());
if(toReturn==null||(currentPriority<priority)){
toReturn=point;
priority=currentPriority;
}
}
}
}
return toReturn;
}
}

View File

@ -0,0 +1,58 @@
package org.gcube.spatial.data.sdi.engine.impl.cache;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.gcube.spatial.data.gis.GISInterface;
import org.gcube.spatial.data.gis.is.AbstractGeoServerDescriptor;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.credentials.AccessType;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import org.gcube.spatial.data.sdi.model.service.GeoServerClusterConfiguration;
import org.gcube.spatial.data.sdi.model.service.GeoServerConfiguration;
import org.gcube.spatial.data.sdi.model.service.Version;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GeoServerClusterRetriever implements ObjectRetriever<GeoServerClusterConfiguration>{
@Override
public GeoServerClusterConfiguration getObject() throws ConfigurationNotFoundException {
//TODO skip library
//TODO use both GCoreEndpoints and ServiceEndpoint
log.info("Retrieving GeoServer cluster configuration under scope {}",ScopeUtils.getCurrentScope());
try{
GISInterface gis=GISInterface.get();
ArrayList<GeoServerConfiguration> availableInstances=new ArrayList<>();
for(AbstractGeoServerDescriptor desc: gis.getCurrentCacheElements(true)){
try{
availableInstances.add(translate(desc));
}catch(Throwable t){
log.warn("Unable to translate descriptor for endpoint"+desc.getUrl(),t);
}
}
return new GeoServerClusterConfiguration(availableInstances);
}catch(Exception e){
log.warn("Unable to gather geoserver cluster configuration on scope "+ScopeUtils.getCurrentScope(),e);
throw new ConfigurationNotFoundException("Unable to gather geoserver cluster configuration. Please ontact administrator.",e);
}
}
private static final GeoServerConfiguration translate(AbstractGeoServerDescriptor desc){
Version version=new Version(2,1,2);
String baseEndpoint=desc.getUrl();
List<Credentials> accessibleCredentials=Collections.singletonList(new Credentials(desc.getUser(), desc.getPassword(), AccessType.ADMIN));
String confidentialWorkspace=null;
String contextVisibilityWorkspace=null;
String sharedWorkspace=null;
String publicWorkspace=null;
return new GeoServerConfiguration(version, baseEndpoint, accessibleCredentials, confidentialWorkspace, contextVisibilityWorkspace, sharedWorkspace, publicWorkspace);
}
}

View File

@ -0,0 +1,46 @@
package org.gcube.spatial.data.sdi.engine.impl.cache;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.List;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ISUtils {
static List<ServiceEndpoint> queryForServiceEndpoints(String category, String platformName){
log.debug("Querying for Service Endpoints [category : {} , platformName : {}, currentScope : {} ]",category,platformName,ScopeUtils.getCurrentScope());
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq '"+category+"'")
.addCondition("$resource/Profile/Platform/Name/text() eq '"+platformName+"'");
// .setResult("$resource/Profile/AccessPoint");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
return client.submit(query);
}
static List<GCoreEndpoint> queryForGCoreEndpoint(String serviceClass,String serviceName){
log.debug("Querying for GCore Endpoints [ServiceClass : {} , ServiceName : {}, currentScope : {} ]",serviceClass,serviceName,ScopeUtils.getCurrentScope());
SimpleQuery query =queryFor(GCoreEndpoint.class);
query.addCondition("$resource/Profile/ServiceClass/text() eq '"+serviceClass+"'")
.addCondition("$resource/Profile/ServiceName/text() eq '"+serviceName+"'");
// .setResult("$resource/Profile/AccessPoint");
DiscoveryClient<GCoreEndpoint> client = clientFor(GCoreEndpoint.class);
return client.submit(query);
}
}

View File

@ -0,0 +1,9 @@
package org.gcube.spatial.data.sdi.engine.impl.cache;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
public interface ObjectRetriever<T> {
public T getObject()throws ConfigurationNotFoundException;
}

View File

@ -0,0 +1,87 @@
package org.gcube.spatial.data.sdi.engine.impl.cache;
import java.util.Collections;
import java.util.List;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.common.Platform;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.credentials.AccessType;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import org.gcube.spatial.data.sdi.model.service.ThreddsConfiguration;
import org.gcube.spatial.data.sdi.model.service.Version;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ThreddsRetriever implements ObjectRetriever<ThreddsConfiguration> {
@Override
public ThreddsConfiguration getObject() throws ConfigurationNotFoundException{
log.info("Loading Thredds information from IS. Current Scope is {} ",ScopeUtils.getCurrentScope());
LocalConfiguration config=LocalConfiguration.get();
// Try to look for GCore Endpoints first
String geClass=config.getProperty(LocalConfiguration.THREDDS_GE_SERVICE_CLASS);
String geName=config.getProperty(LocalConfiguration.THREDDS_GE_SERVICE_NAME);
List<GCoreEndpoint> gCoreEndpoints=ISUtils.queryForGCoreEndpoint(geClass, geName);
if(gCoreEndpoints!=null&&!gCoreEndpoints.isEmpty()){
log.debug("Found {} GCore Endpoints ",gCoreEndpoints.size());
for(int i=0;i<gCoreEndpoints.size();i++){
GCoreEndpoint endpoint=gCoreEndpoints.get(i);
try{
log.debug("Checking element {}, ID {} ",i,endpoint.id());
ThreddsConfiguration toReturn=translate(endpoint);
if(toReturn==null) throw new Exception("Translated configuration was null");
return toReturn;
}catch(Throwable t){
log.warn("Unable to read retrieved gCore endpoint ID "+endpoint.id(),t);
}
}
}
// Code is executed only if no configuration has been retrieved from gCore endpoints
String seCategory=config.getProperty(LocalConfiguration.THREDDS_SE_CATEGORY);
String sePlatform=config.getProperty(LocalConfiguration.THREDDS_SE_PLATFORM);
List<ServiceEndpoint> threddsSE=ISUtils.queryForServiceEndpoints(seCategory, sePlatform);
if(threddsSE!=null&&!threddsSE.isEmpty()){
log.debug("Found {} Service Endpoints ",threddsSE.size());
for(int i=0;i<threddsSE.size();i++){
ServiceEndpoint endpoint=threddsSE.get(i);
try{
log.debug("Checking element {}, ID {} ",i,endpoint.id());
ThreddsConfiguration toReturn=translate(endpoint);
if(toReturn==null) throw new Exception("Translated configuration was null");
return toReturn;
}catch(Throwable t){
log.warn("Unable to read retrieved service endpoint ID "+endpoint.id(),t);
}
}
}
throw new ConfigurationNotFoundException("Thredds has not been found in current scope "+ScopeUtils.getCurrentScope());
}
private static final ThreddsConfiguration translate(GCoreEndpoint toTranslate){
//
// ThreddsConfiguration toReturn=new ThreddsConfiguration(version, baseEndpoint, accessibleCredentials);
return null;
}
private static final ThreddsConfiguration translate(ServiceEndpoint toTranslate){
Platform platform=toTranslate.profile().platform();
Version version=new Version(platform.version(),platform.minorVersion(),platform.revisionVersion());
AccessPoint access=toTranslate.profile().accessPoints().iterator().next();
Credentials credentials=new Credentials(access.username(),access.password(),AccessType.ADMIN);
return new ThreddsConfiguration(version, access.address(), Collections.singletonList(credentials));
}
}

View File

@ -0,0 +1,30 @@
package org.gcube.spatial.data.sdi.engine.impl.faults;
public class ConfigurationNotFoundException extends Exception {
public ConfigurationNotFoundException() {
// TODO Auto-generated constructor stub
}
public ConfigurationNotFoundException(String message) {
super(message);
// TODO Auto-generated constructor stub
}
public ConfigurationNotFoundException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}
public ConfigurationNotFoundException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}
public ConfigurationNotFoundException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub
}
}

View File

@ -17,11 +17,13 @@ import lombok.RequiredArgsConstructor;
public class Version {
@NonNull
private Integer major;
private Short major;
@NonNull
private Integer minor;
private Short minor;
@NonNull
private Integer build;
private Short build;
public Version(Integer maj,Integer min, Integer build){
this(maj.shortValue(),min.shortValue(),build.shortValue());
}
}

View File

@ -10,10 +10,11 @@ import org.gcube.spatial.data.sdi.Constants;
import org.gcube.spatial.data.sdi.engine.SDIManager;
import org.gcube.spatial.data.sdi.model.ScopeConfiguration;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.jaxrs.annotation.JacksonFeatures;
import io.swagger.annotations.Api;
@Slf4j
@Path(Constants.SDI_INTERFACE)
@Api(value=Constants.SDI_INTERFACE)
public class SDI {
@ -24,6 +25,7 @@ public class SDI {
@GET
@Produces(MediaType.APPLICATION_JSON)
@JacksonFeatures(serializationEnable = { SerializationFeature.INDENT_OUTPUT })
public ScopeConfiguration getConfiguration(){
return sdiManager.getContextConfiguration();

View File

@ -25,7 +25,7 @@ no. 654119), SoBigData (grant no. 654024);
Version
--------------------------------------------------
0.0.1-SNAPSHOT (2017-03-30)
0.0.1-SNAPSHOT (2017-04-11)
Please see the file named "changelog.xml" in this directory for the release notes.

View File

@ -0,0 +1,16 @@
#GEONETWORK
gn.cache.TTL=120000
gn.se.category=Gis
gn.se.platform=geonetwork
gn.se.priority=priority
gn.se.endpointName=geonetwork
#GEOSERVER
gs.cache.TTL=120000
gs.se.category=Gis
gs.se.platform=GeoServer
#THREDDS
th.cache.TTL=120000
th.se.category=Gis
th.se.platform=thredds
th.ge.serviceClass=SDI
th.ge.serviceName=THREDDS

View File

@ -0,0 +1,34 @@
package org.gcube.spatial.data.sdi.test;
import org.gcube.spatial.data.sdi.engine.GISManager;
import org.gcube.spatial.data.sdi.engine.impl.GISManagerImpl;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.service.GeoServerClusterConfiguration;
import org.glassfish.hk2.api.Factory;
public class GISManagerFactory implements Factory<GISManager>{
private GISManager manager;
public GISManagerFactory() {
manager=new GISManagerImpl(){
@Override
public GeoServerClusterConfiguration getConfiguration() throws ConfigurationNotFoundException {
TokenSetter.set(TestCommon.TEST_SCOPE);
return super.getConfiguration();
}
};
}
@Override
public void dispose(GISManager arg0) {
// TODO Auto-generated method stub
}
@Override
public GISManager provide() {
return manager;
}
}

View File

@ -0,0 +1,33 @@
package org.gcube.spatial.data.sdi.test;
import org.gcube.spatial.data.sdi.engine.GeoNetworkManager;
import org.gcube.spatial.data.sdi.engine.impl.GeoNetworkManagerImpl;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.service.GeoNetworkConfiguration;
import org.glassfish.hk2.api.Factory;
public class GeoNetworkManagerFactory implements Factory<GeoNetworkManager>{
private GeoNetworkManager manager;
public GeoNetworkManagerFactory() {
manager=new GeoNetworkManagerImpl(){
@Override
public GeoNetworkConfiguration getConfiguration() throws ConfigurationNotFoundException {
TokenSetter.set(TestCommon.TEST_SCOPE);
return super.getConfiguration();
}
};
}
@Override
public void dispose(GeoNetworkManager arg0) {
// TODO Auto-generated method stub
}
@Override
public GeoNetworkManager provide() {
return manager;
}
}

View File

@ -5,7 +5,10 @@ import javax.ws.rs.core.MediaType;
import org.gcube.spatial.data.sdi.Constants;
import org.gcube.spatial.data.sdi.SDIService;
import org.gcube.spatial.data.sdi.engine.GISManager;
import org.gcube.spatial.data.sdi.engine.GeoNetworkManager;
import org.gcube.spatial.data.sdi.engine.SDIManager;
import org.gcube.spatial.data.sdi.engine.ThreddsManager;
import org.gcube.spatial.data.sdi.rest.GeoNetwork;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
@ -16,6 +19,7 @@ import io.swagger.jaxrs.config.BeanConfig;
public class MainTest extends JerseyTest{
public static class MyBinder extends AbstractBinder{
public MyBinder() {
@ -27,6 +31,9 @@ public class MainTest extends JerseyTest{
protected void configure() {
// bindFactory(GeoNetworkProviderFactory.class).to(GeoNetworkProvider.class);
bindFactory(SDIManagerFactory.class).to(SDIManager.class);
bindFactory(ThreddsManagerFactory.class).to(ThreddsManager.class);
bindFactory(GeoNetworkManagerFactory.class).to(GeoNetworkManager.class);
bindFactory(GISManagerFactory.class).to(GISManager.class);
}
}

View File

@ -2,12 +2,22 @@ package org.gcube.spatial.data.sdi.test;
import org.gcube.spatial.data.sdi.engine.SDIManager;
import org.gcube.spatial.data.sdi.engine.impl.SDIManagerImpl;
import org.gcube.spatial.data.sdi.model.ScopeConfiguration;
import org.glassfish.hk2.api.Factory;
public class SDIManagerFactory implements Factory<SDIManager>{
SDIManager manager=null;
public SDIManagerFactory() {
// TODO Auto-generated constructor stub
manager=new SDIManagerImpl(new GeoNetworkManagerFactory().provide(),new ThreddsManagerFactory().provide(),new GISManagerFactory().provide()){
@Override
public ScopeConfiguration getContextConfiguration() {
TokenSetter.set(TestCommon.TEST_SCOPE);
return super.getContextConfiguration();
}
};
}
@Override
@ -18,6 +28,6 @@ public class SDIManagerFactory implements Factory<SDIManager>{
@Override
public SDIManager provide() {
return new SDIManagerImpl();
return manager;
}
}

View File

@ -0,0 +1,7 @@
package org.gcube.spatial.data.sdi.test;
public class TestCommon {
public static final String TEST_SCOPE="/gcube/devsec";
}

View File

@ -0,0 +1,35 @@
package org.gcube.spatial.data.sdi.test;
import org.gcube.spatial.data.sdi.engine.ThreddsManager;
import org.gcube.spatial.data.sdi.engine.impl.ThreddsManagerImpl;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.model.service.ThreddsConfiguration;
import org.glassfish.hk2.api.Factory;
public class ThreddsManagerFactory implements Factory<ThreddsManager>{
private ThreddsManager manager;
public ThreddsManagerFactory() {
manager=new ThreddsManagerImpl(){
@Override
public ThreddsConfiguration getConfiguration() throws ConfigurationNotFoundException {
TokenSetter.set(TestCommon.TEST_SCOPE);
return super.getConfiguration();
}
};
}
@Override
public ThreddsManager provide() {
return manager;
}
@Override
public void dispose(ThreddsManager arg0) {
// TODO Auto-generated method stub
}
}