Inside Esri ArcGIS Enterprise
Map Image Layer
After publishing via Python API, I get an error when I load this and I am trying to take it apart and fix it!
The error is when I open it in a Map Viewer.
Error The layer, Hyperlinked_Surveys, cannot be added to the map.
There is no layer called "Hyperlinked Surveys", so this makes sense! I'd like to know why it's trying to load this though. I cannot find any references to that string in my map! It's called "hyperlinked_surveys".
Code used to publish the service
I used a Notebook running in VSCode to do this. The file config.py contains references to environment settings containing my secrets.
This cell signs in and finds the map and the first layer in the map
from scripts.config import Config import arcpy arcpy.SignInToPortal(Config.PORTAL_URL, Config.PORTAL_USER, Config.PORTAL_PASSWORD) project = arcpy.mp.ArcGISProject("K:/webmaps/basemap/basemap.aprx") maps = project.listMaps() mapnames = [map.name for map in maps] map = maps[mapnames.index('arcgis_utils unit test')] layer = map.listLayers()[0] layer
This cell creates the .sddraft and .sd files, it takes 30 seconds to run
def fn(sd_name, server, service, copy=True): sddraft = map.getWebLayerSharingDraft(server_type=server, service_type=service, service_name=sd_name, layers_and_tables=[layer]) sddraft_name = os.path.join("C:\\Temp", sd_name + '.sddraft') sddraft.overwriteExistingService = True sddraft.copyDataToServer = copy if server=='FEDERATED_SERVER': sddraft.federatedServerUrl = Config.SERVER_URL # required for FEDERATED_SERVER! print(sddraft_name) sddraft.exportToSDDraft(sddraft_name) arcpy.env.overwriteOutput = True arcpy.StageService_server(sddraft_name, os.path.join("C:\\Temp", sd_name + ".sd")) print(os.getcwd()) fn("Survey_Sample_MIL", "FEDERATED_SERVER", "MAP_IMAGE") fn("Survey_Sample_FEATURES", "HOSTING_SERVER", "FEATURE") fn("Survey_Sample_GEODATABASE_FEATURES", "HOSTING_SERVER", "FEATURE", copy=False)
This cell creates or overwrites the Map Image Layer, it also runs in about 30 seconds.
arcpy.server.UploadServiceDefinition(in_sd_file="C:\\Temp\\Survey_Sample_MIL.sd", in_server="K:/webmaps/basemap/server (publisher).ags")
Note that this WORKS in this case.
arcpy.server.UploadServiceDefinition(in_sd_file="C:\\Temp\\Survey_Sample_MIL.sd", in_server=Config.SERVER_URL)
and it produces this output:
Output id value 0 https://CC-GIS.CLATSOP.CO.CLATSOP.OR.US:6443/arcgis/services/Survey_Sample_MIL/MapServer 1 https://CC-GIS.CLATSOP.CO.CLATSOP.OR.US:6443/arcgis/rest/services/Survey_Sample_MIL/MapServer 2 3 4 5 6 7 8 9 10 Messages Start Time: Thursday, December 23, 2021 12:08:23 PM Submitted. Executing... Executing (Publish Service Definition): PublishServiceDefinition ia976f338-6563-4da1-b591-f66b40769178 # {"buildInitialCache":false} Start Time: Thu Dec 23 12:08:24 2021 Submitted. Executing... Start Time: Thursday, December 23, 2021 12:08:25 PM Getting server information (server folders, data stores, etc.). Validating service definition. Creating the service. Succeeded at Thursday, December 23, 2021 12:08:51 PM (Elapsed Time: 25.82 seconds) Succeeded. Succeeded at Thu Dec 23 12:08:51 2021 (Elapsed Time: 27.30 seconds) Succeeded. Succeeded at Thursday, December 23, 2021 12:08:53 PM (Elapsed Time: 29.60 seconds)
This cell creates or overwrites the Feature Service, it takes a minute
arcpy.server.UploadServiceDefinition(in_sd_file="C:\\Temp\\Survey_Sample_FEATURES.sd", in_server="K:/webmaps/basemap/server (publisher).ags")
Note that this DOES NOT WORK in this case.
arcpy.server.UploadServiceDefinition(in_sd_file="C:\\Temp\\Survey_Sample_FEATURES.sd", in_server=Config.SERVER_URL)
Output is
Output id value 0 1 2 3 35886b1683e246638eca2fc2648b962f 4 5 https://delta.co.clatsop.or.us/server/rest/services/Hosted/Survey_Sample_FEATURES/FeatureServer 6 7 hyperlinked_surveys|0 8 9 10 Messages Start Time: Thursday, December 23, 2021 12:13:38 PM Succeeded at Thursday, December 23, 2021 12:14:34 PM (Elapsed Time: 55.88 seconds)
Finally this cell,
arcpy.server.UploadServiceDefinition(in_sd_file="C:\\Temp\\Survey_Sample_FEATURES.sd", in_server="K:/webmaps/basemap/server (publisher).ags")
gives this output in about 20 seconds
Output id value 0 1 2 3 151d6134e5574563937257665b41c132 4 5 https://delta.co.clatsop.or.us/server/rest/services/Hosted/Survey_Sample_GEODATABASE_FEATURES/FeatureServer 6 7 hyperlinked_surveys|0 8 9 10 Messages Start Time: Thursday, December 23, 2021 12:59:22 PM Succeeded at Thursday, December 23, 2021 12:59:45 PM (Elapsed Time: 22.37 seconds)
Files on Portal
When I publish, it creates an entry in Portal. I can see its ID in the URL and then go to the folder on the Portal server, <Portal>/content/items/<ID> where for me <Portal> is C:/arcgis/arcgisportal/ In the folder there is a subfolder called "esriinfo" containing these files. I am exploring with Visual Studio Code with the Remote SSH extension, and formatters installed for XML and JSON. VSCode is awesome.
metadata/metadata.xml thumbnail/thumbnail.JPEG which I presume is... the thumbnail!! that appears in Portal item.pkinfo this is a tiny JSON file that has the ID, a creation date, and the type "Map Service". iteminfo.json this has all the properties in it including a GUID, extent, SRS, keywords (tags), a path to the thumbnail, a blank URL, and the fields you see in Portal like name and description. iteminfo.xml is an XML version of a subset of the same properties
Note there is no list of layers in there and no reference to "Hyperlinked Surveys".
In Portal, I see that my MIL has one layer called "Survey_Sample_MIL", and when I click on that I see this URL: https://delta.co.clatsop.or.us/server/rest/services/Survey_Sample_MIL/MapServer Note it's referring to "server" which is the name of my ArcGIS Server instance, so it lives only on ArcGIS Server, not in Portal.
When I check out that link, everything seems okay. I can if I want enable more features in there such as WFS, WMS, and Feature Access.