Need to publish web service using arcpy tuning up its properties through the parameter names passing them into function parameter_toggle (see code bellow). We are getting error (see picture bellow) in the parse of XML (output of sddraft analysis) with xml.dom.minidom for the parameters:
- "recycleInterval"
- "recycleStartTime"
- "keepAliveInterval"
These parameters represent service properties:
Specify Recycling Settings:
- Recycle this configuration every
- Starting at
Specify Health Check Settings:
- Check and repair instances every
def mapService(wrkspc, con, service):
...
return (sddraft, analysis) # (out_sddraft, out_analysis)
def capability_toggle(doc, server_type, status):
type_names = doc.getElementsByTagName('TypeName')
for type_name in type_names:
if type_name.firstChild.data == "{}".format(server_type) and status.lower() == 'on':
type_name.parentNode.getElementsByTagName("Enabled")[0].firstChild.data = "true"
def parameter_toggle(doc,'maxRecordCount', 'MaxInstances', 'recycleInterval', 'recycleStartTime', 'keepAliveInterval'):
keys = doc.getElementsByTagName('Key')
for key in keys:
if key.firstChild.data == "{}".format(maxRecordCount) : key.nextSibling.firstChild.data = 100000
if key.firstChild.data == "{}".format(MaxInstances) : key.nextSibling.firstChild.data = 5
if key.firstChild.data == "{}".format(recycleInterval) : key.nextSibling.firstChild.data = 20
if key.firstChild.data == "{}".format(recycleStartTime) : key.nextSibling.firstChild.data = '04:00'
if key.firstChild.data == "{}".format(keepAliveInterval) : key.nextSibling.firstChild.data = 86400 #seconds
def publishService(out_analysis, out_ssdraft, sd, con):
...
def main():
# workspace
wrkspc = "path_to_workspace"
# server connection (publisher)
con = os.path.join(wrkspc, "file.ags")
service = "service_name"
# outputs mapservice
(out_sddraft, out_analysis) = mapService(wrkspc, con, service)
# parse of XML (from sddraft analysis)
doc = dom.parse(out_sddraft)
### ERROR HERE PARSING XML ###
with open(out_sddraft, 'w+') as xml:
capability_toggle(doc, 'WMSServer', 'on')
parameter_toggle(doc,'maxRecordCount', 'MaxInstances', 'recycleInterval', 'recycleStartTime', 'keepAliveInterval')
doc.writexml(xml)
sd = os.path.join(wrkspc,service + '.sd')
publishService(out_analysis, out_sddraft, sd, con)
if __name__ == '__main__':
main()