CreateGPSDDraft

Synthèse

Converts Result objects and result files (.rlt) to a service definition draft file (.sddraft).

Remarque :

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

Discussion

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 file (.sddraft). 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 and running a tool. 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 data is copied to the server).

The function returns a dictionary containing errors, warnings, and messages that you should address before creating the service definition file (.sd).

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

Remarque :

If publishing to ArcGIS Enterprise or ArcGIS Server 10.9.1 or earlier, set the number of the staging version when using the Stage Service tool. For a list of server numbers, refer to the Staging Version parameter in the tool.

Syntaxe

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}, {choiceLists})
ParamètreExplicationType de données
result
[result,...]

One or multiple Result objects or result files (.rlt). 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.analysis.Buffer("inPts", "output.shp", "100 Meters")
result2 = arcpy.management.GetCount("FireStations")
arcpy.CreateGPSDDraft([result1, result2], "output.sddraft", "myservice")
Result
out_sddraft

The path and file name for the output .sddraft file.

String
service_name

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.

String
server_type

Specifies the server type. If a connection_file_path parameter value is not provided, a server_type value must be specified. If a connection_file_path parameter value is provided, the server_type value is taken from the connection file. In this case, you can specify FROM_CONNECTION_FILE or skip the parameter.

Remarque :

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

  • ARCGIS_SERVERThe ArcGIS Server server type. This is the default.
  • FROM_CONNECTION_FILEThe connection_file_path parameter value will be used.
  • MY_HOSTED_SERVICESAn .sddraft file is created that will be published to the current portal.

(La valeur par défaut est ARCGIS_SERVER)

String
connection_file_path

The path and file name to the ArcGIS Server connection file (.ags).

String
copy_data_to_server

Specifies whether the data referenced in the result parameter will be copied to the server. This parameter is only used if the server_type value is ARCGIS_SERVER and the connection_file_path value isn't provided. If the connection_file_path value is provided, the server's registered data stores will be used. For example, if the data in the result parameter is registered with the server, copy_data_to_server will always be False. Conversely, if the data in the result parameter is not registered with the server, copy_data_to_server will always be True.

  • FalseThe data will not be copied to the server. This is the default.
  • TrueThe data will be copied to the server.

(La valeur par défaut est False)

Boolean
folder_name

The folder name where the service definition will be published. If the folder does not exist, it will be created. The default folder is the server root level.

(La valeur par défaut est None)

String
summary

The Item Description Summary text.

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.

(La valeur par défaut est None)

String
tags

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.

(La valeur par défaut est None)

String
executionType

