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:
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')
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')
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" {} +
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"
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" {} +
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.