CreateGPSDDraft

Zusammenfassung

The function converts Result objects and result files (.rlt) into Service Definition Draft (.sddraft) files.

Hinweis:

A draft service definition does not contain data. A draft service alone cannot be used to publish a service.

Diskussion

CreateGPSDDraft is the first step to automating the publishing of a geoprocessing result to a GIS Server using ArcPy. The output created from CreateGPSDDraft is a Service Definition Draft (.sddraft) file. A Service Definition Draft is the combination of a result file or Result object, information about the server, and a set of service properties. A Result object can be created in a Python script by setting a variable to a tool execution. For example, the following buffer result is saved to a variable called result.

import arcpy
result = arcpy.Buffer_analysis("inPts", "output.shp", "100 Meters")

Information about the server includes the server connection, server type being published to, type of service being published, metadata for the service (Item info), and data references (whether or not data is being copied to the server).

The function returns a dictionary containing errors, warnings, and messages that you should address prior to creating your Service Definition file.

The Service Definition Draft needs to be converted to a fully consolidated Service Definition (.sd) file using the Stage Service tool. Staging compiles all the necessary information needed to successfully publish the GIS resource. If your data is not registered with the server, the data will be added when the Service Definition Draft is staged. Finally, the Service Definition file can be uploaded and published as a GIS service to a specified GIS server using the Upload Service Definition tool. This step takes the Service Definition file, copies it onto the server, extracts required information, and publishes the GIS resource. For more information, see An overview of the Publishing toolset.

Syntax

CreateGPSDDraft (result, out_sddraft, service_name, {server_type}, {connection_file_path}, {copy_data_to_server}, {folder_name}, {summary}, {tags}, {executionType}, {resultMapServer}, {showMessages}, {maximumRecords}, {minInstances}, {maxInstances}, {maxUsageTime}, {maxWaitTime}, {maxIdleTime}, {capabilities}, {constantValues})
ParameterErläuterungDatentyp
result
[result,...]

A reference to one or multiple Result objects or result files (.rlt) on disk. Multiple results must be supplied in a list format. The following example demonstrates multiple results as input to the CreateGPSDDraft function.

import arcpy
result1 = arcpy.Buffer_analysis("inPts", "output.shp", "100 Meters")
result2 = arcpy.GetCount_management("FireStations")
arcpy.CreateGPSDDraft([result1, result2], "output.sddraft", "myservice")
Result
out_sddraft

A string that represents the path and file name for the output Service Definition Draft (.sddraft) file.

String
service_name

A string that represents the name of the service. This is the name people will see and use to identify the service. The name can only contain alphanumeric characters and underscores. No spaces or special characters are allowed. The name cannot be more than 120 characters in length.

String
server_type

A string representing the server type. If a connection_file_path parameter is not supplied, a server_type must be provided. If a connection_file_path parameter is supplied, the server_type is taken from the connection file. In this case, you can choose FROM_CONNECTION_FILE or skip the parameter entirely.

Hinweis:

MY_HOSTED_SERVICES is only available when creating .sddraft files from ArcGIS Pro.

  • ARCGIS_SERVERArcGIS Server server type.
  • FROM_CONNECTION_FILEGets the server_type as specified in the connection_file_path parameter.
  • MY_HOSTED_SERVICESCreates an .sddraft file to be published to the current portal.

(Der Standardwert ist ARCGIS_SERVER)

String
connection_file_path

A string that represents the path and file name to the ArcGIS Server connection file (.ags).

String
copy_data_to_server

A Boolean that indicates whether or not the data referenced in the result will be copied to the server. The copy_data_to_server parameter is only used if the server_type is ARCGIS_SERVER and the connection_file_path isn't specified. If the connection_file_path is specified, the server's registered data stores are used. For example, if the data in the result is registered with the server, copy_data_to_server will always be False. Conversely, if the data in the result is not registered with the server, copy_data_to_server will always be True.

(Der Standardwert ist False)

Boolean
folder_name

A string that represents a folder name to which you want to publish the service definition. If the folder does not currently exist, it will be created. The default folder is the server root level.

(Der Standardwert ist None)

String
summary

A string that represents the Item Description Summary.

Use this parameter to override the user interface summary or to provide a summary if one does not exist. The summary provided here will not be persisted in the map document.

(Der Standardwert ist None)

String
tags

A string that represents the Item Description Tags.

Use this parameter to override the user interface tags or to provide tags if they do not exist. The tags provided here will not be persisted in the map document.

(Der Standardwert ist None)

String
executionType