Les termes synchrone et asynchrone définissent la façon dont le client (l'application utilisant la tâche) interagit avec le serveur et obtient le résultat à partir de la tâche. Lorsqu'un service est synchrone, le client attend la fin de la tâche. En général, une tâche synchrone s'exécute rapidement, 5 secondes ou moins. L'exécution d'une tâche asynchrone dure généralement plus longtemps et le client doit régulièrement demander au serveur si la tâche est terminée et, si elle est terminée, obtenir le résultat. Une application Web qui utilise une tâche asynchrone doit être dotée d'une logique qui vérifie l'état d'une tâche et gère le résultat une fois l'exécution terminée. Les clients ArcGIS for Desktop gèrent les deux types d'exécution en mode natif.

(La valeur par défaut est Asynchronous)

String
resultMapServer

Specifies whether the result of all tasks will be visualized with the service as a map (in addition to other results of the task) when publishing a geoprocessing service. 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 the output layer. If you are creating result layers in the Python scripting environment (outside ArcGIS Pro), default symbology will be used. To maintain control over symbology, create the layer files with symbology and use them to modify the output symbology of the task.

When True, a map service is automatically created on the server with the same name as the geoprocessing service. The default is False.

(La valeur par défaut est False)

Boolean
showMessages

Specifies the message level that will be used for the geoprocessing service. The following are the valid message levels the service will return to the client:

  • NoneNo geoprocessing messages will be returned to the client except those stating whether the process succeeded or failed. This is the default.
  • ErrorOnly tool messages that produce an error will be returned to the client.
  • WarningAll tool error and warning messages will be returned to the client.
  • InfoAll tool messages from processing will be returned to the client.

(La valeur par défaut est None)

String
maximumRecords

Nombre maximal de résultats que le service peut renvoyer à un client. Si cette valeur est définie sur un nombre élevé, cela signifie que votre serveur SIG peut gérer l'envoi de nombreux enregistrements individuels ou d'entités au client. Si vous ne souhaitez pas renvoyer d'entités, définissez cette valeur sur 0 (zéro). En général, cette valeur est définie sur zéro uniquement lorsque vous activez l'option Visionner le résultat avec un service de carte.

(La valeur par défaut est 1000)

Integer
minInstances

The minimum number of instances a service will start and make available for use. For heavily used services, you can increase this value.

(La valeur par défaut est 1)

Integer
maxInstances

The maximum number of instances a service can start and make available for use. For heavily used services, you can increase this value. Ensure that the server has adequate hardware to support the maximum number of instances indicated.

(La valeur par défaut est 2)

Integer
maxUsageTime

Durée maximale, exprimée en seconde, d'utilisation d'un service. Vous pouvez avoir besoin d'augmenter la valeur par défaut à 600 secondes (10 minutes) pour les tâches de géotraitement avec une durée d'exécution plus longue. Il peut aussi être nécessaire de réduire cette durée pour éviter qu'un client n'abuse de vos services.

(La valeur par défaut est 600)

Integer
maxWaitTime

Période maximale, exprimée en seconde, durant laquelle un client doit attendre pour se connecter à une instance avant la période d'expiration. Lorsque toutes les instances sont occupées avec le traitement de demandes, les demandes sont placées dans une file d'attente. Si cette période d'expiration s'écoule avant qu'une instance ne soit disponible, la tâche échoue. La valeur par défaut est de 60 secondes (1 minute).

(La valeur par défaut est 60)

Integer
maxIdleTime

Période maximale, exprimée en seconde, durant laquelle un client doit attendre pour se connecter à une instance avant la période d'expiration. Toutes les instances inutilisées au-delà du nombre minimal d'instances sont arrêtées dès que la période d'inactivité a atteint la valeur limite définie.

(La valeur par défaut est 1800)

Integer
capabilities

Specifies the capabilities a service will support. Currently, only Uploads is supported.

(La valeur par défaut est 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"].

(La valeur par défaut est None)

String
choiceLists

Constrains values for any input parameter with a choice list input mode in the web tool or geoprocessing service.

The choice list and its values must be created before using this property; you cannot use this property to add new values to the choice list. If you have a feature or raster input, you must create the layer for each value in the choice list first and use this property to constrain.

The property uses a dictionary with the service task and parameter name as the key, and a list of the string values as the value, for example, {"ServiceTaskName.parameterName":["string1", "string2"]}.

(La valeur par défaut est None)

Dictionary
Valeur renvoyée
Type de donnéesExplication
Dictionary

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

Exemple de code

CreateGPSDDraft example 1: Publish 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 running a geoprocessing task that you want to publish. After you successfully run the geoprocessing task, sign in to your portal to proceed. Then use the CreateGPSDDraft function to create a service definition draft. 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 may prevent successful 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.reports.MyCustomAnalysis("c:/gis/data/parcels.gdb/taxlots",
                                        "40", "MyOutput.pdf")

# Sign in to 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'] == {}:
    # The following runs StageService for ArcGIS 11 Enterprise. If you're using version
    # 10.9.1 or earlier, you must provide the staging version. For example, 
    # the staging version for 10.9.1 server is 209.   
    arcpy.server.StageService(sddraft, sd)

    # Run UploadServiceDefinition
    # Use URL to a federated server
    arcpy.server.UploadServiceDefinition(sd, serverURL)
else:
    # If the sddraft analysis contained errors, display them
    print(analyzeMessages['errors'])
CreateGPSDDraft example 2: Publish 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 sign in to your portal. In addition, set the parameter server type to ARCGIS_SERVER, and provide a server connection file (.ags) for the CreateGPSDDraft function. The server connection file parameter from the Upload Service Definition tool must also be provided with a server connection file. Ensure that the existing .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.reports.MyCustomAnalysis("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'] == {}:
    # The following runs StageService for ArcGIS 11 server. If you're using version 10.9.1 
    # or earlier, you must provide the staging version. For example, the staging 
    # version for 10.9.1 server is 209. 
    arcpy.server.StageService(sddraft, sd)

    # Run UploadServiceDefinition
    # Use URL to a federated server 
    arcpy.server.UploadServiceDefinition(sd, serverconnectionfile)
else:
    # If the sddraft analysis contained errors, display them
    print(analyzeMessages['errors'])

Rubriques connexes