Commit 35885daa authored by ipatini's avatar ipatini
Browse files

EMS: Control Service, config: Added 'StaticResourceProperties' class and moved...

EMS: Control Service, config: Added 'StaticResourceProperties' class and moved into it all @Value-annotated properties of StaticResourceConfiguration. Updated code to use StaticResourceProperties instance. Changed corresponding settings in 'eu.melodic.event.control.properties' to kebab-case (effectively replaced '.' with '-') and rearranged them.
parent 1bef34aa
......@@ -44,6 +44,9 @@ control.tc-save-file = ${EMS_TC_FILE:${LOGS_DIR:${MELODIC_CONFIG_DIR}/../logs}/_
### Debug settings - Enable event debugging
control.event-debug-enabled = ${EVENT_DEBUG_ENABLED:true}
#control.event-debug-resource-path=classpath:/public/
control.event-debug-resource-path=file:${PUBLIC_DIR}/
control.event-debug-resource-context=/event-debug/**
################################################################################
### Process CAMEL model on start-up
......@@ -123,24 +126,25 @@ control.ssl.key-entry-ext-san = dns:localhost,ip:127.0.0.1,ip:${DEFAULT_IP},ip:$
#web.form-authentication.username=admin
#web.form-authentication.password=ems
### Web configuration - Resources
### Web configuration - Resources and redirects
spring.mvc.favicon.enabled=false
static.favicon.path=file:${PUBLIC_DIR}/favicon.ico
#static.resource.path=file:${PUBLIC_DIR}/
#static.resource.context=/resources/**
#static.resource.redirect=/resources/index.html
static.resource.path=file:${PUBLIC_DIR}/
static.resource.context=/**
static.resource.redirects={ '/': '/admin/index.html', '/index.html': '/admin/index.html', '/admin': '/admin/index.html', '/admin/': '/admin/index.html', '/resources': '/resources/index.html', '/resources/': '/resources/index.html' }
static.logs.path=file:${LOGS_DIR}/
static.logs.context=/logs/**
# Effective only if 'control.event-debug-enabled' is 'true'
#event-debug.resource.path=classpath:/public/
event-debug.resource.path=file:${PUBLIC_DIR}/
event-debug.resource.context=/event-debug/**
#static.resource.redirect=/event-debug/index.html
static.favicon-path=file:${PUBLIC_DIR}/favicon.ico
#static.resource-path=file:${PUBLIC_DIR}/
#static.resource-context=/resources/**
static.resource-path=file:${PUBLIC_DIR}/
static.resource-context=/**
#static.resource-redirect=/resources/index.html
static.resource-redirects.[/]=/admin/index.html
static.resource-redirects.[/index.html]=/admin/index.html
static.resource-redirects.[/admin]=/admin/index.html
static.resource-redirects.[/admin/]=/admin/index.html
static.resource-redirects.[/resources]=/resources/index.html
static.resource-redirects.[/resources/]=/resources/index.html
static.logs-path=file:${LOGS_DIR}/
static.logs-context=/logs/**
### Web configuration - Authorization check
authorization.enabled = false
......
......@@ -18,6 +18,7 @@ import eu.melodic.event.baguette.server.BaguetteServer;
import eu.melodic.event.baguette.server.NodeRegistryEntry;
import eu.melodic.event.baguette.server.properties.BaguetteServerProperties;
import eu.melodic.event.control.properties.ControlServiceProperties;
import eu.melodic.event.control.properties.StaticResourceProperties;
import eu.melodic.event.control.webconf.WebSecurityConfig;
import eu.melodic.event.translate.TranslationContext;
import eu.melodic.event.util.CredentialsMap;
......@@ -61,6 +62,8 @@ public class ControlServiceController {
@Autowired
private ControlServiceProperties properties;
@Autowired
private StaticResourceProperties staticResourceProperties;
@Autowired
private ControlServiceCoordinator coordinator;
@Autowired
private WebSecurityConfig webSecurityConfig;
......@@ -421,7 +424,7 @@ public class ControlServiceController {
private void updateRegistrationInfo(HttpServletRequest request, NodeRegistryEntry entry) {
// Get web server base URL
String staticResourceContext = coordinator.getControlServiceProperties().getStaticResourceContext();
String staticResourceContext = staticResourceProperties.getResourceContext();
staticResourceContext = StringUtils.substringBeforeLast(staticResourceContext,"/**");
staticResourceContext = StringUtils.substringBeforeLast(staticResourceContext,"/*");
if (!staticResourceContext.startsWith("/")) staticResourceContext = "/"+staticResourceContext;
......
......@@ -15,6 +15,7 @@ import eu.melodic.event.common.misc.SystemResourceMonitor;
import eu.melodic.event.control.ControlServiceCoordinator;
import eu.melodic.event.control.properties.ControlServiceProperties;
import eu.melodic.event.control.properties.InfoServiceProperties;
import eu.melodic.event.control.properties.StaticResourceProperties;
import eu.melodic.event.translate.TranslationContext;
import eu.melodic.event.util.FunctionDefinition;
import eu.melodic.event.util.GROUPING;
......@@ -44,6 +45,7 @@ public class EmsInfoServiceImpl implements IEmsInfoService {
private final ControlServiceProperties controlServiceProperties;
private final InfoServiceProperties infoServiceProperties;
private final ControlServiceCoordinator controlServiceCoordinator;
private final StaticResourceProperties staticResourceProperties;
private final BuildInfoProvider buildInfoProvider;
private final SystemInfoProvider systemInfoProvider;
......@@ -152,7 +154,6 @@ public class EmsInfoServiceImpl implements IEmsInfoService {
controlServiceInfo.put("prop-executionware", controlServiceProperties.getExecutionware().toString());
controlServiceInfo.put("prop-preload-camel-model", controlServiceProperties.getPreloadCamelModel());
controlServiceInfo.put("prop-preload-cp-model", controlServiceProperties.getPreloadCpModel());
controlServiceInfo.put("prop-static-resource-context", controlServiceProperties.getStaticResourceContext());
controlServiceInfo.put("prop-upperware-grouping", controlServiceProperties.getUpperwareGrouping());
controlServiceInfo.put("prop-tc-load-file", controlServiceProperties.getTcLoadFile());
controlServiceInfo.put("prop-tc-save-file", controlServiceProperties.getTcSaveFile());
......@@ -169,6 +170,9 @@ public class EmsInfoServiceImpl implements IEmsInfoService {
debugFlags.put("skip-esb-notification", controlServiceProperties.isSkipEsbNotification());
controlServiceInfo.put("prop-debug-flags",debugFlags);
}
if (staticResourceProperties!=null) {
controlServiceInfo.put("prop-static-resource", staticResourceProperties);
}
metrics.put(CONTROL_INFO_PROVIDER, controlServiceInfo);
// Collect Broker-CEP metrics
......
......@@ -42,6 +42,8 @@ public class ControlServiceProperties {
private IpSetting ipSetting = IpSetting.PUBLIC_IP;
@Value("${EXECUTIONWARE}")
private ExecutionWare executionware = ExecutionWare.PROACTIVE;
@Value("${password-encoder-class:}")
private String passwordEncoderClass;
private String upperwareGrouping;
private String metasolverConfigurationUrl;
......@@ -60,19 +62,16 @@ public class ControlServiceProperties {
private String tcLoadFile;
private String tcSaveFile;
private boolean eventDebugEnabled;
private String eventDebugResourceContext;
private String[] eventDebugResourcePath;
private boolean exitAllowed;
@Min(1)
private long exitGracePeriod = 10;
private int exitCode = 0;
@Value("${static.resource.context}")
private String staticResourceContext = "/**";
@Value("${password-encoder-class:}")
private String passwordEncoderClass;
// control.ssl.** settings
private KeystoreAndCertificateProperties ssl;
}
/*
* Copyright (C) 2017-2022 Institute of Communication and Computer Systems (imu.iccs.gr)
*
* This Source Code Form is subject to the terms of the Mozilla Public License, v2.0, unless
* Esper library is used, in which case it is subject to the terms of General Public License v2.0.
* If a copy of the MPL was not distributed with this file, you can obtain one at
* https://www.mozilla.org/en-US/MPL/2.0/
*/
package eu.melodic.event.control.properties;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated;
import java.util.LinkedHashMap;
import java.util.Map;
@Slf4j
@Data
@Validated
@Configuration
@ConfigurationProperties(prefix = "static")
public class StaticResourceProperties {
private String faviconContext = "/favicon.ico";
private String faviconPath;
private String resourceContext = "/resources/**";
private String[] resourcePath;
private String resourceRedirect;
private Map<String,String> resourceRedirects = new LinkedHashMap<>();
private String logsContext = "/logs/**";
private String[] logsPath;
}
......@@ -9,9 +9,12 @@
package eu.melodic.event.control.webconf;
import eu.melodic.event.control.properties.ControlServiceProperties;
import eu.melodic.event.control.properties.StaticResourceProperties;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -24,60 +27,51 @@ import java.util.Map;
@Slf4j
@Configuration
public class StaticResourceConfiguration implements WebMvcConfigurer {
@Value("${static.favicon.context:/favicon.ico}")
private String faviconContext;
@Value("${static.favicon.path:#{null}}")
private String faviconPath;
@Value("${static.resource.context:/resources/**}")
private String staticResourceContext;
@Value("${static.resource.path:#{null}}")
private String[] staticResourcePath;
@Value("${static.resource.redirect:#{null}}")
private String staticResourceRedirect;
@Value("#{${static.resource.redirects:{}}}")
private Map<String,String> staticResourceRedirects;
@Value("${static.logs.context:/logs/**}")
private String staticLogsContext;
@Value("${static.logs.path:#{null}}")
private String[] staticLogsPath;
@Value("${event-debug.resource.context:/event-debug/**}")
private String eventDebugResourceContext;
@Value("${event-debug.resource.path:#{null}}")
private String[] eventDebugResourcePath;
@Value("${control.event-debug-enabled:false}")
private boolean eventDebugEnabled;
public class StaticResourceConfiguration implements WebMvcConfigurer, InitializingBean {
@Autowired
private StaticResourceProperties properties;
@Autowired
private ControlServiceProperties controlServiceProperties;
public void afterPropertiesSet() {
log.debug("StaticResourceConfiguration: afterPropertiesSet: {}", properties);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String faviconContext = properties.getFaviconContext();
String faviconPath = properties.getFaviconPath();
if(StringUtils.isNotBlank(faviconPath)) {
log.info("Serving favicon.ico from: {} --> {}", faviconContext, faviconPath);
registry
.addResourceHandler(faviconContext)
.addResourceLocations(faviconPath);
}
if(staticResourcePath != null && staticResourcePath.length > 0) {
log.info("Serving static content from: {} --> {}", staticResourceContext, staticResourcePath);
String resourceContext = properties.getResourceContext();
String[] resourcePath = properties.getResourcePath();
if (resourcePath != null && resourcePath.length > 0) {
log.info("Serving static content from: {} --> {}", resourceContext, resourcePath);
registry
.addResourceHandler(staticResourceContext)
.addResourceLocations(staticResourcePath);
.addResourceHandler(resourceContext)
.addResourceLocations(resourcePath);
}
if(staticLogsPath != null && staticLogsPath.length > 0) {
log.info("Serving logs from: {} --> {}", staticLogsContext, staticLogsPath);
String logsContext = properties.getLogsContext();
String[] logsPath = properties.getLogsPath();
if (logsPath != null && logsPath.length > 0) {
log.info("Serving logs from: {} --> {}", logsContext, logsPath);
registry
.addResourceHandler(staticLogsContext)
.addResourceLocations(staticLogsPath);
.addResourceHandler(logsContext)
.addResourceLocations(logsPath);
}
if(eventDebugEnabled && eventDebugResourcePath != null && eventDebugResourcePath.length > 0) {
log.info("Serving event-debug content from: {} --> {}", eventDebugResourceContext, eventDebugResourcePath);
if (controlServiceProperties.isEventDebugEnabled()
&& controlServiceProperties.getEventDebugResourcePath()!=null
&& controlServiceProperties.getEventDebugResourcePath().length > 0)
{
log.info("Serving event-debug content from: {} --> {}", controlServiceProperties.getEventDebugResourceContext(), controlServiceProperties.getEventDebugResourcePath());
registry
.addResourceHandler(eventDebugResourceContext)
.addResourceLocations(eventDebugResourcePath)
.addResourceHandler(controlServiceProperties.getEventDebugResourceContext())
.addResourceLocations(controlServiceProperties.getEventDebugResourcePath())
//.setCachePeriod(0)
;
}
......@@ -88,16 +82,18 @@ public class StaticResourceConfiguration implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// Remains for backward compatibility (of properties file)
if (StringUtils.isNotBlank(staticResourceRedirect)) {
log.info("Redirecting / to: {}", staticResourceRedirect);
String resourceRedirect = properties.getResourceRedirect();
if (StringUtils.isNotBlank(resourceRedirect)) {
log.info("Redirecting / to: {}", resourceRedirect);
registry
.addViewController("/")
.setViewName("redirect:" + staticResourceRedirect);
.setViewName("redirect:" + resourceRedirect);
}
log.debug("Configured resource redirects: {}", staticResourceRedirects);
if (staticResourceRedirects!=null) {
staticResourceRedirects.forEach((context, redirect) -> {
Map<String,String> resourceRedirects = properties.getResourceRedirects();
log.debug("Configured resource redirects: {}", resourceRedirects);
if (resourceRedirects!=null) {
resourceRedirects.forEach((context, redirect) -> {
if (StringUtils.isNotBlank(context) && StringUtils.isNotBlank(redirect)) {
context = context.trim();
redirect = redirect.trim();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment