Skip to content

Commit

Permalink
fix: spawn reload and reset actions to all pods
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlkoch committed Sep 30, 2024
1 parent c9c17dd commit ea41da3
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.geoserver.catalog.Catalog;
import org.geoserver.cloud.event.info.InfoEvent;
import org.geoserver.cloud.event.lifecycle.LifecycleEvent;
import org.geoserver.config.GeoServer;
import org.geoserver.platform.config.UpdateSequence;
import org.springframework.beans.factory.annotation.Qualifier;
Expand All @@ -32,4 +33,12 @@ CatalogApplicationEventPublisher localApplicationEventPublisher( //
return new CatalogApplicationEventPublisher(
publisher, catalog, geoServer, updateSequenceIncrementor);
}

@Bean
GeoServerLifecycleEventPublisher localGeoServerLifecycleEventPublisher(
ApplicationEventPublisher localContextPublisher) {
Consumer<? super LifecycleEvent> publisher = localContextPublisher::publishEvent;

return new GeoServerLifecycleEventPublisher(publisher);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* (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.config.catalog.events;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

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.impl.GeoServerLifecycleHandler;

import java.util.function.Consumer;

@RequiredArgsConstructor
@Slf4j
class GeoServerLifecycleEventPublisher implements GeoServerLifecycleHandler {

private final @NonNull Consumer<? super LifecycleEvent> eventPublisher;

void publish(@NonNull LifecycleEvent event) {
eventPublisher.accept(event);
}

@Override
public void onReset() {
log.info("Publishing the onReset event");

publish(new ResetEvent());
}

@Override
public void onDispose() {
log.info("Ignoring the onDispose event");
}

@Override
public void beforeReload() {
log.info("Ignoring the beforeReload event");
}

@Override
public void onReload() {
log.info("Publishing the onReload event");

publish(new ReloadEvent());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* (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.event.lifecycle;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import org.geoserver.cloud.event.GeoServerEvent;

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonSubTypes({
@JsonSubTypes.Type(value = ReloadEvent.class),
@JsonSubTypes.Type(value = ResetEvent.class)
})
public abstract class LifecycleEvent extends GeoServerEvent {

@Override
public String toShortString() {
String originService = getOrigin();
String type = getClass().getSimpleName();
return "%s[origin: %s]".formatted(type, originService);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* (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.event.lifecycle;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonTypeName("ReloadEvent")
public class ReloadEvent extends LifecycleEvent {
public ReloadEvent() {
// no-op, for serialization
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* (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.event.lifecycle;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonTypeName("ResetEvent")
public class ResetEvent extends LifecycleEvent {
public ResetEvent() {
// no-op, for serialization
}
}

0 comments on commit ea41da3

Please sign in to comment.