Skip to content

Commit

Permalink
wfs-service: use a no-op LayerGroupContainmentCache
Browse files Browse the repository at this point in the history
The wfs-service contributes a no-op `LayerGroupContainmentCache` to
avoid the runtime overhead of building up the cache at startup, and the
unnecessary memory footprint.

`LayerGroupContainmentCache` is a securtity subsystem aid and WFS does not
deal with `LayerGroupInfo` at all.
  • Loading branch information
groldan committed May 14, 2024
1 parent ac6ae91 commit ba8099d
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config
Submodule config updated 1 files
+3 −2 geoserver_logging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
* GPL 2.0 license, available at the root application directory.
*/
package org.geoserver.cloud.wfs.config;

import lombok.extern.slf4j.Slf4j;

import org.geoserver.cloud.autoconfigure.catalog.backend.core.GeoServerBackendAutoConfiguration;
import org.geoserver.cloud.wfs.security.NoopLayerGroupContainmentCache;
import org.geoserver.security.impl.LayerGroupContainmentCache;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;

/**
* Runs before {@link GeoServerBackendAutoConfiguration} to provide a {@link
* NoopLayerGroupContainmentCache} before {@link CoreBackendConfiguration's} {@code
* layerGroupContainmentCache()} does.
*
* @since 1.8.2
*/
@AutoConfiguration(before = GeoServerBackendAutoConfiguration.class)
@Slf4j(topic = "org.geoserver.cloud.wfs.config")
public class WfsSecurityOverridesAutoconfiguration {

@Bean
LayerGroupContainmentCache layerGroupContainmentCache() {
log.info("wfs-service is using a no-op LayerGroupContainmentCache");
return new NoopLayerGroupContainmentCache();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* (c) 2024 Open Source Geospatial Foundation - all rights reserved This code is licensed under the
* GPL 2.0 license, available at the root application directory.
*/
package org.geoserver.cloud.wfs.security;

import org.geoserver.catalog.LayerGroupInfo;
import org.geoserver.catalog.impl.CatalogImpl;
import org.geoserver.security.impl.LayerGroupContainmentCache;

/**
* A no-op {@link LayerGroupContainmentCache}, since the WFS service does not deal with {@link
* LayerGroupInfo layer groups} at all, then avoid the starup overhead.
*
* @since 1.8.2
*/
public class NoopLayerGroupContainmentCache extends LayerGroupContainmentCache {

/**
* Since {@link LayerGroupContainmentCache} is a class and the initialization methods are
* private, we give it an empty in-memory catalog and call it a day
*/
public NoopLayerGroupContainmentCache() {
super(new CatalogImpl());
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.geoserver.cloud.wfs.config.WfsAutoConfiguration
org.geoserver.cloud.wfs.config.WfsAutoConfiguration,\
org.geoserver.cloud.wfs.config.WfsSecurityOverridesAutoconfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
*/
package org.geoserver.cloud.wfs.app;

import static org.assertj.core.api.Assertions.assertThat;

import org.geoserver.cloud.wfs.security.NoopLayerGroupContainmentCache;
import org.geoserver.security.impl.LayerGroupContainmentCache;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.ApplicationContext;
import org.xmlunit.assertj3.XmlAssert;

import java.util.Map;
Expand All @@ -18,6 +24,8 @@ abstract class WfsApplicationTest {

protected TestRestTemplate restTemplate = new TestRestTemplate("admin", "geoserver");

@Autowired protected ApplicationContext appContext;

@Test
void owsGetCapabilitiesSmokeTest(@LocalServerPort int servicePort) {
String url =
Expand All @@ -41,4 +49,10 @@ void wfsGetCapabilitiesSmokeTest(@LocalServerPort int servicePort) {
.withNamespaceContext(nscontext)
.hasXPath("/wfs:WFS_Capabilities");
}

@Test
void noopLayerGroupContainmentCache() {
var lgcc = appContext.getBean(LayerGroupContainmentCache.class);
assertThat(lgcc).isInstanceOf(NoopLayerGroupContainmentCache.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ DefaultResourceAccessManager defaultResourceAccessManager( //
* Update: as of geoserver 2.23.2, {@code LayerGroupContainmentCache} implements {@code ApplicationListener<ContextRefreshedEvent>}
*/
@Bean
@ConditionalOnMissingBean
LayerGroupContainmentCache layerGroupContainmentCache(
@Qualifier("rawCatalog") Catalog rawCatalog) {
return new LayerGroupContainmentCache(rawCatalog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
/**
* @since 1.4
*/
@Slf4j(topic = "org.geoserver.cloud.backend.pgconfig.catalog.repository")
@Slf4j(topic = "org.geoserver.cloud.backend.pgconfig.catalog.repository.rowmapper")
public final class CatalogInfoRowMapper {

protected static final ObjectMapper objectMapper = PgconfigObjectMapper.newObjectMapper();
Expand Down

0 comments on commit ba8099d

Please sign in to comment.