private void UpdateEdgeAgent(JTokenWrapper deploymentJsonObject, EdgeConfiguration edgeConfiguration, EdgeGatewayConfiguration edgeGatewayConfiguration) { var createOptionsToken = GetEdgeAgentDesiredPropertiesEdgeAgentCreateOption(deploymentJsonObject); UpdateSystemModuleCreateOptions(createOptionsToken, edgeConfiguration, edgeGatewayConfiguration); var edgeAgent = GetEdgeAgentDesiredPropertiesEdgeAgentModule(deploymentJsonObject); SetHttpProxyWithUpstreamProtocolDetails(edgeAgent, edgeGatewayConfiguration); }
private void UpdateEdgeHub(JTokenWrapper deploymentJsonObject, EdgeConfiguration edgeConfiguration, EdgeGatewayConfiguration edgeGatewayConfiguration) { var createOptionsToken = GetEdgeAgentDesiredPropertiesEdgeHubCreateOption(deploymentJsonObject); UpdateSystemModuleCreateOptions(createOptionsToken, edgeConfiguration, edgeGatewayConfiguration); var messageTTLToken = GetEdgeHubDesiredPropertiesMessageTTL(deploymentJsonObject).Value; messageTTLToken.Replace(Convert.ToInt32(edgeConfiguration.MessageTTL)); var edgeHub = GetEdgeAgentDesiredPropertiesEdgeHubModule(deploymentJsonObject); SetHttpProxyWithUpstreamProtocolDetails(edgeHub, edgeGatewayConfiguration); }
public async Task <int> RunAsync(Args args) { LogEventLevel consoleLevel = args.Verbose ? LogEventLevel.Verbose : LogEventLevel.Information; var loggerConfig = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.Console(consoleLevel); args.LogFile.ForEach(f => loggerConfig.WriteTo.File(f)); Log.Logger = loggerConfig.CreateLogger(); try { using (var cts = new CancellationTokenSource(args.Timeout)) { Log.Information("Running tempSensor test"); await Profiler.Run( async() => { CancellationToken token = cts.Token; // ** setup var iotHub = new IotHub(args.ConnectionString, args.Endpoint, args.Proxy); EdgeDevice device = await EdgeDevice.GetOrCreateIdentityAsync( args.DeviceId, iotHub, token); var daemon = Platform.CreateEdgeDaemon(args.InstallerPath); await daemon.UninstallAsync(token); await daemon.InstallAsync( device.ConnectionString, args.PackagesPath, args.Proxy, token); await daemon.WaitForStatusAsync(EdgeDaemonStatus.Running, token); var agent = new EdgeAgent(device.Id, iotHub); await agent.WaitForStatusAsync(EdgeModuleStatus.Running, token); await agent.PingAsync(token); // ** test var config = new EdgeConfiguration(device.Id, args.AgentImage, iotHub); args.Registry.ForEach( r => config.AddRegistryCredentials(r.address, r.username, r.password)); config.AddEdgeHub(args.HubImage); args.Proxy.ForEach(p => config.AddProxy(p)); config.AddTempSensor(args.SensorImage); await config.DeployAsync(token); var hub = new EdgeModule("edgeHub", device.Id, iotHub); var sensor = new EdgeModule("tempSensor", device.Id, iotHub); await EdgeModule.WaitForStatusAsync( new[] { hub, sensor }, EdgeModuleStatus.Running, token); await sensor.WaitForEventsReceivedAsync(token); var sensorTwin = new ModuleTwin(sensor.Id, device.Id, iotHub); await sensorTwin.UpdateDesiredPropertiesAsync( new { properties = new { desired = new { SendData = true, SendInterval = 10 } } }, token); await sensorTwin.WaitForReportedPropertyUpdatesAsync( new { properties = new { reported = new { SendData = true, SendInterval = 10 } } }, token); // ** teardown await daemon.StopAsync(token); await device.MaybeDeleteIdentityAsync(token); }, "Completed tempSensor test"); } } catch (OperationCanceledException e) { Log.Error(e, "Cancelled tempSensor test after {Timeout} minutes", args.Timeout.TotalMinutes); } catch (Exception e) { Log.Error(e, "Failed tempSensor test"); return(1); } finally { Log.CloseAndFlush(); } return(0); }
public Task <int> RunAsync(Args args) => Profiler.Run( "Running tempSensor test", async() => { using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5))) { CancellationToken token = cts.Token; // ** setup var iotHub = new IotHub(args.ConnectionString, args.Endpoint, args.Proxy); var device = await EdgeDevice.GetOrCreateIdentityAsync( args.DeviceId, iotHub, token); var daemon = new EdgeDaemon(args.InstallerPath); await daemon.UninstallAsync(token); await daemon.InstallAsync( device.ConnectionString, args.PackagesPath, args.Proxy, token); await args.Proxy.Match( async p => { await daemon.StopAsync(token); var yaml = new DaemonConfiguration(); yaml.AddHttpsProxy(p); yaml.Update(); await daemon.StartAsync(token); }, () => daemon.WaitForStatusAsync(EdgeDaemonStatus.Running, token)); var agent = new EdgeAgent(device.Id, iotHub); await agent.WaitForStatusAsync(EdgeModuleStatus.Running, token); await agent.PingAsync(token); // ** test var config = new EdgeConfiguration(device.Id, args.AgentImage, iotHub); args.Registry.ForEach( r => config.AddRegistryCredentials(r.address, r.username, r.password)); config.AddEdgeHub(args.HubImage); args.Proxy.ForEach(p => config.AddProxy(p)); config.AddTempSensor(args.SensorImage); await config.DeployAsync(token); var hub = new EdgeModule("edgeHub", device.Id, iotHub); var sensor = new EdgeModule("tempSensor", device.Id, iotHub); await EdgeModule.WaitForStatusAsync( new[] { hub, sensor }, EdgeModuleStatus.Running, token); await sensor.WaitForEventsReceivedAsync(token); var sensorTwin = new ModuleTwin(sensor.Id, device.Id, iotHub); await sensorTwin.UpdateDesiredPropertiesAsync( new { properties = new { desired = new { SendData = true, SendInterval = 10 } } }, token); await sensorTwin.WaitForReportedPropertyUpdatesAsync( new { properties = new { reported = new { SendData = true, SendInterval = 10 } } }, token); // ** teardown await daemon.StopAsync(token); await device.MaybeDeleteIdentityAsync(token); } return(0); }, "Completed tempSensor test");
private void UpdateSystemModuleCreateOptions(JTokenWrapper createOptionsToken, EdgeConfiguration edgeConfiguration, EdgeGatewayConfiguration edgeGatewayConfiguration) { string[] communicationPort = edgeConfiguration.UpstreamCommunication.Split('/'); IDictionary <string, Dictionary <string, string>[]> edgeHubPortBindingsConfig = new Dictionary <string, Dictionary <string, string>[]>(); Dictionary <string, string>[] matrix = new Dictionary <string, string> [1]; matrix[0] = new Dictionary <string, string>(); matrix[0].Add(Constants.HostPort, communicationPort[0]); edgeHubPortBindingsConfig.Add(edgeConfiguration.UpstreamCommunication, matrix); var createOption = new { HostConfig = new { PortBindings = JObject.FromObject(edgeHubPortBindingsConfig), LogConfig = new { Type = "json-file", Config = JObject.FromObject(GetModuleLogConfigurationType(edgeConfiguration.AdvanceConfiguration)) } } }; createOptionsToken.Value.Replace(JObject.FromObject(createOption).ToString()); }
private void SetModuleDesiredProperties(IEnumerable <EdgeMessagePipelineModule> moduleList, JTokenWrapper deploymentJsonObject, EdgeAgentDto edgeAgent, EdgeConfiguration edgeConfiguration) { foreach (var edgeModule in moduleList) { var moduleDesiredProperty = new JObject(); switch (edgeModule.ModuleImageName) { case DefaultUpstreamModule: { var desiredProperties = new { configuration = new { } }; moduleDesiredProperty[Constants.DesiredProperties] = JObject.FromObject(desiredProperties); deploymentJsonObject.Value[edgeModule.ConfigurationName] = moduleDesiredProperty; break; } default: { var desiredProperties = new { configuration = new { timeStamp = DateTime.UtcNow.ToString("o"), blobSas = string.IsNullOrEmpty(edgeModule.ModuleConfigurationBlobFileURI) ? string.Empty : edgeModule.ModuleConfigurationBlobFileURI } }; moduleDesiredProperty[Constants.DesiredProperties] = JObject.FromObject(desiredProperties); deploymentJsonObject.Value[edgeModule.ConfigurationName] = moduleDesiredProperty; break; } } } }
private IDictionary <string, DeploymentManifestModule> GetPreaparedModulesOfAgent(IEnumerable <EdgeMessagePipelineModule> modulesOfAgent, EdgeConfiguration edgeConfiguration) { var finalModuleList = new Dictionary <string, DeploymentManifestModule>(); foreach (var edgeModule in modulesOfAgent) { var createOptionsJObject = GetCreateOptions().Value; createOptionsJObject[Constants.HostConfig][Constants.LogConfig][Constants.Config].Replace(JObject.FromObject(GetModuleLogConfigurationType(edgeModule.AdvanceConfiguration))); var deploymentManifestModuleSettings = new DeploymentManifestModuleSettings { CreateOptions = createOptionsJObject.ToString(), EdgeModuleContainerImage = edgeModule.ImageURI }; var module = new DeploymentManifestModule { Settings = deploymentManifestModuleSettings, EnvironmentVariables = JObject.FromObject(GetLogLevelData(edgeModule.AdvanceConfiguration, edgeConfiguration.IsCompressionEnabled)) }; finalModuleList.Add(edgeModule.ConfigurationName, module); } return(finalModuleList); }
private IDictionary <string, DeploymentManifestModule> GetModulesForTemplate(IEnumerable <EdgeMessagePipelineModule> defaultModulesOfAgent, IEnumerable <EdgeMessagePipelineModule> modulesOfAgent, EdgeConfiguration edgeConfiguration) { var preparedDefaultModules = GetPreaparedDefaultModulesOfAgent(defaultModulesOfAgent, edgeConfiguration); var preparedModules = GetPreaparedModulesOfAgent(modulesOfAgent, edgeConfiguration); preparedDefaultModules.ToList().ForEach(x => preparedModules.Add(x.Key, x.Value)); return(preparedModules); }