コード例 #1
0
        private async Task GenerateDockerOutline(DockerOutline outline, ProvisioningData provisioningData,
                                                 IoTHubConnectionStrings iotHubConnectionStrings)
        {
            await Task.Run(() =>
            {
                int serviceCount = 0;
                foreach (KeyValuePair <string, List <DeviceDescription> > provisioningEntry in provisioningData)
                {
                    iotHubConnectionStrings.TryGetValue(provisioningEntry.Key,
                                                        out string iotHubConnectionString);

                    foreach (DeviceDescription device in provisioningEntry.Value)
                    {
                        serviceCount++;
                        string deviceType = device.name.ToLower();
                        string serviceKey = $"sh.d.{deviceType}.{provisioningEntry.Key.ToLower()}";

                        var service = new ServiceDescription
                        {
                            image       = GetContainerImageName(deviceType),
                            environment = new List <EnvironmentSetting>()
                        };
                        service.environment.Add(new EnvironmentSetting {
                            name = HardwareIdSetting, value = device.hardwareId
                        });
                        service.environment.Add(new EnvironmentSetting {
                            name = DigitalTwinsManagementApiSetting, value = DigitalTwinsApiEndpoint
                        });
                        service.environment.Add(new EnvironmentSetting
                        {
                            name  = MessageIntervalSetting,
                            value = MessageInterval > 0 ? MessageInterval.ToString() : MessageIntervalDefault.ToString()
                        });
                        service.environment.Add(new EnvironmentSetting {
                            name = SasTokenSetting, value = device.SasToken
                        });
                        service.environment.Add(new EnvironmentSetting {
                            name = IoTHubConnectionStringSetting, value = iotHubConnectionString
                        });
                        service.environment.Add(new EnvironmentSetting
                        {
                            name  = StartupDelayInSecondsSetting,
                            value = Math.Floor(serviceCount / DigitalTwinsApiCallLimiter).ToString()
                        });

                        outline.services.Add(serviceKey, service);
                    }
                }
            });
        }
コード例 #2
0
        private async Task GenerateKubernetesOutline(KubernetesOutline outline, ProvisioningData provisioningData,
                                                     IoTHubConnectionStrings iotHubConnectionStrings)
        {
            await Task.Run(() =>
            {
                int deploymentCount = 0;
                foreach (KeyValuePair <string, List <DeviceDescription> > provisioningEntry in provisioningData)
                {
                    iotHubConnectionStrings.TryGetValue(provisioningEntry.Key,
                                                        out string iotHubConnectionString);

                    foreach (DeviceDescription device in provisioningEntry.Value)
                    {
                        deploymentCount++;
                        string deviceType = device.name.ToLower();
                        string serviceKey = $"sh.d.{deviceType}.{provisioningEntry.Key.ToLower()}";

                        var container = new KubernetesContainer
                        {
                            name            = $"device-{deviceType}",
                            image           = GetContainerImageName(deviceType),
                            imagePullPolicy = "Always",
                            env             = new List <KubernetesEnvironmentSetting>()
                        };
                        container.env.Add(new KubernetesEnvironmentSetting {
                            name = HardwareIdSetting, value = device.hardwareId
                        });
                        container.env.Add(new KubernetesEnvironmentSetting {
                            name = IoTHubConnectionStringSetting, value = iotHubConnectionString
                        });
                        container.env.Add(new KubernetesEnvironmentSetting {
                            name = DigitalTwinsManagementApiSetting, value = DigitalTwinsApiEndpoint
                        });
                        container.env.Add(new KubernetesEnvironmentSetting
                        {
                            name  = MessageIntervalSetting,
                            value = MessageInterval > 0 ? MessageInterval.ToString() : MessageIntervalDefault.ToString()
                        });
                        container.env.Add(new KubernetesEnvironmentSetting {
                            name = SasTokenSetting, value = device.SasToken
                        });
                        container.env.Add(new KubernetesEnvironmentSetting
                        {
                            name  = StartupDelayInSecondsSetting,
                            value = Math.Floor(deploymentCount / DigitalTwinsApiCallLimiter).ToString()
                        });

                        var template = new KubernetesTemplate
                        {
                            metadata = new KubernetesMetadata {
                                labels = new KubernetesLabels {
                                    app = serviceKey, component = serviceKey
                                }
                            },
                            spec = new KubernetesSpec {
                                containers = new List <KubernetesContainer> {
                                    container
                                }
                            }
                        };
                        var spec = new KubernetesSpec
                        {
                            template = template
                        };
                        var deployment = new KubernetesDeployment
                        {
                            apiVersion = "extensions/v1beta1",
                            kind       = "Deployment",
                            metadata   = new KubernetesMetadata {
                                name = serviceKey
                            },
                            spec = spec
                        };

                        outline.Deployments.Add(deployment);
                    }
                }
            });
        }