Select to view content in your preferred language

Is it possible to get map service layer names using the Admin API?

1376
3
07-05-2017 03:06 PM
ChrisBeaudette
Frequent Contributor

Is it possible to get the layer names as they appear in the MXD using the ArcGIS Server Admin API?  I know you can get the data source names with a manifest request, e.g. http://<HOSTNAME>:6080/arcgis/admin/services/<FOLDER_NAME>/<SERVICE_NAME>.MapServer/iteminfo/manifes..., but I'd also like to get the layer names as they appear in the MXD, but from the admin API and not actually querying the MXD or the REST endpoint of the map service.  I.e. I do NOT want to have to use http://<HOSTNAME>:6080/arcgis/rest/services/<FOLDER_NAME>/<SERVICE_NAME>/MapServer to get the layer names and prefer to use the Admin API entirely for everything.

I thought I found this at one point but now I'm not able to.

3 Replies
RebeccaStrauch__GISP
MVP Emeritus

I don't do exactly what you are asking, but I do use the manifest.json to search for a resource (.gdb) in the service so I know if I need to stop the service before I replace the .gdb.  Since I can search, I would think you could just list.  I don't have time to clean my code up right now, but I'll add a snippet so you can see part of how I'm doing it.  BTW, all the myMsgs can be replaced with print or arcpy.AddMessage  ...I just have a generic function to handle both.

elif ".GPServer" in startedService:
     # configServicesPath
     gpServicePath = os.path.join(configServicesPath, startedService)
     gpJsonPath = os.path.join(gpServicePath, "esriinfo", "manifest", "manifest.json")
     myMsgs("\n        Testing GP Server: {0} ...check the json file.".format(startedService))
     if arcpy.Exists(gpJsonPath):
          myMsgs("          Found manifest.json for {0}".format(startedService))
          """myMsgs("       ->Found...open")  # {0}".format(gpJsonPath))
                    jsonFile = open(gpJsonPath, 'r')
                    jsonData = json.load(jsonFile)
                    jsonFile.close()
                    jsonDatabases = jsonData['databases']"""
          searchTerm = baseCurrentFGDB    # "Master_current.gdb"  
          #myMsgs("The searchterm: {0}".format(searchTerm))
          #pprint(jsonDatabases[0])
          with open(gpJsonPath) as json_data:
               d = json.load(json_data)
               #print(d['databases'][0]['onServerName'])
               #onServerNameValue = (d['databases'][0]['onServerName'])
               try:
                    onServerConnectionStringValue = (d['databases'][0]['onServerConnectionString'])
                    myMsgs("          Check if {0} IN onServerConnectionStringValue".format(searchTerm))
                    sourceUsed = (searchTerm in onServerConnectionStringValue)
                    if sourceUsed:
                         myMsgs("          {0} is being used, add to list of services to stop".format(searchTerm))
                         update = True
                         myMsgs("  +Adding {0}".format(startedService)) #, updateDS[0]))     
                         updateServicesList.append(startedService)
                         #break                                   
                    else:
                         myMsgs("      Skipping...source not used for service: {0}".format(startedService))          
               except:
                    myMsgs("      Skipping...onServerConnectionStringValue not in json for {0}".format(startedService))
     else:
          myMsgs("     ->oops...not right {0}".format(gpJsonPath))
     # if doesn't find an .mxd, might be a GP service
     """if not mxdFound:  #old test
                    myMsgs("\n Didn't find an mxd for {0} \n   ....GP service?".format(startedService))"""
else:
     myMsgs("{0} not a map or gp, what is it?\n".format(startedService))
0 Kudos
ChrisBeaudette
Frequent Contributor

Thanks Rebecca.  Not sure this gets me exactly what I need, but could you give me examples of 'gpServicePath' and 'gpJsonPath' to be sure?  

If I'm not mistaken, you're interrogating the databases array of the manifest.json, which gives the onServerName of each layer but not the layer name as it appears in the MXD. For example, my MXD might have a layer name of 'City Boundary' and it points to a database layer/table name of 'CITY_BDY'.  I can get the onServerName from the Admin API and gets me the 'CITY_BDY' but I'm actually looking for how to get the name as it appears in the MXD, e.g. 'City Boundary'.

Let me know if that doesn't make sense.

RebeccaStrauch__GISP
MVP Emeritus

I'll have to get back to you later tonight when I have a bit more time to remember what I did.  I didn't know if any of the snippet would help or not. Again, my purpose is to make a list of the STARTED services that access a particular .gdb so I only have to stop (and then restart) those services.  Beats guessing, or starting up services that weren't started in the first place (a modification of tools http://www.arcgis.com/home/item.html?id=12dde73e0e784e47818162b4d41ee340  written by khibma-esristaff‌)

0 Kudos