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 6ce29894d..af2fe4681 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 @@ -7,12 +7,13 @@ import lombok.NonNull; import lombok.extern.slf4j.Slf4j; +import org.geoserver.GeoServerConfigurationLock; 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.GeoServerReinitializer; import org.geoserver.gwc.ConfigurableBlobStore; +import org.geoserver.gwc.config.AbstractGwcInitializer; import org.geoserver.gwc.config.GWCConfigPersister; import org.geoserver.gwc.config.GWCInitializer; import org.geoserver.gwc.layer.TileLayerCatalog; @@ -46,8 +47,9 @@ class PgconfigGwcInitializer extends AbstractGwcInitializer { public PgconfigGwcInitializer( @NonNull GWCConfigPersister configPersister, @NonNull ConfigurableBlobStore blobStore, - @NonNull GeoServerTileLayerConfiguration geoseverTileLayers) { - super(configPersister, blobStore, geoseverTileLayers); + @NonNull GeoServerTileLayerConfiguration geoseverTileLayers, + @NonNull GeoServerConfigurationLock configLock) { + super(configPersister, blobStore, geoseverTileLayers, configLock); } @Override diff --git a/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigTileLayerCatalogAutoConfiguration.java b/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigTileLayerCatalogAutoConfiguration.java index b2cc42f16..4d3560bf9 100644 --- a/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigTileLayerCatalogAutoConfiguration.java +++ b/src/gwc/autoconfigure/src/main/java/org/geoserver/cloud/autoconfigure/gwc/backend/PgconfigTileLayerCatalogAutoConfiguration.java @@ -7,6 +7,7 @@ import lombok.NonNull; import lombok.extern.slf4j.Slf4j; +import org.geoserver.GeoServerConfigurationLock; import org.geoserver.catalog.Catalog; import org.geoserver.cloud.autoconfigure.catalog.backend.pgconfig.ConditionalOnPgconfigBackendEnabled; import org.geoserver.cloud.autoconfigure.catalog.backend.pgconfig.PgconfigDataSourceAutoConfiguration; @@ -58,13 +59,18 @@ void log() { log.info("GeoWebCache TileLayerCatalog using PostgreSQL config backend"); } - /** Replacement for {@link GWCInitializer} when using {@link GeoServerTileLayerConfiguration} */ + /** + * Replacement for {@link GWCInitializer} when using {@link GeoServerTileLayerConfiguration} + * + * @param configLock + */ @Bean PgconfigGwcInitializer gwcInitializer( GWCConfigPersister configPersister, ConfigurableBlobStore blobStore, - GeoServerTileLayerConfiguration tileLayerCatalog) { - return new PgconfigGwcInitializer(configPersister, blobStore, tileLayerCatalog); + GeoServerTileLayerConfiguration tileLayerCatalog, + GeoServerConfigurationLock configLock) { + return new PgconfigGwcInitializer(configPersister, blobStore, tileLayerCatalog, configLock); } @Bean(name = "gwcCatalogConfiguration") diff --git a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/AbstractGwcInitializer.java b/src/gwc/core/src/main/java/org/geoserver/gwc/config/AbstractGwcInitializer.java similarity index 83% rename from src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/AbstractGwcInitializer.java rename to src/gwc/core/src/main/java/org/geoserver/gwc/config/AbstractGwcInitializer.java index 673b2cfdd..ac3e8600b 100644 --- a/src/gwc/core/src/main/java/org/geoserver/cloud/gwc/config/core/AbstractGwcInitializer.java +++ b/src/gwc/core/src/main/java/org/geoserver/gwc/config/AbstractGwcInitializer.java @@ -2,7 +2,7 @@ * (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.gwc.config.core; +package org.geoserver.gwc.config; import static com.google.common.base.Preconditions.checkNotNull; @@ -11,21 +11,23 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; +import org.geoserver.GeoServerConfigurationLock; +import org.geoserver.GeoServerConfigurationLock.LockType; 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.geoserver.platform.resource.Resource; +import org.geoserver.platform.resource.Resources; import org.geowebcache.layer.TileLayer; import org.geowebcache.storage.blobstore.memory.CacheConfiguration; import org.geowebcache.storage.blobstore.memory.CacheProvider; import org.geowebcache.storage.blobstore.memory.guava.GuavaCacheProvider; import org.slf4j.Logger; +import org.springframework.beans.factory.InitializingBean; import org.springframework.context.event.EventListener; import org.springframework.util.StringUtils; @@ -54,14 +56,20 @@ * @since 1.8 */ @RequiredArgsConstructor -public abstract class AbstractGwcInitializer implements GeoServerReinitializer { +public abstract class AbstractGwcInitializer implements GeoServerReinitializer, InitializingBean { protected final @NonNull GWCConfigPersister configPersister; protected final @NonNull ConfigurableBlobStore blobStore; protected final @NonNull GeoServerTileLayerConfiguration geoseverTileLayers; + protected final @NonNull GeoServerConfigurationLock configLock; protected abstract Logger logger(); + @Override + public void afterPropertiesSet() throws IOException { + initializeGeoServerIntegrationConfigFile(); + } + /** * @see org.geoserver.config.GeoServerInitializer#initialize(org.geoserver.config.GeoServer) */ @@ -80,6 +88,36 @@ public void initialize(final GeoServer geoServer) throws Exception { setUpNonMemoryCacheableLayers(); } + /** + * Initialize the datadir/gs-gwc.xml file before {@link + * #initialize(org.geoserver.config.GeoServer) super.initialize(GeoServer)} + */ + private void initializeGeoServerIntegrationConfigFile() throws IOException { + if (configFileExists()) { + return; + } + final boolean lockAcquired = configLock.tryLock(LockType.WRITE); + if (lockAcquired) { + try { + if (!configFileExists()) { + logger().info( + "Initializing GeoServer specific GWC configuration {}", + configPersister.findConfigFile()); + GWCConfig defaults = new GWCConfig(); + defaults.setVersion("1.1.0"); + configPersister.save(defaults); + } + } finally { + configLock.unlock(); + } + } + } + + private boolean configFileExists() throws IOException { + Resource configFile = configPersister.findConfigFile(); + return Resources.exists(configFile); + } + @EventListener(TileLayerEvent.class) void onTileLayerEvent(TileLayerEvent event) { cacheProvider().ifPresent(cache -> onTileLayerEvent(event, cache)); diff --git a/src/gwc/core/src/main/java/org/geoserver/gwc/config/DefaultGwcInitializer.java b/src/gwc/core/src/main/java/org/geoserver/gwc/config/DefaultGwcInitializer.java index 42447d268..01c79b31d 100644 --- a/src/gwc/core/src/main/java/org/geoserver/gwc/config/DefaultGwcInitializer.java +++ b/src/gwc/core/src/main/java/org/geoserver/gwc/config/DefaultGwcInitializer.java @@ -8,18 +8,11 @@ import lombok.extern.slf4j.Slf4j; import org.geoserver.GeoServerConfigurationLock; -import org.geoserver.GeoServerConfigurationLock.LockType; -import org.geoserver.cloud.gwc.config.core.AbstractGwcInitializer; import org.geoserver.cloud.gwc.repository.GeoServerTileLayerConfiguration; import org.geoserver.gwc.ConfigurableBlobStore; import org.geoserver.gwc.layer.CatalogConfiguration; import org.geoserver.gwc.layer.TileLayerCatalog; -import org.geoserver.platform.resource.Resource; -import org.geoserver.platform.resource.Resources; import org.slf4j.Logger; -import org.springframework.beans.factory.InitializingBean; - -import java.io.IOException; /** * Replaces {@link GWCInitializer} @@ -37,9 +30,7 @@ * */ @Slf4j(topic = "org.geoserver.cloud.gwc.config.core") -public class DefaultGwcInitializer extends AbstractGwcInitializer implements InitializingBean { - - @NonNull private final GeoServerConfigurationLock configLock; +public class DefaultGwcInitializer extends AbstractGwcInitializer { public DefaultGwcInitializer( @NonNull GWCConfigPersister configPersister, @@ -47,47 +38,11 @@ public DefaultGwcInitializer( @NonNull GeoServerTileLayerConfiguration geoseverTileLayers, @NonNull GeoServerConfigurationLock configLock) { - super(configPersister, blobStore, geoseverTileLayers); - this.configLock = configLock; + super(configPersister, blobStore, geoseverTileLayers, 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 (configFileExists()) { - return; - } - final boolean lockAcquired = configLock.tryLock(LockType.WRITE); - if (lockAcquired) { - try { - if (!configFileExists()) { - log.info( - "Initializing GeoServer specific GWC configuration {}", - configPersister.findConfigFile()); - GWCConfig defaults = new GWCConfig(); - defaults.setVersion("1.1.0"); - configPersister.save(defaults); - } - } finally { - configLock.unlock(); - } - } - } - - private boolean configFileExists() throws IOException { - Resource configFile = configPersister.findConfigFile(); - return Resources.exists(configFile); - } } diff --git a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/GeoWebCacheRemoteEventsBroker.java b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/GeoWebCacheRemoteEventsBroker.java index aabef620a..a34d0622f 100644 --- a/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/GeoWebCacheRemoteEventsBroker.java +++ b/src/gwc/integration-bus/src/main/java/org/geoserver/cloud/gwc/bus/GeoWebCacheRemoteEventsBroker.java @@ -24,7 +24,7 @@ * to the cluster as {@link RemoteGeoWebCacheEvent} on the event bus, and vice-versa. */ @RequiredArgsConstructor -@Slf4j(topic = "org.geoserver.cloud.bus.outgoing.gwc") +@Slf4j(topic = "org.geoserver.cloud.gwc.bus") public class GeoWebCacheRemoteEventsBroker { /**