摘要
将 Result 对象和结果文件 (.rlt) 转换为服务定义草稿文件 (.sddraft)。
注:
草稿服务定义不包含数据。 草稿服务不能单独用于发布服务。
说明
CreateGPSDDraft 是使用 ArcPy 将地理处理结果自动发布到 GIS 服务器的第一步。 通过 CreateGPSDDraft 创建的输出是服务定义草稿文件 (.sddraft)。 服务定义草稿由结果文件或 Result 对象、服务器信息和一组服务属性组成。 通过设置变量并运行工具,可在 Python 脚本中创建 Result 对象。 例如,以下缓冲结果保存至名为 result 的变量中:
import arcpy
result = arcpy.Buffer_analysis("inPts", "output.shp", "100 Meters")
服务器信息包括服务器连接或者要接受发布内容的服务器类型,待发布的服务类型,服务的元数据(项目信息)和数据参考(是否向服务器复制数据)。
此函数会返回字典,其中包含应在创建服务定义文件 (.sd) 之前解决的错误、警告和消息。
必须使用过渡服务工具将服务定义草稿转换为完全合并的 .sd 文件。 过渡过程会编译成功发布 GIS 资源所需的所有必要信息。 如果未将数据注册到服务器,将在过渡服务定义草稿时添加这些数据。 可以使用上传服务定义工具上传 .sd 文件并将其作为 GIS 服务发布到指定 GIS 服务器。 此步骤会将 .sd 文件复制到服务器,提取所需信息并发布 GIS 资源。 有关详细信息,请参阅发布工具集概述。
注:
如果发布到 ArcGIS Enterprise 或 ArcGIS Server 10.9.1 或较早版本,在使用过渡服务工具时需设置过渡版本号。 要获取服务器编号的列表,请参阅工具中的过渡版本参数。
语法
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,...] | 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:
| 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. 注:MY_HOSTED_SERVICES is only available when creating .sddraft files from ArcGIS Pro.
(默认值为 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.
(默认值为 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. (默认值为 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. (默认值为 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. (默认值为 None) | String |
executionType | 同步和异步定义了客户端(使用任务的应用程序)如何与服务器进行交互以及如何获取任务结果。服务设置为同步时,客户端将等待任务完成。通常,同步任务的执行速度很快,大概需要 5 秒或更短。异步任务的执行往往花费的时间较长,客户端必须定期向服务器发出询问以确定任务是否已完成,如果完成,则获取结果。使用异步任务的 Web 应用程序必须添加函数逻辑来检查任务状态,并在执行完毕后处理结果。ArcGIS Desktop 客户端可以处理这两种执行类型。 (默认值为 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. (默认值为 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:
(默认值为 None) | String |
maximumRecords | 服务可返回给客户端的最大结果数。将此值设成一个较大数值意味着您的 GIS 服务器可处理发送大量的个人记录或要素给客户端。如果您不希望返回任何要素,请将此值设为 0(零)。通常情况下,只有当您启用通过地图服务查看结果时才将此值设为零。 (默认值为 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. (默认值为 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. (默认值为 2) | Integer |
maxUsageTime | 一个服务能被使用的最长时间,以秒为单位。您可能需要延长默认值 600 秒(10分钟),以服务于长时间运行的地理处理任务。或者,您可能需要减少此时间,以确保客户端不会滥用您的服务。 (默认值为 600) | Integer |
maxWaitTime | 超时之前客户端连接一个实例需要等待的最长时间(以秒计)。当所有实例都忙于处理请求时,随后的请求将进入排队状态。如果在实例可被使用之前超时,任务会失败。默认值为 60 秒(1 分钟)。 (默认值为 60) | Integer |
maxIdleTime | 池收缩之前一个实例能继续保持活跃的最长时间(以秒计)。对于所有超出最小实例数且未被使用的实例,一旦达到最长空闲时间,即会被关闭。 (默认值为 1800) | Integer |
capabilities | Specifies the capabilities a service will 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 | 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"]}. (默认值为 None) | Dictionary |
数据类型 | 说明 |
Dictionary | 返回由信息性消息、警告和错误组成的字典。 |
代码示例
以下脚本演示了将 web 工具发布到联合服务器的完整过程。 Web 工具的自动发布使用 ArcPy 函数和发布工具集中的地理处理工具。 工作流首先运行要发布的地理处理任务。 成功运行地理处理任务后,请登录门户以继续。 然后使用 CreateGPSDDraft 函数创建服务定义草稿。 使用摘要和标签参数会覆盖输入地理处理结果的“项目描述”、“摘要”和“标签”。 该函数会返回一个分析程序字典,用于识别可能阻止成功发布的问题。 解决所有严重问题后,即可过渡服务定义。 过渡操作获取服务定义草稿并将发布服务所需的所有信息合并到完整的服务定义中。 使用过渡服务工具过渡服务定义。 最后,使用上传服务定义工具将服务定义上传到门户并发布 Web 工具。
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'])
以下脚本演示了将地理处理服务发布到独立服务器的完整过程。 此工作流与发布到联合服务器类似,但您无需登录到门户。 此外,将参数服务器类型设置为 ARCGIS_SERVER,且为 CreateGPSDDraft 函数提供服务器连接文件 (.ags)。 上传服务定义工具的服务器连接文件参数还必须提供服务器连接文件。 确保现有 .ags 文件具有服务器登录凭据。
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'])