Example #1
0
 public Config(IConfigData configData)
 {
     this.Port               = configData.GetInt(PORT_KEY);
     this.LoggingConfig      = GetLogConfig(configData);
     this.ServicesConfig     = GetServicesConfig(configData);
     this.ClientAuthConfig   = GetClientAuthConfig(configData);
     this.RateLimitingConfig = GetRateLimitingConfig(configData);
     this.DeploymentConfig   = GetDeploymentConfig(configData);
 }
 public AzureManagementAdapter(
     IHttpClient httpClient,
     IServicesConfig config,
     IDeploymentConfig deploymentConfig,
     ILogger logger,
     IDiagnosticsLogger diagnosticsLogger)
 {
     this.httpClient        = httpClient;
     this.log               = logger;
     this.config            = config;
     this.deploymentConfig  = deploymentConfig;
     this.diagnosticsLogger = diagnosticsLogger;
 }
Example #3
0
 /// <summary>Map a service model to the corresponding API model</summary>
 public SimulationListApiModel(
     IEnumerable <Services.Models.Simulation> simulations,
     IServicesConfig servicesConfig,
     IDeploymentConfig deploymentConfig,
     IIotHubConnectionStringManager connectionStringManager,
     ISimulationRunner simulationRunner,
     IRateLimiting rateReporter)
 {
     this.Items = new List <SimulationApiModel.SimulationApiModel>();
     foreach (var x in simulations)
     {
         this.Items.Add(SimulationApiModel.SimulationApiModel.FromServiceModel(
                            x, servicesConfig, deploymentConfig, connectionStringManager, simulationRunner, rateReporter));
     }
 }
        // If the simulation is running with the conn string in the config then return a URL to the metrics
        private string GetIoTHubMetricsUrl(IServicesConfig servicesConfig, IDeploymentConfig deploymentConfig, IIotHubConnectionStringManager connectionStringManager)
        {
            var csInUse  = connectionStringManager.GetIotHubConnectionString().ToLowerInvariant().Trim();
            var csInConf = servicesConfig?.IoTHubConnString?.ToLowerInvariant().Trim();

            // Return the URL only when the simulation is running with the configured conn string
            if (csInUse != csInConf)
            {
                return(string.Empty);
            }

            return($"https://portal.azure.com/{deploymentConfig.AzureSubscriptionDomain}" +
                   $"#resource/subscriptions/{deploymentConfig.AzureSubscriptionId}" +
                   $"/resourceGroups/{deploymentConfig.AzureResourceGroup}" +
                   $"/providers/Microsoft.Devices/IotHubs/{deploymentConfig.AzureIothubName}/Metrics");
        }
Example #5
0
        // Append additional Hub properties and Statistics
        private async Task AppendHubPropertiesAndStatisticsAsync(
            IServicesConfig servicesConfig,
            IDeploymentConfig deploymentConfig,
            IIotHubConnectionStringManager connectionStringManager,
            ISimulationRunner simulationRunner,
            IRateLimiting rateReporter)
        {
            var isRunning = this.Running == true;

            foreach (var iotHub in this.IotHubs)
            {
                // Preprovisioned IoT hub status
                var isHubPreprovisioned = this.IsHubConnectionStringConfigured(servicesConfig);

                if (isHubPreprovisioned && isRunning)
                {
                    iotHub.PreprovisionedIoTHubInUse = await this.IsPreprovisionedIoTHubInUseAsync(servicesConfig, connectionStringManager);

                    iotHub.PreprovisionedIoTHubMetricsUrl = await this.GetIoTHubMetricsUrlAsync(servicesConfig, deploymentConfig, connectionStringManager);
                }
            }

            if (isRunning)
            {
                // Average messages per second frequency in the last minutes
                this.Statistics.AverageMessagesPerSecond = rateReporter.GetThroughputForMessages();

                // Total messages count
                this.Statistics.TotalMessagesSent = simulationRunner.TotalMessagesCount;

                // Active devices count
                this.Statistics.ActiveDevicesCount = simulationRunner.ActiveDevicesCount;

                // Failed telemetry messages count
                this.Statistics.FailedMessagesCount = simulationRunner.FailedMessagesCount;

                // Failed device connections count
                this.Statistics.FailedDeviceConnectionsCount = simulationRunner.FailedDeviceConnectionsCount;

                // Failed device connections count
                this.Statistics.FailedDeviceTwinUpdatesCount = simulationRunner.FailedDeviceTwinUpdatesCount;

                // Simulation errors count
                this.Statistics.SimulationErrorsCount = simulationRunner.SimulationErrorsCount;
            }
        }
 public SimulationsController(
     ISimulations simulationsService,
     IServicesConfig servicesConfig,
     IDeploymentConfig deploymentConfig,
     IIotHubConnectionStringManager connectionStringManager,
     IPreprovisionedIotHub preprovisionedIotHub,
     ISimulationAgent simulationAgent,
     ISimulationRunner simulationRunner,
     IRateLimiting rateReporter,
     ILogger logger)
 {
     this.simulationsService      = simulationsService;
     this.servicesConfig          = servicesConfig;
     this.deploymentConfig        = deploymentConfig;
     this.connectionStringManager = connectionStringManager;
     this.simulationAgent         = simulationAgent;
     this.simulationRunner        = simulationRunner;
     this.rateReporter            = rateReporter;
     this.log = logger;
 }
 public StatusController(
     IPreprovisionedIotHub preprovisionedIotHub,
     IStorageAdapterClient storage,
     ISimulations simulations,
     ILogger logger,
     IServicesConfig servicesConfig,
     IDeploymentConfig deploymentConfig,
     IIotHubConnectionStringManager connectionStringManager,
     ISimulationRunner simulationRunner,
     IRateLimiting rateLimiting)
 {
     this.preprovisionedIotHub = preprovisionedIotHub;
     this.storage                 = storage;
     this.simulations             = simulations;
     this.log                     = logger;
     this.servicesConfig          = servicesConfig;
     this.deploymentConfig        = deploymentConfig;
     this.connectionStringManager = connectionStringManager;
     this.simulationRunner        = simulationRunner;
     this.rateReporter            = rateLimiting;
 }
