GeoWebCache – How to Change/Set LayerId of GeoWebCache Layer in GeoServer

geoservergeowebcachepostgis

I am currently creating a Docker Container to Pre-Seed GeoWebCache caches. The idea is to spin up the Docker Container(s) to create the caches when there are new Orthophotos and kill them when done seeding –> see.

The idea is to store the caches in Azure Blob Storages using the Azure Blob Storage Plugin and serve the caches via an "main" Geoserver Instances on an extra VM. The problem I am facing is that the internal Geoserver creates an specific ID like LayerInfoImpl--53dcac5c:17b1025e89f:-7ff8 which is then used as the root container for the Blobs in Azure, which mismatches with the ID on my "main" Geoserver Instance (looks like the ID is randomly created).
Unfortunately I couldn't find a way to explicitly set this ID so my Docker Container and the "main" Geoserver Instance use the same ID and a mapping can be done. Is there a way using the REST API or some script to set / change the id? Preferably like topp:states.

I have already tried the PUT and POST endpoints. Setting / Updating the id in the payload like:

<GeoServerLayer>
    <id>test:test</id>
    <name>test:test</name>
</GeoServerLayer>`

Unfortunately this doesn't work.

Best Answer

I was able to find a workaround:

  1. Prerequirements are that the Workspace, Mosaic Storage and Layer on the main Geoserver Instance already exists and that an Azure Blob Store is configured as the Store for the GWC Layer.
  2. In the Docker Container I create the same Workspace, Mosaic Storage, Layer and Azure Blob Store (using curl and the Geoserver Rest API).
  3. As mentioned the Layer ID is not the same (on the Main Geoserver and the one running in the Docker Container), so I had to query the ID from the Main Geoserver Instance using LAYER_MAIN_ID=$(curl --location --request GET ''"$MAIN_GEOSERVER_URL"'/geoserver/gwc/rest/layers/'"$PROJECT_ID"':'"$PROJECT_ID"'.json' --header 'Content-Type: application/json' --header 'Authorization: Basic '$MAIN_GEOSERVER_BASIC_PW'' | jq -r '.GeoServerLayer.id')
  4. .. and query the Layer ID in the Docker Container: LAYER_DOCKER_ID=$(curl --location --request GET ''"$GEOSERVER_LOCALHOST"':8080/geoserver/gwc/rest/layers/'"$PROJECT_ID"':'"$PROJECT_ID"'.json' --header 'Content-Type: application/json' --header 'Authorization: Basic '$GEOSERVER_BASIC_PW'' | jq -r '.GeoServerLayer.id')
  5. Afterwards the Layer ID had to be replaced in multiple locations:
  6. in the Layer Definition: find "$GEOSERVER_HOME/data_dir/workspaces/$PROJECT_ID/$PROJECT_ID/$PROJECT_ID/layer.xml" -type f -exec sed -i "s/$LAYER_DOCKER_ID/$LAYER_MAIN_ID/g" {} +
  7. Rename the GWC-Layer Definition File: LAYER_DOCKER_ID_FILENAME=${LAYER_DOCKER_ID//\:/_} LAYER_MAIN_ID_FILENAME=${LAYER_MAIN_ID//\:/_} mv "$GEOSERVER_HOME/data_dir/gwc-layers/$LAYER_DOCKER_ID_FILENAME.xml" "$GEOSERVER_HOME/data_dir/gwc-layers/$LAYER_MAIN_ID_FILENAME.xml"
  8. Change the ID in the GWC-Layer Definition File: find "$GEOSERVER_HOME/data_dir/gwc-layers/$LAYER_MAIN_ID_FILENAME.xml" -type f -exec sed -i "s/$LAYER_DOCKER_ID/$LAYER_MAIN_ID/g" {} +
  9. Afterwards the Config needs to be reloaded: curl --location --request POST ''"$GEOSERVER_LOCALHOST"':8080/geoserver/rest/reload' \ --header 'Authorization: Basic '$GEOSERVER_BASIC_PW''

Last step is to start the seeding process using the API. When the container is done it kills the Docker Container. For a 14GB Orthophoto a 8GB 4CPU Azure Docker Container is running ~ 8 hours. Which costs less than 2€. And the main Geoserver is able to concentrate on the hosting rather the processing of the tiles.

Related Question