CreateGPSDDraft (arcpy)

サマリ

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

注意注意:

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 the 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 gets saved to a variable called result:

result = arcpy.Buffer_analysis("inPts", "output.shp", "100 Meters")
Result files can be created by right clicking a result in the Results window and choosing Save As.

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

Service properties include geoprocessing and additional capabilities of the service such as Web Processing Services (WPS). The capabilities are not exposed as a parameter. If you need to modify the value (or any nonexposed parameter), you need to publish the sddraft first and modify the draft by editing the .sddraft using XML libraries such as xml.dom.minidom. Please refer to the example of modifying an sddraft for the usage of the library. Although the example is from a map service draft, you can use the same library and method for the GP service draft since it is an XML file.

The function returns a Python dictionary containing errors and other potential issues that you should address prior to creating your Service Definition file.

A Service Definition Draft can be authored without knowing the specific server connection information. In this case, the connection_file_path parameter may be omitted; however, the server_type must be provided. A server connection can be provided later when the Service Definition Draft is published using the Upload Service Definition tool.

The Service Definition Draft can then 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 the An overview of the Publishing toolset.

構文

CreateGPSDDraft (result, output 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})
パラメータ説明データ タイプ
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.

r1 = arcpy.Buffer_analysis("inPts", "output.shp", "100 Meters")
r2 = arcpy.GetCount_management("FireStations")
arcpy.CreateGPSDDraft([r1, r2], "output.sddraft", "myservice")
Result
output 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, then a server_type must be provided. If a connection_file_path parameter is supplied, then the server_type is taken from the connection file. In this case, you can choose FROM_CONNECTION_FILE or skip the parameter entirely.

  • ARCGIS_SERVERArcGIS for Server server type
  • FROM_CONNECTION_FILEGet the server_type as specified in the connection_file_path parameter

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

String
connection_file_path

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

String
copy_data_to_server

A Boolean that indicates whether the data referenced in the result will be copied to the server or not. 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, then the server's registered data stores are used. For example, if the data in the result is registered with the server, then copy_data_to_server will always be False. Conversely, if the data in the result is not registered with the server, then copy_data_to_server will always be True.

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

(デフォルト値は次のとおりです 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 your task). The map is created on the server using a Map Service for transport back to the client as an image (a .jpeg, 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 ArcMap), 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.

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

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

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

Integer
maxUsageTime

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

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

Integer
maxWaitTime

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

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

Integer
maxIdleTime

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

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

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

Returns a Python Dictionary of information messages, warnings, and errors.

コードのサンプル

CreateGPSDDraft example 1

The following script demonstrates the complete publishing of a geoprocessing service through Python scripting. Automating the publishing of geoprocessing services 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, and have saved a result file, 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. Next, you should analyze the service definition draft for issues that could prevent you from publishing successfully by using the AnalyzeForSD function. After analyzing the service definition draft and addressing serious issues, it is time to stage the service definition. 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 geoprocessing tool to stage the service definition. Finally, use the Upload_Service_Definition geoprocessing tool to upload the service definition to the server and publish the geoprocessing service.

import arcpy

result = "c:/gis/gp/Analysis.rlt"
connectionPath = "c:/gis/conections/myServer.ags"
sddraft = "c:/gis/gp/drafts/AnalysisDraft.sddraft"
sd = "c:/gis/gp/sd/AnalysisDraft.sd"
serviceName = "AnalysisService"

# create service definition draft
arcpy.CreateGPSDDraft(
    result, sddraft, serviceName, server_type="ARCGIS_SERVER",
    connection_file_path=connectionPath, 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)

# analyze the service definition draft
analyzeMessages = arcpy.mapping.AnalyzeForSD(sddraft)

# 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
    arcpy.UploadServiceDefinition_server(sd, connectionPath)
else: 
    # if the sddraft analysis contained errors, display them
    print analysis['errors']
CreateGPSDDraft example 2

This example demonstrates the creation and publishing of the extract data workflow and ensures the data is registered with the server. The Extract Data task takes input layers and allows the user to extract an area of interest, convert to another output type and receive a zip file back as output. The Extract Data tool only uses layers as input. This example creates multiple layers using the Make Feature Layer tool, runs the tool, creates a service definition draft and uploads the service definition to be used in service creation. Any layer that was created in the Python session of the workflow will be considered as possible input in the final service and available as a choice selection.

import arcpy
import os

connPath = "c:/gis/conections/myServer.ags"
sddraft = "c:/gis/gp/drafts/ExtractionDraft.sddraft"
sd = "c:/gis/gp/sd/AnalysisDraft.sd"
serviceName = "DataExtractor"
arcpy.env.workspace = "c:/gis/citydata"

# create layers which will be available as input
arcpy.MakeFeatureLayer_management('Wiarton.gdb/places/Cityhall', 'CityHall')
arcpy.MakeFeatureLayer_management('Wiarton.gdb/places/Airport', 'Airport')
arcpy.MakeFeatureLayer_management('Wiarton.gdb/places/FireStations', 'FireStations')

# run the extract data task and assign it to the 'result' variable
# only the cityhall layer was used as input, but the airport and firestation layers will be used in the service creation
aoi = "c:/gis/citydata/extract.shp"
result = arcpy.ExtractDataTask_server("CityHall", aoi, "File Geodatabase - GDB - .gdb", "ESRI GRID - GRID", os.path.join(arcpy.env.scratchFolder, "output.zip"))

# make sure the folder is registered with the server, if not, add it to the datastore
if arcpy.env.workspace not in [i[2] for i in arcpy.ListDataStoreItems(connPath, 'FOLDER')]:
     # both the client and server paths are the same
     dsStatus = arcpy.AddDataStoreItem(connPath, "FOLDER", "CityData", arcpy.env.workspace, arcpy.env.workspace)
     print "Data store : " + str(dsStatus)


# create service definition draft
arcpy.CreateGPSDDraft(
    result, sddraft, serviceName, server_type="ARCGIS_SERVER",
    connection_file_path=connPath, copy_data_to_server=False, 
    folder_name=None, summary="Extraction Service", tags="extract data, clip")
   

# analyze the service definition draft
analyzeMessages = arcpy.mapping.AnalyzeForSD(sddraft)

# 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
    upStatus = arcpy.UploadServiceDefinition_server(sd, connPath)
    print "Completed upload"
else: 
    # if the sddraft analysis contained errors, display them
    print analysis['errors']

関連トピック

9/14/2013