CreateGPSDDraft

摘要

Result 对象和结果文件 (.rlt) 转换为服务定义草稿文件 (.sddraft)。

注:

草稿服务定义不包含数据。 草稿服务不能单独用于发布服务。

说明

CreateGPSDDraft 是使用 ArcPy 将地理处理结果自动发布到 GIS 服务器的第一步。 通过 CreateGPSDDraft 创建的输出是服务定义草稿文件 (.sddraft)。 服务定义草稿由结果文件或 Result 对象、服务器信息和一组服务属性组成。 通过设置用于执行工具的变量,可在 Python 脚本中创建 Result 对象。 例如,以下缓冲结果保存至名为 result 的变量中:

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

服务器信息包括服务器连接或者要接受发布内容的服务器类型,待发布的服务类型,服务的元数据(项目信息)和数据参考(是否向服务器复制数据)。

此函数会返回字典,其中包含应在创建服务定义文件之前解决的错误、警告和消息。

必须使用过渡服务工具将服务定义草稿转换为完全合并的服务定义文件 (.sd)。 过渡过程会编译成功发布 GIS 资源所需的所有必要信息。 如果未将数据注册到服务器,将在过渡服务定义草稿时添加这些数据。 可以使用上传服务定义工具上传服务定义文件并将其作为 GIS 服务发布到指定 GIS 服务器。 此步骤将获取服务定义文件,并将其复制到服务器,提取所需信息并发布 GIS 资源。 有关详细信息,请参阅发布工具集概述

注:

如果发布到 ArcGIS EnterpriseArcGIS 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,...]

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(零)。通常情况下,只有当您启用通过地图服务查看结果时才将此值设为零。

(默认值为 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

返回由信息性消息、警告和错误组成的字典。

代码示例

CreateGPSDDraft 示例 1:发布到联合服务器

以下脚本演示了将 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 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 示例 2:发布到独立服务器

以下脚本演示了将地理处理服务发布到独立服务器的完整过程。 此工作流与发布到联合服务器类似,但您无需登录到门户。 此外,参数服务器类型应设置为 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 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'])

相关主题