Skip to content

Commit

Permalink
Add missing gs-gwc.xml initialization for pgconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
groldan committed Oct 16, 2024
1 parent 0c985bb commit 7e0b185
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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)
*/
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -37,57 +30,19 @@
* </ul>
*/
@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,
@NonNull ConfigurableBlobStore blobStore,
@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down

0 comments on commit 7e0b185

Please sign in to comment.