-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: spawn reload and reset actions to all pods
Co-authored-by: Nils Bühner <[email protected]>
- Loading branch information
Showing
21 changed files
with
619 additions
and
74 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...g/geoserver/cloud/autoconfigure/catalog/backend/core/LifecycleEventAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...mon/src/main/java/org/geoserver/cloud/event/remote/lifecycle/LifecycleEventProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* (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.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 ResetEvent} and {@link ReloadEvent} events. | ||
* | ||
* @since 1.0 | ||
*/ | ||
@Slf4j(topic = "org.geoserver.cloud.event.remote.lifecycle") | ||
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("Received a remote ResetEvent, triggering a GeoServer reset ({})", event); | ||
rawGeoServer.reset(true); | ||
} | ||
} | ||
|
||
@EventListener(ReloadEvent.class) | ||
public void onReload(ReloadEvent event) { | ||
|
||
if (event.isRemote()) { | ||
log.debug("Received a remote ReloadEvent, triggering a GeoServer reload ({})", event); | ||
try { | ||
rawGeoServer.reload(null, true); | ||
} catch (Exception e) { | ||
log.error("Error reloading catalog: ", e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...oserver/cloud/autoconfigure/catalog/backend/core/LifecycleEventAutoConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...configure/catalog/backend/core/RemoteEventResourcePoolCleanupUpAutoConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...t-bus/src/test/java/org/geoserver/cloud/event/bus/LifecycleRemoteApplicationEventsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* (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.bus; | ||
|
||
import org.geoserver.cloud.event.lifecycle.LifecycleEvent; | ||
import org.geoserver.cloud.event.lifecycle.ReloadEvent; | ||
import org.geoserver.cloud.event.lifecycle.ResetEvent; | ||
import org.geoserver.config.GeoServer; | ||
import org.geoserver.platform.GeoServerExtensions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.function.Consumer; | ||
|
||
class LifecycleRemoteApplicationEventsIT extends BusAmqpIntegrationTests { | ||
|
||
@BeforeAll | ||
static void handleGsExtensions() { | ||
GeoServerExtensions gse = new GeoServerExtensions(); | ||
gse.setApplicationContext(remoteAppContext); | ||
} | ||
|
||
@Test | ||
void testGeoServerHasExecutedReset() { | ||
|
||
this.eventsCaptor.stop().clear().captureLifecycleEventsOf(LifecycleEvent.class).start(); | ||
|
||
Consumer<GeoServer> modifier = GeoServer::reset; | ||
modifier.accept(geoserver); | ||
|
||
eventsCaptor.local().expectOneLifecycleEvent(ResetEvent.class); | ||
eventsCaptor.remote().expectOneLifecycleEvent(ResetEvent.class); | ||
} | ||
|
||
@Test | ||
void testGeoServerHasExecutedReload() { | ||
|
||
this.eventsCaptor.stop().clear().captureLifecycleEventsOf(LifecycleEvent.class).start(); | ||
|
||
Consumer<GeoServer> modifier = | ||
geoServer -> { | ||
try { | ||
geoServer.reload(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}; | ||
modifier.accept(geoserver); | ||
|
||
// reload also triggers reset! | ||
eventsCaptor.local().expectOneLifecycleEvent(ReloadEvent.class); | ||
eventsCaptor.local().expectOneLifecycleEvent(ResetEvent.class); | ||
eventsCaptor.remote().expectOneLifecycleEvent(ReloadEvent.class); | ||
eventsCaptor.remote().expectOneLifecycleEvent(ResetEvent.class); | ||
} | ||
} |
Oops, something went wrong.