0
Geoserver Shell
Administer Geoserver using a CLI

Jared Erickson
CUGOS July 2013
Outline
• What is Geoserver Shell?
• Why does Geoserver need a CLI?
• What are we administering with CLI?
• How does it wo...
What is it?
• Administer Geoserver from a command
line interface (CLI)

• Uses Geoserver Rest interface
• Based on Spring ...
Why a CLI?
• Web UI is a major feature
• Non developers can load data and styles
• CLI is quick, efficient and scriptable
•...
Geoserver UI
Geoserver Catalog
• Workspace
• Namespace
• DataStore
• FeatureType
• CoverageStore
• Coverage

• Layer
• LayerGroups
• St...
Geoserver Rest
•
•
•
•
•

Administer GeoServer without GUI

•

Integrate with 3rd party applications

Multiple representat...
Verbs
Commands

Verbs

list

GET

get

GET

create

POST

modify

PUT

delete

DELETE
Geoserver Rest UI
/geoserver/rest/layers
Client #1 = curl
•

Upload a Shapefile

curl -v -u admin:geoserver -XPUT -H "Content-type: application/zip" --data-binary
@...
Client #2 = Python
• gsconfig.py
• https://github.com/dwins/gsconfig.py/wiki
• Used by GeoNode
>>> from geoserver.catalog im...
Client #3 = Java
• Geoserver Manager Library
• https://github.com/geosolutions-it/
geoserver-manager

GeoServerRESTReader ...
Github

https://github.com/jericks/geoserver-shell
Install
• Download 0.1 release
• https://github.com/jericks/geoserver-shell/
releases

• Put bin directory on path
• run g...
Spring Shell
• Open source project from Spring Source
• Shell extracted from Spring Roo
• Spring Roo is a Java RAD tool fo...
Spring Shell
• Interactive shell environment
• Tab completion for commands, arguments,
and files

