本页面使用 ISO/IEC 14977 扩展巴科斯-诺尔范式 (EBNF) 和 protobuf 指定车辆服务接口定义语言 (VSIDL)。本页面重点介绍该语言的上下文无关语法以及语言元素的含义。
在 Android 17 QPR2 及更高版本中,VSIDL 向 VsidlEntry 添加了系统图语言元素,用于以声明方式定义 APEX 打包规则、主机和虚拟机部署拓扑、生命周期编排以及健康状况和 QoS 监控。
快速参考
下表总结了 VSIDL 语言元素及其主要编译器验证代码:
| 语言元素 | 在 VSIDL 目录中的角色 | 关键编译器错误代码 |
|---|---|---|
VSIDL 条目 (VsidlEntry) |
声明目录 package、服务包和协议映射的根 textproto 容器。
|
E10B、E211 |
服务套装 (ServiceBundle) |
逻辑部署和授权单元,用于对发布者、订阅者、RPC 服务器和 RPC 客户端进行分组。 |
E100、E205–E20C、E301–E303、E308、E309
|
Publisher (Publisher) |
在一个或多个小写短划线大小写主题上发布 protobuf message,且队列 capacity ≥ 2。
|
E20D、E20F、E302、E304、E306、E308、E314、E406、E407、E504、E601
|
Subscriber (Subscriber) |
在一个或多个匹配的发布主题上订阅 protobuf message。
|
E311、E408、E504、E608
|
RPC 服务器 (Server) |
在小写短划线命名法 channel 上公开 protobuf RPC service(一元、客户端流式传输或服务器流式传输)。
|
E100、E20E、E409、E40B、E603
|
RPC 客户端 (Client) |
连接到匹配的 protobuf RPC service 和 channel。
|
E409、E60A、E60B |
build 配置 (BuildConfiguration)
|
可选:snake_case Soong target_name 替换或 skip_codegen 切换服务软件包。
|
E205 - E208,E301 |
APEX (Apex) |
系统图 APEX 打包和 ServiceBundleManifest 资源替换。
|
E10E、E113、E212、E315、E40F、E411、E412、E420、E421、E515、E613
|
主机和虚拟机(Host、Vm) |
系统图计算节点、虚拟机和服务包实例部署拓扑。 |
E213、E316–E318、E413、E614、E615
|
Orchestration (Orchestration) |
虚拟机级组转换、实例重试以及布尔值电源或车辆状态条件。 |
E10F、E110、E114–E117、E319、E414、E415、E417–E419、E41D
|
健康状况监控和 QoS (Health、QualityOfService)
|
定期实例心跳参数以及主题级 QoS 周期和延迟时间阈值。 |
E31A,E41A–E41C,E41E,E41F
|
下表按验证类别对十六进制 vsidlc 诊断代码进行了分组:
| 错误系列(十六进制) | 验证类别 | vsidlc 检查的内容 |
|---|---|---|
E1xx |
目录、构建文件和服务器警告 |
目录 Android.bp 文件组覆盖率 (E10B) 和每个 bundle 的 RPC 服务器限制 (E100)。
|
E2xx |
命名和长度规范 |
软件包长度 (E211)、PascalCase 个软件包名称 (E209–E20C)、snake_case 个目标名称 (E205–E208) 以及小写短划线分隔的主题和渠道 (E20D–E20F)。
|
E3xx |
唯一性和冲突 |
全局 bundle 名称唯一性 (E309)、build 目标唯一性 (E301)、服务单元名称唯一性 (E302–E308) 以及主题唯一性或重新声明 (E311、E314)。
|
E4xx |
必填字段和结构不变量 |
偶数发布商 capacity ≥ 2(E406、E407)、强制性订阅者 topic (E408) 和强制性唯一 RPC channel(E409、E40B)。
|
E5xx |
跨目录配对和中间件限制 |
每个订阅者都有匹配的发布者 (E504),每个客户端都有匹配的 RPC 服务器 (E503),以及不支持双向 RPC 流式传输 (E514)。
|
E6xx |
Protobuf 类型和服务存在性 |
发布者和订阅者上引用的 protobuf message 存在性(E601、E608)以及 RPC 服务器和客户端上唯一的 protobuf service 存在性(E603、E60A、E60B)。
|
语言层次结构
根据元对象设施 (MOF),VSIDL 编译器 (VSIDLC) 使用图 1 所示的语言:
图 1. VSIDLC 语言。
VSIDLC 主要基于协议缓冲区 (protobuf) 语言。Protobuf 指定使用发布-订阅和远程过程调用 (RPC) 交换的数据类型。从技术上讲,VSIDL 模型是 textproto 文件,VSIDL 语法在 protobuf 文件 (syntax.proto) 中定义。
用于指定数据类型的 protobuf 文件和 VSIDL 模型都用于生成 Rust 代码。生成的代码包含用于交换消息数据结构的结构体,以及用于创建服务单元的 Rust 函数,但不会自动调用这些服务单元。然后,自定义 Rust 代码会使用生成的代码来实例化服务单元并实现应用逻辑。
抽象语法
图 2 显示了 VSIDL 中的核心消息类型:
图 2. VSIDL 中的核心消息类型。
VSIDL 条目
本部分介绍了 VsidlEntry 消息类型。
EBNF 语法
start VsidlEntry =
"package" , ":" , String , ";" ,
{ "service_bundle" , ServiceBundle } ,
{ "apex" , Apex } ,
{ "host" , Host } ,
{ "extension" , ":" , Any } ,
{ "some_ip_mapping" , ":" , SomeIpMapping } ,
{ "vhal_mapping" , ":" , VhalMapping }
;
Proto 定义
// The root message for VSIDL files
message VsidlEntry {
// Required. Package name for entities mentioned in the file.
string package = 1;
// Deprecated, use "service_bundle" instead.
repeated ServiceBundle sdv_service_bundle = 2 [deprecated = true];
// Enables custom extensions beyond the standard VSIDL model.
repeated google.protobuf.Any extension = 3;
// SOMEIP mapping rules
repeated sdv.someip.v1.SomeIpMapping some_ip_mapping = 4;
// VHAL mapping rules
repeated VhalMapping vhal_mapping = 5;
// List of SDV service bundles defined in the file.
repeated ServiceBundle service_bundle = 6;
// List of APEXes defined in the file.
repeated Apex apex = 7;
// List of hosts defined in the file.
repeated Host host = 8;
}
用法示例
package: "com.android.sdv.sample.vsidl"
service_bundle {
name: "Manager"
publisher {
message: "TirePressure"
topic: "front-left"
topic: "front-right"
capacity: 10
}
}
说明
VsidlEntry 消息充当扩展名为 .vsidl 的 VSIDL 文件的根容器。此消息将所有定义和配置封装在单个 VSIDL 文件中。VsidlEntry 消息是绑定所有其他元素的顶级元素。
VsidlEntry 消息具有以下用途:
- 定义 VSIDL 文件的整体结构。
- 指定文件中所有实体的软件包命名空间。
- 包含一系列服务包定义。
- 定义 APEX 打包规则以及主机和虚拟机部署拓扑。
- 允许对 VSIDL 模型进行自定义扩展。
- 包含 SOME/IP 和 VHAL 的映射规则。
限制条件
- 软件包名称 (E211):软件包名称不得超过 127 个字符。
- 悬空文件 (E10B):目录中的所有文件都必须在
Android.bp文件组中引用。
服务包
本部分介绍了服务包消息类型。
EBNF 语法
ServiceBundle = "{" , { ServiceBundleElement } , "}" ;
ServiceBundleElement =
"name" , ":" , String |
"publisher" , Publisher |
"subscriber" , Subscriber |
"server" , Server |
"client" , Client |
"extension" , ":" , Any |
"diagnostics_declaration" , DiagnosticsDeclaration |
"build_cfg" , BuildConfiguration |
"register_reflection_metadata" , Boolean
;
Proto 定义
// Defines an SDV service
message ServiceBundle {
// Required. Name of the service bundle (without the package name).
string name = 1;
// List of publications the service bundle provides.
repeated Publisher publisher = 2;
// List of publications a service bundle subscribes to.
repeated Subscriber subscriber = 3;
// RPC services offered by a service bundle.
repeated Server server = 4;
// RPC services consumed by a service bundle.
repeated Client client = 5;
// Enables custom extensions beyond the standard VSIDL model.
repeated google.protobuf.Any extension = 7;
// Diagnostics declarations
sdv.diagnostics.v1.DiagnosticsDeclaration diagnostics_declaration = 8;
// Build Configuration
optional BuildConfiguration build_cfg = 9;
// Register metadata for service units provided by this service bundle.
// Setting this to true will increase the memory footprint
// and network load significantly.
bool register_reflection_metadata = 10;
}
用法示例
service_bundle {
name: "SeatController"
publisher {
message: "SeatHeating"
topic: "driver-seat"
capacity: 10
}
}
说明
服务包定义了相关服务、发布者、订阅者、RPC 服务器和 RPC 客户端的逻辑分组。服务包充当一组特定功能及其交互的容器。
限制条件
- 软件包名称要求(E209、E20A、E20B、E20C):
- 服务包必须具有已填充的名称。
- 名称必须以有效的 Unicode 标识符起始字符(通常为字母)开头。
- 名称中的后续字符必须是有效的 Unicode 标识符延续字符(通常是字母或数字)。
- 名称不得是 Rust、Java 或 C++ 中的预留关键字。
- 全局 bundle 唯一性 (E309):每个服务 bundle 都必须具有唯一的完全限定名称(基于其软件包和名称)。
- 内部唯一性(E100、E302、E303、E308):
- 在单个服务包中,每个 RPC 服务最多可由一个服务器定义提供服务。
- 在单个服务包中,所有用户定义的服务单元名称(对于发布者或服务器)都必须是唯一的。
- 在单个服务包中,所有服务单元名称(无论是用户定义的还是自动生成的)都必须是唯一的。
- 构建目标命名规范(E205、E206、E207、E208):如果提供了自定义构建目标名称 (
build_cfg.target_name),则该名称必须遵循蛇形命名法格式(小写字母、数字和单个下划线,不以下划线开头或结尾)。 - 构建目标名称唯一性 (E301):用户定义的构建目标名称不得与其他服务软件包的任何自动生成的目标名称冲突。
发布商
本部分介绍了“发布商”消息类型。
EBNF 语法
Publisher = "{" , { PublisherElement } , "}" ;
PublisherElement =
"message" , ":" , String |
"topic" , ":" , String |
"capacity" , ":" , Integer |
"service_unit_name" , ":" , String
;
Proto 定义
// Represents a publisher within a service bundle.
message Publisher {
// Name of the service unit. Name may only use characters from [a-z0-9\-]+,
// must start with [a-z], may not end with a hyphen,
// and may not contain consecutive hyphens.
string service_unit_name = 3;
// Required. The type of data being published.
string message = 4;
// Required. The number of messages a publication queue can hold.
// Must be an even number >= 2.
int64 capacity = 6;
// Required. Unique identifier for the publication topic.
// Must be in lowercase dash-case.
repeated string topic = 7;
}
用法示例
publisher {
message: "SeatHeating"
topic: "driver-heating"
capacity: 10
}
说明
Publisher 消息类型定义了 ServiceBundle 提供的数据源。此消息类型指定要发布的数据类型以及该数据的特定主题和容量。
主题
每个 Publisher 实例都有一个 message 字段,该字段引用正在发布的 proto 消息。它必须指定主题(由 topic 表示)和容量(由 capacity 表示)。
- 主题:发布主题的唯一标识符。它必须遵循小写短划线命名法(例如
my-topic)。 - 容量:指定队列的大小,即队列在舍弃未读消息之前可以容纳的消息数量。它必须是大于或等于 2 的偶数。
用户定义的名称
发布商可以设置用户定义的服务单元名称,以覆盖自动选择的服务单元名称。此功能支持选择较短的名称。如果发布者使用用户定义的服务单元名称,则发布者只能声明一个主题,以便服务单元名称映射到一个主题。
# VALID: A publisher assigns a user-defined name to a single topic
publisher {
message: "SeatHeating"
topic: "seat-heating-status"
capacity: 10
service_unit_name: "heating-is-off"
}
# ERROR: User-defined names are allowed only when declaring a single topic
publisher {
message: "SeatHeating"
topic: "driver-seat-heating-status"
topic: "passenger-seat-heating-status"
capacity: 10
service_unit_name: "heating-status"
}
限制条件
- 本地名称唯一性 (E302):在任何单个服务包中,所有发布者都必须具有唯一的用户定义服务单元名称。
- 全局名称唯一性 (E304):同一发布类型的发布者在所有服务包中必须具有全局唯一的用户定义服务单元名称。
- 为单个频道命名 (E306):用户定义的服务单元名称只能分配给声明单个主题的发布者。
- 服务单元名称唯一性 (E308):所有服务单元名称(无论是生成的还是用户定义的)在其服务包中都必须是唯一的;用户定义的名称应用于解决与生成的名称之间的冲突。
- 订阅者的发布者存在性 (E504):每个定义的订阅者都需要至少一个针对指定消息类型和主题的相应发布者。
- 有效的发布者类型 (E601):发布者必须引用与现有 protobuf 消息对应的消息类型。
- 主题命名(E20D、E20F):主题必须采用小写短划线命名法,且不得超过 127 个字符。
- 主题唯一性 (E314):主题在所有发布商中必须是全局唯一的。
- 容量要求 (E406、E407):容量为必填项,且必须是大于或等于 2 的偶数。
订阅者
本部分介绍了 Subscriber 消息类型。
EBNF 语法
Subscriber = "{" , { SubscriberElement } , "}" ;
SubscriberElement =
"message" , ":" , String |
"topic" , ":" , String
;
Proto 定义
// Represents a subscriber within a service bundle.
message Subscriber {
// Required. The type of data being subscribed to.
string message = 4;
// Required. Specific topic(s) of the message to subscribe to.
// Must match the publisher's topic.
repeated string topic = 6;
}
用法示例
subscriber {
message: "SeatHeating"
topic: "driver-seat"
}
说明
Subscriber 消息定义了 ServiceBundle 提供的发布接收器。此消息指定了要订阅的数据类型以及该发布内容的特定主题。如果一个主题有多个发布者,则订阅者会收到所有发布者发布的消息。
限制条件
- 发布者存在 (E504):对于每个定义的订阅者,必须至少存在一个发布指定消息类型和主题的相应发布者。
- 有效的订阅类型 (E608):订阅者必须引用与现有 protobuf 消息对应的消息类型。
- 主题为必填项 (E408):主题是订阅者的必填项。
- 主题重新声明 (E311):不应在同一服务包中重新声明订阅者主题。
RPC 服务器
本部分介绍了 RPC 服务器消息类型。
EBNF 语法
Server = "{" , { ServerElement } , "}" ;
ServerElement =
"service" , ":" , String |
"channel" , ":" , String |
"service_unit_name" , ":" , String
;
Proto 定义
// Represents an RPC server within a service bundle.
message Server {
// Deprecated. Name of the service unit.
string service_unit_name = 3 [ deprecated = true ];
// Required. Name of the RPC service.
string service = 4;
// Required. Name of the RPC channel.
// Must be in lowercase dash-case.
string channel = 5;
}
用法示例
server {
service: "SetTemperature"
channel: "temp-setter"
}
说明
Server 消息定义了 ServiceBundle 提供的 RPC 服务器。此消息指定服务器实现的服务和 RPC 通道。
RPC 服务器会公开一组方法,供客户端远程调用。service 字段用于指定服务器实现的 RPC 服务的名称。此服务在 proto 文件中定义,并在自定义 Rust 代码中实现。RPC 服务可以包含一元、客户端流式传输和服务器流式传输方法,如 protobuf 服务定义中所定义。channel 字段定义了通信端点,并且是必填字段 (E409)。
限制条件
- 服务定义 (E603):RPC 服务器必须指定一个与现有 protobuf RPC
service值对应的service值。 - 每个服务的服务器限制 (E100):在单个服务包中,一个特定的 RPC
service最多只能由一个服务器定义提供服务。 - 频道名称 (E20E):RPC 频道必须采用小写短划线命名法。
- 渠道为必填项 (E409):RPC 渠道为必填项。
- 通道唯一性 (E40B):RPC 通道只能由一项服务使用。
RPC 客户端
本部分介绍了 RPC 客户端消息类型。
EBNF 语法
Client = "{" , { ClientElement } , "}" ;
ClientElement =
"service" , ":" , String |
"channel" , ":" , String
;
Proto 定义
// Represents an RPC client within a service bundle.
message Client {
// Required. Name of the RPC service.
string service = 2;
// Required. Name of the RPC channel.
// Must match the server's channel and be in lowercase dash-case.
string channel = 3;
}
用法示例
client {
service: "SetTemperature"
channel: "temp-setter"
}
说明
client 定义了 ServiceBundle 使用的 RPC 客户端。client 指定客户端与之交互的服务以及要连接的通道。客户端可以与一元、客户端流式传输和服务器流式传输方法进行交互,具体取决于服务定义。
限制条件
- 服务定义 (E60A):RPC 客户端必须指定与现有 protobuf
service定义相对应的service。 - 唯一服务来源 (E60B):RPC 客户端的
service引用的 protobufservice定义必须在所有 protobuf 文件中唯一定义(不能多次定义)。 - 渠道为必填项 (E409):RPC 渠道为必填项。
构建配置
本部分介绍了 build 配置消息类型。
EBNF 语法
BuildConfiguration = "{" , BuildConfigurationElement, "}" ;
BuildConfigurationElement =
"target_name" , ":" , String |
"skip_codegen" , ":" , Boolean
;
Proto 定义
// Defines additional information used to configure build settings
message BuildConfiguration {
/// Build target name
optional string target_name = 1;
// Do not generate code for this service bundle
optional bool skip_codegen = 2;
}
用法示例
build_cfg {
target_name: "my_custom_target_name"
skip_codegen: false
}
说明
BuildConfiguration 为代码生成配置 ServiceBundle 的非标准参数。所有 build 配置都是可选的。
target_name(可选string):指定Android.bp文件中 build 目标的名称。使用此选项可设置比自动选择的名称更短的目标名称。skip_codegen(可选bool):指示是否应为此服务包跳过代码生成。如果设置为true,则不会为此特定服务包生成任何代码。这对于手动实现的服务包非常有用。默认情况下,该设置为false。
限制条件
- 目标名称格式 (E205, E206, E207, E208):如果提供了自定义 build 目标名称 (
build_cfg.target_name),则该名称必须严格遵循蛇形命名法格式:- 它只能包含小写字母(
a到z)、数字(0到9)和下划线 (_)。 - 不得包含连续的下划线 (
__)。 - 不得以下划线开头。
- 不得以下划线结尾。
- 它只能包含小写字母(
- 目标名称唯一性 (E301):用户定义的
build_cfg.target_name在整个构建系统中必须是唯一的,并且不得与从其他服务包定义派生的任何自动生成的目标名称冲突。
APEX
本部分介绍了 Apex 消息类型,该类型定义了 APEX 工件的物理属性和配置。
EBNF 语法
Apex = "{" , { ApexElement } , "}" ;
ApexElement =
"name" , ":" , String |
"prebuilt_etc" , ":" , String |
"service_bundle_manifest" , ServiceBundleManifest
;
ServiceBundleManifest = "{" , { ServiceBundleManifestElement } , "}" ;
ServiceBundleManifestElement =
"name" , ":" , String |
"service_bundle" , ":" , String |
"version_number" , ":" , Integer |
"version_name" , ":" , String |
"log_tag" , ":" , String |
"native_library" , ":" , String |
"native_library_path" , ":" , String |
"orchestration" , Resource |
"authz" , Resource |
"concal" , Resource |
"preferences" , Resource |
"health" , Resource |
"diagnostics" , Resource |
"someip" , Resource |
"vsidl_schema" , Resource |
"scheduling" , Resource |
"metadata" , Metadata
;
Resource = "{" , { ResourceElement } , "}" ;
ResourceElement =
"src" , ":" , String |
"dst" , ":" , String
;
Metadata = "{" , { MetadataElement } , "}" ;
MetadataElement =
"key" , ":" , String |
"value" , ":" , String
;
Proto 定义
// Defines a resource (local source and remote destination paths)
message Resource {
optional string src = 1;
optional string dst = 2;
}
// Defines a metadata entry (key-value pair)
message Metadata {
string key = 1;
string value = 2;
}
// Defines an APEX build rule
message Apex {
// Defines a service bundle manifest within an APEX
message ServiceBundleManifest {
string name = 1;
string service_bundle = 2;
optional int32 version_number = 3;
optional string version_name = 4;
optional string log_tag = 5;
optional string native_library_path = 6;
optional Resource orchestration = 7;
optional Resource authz = 8;
optional Resource concal = 9;
optional Resource preferences = 10;
optional Resource health = 11;
optional Resource diagnostics = 12;
optional Resource someip = 13;
optional Resource vsidl_schema = 14;
optional Resource scheduling = 15;
repeated Metadata metadata = 16;
optional string native_library = 17;
}
string name = 1;
repeated ServiceBundleManifest service_bundle_manifest = 2;
repeated string prebuilt_etc = 3;
}
用法示例
apex {
name: "tire_apex"
prebuilt_etc: "custom_calibration_table"
service_bundle_manifest {
name: "TireAnalytics"
service_bundle: "TireAnalytics"
version_number: 2
version_name: "2.7.0-beta"
log_tag: "ta-bundle"
native_library: "libtpms_service"
authz {
src: "overrides/custom_permissions.textproto"
dst: "etc/TireAnalytics/permissions.textproto"
}
metadata {
key: "domain"
value: "chassis"
}
}
}
说明
Apex 定义了如何将一个或多个服务软件包打包到 Android Pony EXpress (APEX) 工件中,并生成 Android.bp、apex_manifest.json 和 sdv_service_bundles_manifest.textproto。
name(可选string):指定 APEX 名称。如果省略,vsidlc会使用.vsidl文件的package名称作为完全限定的 APEX 名称,并将生成的文件写入generated/apex/<package>/。如果指定,vsidlc会将name范围限定在package下,因此完全限定的 APEX 名称为<package>.<name>,并将生成的文件写入generated/apex/<package>.<name>/。prebuilt_etc(重复string):列出要包含在 APEX 的prebuilts列表中的其他prebuilt_etcSoong 模块名称。service_bundle_manifest(重复ServiceBundleManifest):声明 APEX 中打包的服务软件包:service_bundle(string):对目录中ServiceBundle的必需引用。name(可选string):清单条目名称。如果省略,则默认为所引用service_bundle的非限定名称。version_number(可选int32):服务软件包的版本代码。 默认值为0。version_name(可选string):人类可读的版本字符串。默认值为"0.1 Alpha"。log_tag(可选string):服务软件包的 Logcat 标记。native_library(可选string):服务 bundle 的共享库的 Soong 目标名称。默认值为libsdv_lm_<snake_case_service_bundle_fqn>。native_library_path(可选string):APEX 内共享库的相对路径。默认值为lib64/<native_library>.so。orchestration、authz、health、diagnostics、someip、vsidl_schema(可选Resource):由vsidlc自动生成的配置资源,除非使用src(相对于目录目录)替换或使用dst(相对于 APEX 根目录)重新定位。concal、preferences、scheduling(可选Resource):指定src时,APEX 中包含的仅限手动配置资源。metadata(重复Metadata):添加到服务包清单条目的自定义key和value对。
限制条件
- APEX 中打包的服务包 (E10E):在目录中定义了至少一个
apex块时,每个服务包(除非skip_codegen为true)都应至少由一个service_bundle_manifest引用。 - 替换配置语法 (E113):
orchestration、authz或health资源块中由src引用的自定义配置文件应解析为各自架构(ServiceBundleConfig、AuthzPolicy和ServiceBundleHealthConfiguration)的有效 textproto。 - APEX 名称格式 (E212):APEX 名称(显式或派生自
package)必须不为空,仅包含小写字母(a到z)、数字(0到9)、英文句点 (.) 和下划线 (_),以小写字母(a到z)开头,以小写字母或数字(a到z、0到9)结尾,并且不包含连续的英文句点 (..)。 - APEX 唯一性 (E315):完全限定的 APEX 名称在整个目录中必须是全局唯一的。
- 每个 bundle 对应一个清单 (E40F):在同一
apex块中,一个服务 bundle 最多只能由一个service_bundle_manifest引用。 - 目标路径唯一性 (E411):资源
dst路径在apex块内不得相互冲突。 - 目标路径前缀 (E412):资源
dst路径必须以etc/开头。 - 互斥的库字段 (E420):
service_bundle_manifest不能同时定义native_library和native_library_path。 - 预构建模块命名 (E421):每个
prebuilt_etc模块名称都必须不为空,并且只能包含 ASCII 字母数字字符以及_、-、.、/、@、+和&。 - 源路径存在性 (E515):资源
src路径(相对于目录进行解析)必须存在于文件系统中。 - 有效的服务包引用 (E613):
service_bundle_manifest中的service_bundle字段必须引用现有的ServiceBundle定义。
主机和虚拟机
本部分介绍了 Host、Vm 和 ServiceBundleInstance 消息类型,这些类型定义了系统拓扑和运行时架构。
EBNF 语法
Host = "{" , { HostElement } , "}" ;
HostElement =
"name" , ":" , String |
"vm" , Vm
;
Vm = "{" , { VmElement } , "}" ;
VmElement =
"name" , ":" , String |
"orchestration" , Orchestration |
( "service_bundle_instance" | "instance" ) , ServiceBundleInstance
;
ServiceBundleInstance = "{" , { ServiceBundleInstanceElement } , "}" ;
ServiceBundleInstanceElement =
"name" , ":" , String |
"service_bundle_manifest" , ":" , String |
"group" , ":" , String |
"orchestration" , InstanceOrchestration |
"health" , Health |
"qos" , QualityOfService
;
Proto 定义
// Defines a host machine
message Host {
// Defines a virtual machine
message Vm {
// Defines an instance of a service bundle
message ServiceBundleInstance {
string service_bundle_manifest = 1;
repeated string name = 2;
repeated string group = 3;
optional InstanceOrchestration orchestration = 4;
optional Health health = 5;
repeated QualityOfService qos = 6;
}
string name = 1;
optional Orchestration orchestration = 2;
repeated ServiceBundleInstance service_bundle_instance = 3;
}
string name = 1;
repeated Vm vm = 2;
}
用法示例
host {
name: "TireMonitoringSystem"
vm {
name: "ZoneController"
instance {
name: "instance-front"
name: "instance-rear"
service_bundle_manifest: "TireAnalytics"
group: "auto_start"
}
}
}
说明
Host、Vm 和 ServiceBundleInstance 定义了打包的服务包在运行时如何在主机和虚拟机之间实例化:
Host.name(string):主机的全局唯一标识符。Host.vm(重复Vm次):在主机上运行的虚拟机。Vm.name(string):虚拟机的标识符,在其封闭的Host中是唯一的。Vm.orchestration(可选Orchestration):虚拟机级编排组和状态转换。Vm.service_bundle_instance或instance(重复的ServiceBundleInstance):在虚拟机上声明服务包清单的一个或多个正在运行的实例:name(重复string):一个或多个小写短划线大小写实例名称。在单个块中指定多个name条目时,所有列出的实例都会共享该块的清单、组、编排、运行状况和 QoS 设置。service_bundle_manifest(string):对apex块中定义的ServiceBundleManifest的引用。group(重复string):实例所属的虚拟机级编排组(在同一虚拟机中)的名称。orchestration(可选InstanceOrchestration):实例级编排规则和重试。health(可选Health):定期心跳监测参数。qos(重复QualityOfService):主题级服务质量监控阈值。
限制条件
- 实例名称格式 (E213):服务包实例名称必须遵循小写短划线格式:必须以小写字母(
a到z)开头,只能包含小写字母(a到z)、数字(0到9)和连字符 (-),并且不得包含连续 (--) 或尾随连字符。 - 主机唯一性 (E316):主机名在整个目录中必须是全局唯一的。
- 虚拟机唯一性 (E317):虚拟机名称在每个
host中必须是唯一的。 - 实例唯一性 (E318):对于每个虚拟机、APEX 和服务包组合,服务包实例名称必须是唯一的。
- 同一虚拟机中的组 (E413):服务包实例引用的每个编排组都必须在同一虚拟机中定义。
- 群组存在性 (E614):实例的
group字段中引用的每个编排群组都必须存在。 - 有效的清单引用 (E615):服务 bundle 实例中的
service_bundle_manifest字段必须引用现有的ServiceBundleManifest。
编排
本部分介绍了 Orchestration 和 InstanceOrchestration 消息类型,它们会根据车辆电源状态和车辆状态配置虚拟机级和实例级生命周期行为。
EBNF 语法
Orchestration = "{" , { OrchestrationElement } , "}" ;
OrchestrationElement =
"group" , OrchestrationGroup |
"state" , OrchestrationState
;
OrchestrationGroup = "{" , { OrchestrationGroupElement } , "}" ;
OrchestrationGroupElement =
"name" , ":" , String |
"subgroup" , ":" , String |
"subgroup_of" , ":" , String
;
OrchestrationState = "{" , { OrchestrationStateElement } , "}" ;
OrchestrationStateElement =
"condition" , ":" , Condition |
"groups_states" , GroupsStates
;
GroupsStates = "{" , { GroupsStatesElement } , "}" ;
GroupsStatesElement =
"create" , ":" , String |
"start" , ":" , String |
"destroy" , ":" , String
;
InstanceOrchestration = "{" , { InstanceOrchestrationElement } , "}" ;
InstanceOrchestrationElement =
"retries" , ":" , Integer |
"state" , InstanceOrchestrationState
;
InstanceOrchestrationState = "{" , { InstanceOrchestrationStateElement } , "}" ;
InstanceOrchestrationStateElement =
"condition" , ":" , Condition |
"instances_states" , InstancesStates
;
InstancesStates = "{" , { InstancesStatesElement } , "}" ;
InstancesStatesElement =
"create" , ":" , String |
"start" , ":" , String |
"destroy" , ":" , String
;
Condition = OrExpr ;
OrExpr = AndExpr , { "||" , AndExpr } ;
AndExpr = PrimaryExpr , { "&&" , PrimaryExpr } ;
PrimaryExpr = [ "!" ] , ( "(" , Condition , ")" | Identifier ) ;
Proto 定义
// Inside Host.Vm:
message InstancesStates {
repeated string destroy = 1;
repeated string start = 2;
repeated string create = 3;
}
message GroupsStates {
repeated string destroy = 1;
repeated string start = 2;
repeated string create = 3;
}
// Defines VM-level orchestration configuration
message Orchestration {
message OrchestrationGroup {
string name = 1;
repeated string subgroup = 2 [deprecated = true];
repeated string subgroup_of = 3;
}
message OrchestrationState {
optional string condition = 1;
GroupsStates groups_states = 2;
}
repeated OrchestrationGroup group = 1;
repeated OrchestrationState state = 2;
}
// Inside Host.Vm.ServiceBundleInstance:
// Defines instance-level orchestration configuration
message InstanceOrchestration {
message OrchestrationState {
optional string condition = 1;
InstancesStates instances_states = 2;
}
repeated OrchestrationState state = 1;
optional int32 retries = 2;
}
用法示例
vm {
name: "ZoneController"
orchestration {
group {
name: "auto_start"
}
group {
name: "driving_services"
subgroup_of: "auto_start"
}
state {
condition: "ON || POWER_OFF_EXIT || SUSPEND_TO_RAM_EXIT"
groups_states {
start: "auto_start"
}
}
}
instance {
name: "instance-main"
service_bundle_manifest: "TireAnalytics"
group: "driving_services"
orchestration {
retries: 2
state {
condition: "LOW_POWER && !PARK"
instances_states {
destroy: "instance-main"
}
}
}
}
}
说明
Orchestration(在虚拟机级别)和 InstanceOrchestration(在实例级别)会生成虚拟机编排器配置 (vm_<snake_case_vm_name>_orch_config.textproto) 和每个软件包的编排器配置 (orchestrator.textproto):
Orchestration.group(重复OrchestrationGroup):在虚拟机中定义命名的编排组。一个组可以声明subgroup_of(或父级组中已弃用的subgroup字段),以从同一虚拟机中的一个或多个父级组继承生命周期转换。Orchestration.state(重复OrchestrationState):将布尔值condition表达式映射到虚拟机中群组的groups_states操作(create、start、destroy)。InstanceOrchestration.retries(可选int32):Orchestrator 尝试重启失败实例的次数。如果未定义,则默认为 syspropro.boot.sdv.orchestrator.recovery.max_retries或0的值。InstanceOrchestration.state(重复OrchestrationState):将布尔值condition表达式映射到在同一instance块中声明的实例的instances_states操作(create、start、destroy)。
限制条件
- 非空实例状态 (E10F):
instances_states块应在create、start或destroy中至少指定一个实例。 - 非空组状态 (E110):
groups_states块应在create、start或destroy中至少指定一个组。 - 实例编排或群组成员资格 (E114):每个服务包实例都应至少属于一个群组,或定义一个显式
orchestration块,以便可以启动。 - 实例已启动 (E115):配置了编排的服务包实例应在其自己的
orchestration块中或通过其某个组或超组进行start转换。 - 非空编排组 (E116):每个编排组都应至少包含一个服务包实例或子组。
- 条件状态拼写错误 (E117):
condition表达式中的状态标识符如果与标准 VPM 电源或车辆状态名称非常相似,则会触发拼写错误警告。 - 组唯一性 (E319):编排组名称在每个虚拟机中必须是唯一的。
- 无组循环 (E414):编排组
subgroup和subgroup_of关系不得包含循环依赖项。 - 非负重试次数 (E415):
retries必须大于或等于0。 - 括号成对 (E417):Orchestration
condition表达式必须使用有效且成对的括号序列。 - 有效的实例状态引用 (E418):
instances_states(create、start或destroy)中的每个条目都必须引用在同一instance(service_bundle_instance) 块中声明的实例。 - 有效的组状态引用 (E419):
groups_states(create、start或destroy)中的每个条目都必须引用在同一虚拟机中定义的编排组。 - 有效的条件语法 (E41D):编排
condition表达式必须是语法有效的布尔表达式。
健康监测和 QoS
本部分介绍了 Health 和 QualityOfService 消息类型,它们用于在服务包实例上配置定期心跳监控和主题级服务质量 (QoS) 跟踪。
EBNF 语法
Health = "{" , { HealthElement } , "}" ;
HealthElement =
"initial_delay_ms" , ":" , Integer |
"period_ms" , ":" , Integer |
"num_periods" , ":" , Integer |
"task_duration_ms" , ":" , Integer
;
QualityOfService = "{" , { QualityOfServiceElement } , "}" ;
QualityOfServiceElement =
"topic" , ":" , String |
"config" , QualityOfServiceConfig
;
QualityOfServiceConfig = "{" , { QualityOfServiceConfigElement } , "}" ;
QualityOfServiceConfigElement =
"qos_period_threshold_ms" , ":" , Integer |
"qos_latency_threshold_ms" , ":" , Integer
;
Proto 定义
// Inside Host.Vm.ServiceBundleInstance:
// Defines health monitoring configuration
message Health {
uint64 initial_delay_ms = 1;
uint64 period_ms = 2;
uint64 num_periods = 3;
uint64 task_duration_ms = 4;
}
// Defines Quality of Service configuration
message QualityOfService {
message QualityOfServiceConfig {
optional uint64 qos_period_threshold_ms = 1;
optional uint64 qos_latency_threshold_ms = 2;
}
string topic = 1;
QualityOfServiceConfig config = 2;
}
用法示例
instance {
name: "instance-main"
service_bundle_manifest: "TireAnalytics"
group: "auto_start"
health {
initial_delay_ms: 20
period_ms: 200
num_periods: 4
task_duration_ms: 500
}
qos {
topic: "pressure"
config {
qos_period_threshold_ms: 100
qos_latency_threshold_ms: 50
}
}
}
说明
Health 和 QualityOfService 在为服务包实例生成的 health.textproto 文件 (ServiceBundleHealthConfiguration) 中配置运行时监控:
Health:配置健康监测器的定期心跳监测:initial_delay_ms(uint64):实例启动(STARTED状态)到首次报告心跳之间的最长时间(以毫秒为单位)。period_ms(uint64):连续心跳之间的预期时间间隔(以毫秒为单位)。num_periods(uint64):在健康监控器将实例视为健康状况不佳之前,可以错过的心跳报告期数。task_duration_ms(uint64):服务包执行的定期业务逻辑任务的时长(以毫秒为单位)。
QualityOfService:为特定发布主题配置 QoS 监控:topic(string):要监控的已发布主题的名称。config.qos_period_threshold_ms(可选uint64):主题上连续 QoS 心跳之间的最大允许间隔(以毫秒为单位)。config.qos_latency_threshold_ms(可选uint64):数据发布和数据处理时间戳之间允许的最大间隔(以毫秒为单位)。
限制条件
- QoS 主题不重复 (E31A):实例中的每个
qos块都必须指定一个不重复的topic。 - 正向心跳周期 (E41A):
health块中的period_ms必须大于0。 - 正数个周期 (E41B):
health块中的num_periods必须大于0。 - 强制性 QoS 阈值 (E41C):每个
qos块都必须包含一个config块,该块至少指定一个阈值(qos_period_threshold_ms或qos_latency_threshold_ms)。 - QoS 主题发布者存在 (E41E):与实例
关联的服务包必须声明一个
publisher,该在每个qos块中指定的topic上发布。 - 心跳发布者存在 (E41F):如果实例定义了
health块,则其关联的服务包必须声明引用com.android.sdv.health.ServiceHeartbeat消息的publisher。