I have added a shutdown Python script to my FME workbench to publish the TIFFs written as a service.
import fme
import arcpy
AGSconnection = "W:\\Entity\\ABZ\\myfolderpath\\gbepabz-file.name.ags"
print fme.featuresWritten
layerlist = []
mxd = arcpy.mapping.MapDocument("\\\\gbepabz-aqgis02\\OWProcessing\\temptest\\TEMPLATE.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
sr = arcpy.SpatialReference(23031)
df.SpatialReference = sr
mxd.activeDataFrame.spatialReference = sr
for tiff in fme.featuresWritten:
filepath = "\\\\gbepabz-apgis01\\ArcGisServer_data\\Vendor\\Sentinel\\"+tiff+".tif"
tifflayer = arcpy.MakeRasterLayer_management(filepath, tiff)
#addlayer = arcpy.mapping.Layer(tifflayer)
#layerlist.append(tifflayer)
layerfile = "\\\\gbepabz-apgis01\\ArcGisServer_data\\Vendor\\Sentinel\\"+tiff+".lyr"
arcpy.SaveToLayerFile_management (tifflayer, layerfile)
addlayer = arcpy.mapping.Layer(layerfile)
arcpy.mapping.AddLayer(df,addlayer)
print filepath
mxdpath = "\\\\gbepabz-apgis01\\ArcGisServer_data\\Vendor\\Sentinel\\temp3.mxd"
print mxdpath
mxd.saveACopy(mxdpath)
df.SpatialReference = sr
mxd.activeDataFrame.spatialReference = sr
mxd.save()
sddraftpath = "\\\\gbepabz-apgis01\\ArcGisServer_data\\Vendor\\Sentinel\\sentinel.sddraft"
SDpath = "\\\\gbepabz-aPgis01\\ArcGisServer_data\\Vendor\\Sentinel\\sentinel.sd"
service = "Sentinel"
arcpy.mapping.CreateMapSDDraft(mxd, sddraftpath, service, "ARCGIS_SERVER", AGSconnection, "FALSE", "GENERAL")
arcpy.mapping.AnalyzeForSD(sddraftpath)
arcpy.StageService_server(sddraftpath, SDpath)
arcpy.UploadServiceDefinition_server(SDpath, AGSconnection, in_startupType="STARTED")
When this runs at the end of my workbench I get an error on the analyser.
Python Exception : ERROR 001272: Analyzer errors were encountered (codes = 179, 179, 179, 179). Failed to execute (StageService).
Online I've found that this error code means that the data is not registered with the server. It is on the server and registered with the server. It is in the same directory as other data that have been successfully published.
If I then open temp3.mxd and run the following
mxd = arcpy.mapping.MapDocument("CURRENT")
AGSconnection = "W:\\Entity\\ABZ\\myfolderpath\\gbepabz-file.name.ags"
sddraftpath = "\\\\gbepabz-apgis01\\ArcGisServer_data\\Vendor\\Sentinel\\sentinel.sddraft"
SDpath = "\\\\gbepabz-aPgis01\\ArcGisServer_data\\Vendor\\Sentinel\\sentinel.sd"
service = "Sentinel"
arcpy.mapping.CreateMapSDDraft(mxd, sddraftpath, service, "ARCGIS_SERVER", AGSconnection, "FALSE", "GENERAL")
arcpy.mapping.AnalyzeForSD(sddraftpath)
arcpy.StageService_server(sddraftpath, SDpath)
arcpy.UploadServiceDefinition_server(SDpath, AGSconnection, in_startupType="STARTED")
It will sucessfully publish the service. The Analyze for SD step gives warnings but no errors.
The whole point of the process is to work without any manual intervention so I need to get this workiing from FME.
Is it a difference in the Python interpretation, or is ArcGIS Server easier to work with from ArcMap?
1 Answer 1
This is more a visual comment than answer (apologies)
I think that you need to add the interpreter to the FME Server side of things
When uploading (publishing) the workspace you can set the resources to upload the python it requires
(not an expert on python)
-
Good info! But as I understand correctly he is currently still trying to get it to work on his desktop, not on server.nielsgerrits– nielsgerrits2019年05月29日 08:46:35 +00:00Commented May 29, 2019 at 8:46
-
this should work for desktop as well, as FME Workbench is the authoring source. I not a python expert so the other option the user has is to run fme.exe in batch mode knowledge.safe.com/articles/1384/… which can be scheduled in task scheduler.2019年05月29日 12:58:07 +00:00Commented May 29, 2019 at 12:58