Beispiel #1
0
        public SimulationRunner(
            IRateLimitingConfig ratingConfig,
            IRateLimiting rateLimiting,
            ISimulationConcurrencyConfig simulationConcurrencyConfig,
            ILogger logger,
            IDiagnosticsLogger diagnosticsLogger,
            IDeviceModels deviceModels,
            IDeviceModelsGeneration deviceModelsOverriding,
            IDevices devices,
            ISimulations simulations,
            IFactory factory)
        {
            this.connectionLoopSettings = new ConnectionLoopSettings(ratingConfig);
            this.propertiesLoopSettings = new PropertiesLoopSettings(ratingConfig);

            this.simulationConcurrencyConfig = simulationConcurrencyConfig;
            this.log = logger;
            this.diagnosticsLogger      = diagnosticsLogger;
            this.deviceModels           = deviceModels;
            this.deviceModelsOverriding = deviceModelsOverriding;
            this.devices     = devices;
            this.simulations = simulations;
            this.factory     = factory;

            this.startLock    = new { };
            this.running      = false;
            this.starting     = false;
            this.rateLimiting = rateLimiting;

            this.deviceStateActors      = new ConcurrentDictionary <string, IDeviceStateActor>();
            this.deviceConnectionActors = new ConcurrentDictionary <string, IDeviceConnectionActor>();
            this.deviceTelemetryActors  = new ConcurrentDictionary <string, IDeviceTelemetryActor>();
            this.devicePropertiesActors = new ConcurrentDictionary <string, IDevicePropertiesActor>();
        }
        public DeviceConnectionActor(
            ILogger logger,
            IActorsLogger actorLogger,
            IRateLimiting rateLimiting,
            CredentialsSetup credentialsSetupLogic,
            FetchFromRegistry fetchFromRegistryLogic,
            Register registerLogic,
            Connect connectLogic,
            Deregister deregisterLogic,
            Disconnect disconnectLogic)
        {
            this.log          = logger;
            this.actorLogger  = actorLogger;
            this.rateLimiting = rateLimiting;

            this.credentialsSetupLogic  = credentialsSetupLogic;
            this.fetchFromRegistryLogic = fetchFromRegistryLogic;
            this.registerLogic          = registerLogic;
            this.connectLogic           = connectLogic;
            this.deregisterLogic        = deregisterLogic;
            this.disconnectLogic        = disconnectLogic;

            this.Message = null;
            this.Client  = null;
            this.Device  = null;

            this.status           = ActorStatus.None;
            this.deviceModel      = null;
            this.deviceId         = null;
            this.deviceStateActor = null;

            this.failedDeviceConnectionsCount = 0;
            this.failedRegistrationsCount     = 0;
            this.failedFetchCount             = 0;
        }
Beispiel #3
0
        public DeviceConnectionActor(
            ILogger logger,
            IActorsLogger actorLogger,
            IRateLimiting rateLimiting,
            Fetch fetchLogic,
            Register registerLogic,
            Connect connectLogic)
        {
            this.log          = logger;
            this.actorLogger  = actorLogger;
            this.rateLimiting = rateLimiting;

            this.fetchLogic    = fetchLogic;
            this.registerLogic = registerLogic;
            this.connectLogic  = connectLogic;

            this.Message = null;
            this.Client  = null;
            this.Device  = null;

            this.status           = ActorStatus.None;
            this.deviceModel      = null;
            this.deviceId         = null;
            this.deviceStateActor = null;

            this.failedDeviceConnectionsCount = 0;
            this.failedRegistrationsCount     = 0;
            this.failedFetchCount             = 0;
        }
Beispiel #4
0
 public SimulationContext(
     IDevices devices,
     IRateLimiting rateLimiting,
     IInstance instance)
 {
     this.instance     = instance;
     this.Devices      = devices;
     this.RateLimiting = rateLimiting;
 }
 public Devices(
     IRateLimiting rateLimiting,
     IServicesConfig config,
     ILogger logger)
 {
     this.rateLimiting   = rateLimiting;
     this.log            = logger;
     this.registry       = RegistryManager.CreateFromConnectionString(config.IoTHubConnString);
     this.ioTHubHostName = IotHubConnectionStringBuilder.Create(config.IoTHubConnString).HostName;
     this.log.Debug("Devices service instantiated", () => new { this.ioTHubHostName });
 }