Asynchron und synchron definieren, wie der Client (die Anwendung, die den Task verwendet) mit dem Server interagiert und das Task-Ergebnis erhält. Wenn ein Service auf synchron eingestellt ist, wartet der Client, bis der Task beendet ist. In der Regel dauert die Ausführung eines synchronen Tasks kurz – fünf Sekunden oder weniger. Ein asynchroner Task braucht in der Regel länger, und der Client muss den Server regelmäßig abfragen, ob der Task beendet ist, und nach Fertigstellung das Ergebnis abrufen. Eine Webanwendung, die einen asynchronen Task verwendet, muss Logik implementiert haben, um den Task-Status zu überprüfen und das Ergebnis nach der Fertigstellung zu verarbeiten. ArcGIS for Desktop-Clients verarbeiten beide Ausführungstypen nativ.

(Der Standardwert ist Asynchronous)

String
resultMapServer

When publishing a geoprocessing service, you can choose to view the result of all tasks with the service as a map (in addition to other results of your task). The map is created on the server using a Map Service for transport back to the client as an image (a .jpeg file for example). The symbology, labeling, transparency, and all other properties of the returned map are the same as the settings of your output layer. Remember, if you are creating result layers within the Python scripting environment (outside ArcGIS Pro), default symbologies will be used. To maintain control over symbology, you will need to pre-create layer files with rich symbology and use them to modify the output symbology of your task.

When you choose this option, a map service is automatically created on the server with the same name as your geoprocessing service.

(Der Standardwert ist False)

Boolean
showMessages

A string setting the message level for the geoprocessing service. The following is a list of valid message levels the service will return to the client:

  • NoneNo geoprocessing messages are returned to the client except those regarding whether the execution was successful or failed.
  • ErrorOnly tool messages that produce an error are returned to the client.
  • WarningAll tool error and warning messages are returned to the client.
  • InfoAll tool messages from execution are returned to the client.

(Der Standardwert ist None)

String
maximumRecords

Die maximale Anzahl von Ergebnissen, die der Service an einen Client zurückgeben kann. Wenn Sie diesen Wert auf eine große Zahl einstellen, kann Ihr GIS-Server eine Menge einzelner Datensätze oder Features verarbeiten, die an den Client gesendet werden. Wenn Sie keine Features zurückgeben möchten, setzen Sie diesen Wert auf 0 (Null). In der Regel setzen Sie diesen Wert nur dann auf Null, wenn Sie Ergebnisse mit einem Kartenservice anzeigen verwenden.

(Der Standardwert ist 1000)

Integer
minInstances

An integer value representing the minimum number of instances a service will start and make available for use. For heavily used services, you may want to increase this value.

(Der Standardwert ist 1)

Integer
maxInstances

An integer value representing the maximum number of instances a service can start and make available for use. For heavily used services, you may need to increase this value. Ensure the server has adequate hardware to support the maximum number of instances you will allow.

(Der Standardwert ist 2)

Integer
maxUsageTime

Die maximale Zeit in Sekunden, die ein Service verwendet werden kann. Sie müssen ggf. den Standardwert von 600 Sekunden (10 Minuten) für länger dauernde Geoverarbeitungs-Tasks erhöhen. Alternativ können Sie die Zeit reduzieren, um sicherzustellen, dass ein Client den Service nicht missbräuchlich verwendet.

(Der Standardwert ist 600)

Integer
maxWaitTime

Die maximale Zeit in Sekunden, die ein Client auf eine Verbindung mit einer Instanz wartet, bevor ein Timeout erfolgt. Wenn alle Instanzen mit der Verarbeitung von Anforderungen ausgelastet sind, werden nachfolgende Anforderungen in eine Warteschlange gestellt. Wenn dieses Timeout eintritt, bevor eine Instanz verfügbar wird, schlägt der Task fehl. Der Standard ist 60 Sekunden (1 Minute).

(Der Standardwert ist 60)

Integer
maxIdleTime

Die maximale Zeit in Sekunden, die eine Instanz aktiv bleibt, bevor eine Poolverkleinerung erfolgt. Instanzen oberhalb der Mindestanzahl von Instanzen, die nicht verwendet wurden, werden heruntergefahren, sobald die maximale Leerlaufzeit abgelaufen ist.

(Der Standardwert ist 1800)

Integer
capabilities

Specifies the capabilities a service can support. Currently, only UPLOADS is supported.

(Der Standardwert ist None)

String
constantValues
[constantValues,...]

A list of parameter names to be set as a constant. If multiple tools are included, parameter names must be qualified with the tool name, for example, ["toolX.parameterA", "toolY.parameterD"].

(Der Standardwert ist None)

String
Rückgabewert
DatentypErläuterung
Dictionary

Returns a dictionary of information messages, warnings, and errors.

Codebeispiel

CreateGPSDDraft example 1: Publishing to a federated server

