removed all JAXB dependencies
parent
e48f50e91b
commit
766238c8e3
@ -0,0 +1,10 @@
|
||||
package org.gcube.smartgears.configuration;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo.As;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
|
||||
|
||||
@JsonTypeInfo(include=As.PROPERTY, use=Id.CLASS, property= "className")
|
||||
public interface ComponentConfiguration {
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package org.gcube.smartgears.configuration;
|
||||
|
||||
public interface Configurable {
|
||||
|
||||
void configure(ComponentConfiguration configuration);
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package org.gcube.smartgears.configuration;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface ConfiguredWith {
|
||||
|
||||
public Class<? extends ComponentConfiguration> value();
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package org.gcube.smartgears.configuration;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import org.gcube.common.validator.annotations.IsValid;
|
||||
import org.gcube.common.validator.annotations.NotNull;
|
||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||
|
||||
@JsonInclude(value = Include.NON_NULL)
|
||||
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
|
||||
public class PersistenceConfiguration {
|
||||
|
||||
@NotNull
|
||||
private Class<? extends PersistenceWriter> implementationClass;
|
||||
|
||||
@IsValid
|
||||
private ComponentConfiguration writerConfiguration;
|
||||
|
||||
protected PersistenceConfiguration() {}
|
||||
|
||||
public <T extends ComponentConfiguration> PersistenceConfiguration(Class<? extends PersistenceWriter> implementationClass, T writerConfiguration) {
|
||||
super();
|
||||
this.implementationClass = implementationClass;
|
||||
this.writerConfiguration = writerConfiguration;
|
||||
}
|
||||
|
||||
public Class<? extends PersistenceWriter> getImplementationClass() {
|
||||
return this.implementationClass;
|
||||
}
|
||||
|
||||
public ComponentConfiguration getWriterConfiguration() {
|
||||
return writerConfiguration;
|
||||
}
|
||||
|
||||
}
|
@ -1,140 +1,182 @@
|
||||
package org.gcube.smartgears.configuration.application;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.smartgears.configuration.ProxyAddress;
|
||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.gcube.common.validator.ValidationError;
|
||||
import org.gcube.common.validator.Validator;
|
||||
import org.gcube.common.validator.ValidatorFactory;
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
import org.gcube.common.validator.annotations.NotNull;
|
||||
import org.gcube.smartgears.configuration.PersistenceConfiguration;
|
||||
|
||||
/**
|
||||
* The configuration of the application.
|
||||
*
|
||||
* @author Fabio Simeoni
|
||||
* The configuration of a managed app.
|
||||
* <p>
|
||||
* Includes the list of its client services.
|
||||
*
|
||||
* @author Lucio Lelii
|
||||
*
|
||||
*/
|
||||
public interface ApplicationConfiguration {
|
||||
@JsonInclude(value = Include.NON_NULL)
|
||||
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
|
||||
public class ApplicationConfiguration {
|
||||
|
||||
|
||||
/**
|
||||
* Returns the context path of the application
|
||||
* @return the context path
|
||||
*/
|
||||
String context();
|
||||
@NotNull
|
||||
String name;
|
||||
|
||||
@NotNull
|
||||
String group;
|
||||
|
||||
@NotNull
|
||||
String version;
|
||||
|
||||
boolean proxable();
|
||||
String description="";
|
||||
|
||||
ProxyAddress proxyAddress();
|
||||
@JsonIgnore
|
||||
String context;
|
||||
|
||||
ApplicationConfiguration proxyAddress(ProxyAddress proxy);
|
||||
private boolean proxable = true;
|
||||
|
||||
Set<GCubeExclude> excludes= null;
|
||||
|
||||
/**
|
||||
* Sets the context path of the application
|
||||
* @param context the context path
|
||||
* @return this configuration
|
||||
*/
|
||||
ApplicationConfiguration context(String context);
|
||||
Set<GCubeInclude> includes= null;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the application.
|
||||
* @return the name
|
||||
*/
|
||||
String name();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the name of the application.
|
||||
* @param name the name
|
||||
* @return this configuration
|
||||
*/
|
||||
ApplicationConfiguration name(String name);
|
||||
|
||||
/**
|
||||
* Returns the class of the application
|
||||
* @return the class
|
||||
*/
|
||||
String serviceClass();
|
||||
|
||||
/**
|
||||
* Sets the class of the application.
|
||||
* @param serviceClass the class
|
||||
* @return this configuration
|
||||
*/
|
||||
ApplicationConfiguration serviceClass(String serviceClass);
|
||||
|
||||
/**
|
||||
* Returns the version of the application.
|
||||
* @return the version
|
||||
*/
|
||||
String version();
|
||||
|
||||
/**
|
||||
* Sets the version of the application.
|
||||
* @param version the version
|
||||
* @return this configuration
|
||||
*/
|
||||
ApplicationConfiguration version(String version);
|
||||
|
||||
/**
|
||||
* Returns the description of the application.
|
||||
* @return the description
|
||||
*/
|
||||
String description();
|
||||
|
||||
/**
|
||||
* Sets the description of the application.
|
||||
* @param description the description
|
||||
* @return this configuration
|
||||
*/
|
||||
ApplicationConfiguration description(String description);
|
||||
@NotEmpty @JsonProperty("persistence")
|
||||
PersistenceConfiguration persistenceConfiguration;
|
||||
|
||||
public Set<GCubeExclude> excludes() {
|
||||
return excludes;
|
||||
}
|
||||
|
||||
public Set<GCubeInclude> includes() {
|
||||
return includes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the persistence manager of the application.
|
||||
* @return the manager
|
||||
*/
|
||||
PersistenceWriter persistence();
|
||||
public ApplicationConfiguration() {}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String context() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of request paths that should not be subjected to request management.
|
||||
* @return the set of exclude paths.
|
||||
*/
|
||||
Set<Exclude> excludes();
|
||||
public ApplicationConfiguration excludes(GCubeExclude ... excludes) {
|
||||
this.excludes=new HashSet<GCubeExclude>(Arrays.asList(excludes));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of request paths that should be subjected to request management.
|
||||
* @return the set of exclude paths.
|
||||
*/
|
||||
Set<Include> includes();
|
||||
public ApplicationConfiguration includes(GCubeInclude... includes) {
|
||||
this.includes=new HashSet<GCubeInclude>(Arrays.asList(includes));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the persistence manager of the application.
|
||||
* @param manager the manager
|
||||
* @return this configuration
|
||||
*/
|
||||
ApplicationConfiguration persistence(PersistenceWriter manager);
|
||||
|
||||
public ApplicationConfiguration context(String context) {
|
||||
this.context = context;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates this configuration.
|
||||
*
|
||||
* @throws IllegalStateException if the configuration is not valid
|
||||
*/
|
||||
void validate();
|
||||
|
||||
public ApplicationConfiguration name(String name) {
|
||||
this.name=name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges this configuration with another configuration
|
||||
* @param config the other configuration
|
||||
*/
|
||||
void merge(ApplicationConfiguration config);
|
||||
public ApplicationConfiguration persistenceConfiguration(PersistenceConfiguration configuration) {
|
||||
this.persistenceConfiguration = configuration;
|
||||
return this;
|
||||
}
|
||||
|
||||
ApplicationConfiguration excludes(Exclude ... excludes);
|
||||
public ApplicationConfiguration proxable(boolean proxable) {
|
||||
this.proxable = proxable;
|
||||
return this;
|
||||
}
|
||||
|
||||
ApplicationConfiguration includes(Include ... includes);
|
||||
|
||||
public String serviceClass() {
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
public ApplicationConfiguration serviceClass(String group) {
|
||||
this.group=group;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String version() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public ApplicationConfiguration version(String version) {
|
||||
this.version=version;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public String description() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public ApplicationConfiguration description(String description) {
|
||||
this.description=description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean proxable() {
|
||||
return proxable;
|
||||
}
|
||||
|
||||
public PersistenceConfiguration persistenceConfiguration() {
|
||||
return persistenceConfiguration;
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
|
||||
List<String> msgs = new ArrayList<String>();
|
||||
|
||||
Validator validator = ValidatorFactory.validator();
|
||||
|
||||
for (ValidationError error : validator.validate(this))
|
||||
msgs.add(error.toString());
|
||||
|
||||
if (!this.excludes().isEmpty() && !this.includes().isEmpty())
|
||||
msgs.add("exclude tags and includes tags are mutually exclusive");
|
||||
|
||||
if (!msgs.isEmpty())
|
||||
throw new IllegalStateException("invalid configuration: "+msgs);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(description, excludes, group, includes, name, proxable, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ApplicationConfiguration other = (ApplicationConfiguration) obj;
|
||||
return Objects.equals(description, other.description)
|
||||
&& Objects.equals(excludes, other.excludes) && Objects.equals(group, other.group)
|
||||
&& Objects.equals(includes, other.includes) && Objects.equals(name, other.name)
|
||||
&& proxable == other.proxable && Objects.equals(version, other.version);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package org.gcube.smartgears.configuration.application;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.annotation.XmlAnyElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.gcube.common.validator.ValidationError;
|
||||
import org.gcube.common.validator.Validator;
|
||||
import org.gcube.common.validator.ValidatorFactory;
|
||||
import org.gcube.common.validator.annotations.IsValid;
|
||||
import org.gcube.smartgears.extensions.ApplicationExtension;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* The {@link ApplicationExtension}s that manage the application.
|
||||
*
|
||||
* @author Fabio Simeoni
|
||||
*
|
||||
*/
|
||||
@XmlRootElement(name="extensions")
|
||||
public class ApplicationExtensions {
|
||||
|
||||
@XmlAnyElement(lax=true) @IsValid
|
||||
List<ApplicationExtension> extensions = new ArrayList<ApplicationExtension>();
|
||||
|
||||
public ApplicationExtensions() {}
|
||||
|
||||
/**
|
||||
* Returns the extensions for the application.
|
||||
* @return the extensions
|
||||
*/
|
||||
public List<ApplicationExtension> extensions() {
|
||||
return extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the extensions for the application.
|
||||
* @param extensions the extensions
|
||||
* @return this configuration
|
||||
*/
|
||||
public ApplicationExtensions set(ApplicationExtension ... extensions) {
|
||||
this.extensions = Arrays.asList(extensions);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return extensions.toString();
|
||||
}
|
||||
|
||||
public void validate() {
|
||||
|
||||
List<String> msgs = new ArrayList<String>();
|
||||
|
||||
Validator validator = ValidatorFactory.validator();
|
||||
|
||||
for (ValidationError error : validator.validate(this))
|
||||
msgs.add(error.toString());
|
||||
|
||||
if (!msgs.isEmpty())
|
||||
throw new IllegalStateException("invalid configuration: "+msgs);
|
||||
|
||||
}
|
||||
|
||||
//since we use @AnyElement, after deserialisation, we check there are no DOM elements
|
||||
void afterUnmarshal(Unmarshaller u, Object parent) {
|
||||
for (Object o : extensions)
|
||||
if (o instanceof Element)
|
||||
throw new RuntimeException("invalid extensions detected: "+Element.class.cast(o).getLocalName());
|
||||
}
|
||||
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
package org.gcube.smartgears.configuration.application;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.smartgears.configuration.ProxyAddress;
|
||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||
import org.gcube.smartgears.persistence.LocalPersistence;
|
||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Fabio Simeoni
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class BridgedApplicationConfiguration implements ApplicationConfiguration {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(ApplicationConfiguration.class);
|
||||
|
||||
private final ApplicationConfiguration application;
|
||||
|
||||
|
||||
public BridgedApplicationConfiguration(ContainerConfiguration container, ApplicationConfiguration config) {
|
||||
|
||||
this.application=config;
|
||||
|
||||
if (application.persistence()==null) {
|
||||
|
||||
String location = container.persistence().getLocation()+"/"+application.name();
|
||||
File dir = new File(location);
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
|
||||
application.persistence(new LocalPersistence(location));
|
||||
|
||||
log.trace("setting persistence location for {} @ {}",application.name(), dir.getAbsolutePath());
|
||||
|
||||
}
|
||||
|
||||
if (application.proxable() && container.proxy()!=null)
|
||||
application.proxyAddress(container.proxy());
|
||||
|
||||
}
|
||||
|
||||
public ApplicationConfiguration inner() {
|
||||
return application;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String context() {
|
||||
return application.context();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration context(String context) {
|
||||
return application.context(context);
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return application.name();
|
||||
}
|
||||
|
||||
public ApplicationConfiguration name(String name) {
|
||||
return application.name(name);
|
||||
}
|
||||
|
||||
public String serviceClass() {
|
||||
return application.serviceClass();
|
||||
}
|
||||
|
||||
public ApplicationConfiguration serviceClass(String group) {
|
||||
return application.serviceClass(group);
|
||||
}
|
||||
|
||||
public String version() {
|
||||
return application.version();
|
||||
}
|
||||
|
||||
public ApplicationConfiguration version(String version) {
|
||||
return application.version(version);
|
||||
}
|
||||
|
||||
public String description() {
|
||||
return application.description();
|
||||
}
|
||||
|
||||
public ApplicationConfiguration description(String description) {
|
||||
return application.description(description);
|
||||
}
|
||||
|
||||
public PersistenceWriter persistence() {
|
||||
return application.persistence();
|
||||
}
|
||||
|
||||
public ApplicationConfiguration persistence(PersistenceWriter manager) {
|
||||
return application.persistence(manager);
|
||||
}
|
||||
|
||||
|
||||
public void validate() {
|
||||
|
||||
application.validate();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Exclude> excludes() {
|
||||
return application.excludes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Include> includes() {
|
||||
return application.includes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(ApplicationConfiguration config) {
|
||||
application.merge(config);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean proxable() {
|
||||
return application.proxable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration excludes(Exclude ... excludes) {
|
||||
return application.excludes(excludes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration includes(Include... includes) {
|
||||
return application.includes(includes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProxyAddress proxyAddress() {
|
||||
return application.proxyAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration proxyAddress(ProxyAddress proxy) {
|
||||
return proxyAddress(proxy);
|
||||
}
|
||||
|
||||
}
|
@ -1,207 +0,0 @@
|
||||
package org.gcube.smartgears.configuration.application;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementRef;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.gcube.common.validator.ValidationError;
|
||||
import org.gcube.common.validator.Validator;
|
||||
import org.gcube.common.validator.ValidatorFactory;
|
||||
import org.gcube.common.validator.annotations.IsValid;
|
||||
import org.gcube.common.validator.annotations.NotNull;
|
||||
import org.gcube.smartgears.configuration.ProxyAddress;
|
||||
import org.gcube.smartgears.persistence.LocalPersistence;
|
||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||
|
||||
/**
|
||||
* The configuration of a managed app.
|
||||
* <p>
|
||||
* Includes the list of its client services.
|
||||
*
|
||||
* @author Fabio Simeoni
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
@XmlRootElement(name="application")
|
||||
public class DefaultApplicationConfiguration implements ApplicationConfiguration {
|
||||
|
||||
String context;
|
||||
|
||||
@XmlAttribute(name = "proxable")
|
||||
private boolean proxable = true;
|
||||
|
||||
@XmlElement(name="name" , required=true)
|
||||
@NotNull
|
||||
String name;
|
||||
|
||||
@XmlElement(name="group", required=true)
|
||||
@NotNull
|
||||
String group;
|
||||
|
||||
@XmlElement(name="version", required=true)
|
||||
@NotNull
|
||||
String version;
|
||||
|
||||
@XmlElement(name="description")
|
||||
String description="";
|
||||
|
||||
@XmlElementRef
|
||||
Set<Exclude> excludes= new LinkedHashSet<Exclude>();
|
||||
|
||||
@XmlElementRef
|
||||
Set<Include> includes= new LinkedHashSet<Include>();
|
||||
|
||||
@XmlElementRef(type=LocalPersistence.class)
|
||||
@NotNull @IsValid
|
||||
private PersistenceWriter persistenceManager;
|
||||
|
||||
@IsValid
|
||||
ProxyAddress proxyAddress;
|
||||
|
||||
@Override
|
||||
public Set<Exclude> excludes() {
|
||||
return excludes;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<Include> includes() {
|
||||
return includes;
|
||||
}
|
||||
|
||||
public DefaultApplicationConfiguration() {}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String context() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration context(String context) {
|
||||
this.context=context;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration excludes(Exclude ... excludes) {
|
||||
this.excludes=new HashSet<Exclude>(Arrays.asList(excludes));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration includes(Include... includes) {
|
||||
this.includes=new HashSet<Include>(Arrays.asList(includes));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration name(String name) {
|
||||
this.name=name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serviceClass() {
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration serviceClass(String group) {
|
||||
this.group=group;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String version() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration version(String version) {
|
||||
this.version=version;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration description(String description) {
|
||||
this.description=description;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean proxable() {
|
||||
return proxable;
|
||||
}
|
||||
|
||||
public ProxyAddress proxyAddress() {
|
||||
return proxyAddress;
|
||||
}
|
||||
|
||||
|
||||
public ApplicationConfiguration proxyAddress(ProxyAddress proxyAddress) {
|
||||
this.proxyAddress = proxyAddress;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PersistenceWriter persistence() {
|
||||
return persistenceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationConfiguration persistence(PersistenceWriter manager) {
|
||||
this.persistenceManager=manager;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
|
||||
List<String> msgs = new ArrayList<String>();
|
||||
|
||||
Validator validator = ValidatorFactory.validator();
|
||||
|
||||
for (ValidationError error : validator.validate(this))
|
||||
msgs.add(error.toString());
|
||||
|
||||
if (!this.excludes().isEmpty() && !this.includes().isEmpty())
|
||||
msgs.add("exclude tags and includes tags are mutually exclusive");
|
||||
|
||||
if (!msgs.isEmpty())
|
||||
throw new IllegalStateException("invalid configuration: "+msgs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void merge(ApplicationConfiguration config) {
|
||||
|
||||
if (config.persistence()!=null)
|
||||
persistence(config.persistence());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package org.gcube.smartgears.configuration.library;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
|
||||
import org.gcube.smartgears.utils.Utils;
|
||||
|
||||
/**
|
||||
* Binds {@link ContainerConfiguration}s to and from XML serialisations.
|
||||
*
|
||||
* @author Fabio Simeoni
|
||||
*
|
||||
*/
|
||||
public class SmartGearsConfigurationBinder {
|
||||
|
||||
/**
|
||||
* Returns a {@link ContainerConfiguration} from its XML serialisation.
|
||||
*
|
||||
* @param stream the serialisation
|
||||
* @return the configuration
|
||||
* @throws RuntimeException if the serialisation is invalid
|
||||
*/
|
||||
public SmartGearsConfiguration bind(InputStream stream) {
|
||||
|
||||
try {
|
||||
|
||||
JAXBContext ctx = JAXBContext.newInstance(SmartGearsConfiguration.class);
|
||||
|
||||
SmartGearsConfiguration config = (SmartGearsConfiguration) ctx.createUnmarshaller().unmarshal(stream);
|
||||
|
||||
return config;
|
||||
|
||||
} catch (JAXBException e) {
|
||||
|
||||
throw new RuntimeException("invalid library configuration", e);
|
||||
|
||||
}
|
||||
finally {
|
||||
|
||||
Utils.closeSafely(stream);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package org.gcube.smartgears.persistence;
|
||||
|
||||
import org.gcube.common.validator.annotations.NotEmpty;
|
||||
import org.gcube.common.validator.annotations.NotNull;
|
||||
import org.gcube.smartgears.configuration.ComponentConfiguration;
|
||||
|
||||
public class LocalWriterConfiguration implements ComponentConfiguration{
|
||||
|
||||
@NotEmpty @NotNull
|
||||
private String location;
|
||||
|
||||
protected LocalWriterConfiguration() {}
|
||||
|
||||
public LocalWriterConfiguration(String location) {
|
||||
super();
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<extensions>
|
||||
<remote-management/>
|
||||
</extensions>
|
@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<Resource>
|
||||
<ID />
|
||||
<Type>Service</Type>
|
||||
<Profile>
|
||||
<Description>${description}</Description>
|
||||
<Class>${serviceClass}</Class>
|
||||
<Name>common-smartgears</Name>
|
||||
<Version>1.0.0</Version>
|
||||
<Packages>
|
||||
<Software>
|
||||
<Description>${description}</Description>
|
||||
<Name>common-smartgears</Name>
|
||||
<Version>4.0.0-SNAPSHOT</Version>
|
||||
<MavenCoordinates>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-smartgears</artifactId>
|
||||
<version>4.0.0-SNAPSHOT</version>
|
||||
</MavenCoordinates>
|
||||
<Type>Library</Type>
|
||||
<Files>
|
||||
<File>common-smartgears-4.0.0-SNAPSHOT.jar</File>
|
||||
</Files>
|
||||
</Software>
|
||||
</Packages>
|
||||
</Profile>
|
||||
</Resource>
|
||||
|
@ -0,0 +1,88 @@
|
||||
package utils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.smartgears.configuration.PersistenceConfiguration;
|
||||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||
import org.gcube.smartgears.configuration.application.GCubeExclude;
|
||||
import org.gcube.smartgears.persistence.LocalWriter;
|
||||
import org.gcube.smartgears.persistence.LocalWriterConfiguration;
|
||||
import org.junit.Test;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class ConfigurationTest {
|
||||
|
||||
static final String yamlConf = "name: test\n"
|
||||
+ "group: group\n"
|
||||
+ "version: 1.0.0\n"
|
||||
+ "description: pippo\n"
|
||||
+ "proxable: true\n"
|
||||
+ "excludes:\n"
|
||||
+ "- path: /pippo/*\n"
|
||||
+ "- handlers: [H1, H2]\n"
|
||||
+ " path: /trip\n"
|
||||
+ "persistence:\n"
|
||||
+ " implementationClass: org.gcube.smartgears.persistence.LocalWriter\n"
|
||||
+ " writerConfiguration:\n"
|
||||
+ " className: org.gcube.smartgears.persistence.LocalWriterConfiguration\n"
|
||||
+ " location: /tmp";
|
||||
|
||||
static final String yamlConfBase = "name: test\n"
|
||||
+ "group: group\n"
|
||||
+ "version: 1.0.0\n"
|
||||
+ "description: pippo";
|
||||
|
||||
@Test
|
||||
public void deserialize() {
|
||||
Yaml yaml = new Yaml();
|
||||
InputStream inputStream = this.getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("applicationTest.yaml");
|
||||
ApplicationConfiguration customer = yaml.load(inputStream);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serialize() throws Exception{
|
||||
ApplicationConfiguration configuration =new ApplicationConfiguration();
|
||||
configuration.name("test").serviceClass("group").description("pippo").version("1.0.0").excludes(new GCubeExclude("/pippo/*"), new GCubeExclude(List.of("H1","H2"), "/trip"));
|
||||
configuration.persistenceConfiguration(new PersistenceConfiguration(LocalWriter.class, new LocalWriterConfiguration("/tmp")));
|
||||
/*
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String value = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(configuration);
|
||||
System.out.println(value);
|
||||
Map<String, Object> res = mapper.readValue(value, Map.class);
|
||||
|
||||
|
||||
|
||||
Yaml yaml = new Yaml();
|
||||
String yamlValue = yaml.dump(res);
|
||||
System.out.println(yamlValue);
|
||||
*/
|
||||
|
||||
Yaml yaml = new Yaml();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String mapAsString = mapper.writeValueAsString(yaml.load(yamlConf));
|
||||
System.out.println(mapAsString);
|
||||
|
||||
ApplicationConfiguration conf2 = mapper.readValue(mapAsString, ApplicationConfiguration.class);
|
||||
Assert.assertTrue(configuration.equals(conf2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeBase() throws Exception{
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Yaml yaml = new Yaml();
|
||||
|
||||
String mapAsString = mapper.writeValueAsString(yaml.load(yamlConfBase));
|
||||
System.out.println(mapAsString);
|
||||
|
||||
ApplicationConfiguration conf2 = mapper.readValue(mapAsString, ApplicationConfiguration.class);
|
||||
Assert.assertEquals("test", conf2.name());
|
||||
|
||||
}
|
||||
}
|
@ -1,155 +0,0 @@
|
||||
package utils;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
||||
import org.gcube.smartgears.configuration.application.ApplicationExtensions;
|
||||
import org.gcube.smartgears.configuration.application.ApplicationHandlers;
|
||||
import org.gcube.smartgears.configuration.application.DefaultApplicationConfiguration;
|
||||
import org.gcube.smartgears.extensions.ApplicationExtension;
|
||||
import org.gcube.smartgears.handlers.application.ApplicationHandler;
|
||||
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
|
||||
public static String location = "/tmp/ghn-home";
|
||||
public static String context_root = "test-app";
|
||||
public static String context_root_path = "/" + context_root;
|
||||
public static String servlet_name = "test";
|
||||
public static String scope = "/gcube/devsec";
|
||||
|
||||
public static class Box<T> {
|
||||
|
||||
T t;
|
||||
|
||||
public void put(T t) {
|
||||
this.t=t;
|
||||
}
|
||||
|
||||
public T get() {
|
||||
return t;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serialises a {@link ApplicationConfiguration} to XML.
|
||||
*
|
||||
* @param config the configuration
|
||||
* @return the serialisation
|
||||
* @throws RuntimeException if the configuration cannot be serialised
|
||||
*/
|
||||
public static String bind(ApplicationConfiguration config) {
|
||||
|
||||
try {
|
||||
|
||||
//collect handler classes
|
||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
|
||||
classes.add(DefaultApplicationConfiguration.class);
|
||||
if (config.persistence()!=null)
|
||||
classes.add(config.persistence().getClass());
|
||||
|
||||
//serialises configuration
|
||||
|
||||
JAXBContext ctx = JAXBContext.newInstance(classes.toArray(new Class<?>[0]));
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
ctx.createMarshaller().marshal(config, writer);
|
||||
|
||||
return writer.toString();
|
||||
|
||||
|
||||
} catch (JAXBException e) {
|
||||
|
||||
throw new RuntimeException("invalid application configuration", e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialises application handlers.
|
||||
*
|
||||
* @param handlers the handlers
|
||||
* @return the serialisation
|
||||
* @throws RuntimeException if the handlers cannot be serialised
|
||||
*/
|
||||
public static String bind(ApplicationHandlers handlers) {
|
||||
|
||||
try {
|
||||
|
||||
//collect handler classes
|
||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
|
||||
classes.add(ApplicationHandlers.class);
|
||||
|
||||
for (ApplicationHandler<?> h : handlers.lifecycleHandlers())
|
||||
classes.add(h.getClass());
|
||||
|
||||
for (ApplicationHandler<?> h : handlers.requestHandlers())
|
||||
classes.add(h.getClass());
|
||||
|
||||
|
||||
//serialises configuration
|
||||
|
||||
JAXBContext ctx = JAXBContext.newInstance(classes.toArray(new Class<?>[0]));
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
ctx.createMarshaller().marshal(handlers, writer);
|
||||
|
||||
return writer.toString();
|
||||
|
||||
} catch (JAXBException e) {
|
||||
|
||||
throw new RuntimeException("invalid handler configuration", e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialises application extensions.
|
||||
*
|
||||
* @param extensions the extensions
|
||||
* @return the serialisation
|
||||
* @throws RuntimeException if the extensions cannot be serialised
|
||||
*/
|
||||
public static String bind(ApplicationExtensions extensions) {
|
||||
|
||||
try {
|
||||
|
||||
//collect handler classes
|
||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
|
||||
classes.add(ApplicationExtensions.class);
|
||||
|
||||
for (ApplicationExtension h : extensions.extensions())
|
||||
classes.add(h.getClass());
|
||||
|
||||
|
||||
//serialises configuration
|
||||
|
||||
JAXBContext ctx = JAXBContext.newInstance(classes.toArray(new Class<?>[0]));
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
ctx.createMarshaller().marshal(extensions, writer);
|
||||
|
||||
return writer.toString();
|
||||
|
||||
} catch (JAXBException e) {
|
||||
|
||||
throw new RuntimeException("invalid handler configuration", e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
name: test
|
||||
group: group
|
||||
version: 1.0.0
|
||||
#not mandatory
|
||||
description: pippo
|
||||
#not mandatory
|
||||
proxable: true
|
||||
#not mandatory
|
||||
excludes:
|
||||
- path: /pippo/*
|
||||
- handlers: [H1, H2]
|
||||
path: /trip
|
||||
#not mandatory
|
||||
persistence:
|
||||
implementationClass: org.gcube.smartgears.persistence.LocalWriter
|
||||
writerConfiguration:
|
||||
className: org.gcube.smartgears.persistence.LocalWriterConfiguration
|
||||
location: /tmp
|
Loading…
Reference in New Issue