Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawn reload and reset actions to all pods #573

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compose/.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GEOSERVER_BASE_PATH=/geoserver/cloud
# logging profile, either "default" or "json-logs"
#LOGGING_PROFILE=json-logs
LOGGING_PROFILE=default
GEOSERVER_DEFAULT_PROFILES="${LOGGING_PROFILE},acl"
GEOSERVER_DEFAULT_PROFILES="${LOGGING_PROFILE},acl,logging_debug_events"

GATEWAY_DEFAULT_PROFILES=${LOGGING_PROFILE}
DISCOVERY_SERVER_DEFAULT_PROFILES=${LOGGING_PROFILE}
Expand Down
2 changes: 1 addition & 1 deletion config
Submodule config updated 1 files
+1 −0 geoserver_logging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* (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.autoconfigure.catalog.backend.core;

import org.geoserver.cloud.autoconfigure.catalog.event.ConditionalOnCatalogEvents;
import org.geoserver.cloud.event.lifecycle.LifecycleEvent;
import org.geoserver.cloud.event.remote.lifecycle.LifecycleEventProcessor;
import org.geoserver.config.plugin.GeoServerImpl;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;

/**
* @since 1.0
*/
@AutoConfiguration
@ConditionalOnClass(LifecycleEvent.class)
@ConditionalOnCatalogEvents
public class LifecycleEventAutoConfiguration {

@Bean
LifecycleEventProcessor lifecycleEventProcessor(
@Qualifier("geoServer") GeoServerImpl rawGeoServer) {

return new LifecycleEventProcessor(rawGeoServer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@AutoConfiguration
@ConditionalOnClass(InfoEvent.class)
@ConditionalOnCatalogEvents
public class RemoteEventResourcePoolCleaupUpAutoConfiguration {
public class RemoteEventResourcePoolCleanupUpAutoConfiguration {

@Bean
RemoteEventResourcePoolProcessor remoteEventResourcePoolProcessor(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* (c) 2020 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.event.remote.lifecycle;

import lombok.extern.slf4j.Slf4j;

import org.geoserver.cloud.config.catalog.events.CatalogApplicationEventPublisher;
import org.geoserver.cloud.event.GeoServerEvent;
import org.geoserver.cloud.event.lifecycle.ReloadEvent;
import org.geoserver.cloud.event.lifecycle.ResetEvent;
import org.geoserver.config.plugin.GeoServerImpl;
import org.springframework.context.event.EventListener;

/**
* Listens for and processes {@link GeoServerEvent#isRemote() remote} {@link ResetEvent} and {@link
* ReloadEvent} events.
*
* @since 1.0
*/
@Slf4j
public class LifecycleEventProcessor {

private final GeoServerImpl rawGeoServer;

/**
* @param rawGeoServer used to reset or reload
*/
public LifecycleEventProcessor(GeoServerImpl rawGeoServer) {
this.rawGeoServer = rawGeoServer;
}

@EventListener(ResetEvent.class)
public void onReset(ResetEvent event) {

if (event.isRemote()) {
log.debug("Disabling event publishing while processing {}", event);
CatalogApplicationEventPublisher.disable();
try {
rawGeoServer.reset();
log.debug("Reenabling event publishing after {}", event);
} finally {
CatalogApplicationEventPublisher.enable();
}
} else {
log.debug("Ignoring local {}", event);
}
}

@EventListener(ReloadEvent.class)
public void onReload(ReloadEvent event) {

if (event.isRemote()) {
log.debug("Disabling event publishing while processing {}", event);
CatalogApplicationEventPublisher.disable();
try {
rawGeoServer.reload();
log.debug("Reenabling event publishing after {}", event);
} catch (Exception e) {
log.error("Error reloading catalog: ", e);
} finally {
CatalogApplicationEventPublisher.enable();
}
} else {
log.debug("Ignoring local {}", event);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ org.geoserver.cloud.autoconfigure.geotools.GeoToolsHttpClientAutoConfiguration,\
org.geoserver.cloud.autoconfigure.catalog.backend.core.GeoServerBackendAutoConfiguration,\
org.geoserver.cloud.autoconfigure.catalog.backend.core.DefaultUpdateSequenceAutoConfiguration,\
org.geoserver.cloud.autoconfigure.catalog.backend.core.XstreamServiceLoadersAutoConfiguration,\
org.geoserver.cloud.autoconfigure.catalog.backend.core.RemoteEventResourcePoolCleaupUpAutoConfiguration,\
org.geoserver.cloud.autoconfigure.catalog.backend.core.RemoteEventResourcePoolCleanupUpAutoConfiguration,\
org.geoserver.cloud.autoconfigure.catalog.backend.core.LifecycleEventAutoConfiguration,\
org.geoserver.cloud.autoconfigure.security.GeoServerSecurityAutoConfiguration,\
org.geoserver.cloud.autoconfigure.metrics.catalog.CatalogMetricsAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* (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.autoconfigure.catalog.backend.core;

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

import org.geoserver.cloud.event.lifecycle.LifecycleEvent;
import org.geoserver.config.plugin.GeoServerImpl;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

class LifecycleEventAutoConfigurationTest {

private final ApplicationContextRunner runner =
new ApplicationContextRunner()
.withBean("geoServer", GeoServerImpl.class)
.withConfiguration(
AutoConfigurations.of(LifecycleEventAutoConfiguration.class));

@Test
void testDefaultAppContextContributions() {
runner.run(
context -> assertThat(context).hasNotFailed().hasBean("lifecycleEventProcessor"));
}

@Test
void whenDependentClassesAreNotPresent_thenBeanMissing() {
runner.withClassLoader(new FilteredClassLoader(LifecycleEvent.class))
.run(
context ->
assertThat(context)
.hasNotFailed()
.doesNotHaveBean("lifecycleEventProcessor"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* (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.autoconfigure.catalog.backend.core;

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

import org.geoserver.catalog.plugin.CatalogPlugin;
import org.geoserver.cloud.event.info.InfoEvent;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

class RemoteEventResourcePoolCleanupUpAutoConfigurationTest {

private final ApplicationContextRunner runner =
new ApplicationContextRunner()
.withBean("rawCatalog", CatalogPlugin.class)
.withConfiguration(
AutoConfigurations.of(
RemoteEventResourcePoolCleanupUpAutoConfiguration.class));

@Test
void testDefaultAppContextContributions() {
runner.run(
context ->
assertThat(context)
.hasNotFailed()
.hasBean("remoteEventResourcePoolProcessor"));
}

@Test
void whenDependentClassesAreNotPresent_thenBeanMissing() {
runner.withClassLoader(new FilteredClassLoader(InfoEvent.class))
.run(
context ->
assertThat(context)
.hasNotFailed()
.doesNotHaveBean("remoteEventResourcePoolProcessor"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void onRemoteUpdateSequenceEvent(UpdateSequenceEvent event) {
}
final long updateSequence = event.getUpdateSequence();
GeoServerInfo info = ModificationProxy.unwrap(configFacade.getGlobal());
if (null == info) return;
final long current = info.getUpdateSequence();
if (updateSequence > current) {
info.setUpdateSequence(updateSequence);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class DataDirectoryAutoConfigurationTest {
org.geoserver.cloud.autoconfigure.catalog.backend.core
.XstreamServiceLoadersAutoConfiguration.class,
org.geoserver.cloud.autoconfigure.catalog.backend.core
.RemoteEventResourcePoolCleaupUpAutoConfiguration.class,
.RemoteEventResourcePoolCleanupUpAutoConfiguration
.class,
org.geoserver.cloud.autoconfigure.security
.GeoServerSecurityAutoConfiguration.class,
org.geoserver.cloud.autoconfigure.metrics.catalog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.geoserver.cloud.event.info.InfoEvent;
import org.geoserver.cloud.event.info.InfoModified;
import org.geoserver.cloud.event.info.InfoRemoved;
import org.geoserver.cloud.event.lifecycle.LifecycleEvent;
import org.geoserver.config.GeoServer;
import org.geoserver.config.GeoServerInfo;
import org.geoserver.config.LoggingInfo;
Expand Down Expand Up @@ -93,7 +94,7 @@ public abstract class BusAmqpIntegrationTests {

@Container
private static final RabbitMQContainer rabbitMQContainer =
new RabbitMQContainer("rabbitmq:3.11-management");
new RabbitMQContainer("rabbitmq:3.13-management");

protected static ConfigurableApplicationContext remoteAppContext;
private @Autowired ConfigurableApplicationContext localAppContext;
Expand All @@ -113,6 +114,7 @@ static void properties(DynamicPropertyRegistry registry) {

@BeforeAll
static void setUpRemoteApplicationContext() {

remoteAppContext =
new SpringApplicationBuilder(
TestConfigurationAutoConfiguration.class, BusEventCollector.class)
Expand Down Expand Up @@ -430,6 +432,12 @@ public <E extends InfoEvent> EventsCaptor captureEventsOf(Class<E> type) {
return this;
}

public <E extends LifecycleEvent> EventsCaptor captureLifecycleEventsOf(Class<E> type) {
local.captureLifecycle(type);
remote.captureLifecycle(type);
return this;
}

public EventsCaptor stop() {
remote.stop();
local.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.geoserver.cloud.event.GeoServerEvent;
import org.geoserver.cloud.event.info.ConfigInfoType;
import org.geoserver.cloud.event.info.InfoEvent;
import org.geoserver.cloud.event.lifecycle.LifecycleEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
Expand All @@ -38,7 +39,7 @@ public class BusEventCollector {
private @Value("${spring.cloud.bus.id}") String busId;
private @Autowired RemoteGeoServerEventBridge bridge;

private @NonNull Class<? extends InfoEvent> eventType = InfoEvent.class;
private @NonNull Class<? extends GeoServerEvent> eventType = GeoServerEvent.class;

private volatile boolean capturing = false;

Expand Down Expand Up @@ -66,6 +67,10 @@ public void capture(@NonNull Class<? extends InfoEvent> type) {
this.eventType = type;
}

public void captureLifecycle(@NonNull Class<? extends LifecycleEvent> type) {
this.eventType = type;
}

public <T extends InfoEvent> RemoteGeoServerEvent expectOne(Class<T> payloadType) {

return expectOne(payloadType, x -> true);
Expand All @@ -80,7 +85,7 @@ public <T extends InfoEvent> RemoteGeoServerEvent expectOne(
Class<T> payloadType, Predicate<T> filter) {

List<RemoteGeoServerEvent> matches =
await().atMost(Duration.ofSeconds(500)) //
await().atMost(Duration.ofSeconds(10)) //
.until(() -> allOf(payloadType, filter), not(List::isEmpty));

Supplier<String> message =
Expand All @@ -92,7 +97,22 @@ public <T extends InfoEvent> RemoteGeoServerEvent expectOne(
return matches.get(0);
}

public <T extends InfoEvent> List<RemoteGeoServerEvent> allOf(
public <T extends LifecycleEvent> RemoteGeoServerEvent expectOneLifecycleEvent(
Class<T> payloadType) {

List<RemoteGeoServerEvent> matches =
await().atMost(Duration.ofSeconds(10)) //
.until(
() -> allOfLifecycle(payloadType, filter -> true),
not(List::isEmpty));

assertThat(matches.size()).isOne();

//noinspection OptionalGetWithoutIsPresent
return matches.stream().findFirst().get();
}

public <T extends GeoServerEvent> List<RemoteGeoServerEvent> allOf(
Class<T> payloadEventType, Predicate<T> eventFilter) {

return capturedEvents(payloadEventType)
Expand All @@ -102,15 +122,30 @@ public <T extends InfoEvent> List<RemoteGeoServerEvent> allOf(
.toList();
}

public <T extends InfoEvent> List<RemoteGeoServerEvent> allOf(Class<T> payloadType) {
public <T extends LifecycleEvent> List<RemoteGeoServerEvent> allOfLifecycle(
Class<T> payloadEventType, Predicate<T> eventFilter) {

return capturedLifecycleEvents(payloadEventType)
.filter(
remoteEvent ->
eventFilter.test(payloadEventType.cast(remoteEvent.getEvent())))
.toList();
}

public <T extends GeoServerEvent> List<RemoteGeoServerEvent> allOf(Class<T> payloadType) {
return capturedEvents(payloadType).toList();
}

public <T extends InfoEvent> Optional<RemoteGeoServerEvent> first(Class<T> payloadType) {
public <T extends GeoServerEvent> Optional<RemoteGeoServerEvent> first(Class<T> payloadType) {
return capturedEvents(payloadType).findFirst();
}

private <T extends InfoEvent> Stream<RemoteGeoServerEvent> capturedEvents(
private <T extends GeoServerEvent> Stream<RemoteGeoServerEvent> capturedEvents(
Class<T> payloadType) {
return capturedEvents().filter(remote -> payloadType.isInstance(remote.getEvent()));
}

private <T extends LifecycleEvent> Stream<RemoteGeoServerEvent> capturedLifecycleEvents(
Class<T> payloadType) {
return capturedEvents().filter(remote -> payloadType.isInstance(remote.getEvent()));
}
Expand Down
Loading
Loading