The following script demonstrates the complete publishing of a web tool to a federated server. Automating the publishing of web tools uses a combination of ArcPy functions and geoprocessing tools in the Publishing toolset. The workflow begins by executing a geoprocessing task that you want to publish. After you have successfully run the geoprocessing task, log in to your portal to proceed. Then use the ArcPy function CreateGPSDDraft to create a service definition draft. Note that the Item Description, Summary, and Tags for the input geoprocessing result are overwritten using the summary and tags parameters. The function returns an analyzer dictionary that identifies issues that could prevent you from successfully publishing. After resolving any serious issues, the service definition can be staged. Staging takes the service definition draft and consolidates all the information needed to publish the service into a complete service definition. Use the Stage Service tool to stage the service definition. Finally, use the Upload Service Definition tool to upload the service definition to the portal and publish the web tool.

import arcpy

toolbox = "c:/gis/gp/MyAnalysisTools.tbx"
sddraft = "c:/gis/gp/drafts/AnalysisReport.sddraft"
sd = "c:/gis/gp/sd/AnalysisReport.sd"
portalurl = "https://myportal.esri.com/portal"
portalusername = "username"
portalpassword = "password"
serverURL = "https://myserver.esri.com/server"
serviceName = "AnalysisReportService"

# Run the tool and set to a result object
arcpy.ImportToolbox(toolbox)
result = arcpy.MyCustomAnalysis_reports("c:/gis/data/parcels.gdb/taxlots",
    "40", "MyOutput.pdf")

# Sign in Portal
arcpy.SignInToPortal(portalurl, portalusername, portalpassword)

# Create service definition draft and return analyzer messages
analyzeMessages = arcpy.CreateGPSDDraft(
    result, sddraft, serviceName, server_type="MY_HOSTED_SERVICES",
    copy_data_to_server=True, folder_name=None, 
    summary="Analysis Service", tags="gp", executionType="Synchronous",
    resultMapServer=False, showMessages="INFO", maximumRecords=5000,
    minInstances=2, maxInstances=3, maxUsageTime=100, maxWaitTime=10,
    maxIdleTime=180)

# Stage and upload the service if the sddraft analysis did not
# contain errors
if analyzeMessages['errors'] == {}:
    # Execute StageService
    arcpy.StageService_server(sddraft, sd)
    # Execute UploadServiceDefinition
    # Use URL to a federated server
    arcpy.UploadServiceDefinition_server(sd, serverURL)
else:
    # If the sddraft analysis contained errors, display them
    print(analyzeMessages['errors'])
CreateGPSDDraft example 2: Publishing to a stand-alone server

The following script demonstrates the complete process of publishing a geoprocessing service to a stand-alone server. The workflow is similar to publishing to a federated Server, except you do not need to log in to a portal. In addition, the parameter server type should be set to ARCGIS_SERVER, and a server connection .ags file needs to be provided for the CreateGPSDDraft function. The server connection file of the Upload Service Definition tool also needs to be provided with a server connection .ags file. Make sure the preexisting .ags file has server login credentials.

import arcpy

toolbox = "c:/gis/gp/MyAnalysisTools.tbx"
sddraft = "c:/gis/gp/drafts/AnalysisReport.sddraft"
sd = "c:/gis/gp/sd/AnalysisReport.sd"

serverconnectionfile = "c:/gis/gp/myserver.ags"
serviceName = "AnalysisReportService"

# Run the tool and set to a result object
arcpy.ImportToolbox(toolbox)
result = arcpy.MyCustomAnalysis_reports("c:/gis/data/parcels.gdb/taxlots",
                                        "40", "MyOutput.pdf")

# Create service definition draft and returns analyzer messages
analyzeMessages = arcpy.CreateGPSDDraft(
    result, sddraft, serviceName, server_type="MY_HOSTED_SERVICES",  
    connection_file_path= serverconnectionfile,
    copy_data_to_server=True, folder_name=None, 
    summary="Analysis Service", tags="gp", executionType="Synchronous",
    resultMapServer=False, showMessages="INFO", maximumRecords=5000,
    minInstances=2, maxInstances=3, maxUsageTime=100, maxWaitTime=10,
    maxIdleTime=180)

# Stage and upload the service if the sddraft analysis did not
# contain errors
if analyzeMessages['errors'] == {}:
    # Execute StageService
    arcpy.StageService_server(sddraft, sd)
    # Execute UploadServiceDefinition
    # Use URL to a federated server 
    arcpy.UploadServiceDefinition_server(sd, serverconnectionfile)
else:
    # If the sddraft analysis contained errors, display them
    print(analyzeMessages['errors'])

Verwandte Themen