CreateGPSDDraft

サマリー

Converts Result objects and result files (.rlt) to a Service Definition Draft file (.sddraft).

注意:

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

説明

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 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 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.

The Service Definition Draft must be converted to a fully consolidated Service Definition file (.sd) 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 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 and copies it to the server, extracts required information, and publishes the GIS resource. For more information, see An overview of the Publishing toolset.

注意:

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

構文

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})
パラメーター説明データ タイプ
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.analysis.Buffer("inPts", "output.shp", "100 Meters")
result2 = arcpy.management.GetCount("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 file (.sddraft).

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.

String
server_type

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

注意:

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

  • ARCGIS_SERVERThe ArcGIS Server server type.
  • FROM_CONNECTION_FILEGets the server_type value as specified by the connection_file_path parameter.
  • MY_HOSTED_SERVICESCreates an .sddraft file to be published to the current portal.

(デフォルト値は次のとおりです 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 the data referenced in the result parameter will be copied to the server. The copy_data_to_server parameter is only used if the server_type value is ARCGIS_SERVER and the connection_file_path value isn't specified. If the connection_file_path value is specified, the server's registered data stores are 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.

(デフォルト値は次のとおりです False)

Boolean
folder_name

A string that represents 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.

(デフォルト値は次のとおりです 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.

(デフォルト値は次のとおりです 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.

(デフォルト値は次のとおりです None)

String
executionType

同期と非同期は、クライアント (タスクを使用するアプリケーション) がどのようにサーバーとやり取りし、タスクから結果を取得するかを定義するものです。サービスが同期に設定されている場合、クライアントはタスクが終了するまで待ちます。同期タスクは実行所要時間が短く、5 秒以下が一般的です。非同期タスクは一般的に実行時間が長いため、クライアントはサーバーに対してタスクが終了したかどうかを定期的に問い合わせて、終了したら結果を得る必要があります。非同期タスクを使用する Web アプリケーションには、タスクのステータスを検査して実行終了後に結果を処理するロジックを実装する必要があります。ArcGIS Desktop クライアントは、どちらの実行タイプもネイティブに処理します。

(デフォルト値は次のとおりです 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 the 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 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, precreate the layer files with symbology and use them to modify the output symbology of the task.

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

(デフォルト値は次のとおりです False)

Boolean
showMessages

A string specifying the message level 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 execution succeeded or failed.
  • 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 execution will be returned to the client.

(デフォルト値は次のとおりです None)

String
maximumRecords

サーバーがクライアントに返すことのできる結果の最大数です。この値を大きな数字に設定すると、GIS サーバーで数多くの個別レコードまたはフィーチャをクライアントに返す処理をすることができます。フィーチャをまったく返さないようにするには、この値を 0 に設定します。通常、この値を 0 に設定するのは、[マップ サービスに結果を表示] を有効にした場合のみです。

(デフォルト値は次のとおりです 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 can increase this value.

(デフォルト値は次のとおりです 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 can increase this value. Ensure that the server has adequate hardware to support the maximum number of instances you indicate.

(デフォルト値は次のとおりです 2)

Integer
maxUsageTime

インスタンスを使用できる秒単位の最大時間です。実行時間の長いジオプロセシング タスクでは、場合によっては、デフォルトの 600 秒 (10 分) を長くする必要があります。また、クライアントがインスタンスを濫用しないように、このタイムアウト時間を短くする必要がある場合もあります。

(デフォルト値は次のとおりです 600)

Integer
maxWaitTime

クライアントがインスタンスへの接続を待つ秒単位の最大時間です。すべてのインスタンスがリクエストの処理に使用されている場合、以降のリクエストはキューに配置されます。インスタンスを取得する前にタイムアウトが経過すると、タスクは失敗します。デフォルト値は 60 秒 (1 分) です。

(デフォルト値は次のとおりです 60)

Integer
maxIdleTime

プールが縮小するまでインスタンスがアクティブであり続ける秒単位の最大時間です。使用されていないインスタンスが実行を継続できる最大時間が経過すると、インスタンスの最小数より多い、使用されなかったインスタンスは停止します。

(デフォルト値は次のとおりです 1800)

Integer
capabilities

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

(デフォルト値は次のとおりです 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"].

(デフォルト値は次のとおりです None)

String
choicelists

The supported choice values for a string parameter using the service task name parameter and the list of the string values, for example, {"ServiceTaskName.parameterName":["string1", "string2"]}.

(デフォルト値は次のとおりです None)

Dictionary
戻り値
データ タイプ説明
Dictionary

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

コードのサンプル

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, sign in to your portal to proceed. Then use the CreateGPSDDraft function 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 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 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 is to run StageService for ArcGIS 11 Enterprise. If it is 
    # 10.9.1 server or older, need to provide staging version. For instance, 
    # 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: 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 sign in to your portal. In addition, the parameter server type should be set to ARCGIS_SERVER, and a server connection file (.ags) must be provided for the CreateGPSDDraft function. The server connection file of 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 is to run StageService for ArcGIS 11 server. If it is 10.9.1 
    # server or older, need to provide 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'])

関連トピック