多步骤有序执行

多步骤有序执行使你可以在部署无线更新时运行预安装和安装后任务。 此功能是公共预览版刷新更新清单 v4 架构的一部分。

在公共预览版刷新版本中查看以下更改之前,请参阅 更新清单 文档。

在多步骤有序执行中,有两种类型的步骤:

  • 内联步骤 (默认值)
  • 参考步骤

包含一个嵌入步骤的示例更新清单:

{
    "updateId": {...},
    "isDeployable": true,
    "compatibility": [
        {
            "deviceManufacturer": "du-device",
            "deviceModel": "e2e-test"
        }
    ],
    "instructions": {
        "steps": [
            {
                "description": "Example APT update that install libcurl4-doc on a host device.",
                "handler": "microsoft/apt:1",
                "files": [
                    "apt-manifest-1.0.json"
                ],
                "handlerProperties": {
                    "installedCriteria": "apt-update-test-1.0"
                }
            }
        ]
    },
    "manifestVersion": "4.0",
    "importedDateTime": "2021-11-16T14:54:55.8858676Z",
    "createdDateTime": "2021-11-16T14:50:47.3511877Z"
}

包含两个嵌入式步骤的示例更新清单:

{
    "updateId": {...},
    "isDeployable": true,
    "compatibility": [
        {
            "deviceManufacturer": "du-device",
            "deviceModel": "e2e-test"
        }
    ],
    "instructions": {
        "steps": [
            {
                "description": "Install libcurl4-doc on host device",
                "handler": "microsoft/apt:1",
                "files": [
                    "apt-manifest-1.0.json"
                ],
                "handlerProperties": {
                    "installedCriteria": "apt-update-test-2.2"
                }
            },
            {
                "description": "Install tree on host device",
                "handler": "microsoft/apt:1",
                "files": [
                    "apt-manifest-tree-1.0.json"
                ],
                "handlerProperties": {
                    "installedCriteria": "apt-update-test-tree-2.2"
                }
            }
        ]
    },
    "manifestVersion": "4.0",
    "importedDateTime": "2021-11-16T20:21:33.6514738Z",
    "createdDateTime": "2021-11-16T20:19:29.4019035Z"
}

包含一个引用步骤的示例更新清单:

  • 引用子更新的父更新

    {
        "updateId": {...},
        "isDeployable": true,
        "compatibility": [
            {
                "deviceManufacturer": "du-device",
                "deviceModel": "e2e-test"
            }
        ],
        "instructions": {
            "steps": [
                {
                    "type": "reference",
                    "description": "Cameras Firmware Update",
                    "updateId": {
                        "provider": "contoso",
                        "name": "virtual-camera",
                        "version": "1.2"
                    }
                }
            ]
        },
        "manifestVersion": "4.0",
        "importedDateTime": "2021-11-17T07:26:14.7484389Z",
        "createdDateTime": "2021-11-17T07:22:10.6014567Z"
    }
    
  • 包含逐步指引的子更新

    {
        "updateId": {
            "provider": "contoso",
            "name": "virtual-camera",
            "version": "1.2"
        },
        "isDeployable": false,
        "compatibility": [
            {
                "group": "cameras"
            }
        ],
        "instructions": {
            "steps": [
                {
                    "description": "Cameras Update - pre-install step",
                    "handler": "microsoft/script:1",
                    "files": [
                        "contoso-camera-installscript.sh"
                    ],
                    "handlerProperties": {
                        "scriptFileName": "contoso-camera-installscript.sh",
                        "arguments": "--pre-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path",
                        "installedCriteria": "contoso-virtual-camera-1.2-step-0"
                    }
                },
                {
                    "description": "Cameras Update - firmware installation (failure - missing file)",
                    "handler": "microsoft/script:1",
                    "files": [
                        "contoso-camera-installscript.sh",
                        "camera-firmware-1.1.json"
                    ],
                    "handlerProperties": {
                        "scriptFileName": "missing-contoso-camera-installscript.sh",
                        "arguments": "--firmware-file camera-firmware-1.1.json --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path",
                        "installedCriteria": "contoso-virtual-camera-1.2-step-1"
                    }
                },
                {
                    "description": "Cameras Update - post-install step",
                    "handler": "microsoft/script:1",
                    "files": [
                        "contoso-camera-installscript.sh"
                    ],
                    "handlerProperties": {
                        "scriptFileName": "contoso-camera-installscript.sh",
                        "arguments": "--post-install-sim-success --component-name --component-name-val --component-group --component-group-val --component-prop path --component-prop-val path",
                        "installedCriteria": "contoso-virtual-camera-1.2-stop-2"
                    }
                }
            ]
        },
        "referencedBy": [
            {
                "provider": "DU-Client-Eng",
                "name": "MSOE-Update-Demo",
                "version": "3.1"
            }
        ],
        "manifestVersion": "4.0",
        "importedDateTime": "2021-11-17T07:26:14.7376536Z",
        "createdDateTime": "2021-11-17T07:22:09.2232968Z",
        "etag": "\"ad7a553d-24a8-492b-9885-9af424d44d58\""
    }
    

