geoserver-cloud
geoserver-cloud copied to clipboard
Unable to create a LayerGroup with REST API
When I try to create a LayerGroup with the REST API, the call fails with a http 500 error. The error is raised in GS Cloud specific code which validates the LayerGroup configuration, with two subcases:
- With one of the default style provided with GeoServer (for example 'generic') associated to a layer, the error message is: "Invalid style group: No layer or layer group named 'generic' found in the catalog". The name of the style is ok in the error message.
- With a style created with the REST API (for example 'osm:admin_labels') associated to a layer, the error message is: "Invalid style group: No layer or layer group named 'Default Styler' found in the catalog". The name of the style is not ok in the error message.
I also tried with a layer group created with the admin interface (retrieved with a GET call) : same result.
The error is raised in https://github.com/geoserver/geoserver-cloud/blob/cbab7713fedcec1b25bf013d2e37648a3164cfb6/src/catalog/plugin/src/main/java/org/geoserver/catalog/plugin/validation/DefaultCatalogValidator.java#L269
The setup uses jdbc config and jdbc store extensions.
- Test on a vanilla geoserver with default config and store : no error
- Test on a vanilla geoserver with jdbc config and jdbc store : no error
Tested with docker compose provided in the repo : no error
I can no longer reproduce the issue : closing it
Reopening the ticket : with the same codebase, I today have again the issue with style groupe REST API.
@AlexGacon the only way I can see for that to happen is that in the request payload, you're using the style name as the layer name, like in:
<layerGroup>
<name>ws1_lg</name>
<mode>SINGLE</mode>
<title>ws1_lg</title>
<publishables>
<published type="layer">
<name>generic</name>
</published>
</publishables>
<styles>
<style>
<name>generic</name>
</style>
</styles>
</layerGroup>
Then SLDNamedLayerValidator
will do:
@Override
public PublishedInfo visitNamedLayerInternal(StyledLayer namedLayer) {
PublishedInfo p = catalog.getLayerGroupByName(namedLayer.getName());
if (p == null) {
p = catalog.getLayerByName(namedLayer.getName());
}
if (p == null) {
validationErrors.add(
new Exception(
"No layer or layer group named '"
+ namedLayer.getName()
+ "' found in the catalog"));
}
return p;
}
The error will then be used by DefaultCatalogValidator.validate(LayerGroupInfo layerGroup, boolean isNew)
:
List<Exception> errors = SLDNamedLayerValidator.validate(catalog, sld);
if (errors.size() > 0) {
throw new IllegalArgumentException(
"Invalid style group: " + errors.get(0).getMessage(),
errors.get(0));
}
This is consistent with the error messages you're getting, since StyledLayer
maps to the SLD "title", so Default Styler
must be in osm:admin_labels
SLD as <title>Default Styler</title>
.
Please verify that.
I will close the issue : the problem is indeed related to a layer or a style not found (style names must not include namespace).