geoserver-cloud icon indicating copy to clipboard operation
geoserver-cloud copied to clipboard

Unable to create a LayerGroup with REST API

Open AlexGacon opened this issue 2 years ago • 3 comments

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.

AlexGacon avatar Oct 03 '22 09:10 AlexGacon

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

AlexGacon avatar Oct 03 '22 09:10 AlexGacon

The setup uses jdbc config and jdbc store extensions.

AlexGacon avatar Oct 03 '22 11:10 AlexGacon

  • 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

AlexGacon avatar Oct 03 '22 12:10 AlexGacon

Tested with docker compose provided in the repo : no error

AlexGacon avatar Oct 19 '22 08:10 AlexGacon

I can no longer reproduce the issue : closing it

AlexGacon avatar Oct 19 '22 08:10 AlexGacon

Reopening the ticket : with the same codebase, I today have again the issue with style groupe REST API.

AlexGacon avatar Oct 20 '22 10:10 AlexGacon

@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.

groldan avatar Oct 27 '22 17:10 groldan

I will close the issue : the problem is indeed related to a layer or a style not found (style names must not include namespace).

AlexGacon avatar Oct 27 '22 20:10 AlexGacon