注释

更新清单中,如果使用该字符串来确定是否应执行该步骤,则每个步骤都应具有不同的 installedCriteria 字符串。

父更新和子更新

当更新清单相互引用时,顶级清单称为 父更新 ,引用步骤中指定的清单称为 子更新

目前,子更新不能包含任何引用步骤。 在导入时验证此限制,如果未遵循导入,则导入将失败。

父级更新中的内联步骤

父更新中指定的内联步骤将应用于宿主设备。 在这里,传递给步骤处理程序(也称为更新内容处理程序)的ADUC_WorkflowData对象,它不包含 Selected Components 数据。 此类型的步骤的处理程序 不应 是处理程序 Component-Aware

步骤内容处理程序为每个步骤应用 IsInstalled 验证逻辑。 设备更新代理的步骤处理程序通过检查 IsInstalled() 是否导致结果代码“900”(表示“true”)来检查是否已安装特定更新。 如果已安装更新,为了避免重新安装设备上已有的更新,DU 代理将跳过后续步骤,因为我们使用它来确定是否执行步骤。

若要报告更新结果,必须将步骤处理程序执行结果写入到指定的结果文件中的 ADUC_Result 结构体,如 --result-file 选项中所指定。 然后,根据执行结果,成功时返回 0,遇到任何致命错误时返回 -1 或 0xFF。

有关详细信息,请参阅 步骤内容处理程序实现自定义组件感知内容处理程序

父更新中参考的步骤

父更新中指定的引用步骤将应用于宿主设备上或与之连接的组件。 引用步骤是包含另一个更新的更新标识符的步骤,称为子更新。

处理引用步骤时,步骤处理程序会下载引用步骤数据中指定的分离更新清单文件,然后验证文件完整性。 接下来,步骤处理程序通过合并子更新清单中的数据和父更新清单中的文件 URL 信息来创建 ADUC_Workflow 对象(也称为子工作流数据)。 此子工作流数据还具有一个名为“level”的属性,其值设置为“1”。

注释

目前,子更新不能包含任何引用步骤。

分离的更新清单

为了避免由于 IoT 中心孪生数据大小限制而导致部署失败,任何大型更新清单将以 JSON 数据文件的形式交付,也称为 分离的更新清单

如果将包含大型内容的更新导入到 IoT 中心的设备更新中,生成的更新清单将包含另一个名为 Detached Update Manifest的有效负载文件,其中包含更新清单的完整数据。

UpdateManifest设备或模块孪生中的属性将包含分离的更新清单文件信息。

处理 PnP 属性更改事件时,设备更新代理将自动下载分离的更新清单文件,并创建包含完整更新清单数据的ADUC_WorkflowData对象。