diff --git a/src/gwc/autoconfigure/pom.xml b/src/gwc/autoconfigure/pom.xml
index 8f9dea3bf..63c7c7cf2 100644
--- a/src/gwc/autoconfigure/pom.xml
+++ b/src/gwc/autoconfigure/pom.xml
@@ -74,5 +74,10 @@
This default configuration applies if there's no other {@link GeoServerTileLayerConfiguration}
+ * provided.
*
* @see DefaultTileLayerCatalogConfiguration
* @see ConditionalOnGeoWebCacheEnabled
+ * @see PgconfigTileLayerCatalogAutoConfiguration
* @since 1.0
*/
@AutoConfiguration(after = PgconfigTileLayerCatalogAutoConfiguration.class)
diff --git a/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigGwcInitializer.java b/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigGwcInitializer.java
index 77d366388..6ce29894d 100644
--- a/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigGwcInitializer.java
+++ b/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigGwcInitializer.java
@@ -4,39 +4,22 @@
*/
package org.geoserver.cloud.autoconfigure.gwc.backend;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Stopwatch;
-
import lombok.NonNull;
-import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.geoserver.cloud.gwc.backend.pgconfig.PgconfigTileLayerCatalog;
+import org.geoserver.cloud.gwc.config.core.AbstractGwcInitializer;
import org.geoserver.cloud.gwc.event.TileLayerEvent;
import org.geoserver.cloud.gwc.repository.GeoServerTileLayerConfiguration;
-import org.geoserver.config.GeoServer;
import org.geoserver.config.GeoServerReinitializer;
import org.geoserver.gwc.ConfigurableBlobStore;
-import org.geoserver.gwc.config.GWCConfig;
import org.geoserver.gwc.config.GWCConfigPersister;
import org.geoserver.gwc.config.GWCInitializer;
-import org.geoserver.gwc.layer.GeoServerTileLayer;
import org.geoserver.gwc.layer.TileLayerCatalog;
import org.geowebcache.config.TileLayerConfiguration;
-import org.geowebcache.layer.TileLayer;
import org.geowebcache.layer.TileLayerDispatcher;
-import org.geowebcache.storage.blobstore.memory.CacheConfiguration;
import org.geowebcache.storage.blobstore.memory.CacheProvider;
-import org.geowebcache.storage.blobstore.memory.guava.GuavaCacheProvider;
-import org.springframework.context.event.EventListener;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
+import org.slf4j.Logger;
/**
* Replacement for {@link GWCInitializer} when using the "pgconfig" storage.
@@ -57,151 +40,18 @@
*
* @since 1.8
*/
-@RequiredArgsConstructor
@Slf4j(topic = "org.geoserver.cloud.autoconfigure.gwc.backend")
-class PgconfigGwcInitializer implements GeoServerReinitializer {
-
- private final @NonNull GWCConfigPersister configPersister;
- private final @NonNull ConfigurableBlobStore blobStore;
- private final @NonNull GeoServerTileLayerConfiguration geoseverTileLayers;
-
- /**
- * @see org.geoserver.config.GeoServerInitializer#initialize(org.geoserver.config.GeoServer)
- */
- @Override
- public void initialize(final GeoServer geoServer) throws Exception {
- log.info("Initializing GeoServer specific GWC configuration from gwc-gs.xml");
-
- final GWCConfig gwcConfig = configPersister.getConfig();
- checkNotNull(gwcConfig);
+class PgconfigGwcInitializer extends AbstractGwcInitializer {
- configureInMemoryCacheProvider(gwcConfig);
-
- final boolean initialization = true;
- blobStore.setChanged(gwcConfig, initialization);
-
- setUpNonMemoryCacheableLayers();
- }
-
- @EventListener(TileLayerEvent.class)
- void onTileLayerEvent(TileLayerEvent event) {
- cacheProvider()
- .ifPresent(
- cache -> {
- switch (event.getEventType()) {
- case DELETED:
- log.debug(
- "TileLayer {} deleted, notifying in-memory CacheProvider",
- event.getName());
- cache.removeUncachedLayer(event.getName());
- break;
- case MODIFIED:
- if (event.getOldName() != null
- && !Objects.equals(
- event.getOldName(), event.getName())) {
- log.info(
- "TileLayer {} renamed to {}, notifying in-memory CacheProvider",
- event.getOldName(),
- event.getName());
- cache.removeUncachedLayer(event.getOldName());
- }
- setInMemoryLayerCaching(event.getName());
- break;
- default:
- setInMemoryLayerCaching(event.getName());
- break;
- }
- });
+ public PgconfigGwcInitializer(
+ @NonNull GWCConfigPersister configPersister,
+ @NonNull ConfigurableBlobStore blobStore,
+ @NonNull GeoServerTileLayerConfiguration geoseverTileLayers) {
+ super(configPersister, blobStore, geoseverTileLayers);
}
- private void configureInMemoryCacheProvider(final GWCConfig gwcConfig) throws IOException {
- // Setting default CacheProvider class if not present
- if (gwcConfig.getCacheProviderClass() == null
- || gwcConfig.getCacheProviderClass().isEmpty()) {
- gwcConfig.setCacheProviderClass(GuavaCacheProvider.class.toString());
- configPersister.save(gwcConfig);
- }
-
- // Setting default Cache Configuration
- if (gwcConfig.getCacheConfigurations() == null) {
- log.debug("Setting default CacheConfiguration");
- Map This is required because GeoServer Cloud may not set up a {@link TileLayerCatalog}, which
+ * {@link GWCInitializer} requires.
+ *
+ * This {@link GeoServerReinitializer} is hence in charge of notifying {@link
+ * ConfigurableBlobStore#setChanged(org.geoserver.gwc.config.GWCConfig, boolean)}
+ *
+ * This bean also listens to {@link TileLayerEvent}s and notifies the {@link CacheProvider} to
+ * either {@link CacheProvider#removeLayer(String) removeLayer} or {@link
+ * CacheProvider#removeUncachedLayer(String) removeUncachedLayer} on changes and deletions as
+ * appropriate, or to {@link CacheProvider#addUncachedLayer(String) addUncachedLayer} when a layer
+ * is created to changed to not be memory cached.
+ *
+ * @since 1.8
+ */
+@RequiredArgsConstructor
+public abstract class AbstractGwcInitializer implements GeoServerReinitializer {
+
+ protected final @NonNull GWCConfigPersister configPersister;
+ protected final @NonNull ConfigurableBlobStore blobStore;
+ protected final @NonNull GeoServerTileLayerConfiguration geoseverTileLayers;
+
+ protected abstract Logger logger();
+
+ /**
+ * @see org.geoserver.config.GeoServerInitializer#initialize(org.geoserver.config.GeoServer)
+ */
+ @Override
+ public void initialize(final GeoServer geoServer) throws Exception {
+ logger().info("Initializing GeoServer specific GWC configuration from gwc-gs.xml");
+
+ final GWCConfig gwcConfig = configPersister.getConfig();
+ checkNotNull(gwcConfig);
+
+ configureInMemoryCacheProvider(gwcConfig);
+
+ final boolean initialization = true;
+ blobStore.setChanged(gwcConfig, initialization);
+
+ setUpNonMemoryCacheableLayers();
+ }
+
+ @EventListener(TileLayerEvent.class)
+ void onTileLayerEvent(TileLayerEvent event) {
+ cacheProvider().ifPresent(cache -> onTileLayerEvent(event, cache));
+ }
+
+ private void onTileLayerEvent(TileLayerEvent event, CacheProvider cache) {
+ @NonNull String layerName = event.getName();
+
+ switch (event.getEventType()) {
+ case DELETED:
+ logger().debug(
+ "TileLayer {} deleted, notifying in-memory CacheProvider",
+ layerName);
+ cache.removeUncachedLayer(layerName);
+ break;
+ case MODIFIED:
+ if (isRename(event)) {
+ String oldName = event.getOldName();
+ logger().info(
+ "TileLayer {} renamed to {}, notifying in-memory CacheProvider",
+ oldName,
+ layerName);
+ cache.removeUncachedLayer(oldName);
+ }
+ setInMemoryLayerCaching(layerName);
+ break;
+ default:
+ setInMemoryLayerCaching(layerName);
+ break;
+ }
+ }
+
+ private boolean isRename(TileLayerEvent event) {
+ String layerName = event.getName();
+ String oldName = event.getOldName();
+ return oldName != null && !Objects.equals(oldName, layerName);
+ }
+
+ private void configureInMemoryCacheProvider(final GWCConfig gwcConfig) throws IOException {
+ // Setting default CacheProvider class if not present
+ if (!StringUtils.hasText(gwcConfig.getCacheProviderClass())) {
+ gwcConfig.setCacheProviderClass(GuavaCacheProvider.class.toString());
+ configPersister.save(gwcConfig);
+ }
+
+ // Setting default Cache Configuration
+ if (gwcConfig.getCacheConfigurations() == null) {
+ logger().debug("Setting default CacheConfiguration");
+ Map
+ *
+ *
- *
- * Using package {@code org.geoserver.gwc.config} to be able of accessing the package-private
+ * method {@link GWCConfigPersister#findConfigFile()}
+ *
*
*
*
+ *
- *
@@ -31,27 +36,46 @@
* it's not the case for GS cloud
*
*/
-@Slf4j
-@RequiredArgsConstructor
-public class GwcGeoserverConfigurationInitializer {
+@Slf4j(topic = "org.geoserver.cloud.gwc.config.core")
+public class DefaultGwcInitializer extends AbstractGwcInitializer implements InitializingBean {
- @NonNull private final GWCConfigPersister configPersister;
@NonNull private final GeoServerConfigurationLock configLock;
- @PostConstruct
- void initialize() throws IOException {
+ public DefaultGwcInitializer(
+ @NonNull GWCConfigPersister configPersister,
+ @NonNull ConfigurableBlobStore blobStore,
+ @NonNull GeoServerTileLayerConfiguration geoseverTileLayers,
+ @NonNull GeoServerConfigurationLock configLock) {
+
+ super(configPersister, blobStore, geoseverTileLayers);
+ this.configLock = configLock;
+ }
+
+ @Override
+ protected Logger logger() {
+ return log;
+ }
+
+ /**
+ * Initialize the datadir/gs-gwc.xml file before {@link
+ * #initialize(org.geoserver.config.GeoServer) super.initialize(GeoServer)}
+ */
+ @Override
+ public void afterPropertiesSet() throws Exception {
initializeGeoServerIntegrationConfigFile();
}
private void initializeGeoServerIntegrationConfigFile() throws IOException {
- if (configExists()) {
+ if (configFileExists()) {
return;
}
final boolean lockAcquired = configLock.tryLock(LockType.WRITE);
if (lockAcquired) {
try {
- if (!configExists()) {
- log.info("Initializing GeoServer specific GWC configuration");
+ if (!configFileExists()) {
+ log.info(
+ "Initializing GeoServer specific GWC configuration {}",
+ configPersister.findConfigFile());
GWCConfig defaults = new GWCConfig();
defaults.setVersion("1.1.0");
configPersister.save(defaults);
@@ -62,7 +86,7 @@ private void initializeGeoServerIntegrationConfigFile() throws IOException {
}
}
- private boolean configExists() throws IOException {
+ private boolean configFileExists() throws IOException {
Resource configFile = configPersister.findConfigFile();
return Resources.exists(configFile);
}
diff --git a/src/pom.xml b/src/pom.xml
index c7013ae7b..1b13798d4 100644
--- a/src/pom.xml
+++ b/src/pom.xml
@@ -856,6 +856,12 @@