Example #8
0
 public override void InitializeDeployment(IDeploymentConfig deploymentConfig)
 {
     deploymentConfig.Hosts = Hosts;
     deploymentConfig.Logger = new ColorizedConsoleLogger();
 }
        // Map service model to API model
        public static SimulationApiModel FromServiceModel(
            Simulation value,
            IServicesConfig servicesConfig,
            IDeploymentConfig deploymentConfig,
            IIotHubConnectionStringManager connectionStringManager,
            ISimulationRunner simulationRunner,
            IRateLimiting rateReporter)
        {
            if (value == null)
            {
                return(null);
            }

            var result = new SimulationApiModel
            {
                ETag        = value.ETag,
                Id          = value.Id,
                Name        = value.Name,
                Description = value.Description,
                Enabled     = value.Enabled,
                Running     = value.ShouldBeRunning,
                StartTime   = value.StartTime.ToString(),
                EndTime     = value.EndTime.ToString(),
                StoppedTime = value.StoppedTime.ToString(),
                IotHubs     = new List <SimulationIotHub>()
            };

            foreach (var iotHubConnectionString in value.IotHubConnectionStrings)
            {
                var iotHub = new SimulationIotHub {
                    ConnectionString = iotHubConnectionString
                };
                result.IotHubs.Add(iotHub);
            }

            // Ignore the date if the simulation doesn't have a start time
            if (value.StartTime.HasValue && !value.StartTime.Value.Equals(DateTimeOffset.MinValue))
            {
                result.StartTime = value.StartTime?.ToString(DATE_FORMAT);
            }

            // Ignore the date if the simulation doesn't have an end time
            if (value.EndTime.HasValue && !value.EndTime.Value.Equals(DateTimeOffset.MaxValue))
            {
                result.EndTime = value.EndTime?.ToString(DATE_FORMAT);
            }

            // Ignore the date if the simulation doesn't have an end time
            if (value.StoppedTime.HasValue && !value.StoppedTime.Value.Equals(DateTimeOffset.MaxValue))
            {
                result.StoppedTime = value.StoppedTime?.ToString(DATE_FORMAT);
            }

            result.DeviceModels = SimulationDeviceModelRef.FromServiceModel(value.DeviceModels);
            result.Statistics   = SimulationStatistics.FromServiceModel(value.Statistics);
            result.created      = value.Created;
            result.modified     = value.Modified;

            result.AppendHubPropertiesAndStatistics(servicesConfig, deploymentConfig, connectionStringManager, simulationRunner, rateReporter);

            return(result);
        }
Example #10
0
 private static void InitializeWithAction(IDeploymentConfig deployment, IConfig config)
 {
     config.InitializeDeployment(deployment);
 }