Does anyone have a batch script to change the pooling paramaters of all services in a AGS Enterprise folder?

1556
6
03-02-2021 12:25 AM
RobertBuckley1
Occasional Contributor

I have 80 services which are hardly used. I want to set the pooling parameter to Min=0 and Max=2 for all services using a batch script. Would anyone know how to do this?

6 Replies
DavinWalker2
Esri Contributor

You could edit this script to loop through your  services. Example Edit Service Properties

RobertBuckley1
Occasional Contributor

This is exactly the script that I have been trying to adapt. I can't seem to find one which loops through an AGS Folder though.

0 Kudos
DavinWalker2
Esri Contributor

Add a for loop like in this script. Example Stop or Start All Services in a folder 

AngusHooper1
Occasional Contributor III

Use the python API.

https://developers.arcgis.com/python/api-reference/arcgis.gis.server.html#service

Specifically an edit operation against the GIS admin service object. You would parse back the exact same JSON properties with your edits to minInstancePerNode and maxInstancePerNode. 

 

https://developers.arcgis.com/python/guide/managing-your-gis-servers/#Administering-services

Here is the section of the guide that introduces the object.

0 Kudos
RobertBuckley1
Occasional Contributor

This is my script ...but the properties do not get  changed. Anyone know why?

 

 

# For Http calls
import httplib, urllib, json

# For system tools
import sys

# For reading passwords without echoing
import getpass


# Defines the entry point into the script
def main(argv=None):
# Print some info
print
print "This tool is a sample script"
print

# Ask for admin/publisher user name and password
username = "xxx"
password = "xxx"

# Ask for server name
serverName = "xxx"
serverPort = 6080

folder = 'Geobasisdaten'

# Get a token
token = getToken(username, password, serverName, serverPort)
if token == "":
print "Could not generate a token with the username and password provided."
return


folderURL = "/arcgis/admin/services/commandx/"

# This request only needs the token and the response formatting parameter
params = urllib.urlencode({'token': token, 'f': 'json'})

headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}

# Connect to URL and post parameters
httpConn = httplib.HTTPConnection(serverName, serverPort)
httpConn.request("POST", folderURL, params, headers)

# Read response
response = httpConn.getresponse()
if (response.status != 200):
httpConn.close()
print "Could not read folder information."
return
else:
data = response.read()

# Check that data returned is not an error object
if not assertJsonSuccess(data):
print "Error when reading folder information. " + str(data)
else:
print "Processed folder information successfully. Now processing services..."

# Deserialize response into Python object
dataObj = json.loads(data)
httpConn.close()

# Loop through each service in the folder and stop or start it
for item in dataObj['services']:

# Edit desired properties of the service
dataObj["minInstancesPerNode"] = 0
dataObj["maxInstancesPerNode"] = 2

# Serialize back into JSON
updatedSvcJson = json.dumps(dataObj)

# Call the edit operation on the service. Pass in modified JSON.
editSvcURL = folderURL + str(item["serviceName"])+ ".MapServer" + "/edit"
print editSvcURL
params = urllib.urlencode({'token': token, 'f': 'json', 'service': updatedSvcJson})

httpConn.request("POST", editSvcURL, params, headers)

# Read service edit response
editResponse = httpConn.getresponse()
if (editResponse.status != 200):
httpConn.close()
print "Error while executing edit."
return
else:
editData = editResponse.read()

# Check that data returned is not an error object
if not assertJsonSuccess(editData):
print "Error returned while editing service" + str(editData)
else:
print "Service edited successfully."

httpConn.close()

return


# A function to generate a token given username, password and the adminURL.
def getToken(username, password, serverName, serverPort):
# Token URL is typically http://server[:port]/arcgis/admin/generateToken
tokenURL = "/arcgis/admin/generateToken"

params = urllib.urlencode({'username': username, 'password': password, 'client': 'requestip', 'f': 'json'})

headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}

# Connect to URL and post parameters
httpConn = httplib.HTTPConnection(serverName, serverPort)
httpConn.request("POST", tokenURL, params, headers)

# Read response
response = httpConn.getresponse()
if (response.status != 200):
httpConn.close()
print "Error while fetching tokens from admin URL. Please check the URL and try again."
return
else:
data = response.read()
httpConn.close()

# Check that data returned is not an error object
if not assertJsonSuccess(data):
return

# Extract the token from it
token = json.loads(data)
return token['token']

# A function that checks that the input JSON object
# is not an error object.
def assertJsonSuccess(data):
obj = json.loads(data)
if 'status' in obj and obj['status'] == "error":
print "Error: JSON object returns an error. " + str(obj)
return False
else:
return True


# Script start
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))

0 Kudos
Todd_Metzler
Occasional Contributor III

Hello,

Somewhat off topic but I'll share for your consideration anyway.  If your version of ArcGIS Enterprise supports shared instances, suggest changing all your infrequently used services from dedicated to shared pool.  In our Enterprise this has improved overall computing resource utilization at the cost of supporting a few ArcSOC processes that are fairly large resource consumers.  The major benefit has been an overall reduction in the number of ArcSOC processes running and the ability to host more services without running up against heap space limits in the Windows OS.

Now a question:  Who has a script to change existing dedicated service to shared pool.

Todd

0 Kudos