-
-
Save soiqualang/e4f256706445268e988a75f58aebc6c1 to your computer and use it in GitHub Desktop.
Truncate and Seed GWC cached layers in GeoServer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib2 | |
import base64 | |
baseURL = "https://domain.example:8080/geoserver/gwc/rest/seed/" | |
descURL = "https://domain.example:8080/geoserver/gwc/rest/layers/" | |
un = 'username' | |
pw = 'biglongtrickypassword' | |
def truncateLayer(layer): | |
print 'TRUNCATING: ' + layer | |
url = baseURL + 'WORKSPACE:' + layer + '.json' | |
urlDesc = descURL + 'WORKSPACE:' + layer + '.json' | |
base64string = base64.encodestring('%s:%s' % (un, pw)).replace('\n', '') | |
gridsets = [] | |
#try the creative commons workspace, if not found ,try planning schemes. | |
try: | |
desc = urllib2.Request(urlDesc) | |
desc.add_header("Authorization", "Basic %s" % base64string) | |
layerInfo = json.loads(urllib2.urlopen(desc).read())['GeoServerLayer'] | |
imageFormats = layerInfo['mimeFormats'] | |
for gridset in layerInfo['gridSubsets']: | |
gridsets.append(gridset['gridSetName']) | |
except: | |
print 'identifying gridsets failed...' | |
for gs in gridsets: | |
print 'removing gridset: ' + gs | |
for imf in imageFormats: | |
print ' removing image format: ' + imf | |
try: | |
request = urllib2.Request(url) | |
base64string = base64.encodestring('%s:%s' % (un, pw)).replace('\n', '') | |
request.add_header("Authorization", "Basic %s" % base64string) | |
request.add_header('Content-Type', 'application/json') | |
data = {'seedRequest':{'minX':[],'minY':[],'maxX':[],'maxY':[],'gridSetId':gs,'zoomStart':00,'zoomStop':20,'format':imf,'type':'truncate','threadCount':2}} | |
data = json.dumps(data) | |
request.add_data(data) | |
req = urllib2.urlopen(request) | |
print ' success' | |
except: | |
print 'removing gridset failed' | |
print data | |
pass | |
def seedLayer(layer): | |
url = baseURL + layer + '.json' | |
request = urllib2.Request(url) | |
base64string = base64.encodestring('%s:%s' % (un, pw)).replace('\n', '') | |
request.add_header("Authorization", "Basic %s" % base64string) | |
request.add_header('Content-Type', 'application/json') | |
data = {'seedRequest':{'minX':[],'minY':[],'maxX':[],'maxY':[],'gridSetId':'EPSG:900913','zoomStart':00,'zoomStop':18,'format':'image/png','type':'seed','threadCount':2}} | |
data = json.dumps(data) | |
request.add_data(data) | |
req = urllib2.urlopen(request) | |
#truncate layers | |
truncateLayer('examplelayer') | |
#seed high-use layers | |
seedLayer('GCC_cc:examplelayer') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment