-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #573 from groldan/518-spawn-reload-reset
Spawn reload and reset actions to all pods
- Loading branch information
Showing
24 changed files
with
564 additions
and
32 deletions.
There are no files selected for viewing
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
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
69 changes: 69 additions & 0 deletions
69
...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,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); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.