微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用RegistryManager.ApplyConfigurationContentOnDeviceAsync进行部署-格式错误的内容

如何解决使用RegistryManager.ApplyConfigurationContentOnDeviceAsync进行部署-格式错误的内容

我正在构建一个工具,该工具可用于基于CMDB中的配置集或属性将模块部署到IoTEdge。

该工具能够生成部署清单,并且正在使用.NET SDK-特别是-RegistryManager.ApplyConfigurationContentOnDeviceAsync来应用部署。

ConfigurationContent中的序列化字符串如下。应用此模板后,SDK中没有错误,但是在Edge的门户中,其状态显示为400-部署配置格式错误或无效。

使用VSCode中的“单设备”部署来应用时,相同的模板(只是ModulesContent)可以正常工作。因此,不确定是什么原因导致模板部署无法通过RegistryManager失败。无法找出模板中格式错误内容。感谢任何指导。

{
  "ModulesContent": {
    "$edgeAgent": {
      "properties.desired": {
        "schemaVersion": "1.0","runtime": {
          "type": "docker","settings": {
            "minDockerVersion": "v1.25","loggingOptions": "","registryCredentials": {
              "paddycontainers": {
                "username": "XXXXXXcontainers","password": "EdgeHUBT9QuW=x2v3Z37jAZUREIOTg11uoT9Y","address": "XXXXXXcontainers.azurecr.io"
              }
            }
          }
        },"systemModules": {
          "edgeAgent": {
            "type": "docker","settings": {
              "image": "mcr.microsoft.com/azureiotedge-agent:1.0.9.2","createOptions": "{}"
            }
          },"edgeHub": {
            "type": "docker","status": "running","restartPolicy": "always","settings": {
              "image": "mcr.microsoft.com/azureiotedge-hub:1.0.9.2","createOptions": "{\"HostConfig\":{\"ExposedPorts\":{\"9600/tcp\":{},\"5671/tcp\":{},\"8883/tcp\":{}}}}"
            },"env": {
              "experimentalfeatures__enabled": {
                "value": true
              },"experimentalfeatures__enableMetrics": {
                "value": true
              }
            }
          }
        },"modules": {
          "PySendModule1": {
            "version": "1.0","type": "docker","settings": {
              "image": "paddycontainers.azurecr.io/pysendmodule:0.0.1-amd64.debug"
            }
          },"PySendModule2": {
            "version": "1.0","PySendModule3": {
            "version": "1.0","PySendModule4": {
            "version": "1.0","PySendModule5": {
            "version": "1.0","PySendModule6": {
            "version": "1.0","SimulatedTemperatureSensor1": {
            "version": "1.0","settings": {
              "image": "mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.0","metricscollector1": {
            "version": "1.0","settings": {
              "image": "veyalla/metricscollector:0.0.4-amd64","createOptions": "{}"
            },"env": {
              "AzMonWorkspaceId": {
                "value": "81nsaux72-0fec-8818-a258-71hshs7jas9"
              },"AzMonWorkspaceKey": {
                "value": "81jsajswkjsdkahialkasdmacjklaja=="
              }
            }
          }
        }
      }
    },"$edgeHub": {
      "properties.desired": {
        "schemaVersion": "1.0","routes": {},"storeAndForwardConfiguration": {
          "timetoLiveSecs": 7200
        }
      }
    },"PySendModule1": {
      "properties.desired": {
        "camera360": "172.1.1.1","fontSize": "10","message": 300,"format": "Json","target": "AzureLogAnalytics","endpoints": {
          "edgeHub": "http://edgeHub:9600/metrics"
        }
      }
    },"PySendModule2": {
      "properties.desired": {
        "camera360": "172.1.1.2","PySendModule3": {
      "properties.desired": {
        "camera360": "172.1.1.3","PySendModule4": {
      "properties.desired": {
        "camera360": "172.1.1.4","PySendModule5": {
      "properties.desired": {
        "camera360": "172.1.1.5","PySendModule6": {
      "properties.desired": {
        "camera360": "172.1.1.6","endpoints": {
          "edgeHub": "http://edgeHub:9600/metrics"
        }
      }
    }
  },"DeviceContent": null
}

解决方法

我不完全知道区别以及为什么会起作用。我有一个可以成功部署的工具版本。我正在使用Newtonsoft进行JSON解析。我已经在CSharp SDK中切换到System.Text.Json,这似乎已将JSON分解为格式错误的状态。我切换回Newtonsoft,部署很好。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。