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?