• History support (up and...
Geoserver Shell
• Commands for each major Geoserver
Catalog item

• Methods in command construct a URL,

create a request ...
Commands
geoserver

datastore

ows

workspace

shapefile

settings

version

postgis

gwc

manifest

featuretype

wmsstore
...
Workspace Commands
• workspace list
• workspace create --name test
• workspace get --name test
• workspace delete --name t...
Workspace
gs-shell> geoserver set --url http://localhost:8080/geoserver
gs-shell> workspace create --name naturalearth
tru...
Shapefile
gs-shell> geoserver set --url http://localhost:8080/geoserver
gs-shell> workspace create --name naturalearth
true...
PostGIS
gs-shell> geoserver set --url http://localhost:8080/geoserver
gs-shell> workspace create --name post
gs-shell> pos...
GeoTiff
gs-shell> geoserver set --url http://localhost:8080/geoserver
gs-shell> coverage store upload --workspace naturale...
Styles
gs-shell> style create --file 110m_admin_0_countries.sld --name
110m_admin_0_countries
true
gs-shell> layer style ad...
Scripts
• Scripts contain the same commands entered
interactively

• History support saves session to geoservershell.log

...
Thank you!
Jared Erickson
jared.erickson@gmail.com
https://github.com/jericks
Upcoming SlideShare
Loading in...5
×

Geo servershell

593

Published on

Administer GeoServer from a Command Line Interface`

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
593
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Geo servershell"

  1. 1. Geoserver Shell Administer Geoserver using a CLI Jared Erickson CUGOS July 2013
  2. 2. Outline • What is Geoserver Shell? • Why does Geoserver need a CLI? • What are we administering with CLI? • How does it work? • What does it look like in action?
  3. 3. What is it? • Administer Geoserver from a command line interface (CLI) • Uses Geoserver Rest interface • Based on Spring Shell • Uses GeoServer Manager and GeoTools • Written in Java • Open Source MIT License • Hosted on Github
  4. 4. Why a CLI? • Web UI is a major feature • Non developers can load data and styles • CLI is quick, efficient and scriptable • Once a script is written it can be replayed on other Geoservers (set up dev, then test, then production)
  5. 5. Geoserver UI
  6. 6. Geoserver Catalog • Workspace • Namespace • DataStore • FeatureType • CoverageStore • Coverage • Layer • LayerGroups • Style • WMSStore
  7. 7. Geoserver Rest • • • • • Administer GeoServer without GUI • Integrate with 3rd party applications Multiple representations: HTML, JSON, XML HTTP Verbs: GET, POST, PUT, DELETE HATEOS - linking http://docs.geoserver.org/stable/en/user/rest/ index.html
  8. 8. Verbs Commands Verbs list GET get GET create POST modify PUT delete DELETE
  9. 9. Geoserver Rest UI
  10. 10. /geoserver/rest/layers
  11. 11. Client #1 = curl • Upload a Shapefile curl -v -u admin:geoserver -XPUT -H "Content-type: application/zip" --data-binary @roads.zip http://localhost:8080/geoserver/rest/workspaces/acme/datastores/roads/ file.shp • Create a Workspace curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<workspace><name>acme</name></workspace>" http://localhost:8080/geoserver/rest/ workspaces
  12. 12. Client #2 = Python • gsconfig.py • https://github.com/dwins/gsconfig.py/wiki • Used by GeoNode >>> from geoserver.catalog import Catalog >>> cat = Catalog("http://localhost:8080/geoserver/rest", "admin", "geoserver") >>> cat.get_layers() [Layer[Arc_Sample], Layer[Pk50095], Layer[Img_Sample], ... >>> that_layer = cat.get_layer("roads") >>> that_layer.enabled = False >>> cat.save(that_layer)
  13. 13. Client #3 = Java • Geoserver Manager Library • https://github.com/geosolutions-it/ geoserver-manager GeoServerRESTReader reader = new GeoServerRESTReader(url, user, password); RESTStyleList styleList = reader.getStyles(); List<String> names = styleList.getNames(); GeoServerRESTPublisher publisher = new GeoServerRESTPublisher(url, user, password); publisher.createWorkspace(name);
  14. 14. Github https://github.com/jericks/geoserver-shell
  15. 15. Install • Download 0.1 release • https://github.com/jericks/geoserver-shell/ releases • Put bin directory on path • run gs-shell • Requires Java
  16. 16. Spring Shell • Open source project from Spring Source • Shell extracted from Spring Roo • Spring Roo is a Java RAD tool for creating web apps
  17. 17. Spring Shell • Interactive shell environment • Tab completion for commands, arguments, and files • History support (up and down arrows) • Knows your commands and when you can use them
  18. 18. Geoserver Shell • Commands for each major Geoserver Catalog item • Methods in command construct a URL, create a request body (xml, file) and make an Http Request to Geoserver. The Geoserver response is parsed and displayed to the user
  19. 19. Commands geoserver datastore ows workspace shapefile settings version postgis gwc manifest featuretype wmsstore namespace coverage stores style coverage template worldimage font layers
  20. 20. Workspace Commands • workspace list • workspace create --name test • workspace get --name test • workspace delete --name test • workspace default get • workspace default set --name test
  21. 21. Workspace gs-shell> geoserver set --url http://localhost:8080/geoserver gs-shell> workspace create --name naturalearth true gs-shell> workspace list topp nurc gs-shell> workspace get --name naturalearth naturalearth
  22. 22. Shapefile gs-shell> geoserver set --url http://localhost:8080/geoserver gs-shell> workspace create --name naturalearth true gs-shell> shapefile zip --shapefile 110m_admin_0_countries.shp true gs-shell> shapefile publish --file 110m_admin_0_countries.zip -workspace naturalearth true
  23. 23. PostGIS gs-shell> geoserver set --url http://localhost:8080/geoserver gs-shell> workspace create --name post gs-shell> postgis datastore create --workspace post --datastore postgis -host localhost --port 5432 --database postgres --schema public --user postgres --password postgres true gs-shell> featuretype list --workspace post --datastore postgis --list available states countries cities gs-shell> postgis featuretype publish --workspace post --datastore postgis -table 110m-admin-0-countries true
  24. 24. GeoTiff gs-shell> geoserver set --url http://localhost:8080/geoserver gs-shell> coverage store upload --workspace naturalearth --file GRAY_50M_SR_OB.zip --coveragestore world --type worldimage -configure first true gs-shell> coverage list --workspace naturalearth --coveragestore world GRAY_50M_SR_OB BLUE_MARBLE gs-shell> coverage modify --workspace naturalearth --coveragestore world --coverage GRAY_50M_SR_OB --srs EPSG:4326 --enabled true true
  25. 25. Styles gs-shell> style create --file 110m_admin_0_countries.sld --name 110m_admin_0_countries true gs-shell> layer style add --name 110m_admin_0_countries --style 110m_admin_0_countries true gs-shell> layer get --name 110m_admin_0_countries 110m_admin_0_countries Title: null Type:VECTOR Abstract: null Default Style: 110m_admin_0_countries Namespace: Type String:VECTOR gs-shell> layer modify --name 110m_admin_0_countries --defaultStyle 110m_admin_0_countries true
  26. 26. Scripts • Scripts contain the same commands entered interactively • History support saves session to geoservershell.log $ gs-shell --cmdfile mycommands.gs gs-shell> script --file naturalearth_countries.gs
  27. 27. Thank you! Jared Erickson jared.erickson@gmail.com https://github.com/jericks
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×