2016-11-25 15:42:29 +01:00
|
|
|
package org.gcube.smartgears.configuration.container;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2022-03-17 17:17:15 +01:00
|
|
|
import java.util.Collections;
|
2016-11-25 15:42:29 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
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.NotEmpty;
|
|
|
|
import org.gcube.common.validator.annotations.NotNull;
|
2023-01-19 16:16:14 +01:00
|
|
|
import org.gcube.smartgears.configuration.AuthorizationProviderConfiguration;
|
2016-11-25 15:42:29 +01:00
|
|
|
import org.gcube.smartgears.configuration.Mode;
|
2023-02-06 17:34:18 +01:00
|
|
|
import org.gcube.smartgears.configuration.PersistenceConfiguration;
|
2022-03-17 17:17:15 +01:00
|
|
|
import org.gcube.smartgears.configuration.ProxyAddress;
|
2016-11-25 15:42:29 +01:00
|
|
|
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The configuration of the container.
|
|
|
|
*
|
|
|
|
* @author Fabio Simeoni
|
2021-02-22 09:49:18 +01:00
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
2016-11-25 15:42:29 +01:00
|
|
|
*/
|
|
|
|
public class ContainerConfiguration {
|
|
|
|
|
2022-03-17 17:17:15 +01:00
|
|
|
@NotNull @IsValid
|
|
|
|
private BaseConfiguration baseConfiguration;
|
|
|
|
|
|
|
|
@IsValid
|
|
|
|
private Map<String,String> properties = new HashMap<String, String>();
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
@NotNull @IsValid
|
2022-03-17 17:17:15 +01:00
|
|
|
private Site site;
|
2016-11-25 15:42:29 +01:00
|
|
|
|
|
|
|
@IsValid
|
2022-03-17 17:17:15 +01:00
|
|
|
private ProxyAddress proxy;
|
|
|
|
|
|
|
|
@NotEmpty @NotNull
|
|
|
|
private String accountingFallbackLocation;
|
|
|
|
|
|
|
|
private List<ApplicationConfiguration> apps = new ArrayList<ApplicationConfiguration>();
|
|
|
|
|
2023-01-19 16:16:14 +01:00
|
|
|
|
2022-03-17 17:17:15 +01:00
|
|
|
|
|
|
|
@NotNull @IsValid
|
2023-02-06 17:34:18 +01:00
|
|
|
private PersistenceConfiguration persistenceConfiguration;
|
2022-03-17 17:17:15 +01:00
|
|
|
|
|
|
|
@NotNull @IsValid
|
2023-01-19 16:16:14 +01:00
|
|
|
private AuthorizationProviderConfiguration authorizationConfiguration;
|
2016-11-25 15:42:29 +01:00
|
|
|
|
2022-05-25 18:56:42 +02:00
|
|
|
|
|
|
|
protected void setBaseConfiguration(BaseConfiguration baseConfiguration) {
|
|
|
|
this.baseConfiguration = baseConfiguration;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void setProperties(Map<String, String> properties) {
|
|
|
|
this.properties = properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void setSite(Site site) {
|
|
|
|
this.site = site;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void setProxy(ProxyAddress proxy) {
|
|
|
|
this.proxy = proxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void setAccountingFallbackLocation(String accountingFallbackLocation) {
|
|
|
|
this.accountingFallbackLocation = accountingFallbackLocation;
|
|
|
|
}
|
|
|
|
|
2023-02-06 17:34:18 +01:00
|
|
|
protected void setPersistenceConfiguration(PersistenceConfiguration persistenceConfiguration) {
|
|
|
|
this.persistenceConfiguration = persistenceConfiguration;
|
2022-05-25 18:56:42 +02:00
|
|
|
}
|
|
|
|
|
2023-01-19 16:16:14 +01:00
|
|
|
protected void setAuthorizationProviderConfiguration(
|
|
|
|
AuthorizationProviderConfiguration authorizationConfiguration) {
|
|
|
|
this.authorizationConfiguration = authorizationConfiguration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setApps(List<ApplicationConfiguration> apps) {
|
|
|
|
this.apps = apps;
|
2022-05-25 18:56:42 +02:00
|
|
|
}
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Returns the management mode for the container.
|
|
|
|
* @return the management mode
|
|
|
|
*/
|
|
|
|
public Mode mode() {
|
2022-03-17 17:17:15 +01:00
|
|
|
return baseConfiguration.getMode();
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Returns the application configurations included in this configuration.
|
|
|
|
* @return the application configurations
|
|
|
|
*/
|
|
|
|
public List<ApplicationConfiguration> apps() {
|
|
|
|
return apps;
|
|
|
|
}
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Returns the configuration of an application with a given context path.
|
|
|
|
* @param context the context path
|
|
|
|
* @return the application configuration
|
|
|
|
*/
|
|
|
|
public ApplicationConfiguration app(String context) {
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
for (ApplicationConfiguration app : apps)
|
|
|
|
if (context.equals(app.context()))
|
|
|
|
return app;
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
return null;
|
|
|
|
}
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Adds the configuration of an application to this configuration.
|
|
|
|
* @param app the application configuration
|
|
|
|
* @return this configuration
|
|
|
|
*/
|
|
|
|
public synchronized ContainerConfiguration app(ApplicationConfiguration app) {
|
|
|
|
int indexToRemove =-1;
|
|
|
|
int index =0;
|
|
|
|
for (ApplicationConfiguration application : apps){
|
|
|
|
if (app.context().equals(application.context()))
|
|
|
|
indexToRemove = index;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
if(indexToRemove!=-1)
|
|
|
|
apps.remove(indexToRemove);
|
|
|
|
apps.add(app);
|
|
|
|
return this;
|
|
|
|
}
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Returns the geographical site of the container.
|
|
|
|
* @return the site
|
|
|
|
*/
|
|
|
|
public Site site() {
|
|
|
|
return site;
|
|
|
|
}
|
|
|
|
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Returns the infrastructure in which the container is running.
|
|
|
|
* @return the infrastructure
|
|
|
|
*/
|
|
|
|
public String infrastructure() {
|
2022-03-17 17:17:15 +01:00
|
|
|
return baseConfiguration.getInfrastructure();
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
|
|
|
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Returns the host name of the container.
|
|
|
|
* @return the host name;
|
|
|
|
*/
|
|
|
|
public String hostname() {
|
2022-03-17 17:17:15 +01:00
|
|
|
return baseConfiguration.getHostname();
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Returns the port at which the container is listening for requests.
|
|
|
|
* @return the port
|
|
|
|
*/
|
|
|
|
public int port() {
|
2022-03-17 17:17:15 +01:00
|
|
|
return baseConfiguration.getPort();
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
2022-03-17 17:17:15 +01:00
|
|
|
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Returns the port at which the container is listening for requests.
|
|
|
|
* @return the port
|
|
|
|
*/
|
2019-01-16 15:37:56 +01:00
|
|
|
public String protocol() {
|
2022-03-17 17:17:15 +01:00
|
|
|
return baseConfiguration.getProtocol();
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
|
|
|
|
2017-03-21 14:42:21 +01:00
|
|
|
|
2022-03-17 17:17:15 +01:00
|
|
|
public boolean authorizeChildrenContext() {
|
|
|
|
return baseConfiguration.isAuthorizeChildrenContext();
|
2017-03-21 14:42:21 +01:00
|
|
|
}
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
2022-03-17 17:17:15 +01:00
|
|
|
* Returns the proxy of the container.
|
|
|
|
* @return the proxy
|
2016-11-25 15:42:29 +01:00
|
|
|
*/
|
2022-03-17 17:17:15 +01:00
|
|
|
public ProxyAddress proxy() {
|
|
|
|
return proxy;
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
2022-03-17 17:17:15 +01:00
|
|
|
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Returns the persistence manager of the container.
|
|
|
|
* @return the manager
|
|
|
|
*/
|
2023-02-06 17:34:18 +01:00
|
|
|
public PersistenceConfiguration persistenceConfiguration() {
|
|
|
|
return this.persistenceConfiguration;
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-03-17 17:17:15 +01:00
|
|
|
* Returns the persistence manager of the container.
|
|
|
|
* @return the manager
|
2016-11-25 15:42:29 +01:00
|
|
|
*/
|
2022-03-17 17:17:15 +01:00
|
|
|
public String accountingFallbackLocation() {
|
|
|
|
return accountingFallbackLocation;
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2023-01-19 16:16:14 +01:00
|
|
|
/**
|
|
|
|
* Returns the authorization configuration.
|
|
|
|
* @return AuthorizationProviderConfiguration the configuration
|
|
|
|
*/
|
2023-02-06 17:34:18 +01:00
|
|
|
public AuthorizationProviderConfiguration authorizationConfiguration() {
|
2023-01-19 16:16:14 +01:00
|
|
|
return authorizationConfiguration;
|
|
|
|
}
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Returns the configuration properties of the container.
|
|
|
|
* @return the properties
|
|
|
|
*/
|
|
|
|
public Map<String,String> properties() {
|
2022-03-17 17:17:15 +01:00
|
|
|
return Collections.unmodifiableMap(properties);
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the publication frequency for the container's profile.
|
|
|
|
* @return the frquency;
|
|
|
|
*/
|
|
|
|
public long publicationFrequency() {
|
2022-03-17 17:17:15 +01:00
|
|
|
return baseConfiguration.getPublicationFrequencyInSeconds();
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
/**
|
|
|
|
* Validates this configuration
|
|
|
|
*
|
|
|
|
* @throws IllegalStateException if the configuration is invalid
|
|
|
|
*/
|
|
|
|
public void validate() {
|
|
|
|
|
|
|
|
List<String> msgs = new ArrayList<String>();
|
|
|
|
|
|
|
|
Validator validator = ValidatorFactory.validator();
|
2022-03-17 17:17:15 +01:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
for (ValidationError error : validator.validate(this))
|
|
|
|
msgs.add(error.toString());
|
|
|
|
|
|
|
|
if (!msgs.isEmpty())
|
|
|
|
throw new IllegalStateException("invalid configuration: "+msgs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-05-25 18:56:42 +02:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "ContainerConfiguration [baseConfiguration=" + baseConfiguration + ", properties=" + properties
|
|
|
|
+ ", site=" + site + ", proxy=" + proxy + ", accountingFallbackLocation=" + accountingFallbackLocation
|
2023-02-06 17:34:18 +01:00
|
|
|
+ ", persistence=" + persistenceConfiguration.getImplementationClass().getSimpleName()
|
2023-01-19 16:16:14 +01:00
|
|
|
+ ", authorizationProvider=" + authorizationConfiguration + "]";
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
|
|
|
|
2022-03-17 17:17:15 +01:00
|
|
|
|
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|