void PopulateModuleConfig(Corev1ConfigMapList configMapList, string moduleName, EdgeModule module)
        {
            // see if there is an entry for this module in the config maps
            Corev1ConfigMap configMap = configMapList.Items.Where(cm => cm.Metadata.Name == moduleName).FirstOrDefault();

            module.RestartPolicy          = configMap?.Data?["restartPolicy"] ?? "on-unhealthy";
            module.Version                = configMap?.Data?["version"] ?? "1.0";
            module.Status                 = configMap?.Data?["status"] ?? "running";
            module.Settings.CreateOptions = configMap?.Data?["createOptions"] ?? "{}";
        }
        private IList <(string Name, JObject Twin)> PopulateModuleTwins(Corev1ConfigMapList configMapList, ICollection <string> moduleNames)
        {
            var moduleTwins = new List <(string Name, JObject Twin)>();

            foreach (string moduleName in moduleNames)
            {
                Corev1ConfigMap configMap = configMapList.Items.Where(cm => cm.Metadata.Name == moduleName).FirstOrDefault();
                if (configMap != null && configMap.Data.TryGetValue("desiredProperties", out string desiredPropsJson))
                {
                    moduleTwins.Add((moduleName, JObject.Parse(desiredPropsJson)));
                }
            }

            return(moduleTwins);
        }
コード例 #3
0
        void PopulateModuleConfig(Corev1ConfigMapList configMapList, string moduleName, EdgeModule module)
        {
            // see if there is an entry for this module in the config maps
            Corev1ConfigMap configMap = configMapList.Items.Where(cm => cm.Metadata.Name == moduleName).FirstOrDefault();

            if (configMap != null && configMap.Data != null)
            {
                if (configMap.Data.TryGetValue("restartPolicy", out string configMapRestartPolicy))
                {
                    module.RestartPolicy = configMapRestartPolicy ?? "on-unhealthy";
                }
                else
                {
                    module.RestartPolicy = "on-unhealthy";
                }
                if (configMap.Data.TryGetValue("version", out string configMapVersion))
                {
                    module.Version = configMapVersion ?? "1.0";
                }
                else
                {
                    module.Version = "1.0";
                }
                if (configMap.Data.TryGetValue("status", out string configMapStatus))
                {
                    module.Status = configMapStatus ?? "running";
                }
                else
                {
                    module.Status = "running";
                }
                if (configMap.Data.TryGetValue("createOptions", out string configMapCreateOptions))
                {
                    module.Settings.CreateOptions = configMapCreateOptions ?? "{}";
                }
                else
                {
                    module.Settings.CreateOptions = "{}";
                }
            }
            else
            {
                module.RestartPolicy          = "on-unhealthy";
                module.Version                = "1.0";
                module.Status                 = "running";
                module.Settings.CreateOptions = "{}";
            }
        }
        void PopulateEdgeHubConfig(Corev1ConfigMapList configMapList, EdgeHub edgeHub)
        {
            Corev1ConfigMap configMap = configMapList.Items.Where(cm => cm.Metadata.Name == "edgehub").FirstOrDefault();

            if (configMap != null && configMap.Data.TryGetValue("desiredProperties", out string desiredPropsJson))
            {
                EdgeHub edgeHub2 = JsonConvert.DeserializeObject <EdgeHub>(desiredPropsJson);
                if (edgeHub2.Routes != null)
                {
                    edgeHub.Routes = edgeHub2.Routes;
                }
                if (edgeHub2.StoreForwardConfiguration != null)
                {
                    edgeHub.StoreForwardConfiguration = edgeHub2.StoreForwardConfiguration;
                }
            }
        }
        void PopulateEdgeAgentConfig(Corev1ConfigMapList configMapList, EdgeAgent edgeAgent)
        {
            Corev1ConfigMap configMap = configMapList.Items.Where(cm => cm.Metadata.Name == "edgeagent").FirstOrDefault();

            if (configMap != null && configMap.Data.TryGetValue("desiredProperties", out string desiredPropsJson))
            {
                EdgeAgent edgeAgent2 = JsonConvert.DeserializeObject <EdgeAgent>(desiredPropsJson);
                if (edgeAgent2.Runtime != null)
                {
                    if (edgeAgent2.Runtime.Settings.RegistryCredentials != null)
                    {
                        edgeAgent.Runtime.Settings.RegistryCredentials = edgeAgent2.Runtime.Settings.RegistryCredentials;
                    }
                }
                if (edgeAgent2.SystemModules != null)
                {
                    if (edgeAgent2.SystemModules.ContainsKey("edgeHub"))
                    {
                        edgeAgent.SystemModules["edgeHub"].Env = edgeAgent2.SystemModules["edgeHub"].Env;
                    }
                }
            }
        }