Beispiel #6
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));
     }
 }
Beispiel #7
0
 public DeviceClient(
     string deviceId,
     IoTHubProtocol protocol,
     Azure.Devices.Client.DeviceClient client,
     IDeviceMethods deviceMethods,
     IRateLimiting rateLimiting,
     ILogger logger)
 {
     this.deviceId      = deviceId;
     this.protocol      = protocol;
     this.client        = client;
     this.deviceMethods = deviceMethods;
     this.rateLimiting  = rateLimiting;
     this.log           = logger;
     this.connected     = false;
 }
Beispiel #8
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 Agent(
     ILogger logger,
     IDiagnosticsLogger diagnosticsLogger,
     ISimulations simulations,
     ISimulationRunner runner,
     IRateLimiting rateReporter,
     IDeviceModels deviceModels,
     IDevices devices)
 {
     this.log            = logger;
     this.logDiagnostics = diagnosticsLogger;
     this.simulations    = simulations;
     this.runner         = runner;
     this.rateReporter   = rateReporter;
     this.deviceModels   = deviceModels;
     this.devices        = devices;
     this.running        = true;
     this.lastPolledTime = DateTimeOffset.UtcNow;
 }
        public DevicePropertiesActor(
            ILogger logger,
            IActorsLogger actorLogger,
            IRateLimiting rateLimiting,
            UpdateReportedProperties updatePropertiesLogic,
            SetDeviceTag deviceSetDeviceTagLogic)
        {
            this.log                     = logger;
            this.actorLogger             = actorLogger;
            this.rateLimiting            = rateLimiting;
            this.updatePropertiesLogic   = updatePropertiesLogic;
            this.deviceSetDeviceTagLogic = deviceSetDeviceTagLogic;

            this.status                = ActorStatus.None;
            this.deviceId              = null;
            this.deviceStateActor      = null;
            this.deviceConnectionActor = null;

            this.failedTwinUpdatesCount = 0;
        }
        public DeviceTelemetryActor(
            ILogger logger,
            IActorsLogger actorLogger,
            IRateLimiting rateLimiting,
            SendTelemetry sendTelemetryLogic)
        {
            this.log                = logger;
            this.actorLogger        = actorLogger;
            this.rateLimiting       = rateLimiting;
            this.sendTelemetryLogic = sendTelemetryLogic;

            this.Message = null;

            this.status              = ActorStatus.None;
            this.deviceModel         = null;
            this.deviceId            = null;
            this.deviceStateActor    = null;
            this.totalMessagesCount  = 0;
            this.failedMessagesCount = 0;
        }
 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;
 }
Beispiel #14
0
        public DeviceActor(
            ILogger logger,
            Connect connectLogic,
            DeviceBootstrap deviceBootstrapLogic,
            UpdateDeviceState updateDeviceStateLogic,
            UpdateReportedProperties updateReportedPropertiesLogic,
            SendTelemetry sendTelemetryLogic,
            IRateLimiting rateLimiting,
            ITimer cancellationCheckTimer)
        {
            this.log          = logger;
            this.rateLimiting = rateLimiting;

            this.connectLogic                  = connectLogic;
            this.deviceBootstrapLogic          = deviceBootstrapLogic;
            this.updateDeviceStateLogic        = updateDeviceStateLogic;
            this.updateReportedPropertiesLogic = updateReportedPropertiesLogic;
            this.sendTelemetryLogic            = sendTelemetryLogic;

            this.cancellationCheckTimer = cancellationCheckTimer;
            this.cancellationCheckTimer.Setup(CancellationCheck, this);

            this.ActorStatus = Status.None;
        }
        // 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);
        }