Пример #1
0
        public SimulationManager(
            ISimulationContext simulationContext,
            IDevicePartitions devicePartitions,
            IClusterNodes clusterNodes,
            IDeviceModels deviceModels,
            IFactory factory,
            IClusteringConfig clusteringConfig,
            ILogger logger,
            IInstance instance,
            ISimulationStatistics simulationStatistics,
            ISimulations simulations)
        {
            this.simulationContext    = simulationContext;
            this.devicePartitions     = devicePartitions;
            this.clusterNodes         = clusterNodes;
            this.deviceModels         = deviceModels;
            this.simulationStatistics = simulationStatistics;
            this.factory          = factory;
            this.log              = logger;
            this.instance         = instance;
            this.maxDevicePerNode = clusteringConfig.MaxDevicesPerNode;
            this.simulations      = simulations;

            this.assignedPartitions = new ConcurrentDictionary <string, DevicesPartition>();
            this.nodeCount          = 1;
            this.deviceCount        = 0;
        }
 public SimulationsController(
     ISimulations simulationsService,
     ILogger logger)
 {
     this.simulationsService = simulationsService;
     this.log = logger;
 }
        public Agent(
            IServicesConfig servicesConfig,
            IAppConcurrencyConfig appConcurrencyConfig,
            ISimulations simulations,
            IFactory factory,
            ILogger logger,
            IDiagnosticsLogger diagnosticsLogger)
        {
            this.appConcurrencyConfig = appConcurrencyConfig;
            this.simulations          = simulations;
            this.factory        = factory;
            this.log            = logger;
            this.logDiagnostics = diagnosticsLogger;

            this.startingOrStopping      = false;
            this.running                 = false;
            this.deviceTwinEnabled       = servicesConfig.DeviceTwinEnabled;
            this.runningToken            = new CancellationTokenSource();
            this.lastPolledTime          = DateTimeOffset.UtcNow;
            this.lastPrintStatisticsTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            this.lastSaveStatisticsTime  = DateTimeOffset.UtcNow;

            this.simulationManagers     = new ConcurrentDictionary <string, ISimulationManager>();
            this.deviceStateActors      = new ConcurrentDictionary <string, IDeviceStateActor>();
            this.deviceConnectionActors = new ConcurrentDictionary <string, IDeviceConnectionActor>();
            this.deviceTelemetryActors  = new ConcurrentDictionary <string, IDeviceTelemetryActor>();
            this.devicePropertiesActors = new ConcurrentDictionary <string, IDevicePropertiesActor>();
        }
Пример #4
0
        private void StartAgents(IApplicationLifetime appLifetime)
        {
            // Temporary workaround to allow twin JSON deserialization in IoT SDK
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                CheckAdditionalContent = false
            };

            var config = this.ApplicationContainer.Resolve <IConfig>();

            // Start the partitioning agent, unless disabled
            this.partitioningAgent     = this.ApplicationContainer.Resolve <IPartitioningAgent>();
            this.partitioningAgentTask = config.ServicesConfig.DisablePartitioningAgent
                ? Task.Run(() => Thread.Sleep(TimeSpan.FromHours(1)))
                : this.partitioningAgent.StartAsync(this.appStopToken.Token);

            // Start the simulation agent, unless disabled
            this.simulationAgent     = this.ApplicationContainer.Resolve <ISimulationAgent>();
            this.simulationAgentTask = config.ServicesConfig.DisableSimulationAgent
                ? Task.Run(() => Thread.Sleep(TimeSpan.FromHours(1)))
                : this.simulationAgent.StartAsync(this.appStopToken.Token);

            // This creates sample simulations that will be shown on simulation dashboard by default
            this.simulationService = this.ApplicationContainer.Resolve <ISimulations>();
            if (!config.ServicesConfig.DisableSeedByTemplate)
            {
                this.simulationService.TrySeedAsync();
            }

            this.threadsMonitoringTask = this.MonitorThreadsAsync(appLifetime);
        }
Пример #5
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>();
        }
Пример #6
0
 public SimulationsController(
     ISimulations simulationsService,
     IIotHubConnectionStringManager connectionStringManager,
     ILogger logger)
 {
     this.simulationsService      = simulationsService;
     this.connectionStringManager = connectionStringManager;
     this.log = logger;
 }
Пример #7
0
 public Simulation(
     ILogger logger,
     ISimulations simulations,
     ISimulationRunner runner)
 {
     this.log         = logger;
     this.simulations = simulations;
     this.runner      = runner;
 }
Пример #8
0
 public Agent(
     ILogger logger,
     ISimulations simulations,
     ISimulationRunner runner)
 {
     this.log         = logger;
     this.simulations = simulations;
     this.runner      = runner;
     this.running     = true;
 }
Пример #9
0
 public StatusController(
     IDevices devices,
     IStorageAdapterClient storage,
     ISimulations simulations,
     ILogger logger)
 {
     this.devices     = devices;
     this.storage     = storage;
     this.simulations = simulations;
     this.log         = logger;
 }
 public StatusController(
     IPreprovisionedIotHub preprovisionedIotHub,
     IStorageAdapterClient storage,
     ISimulations simulations,
     ILogger logger,
     IServicesConfig servicesConfig)
 {
     this.preprovisionedIotHub = preprovisionedIotHub;
     this.storage        = storage;
     this.simulations    = simulations;
     this.log            = logger;
     this.servicesConfig = servicesConfig;
 }
Пример #11
0
        public DevicePartitions(
            IServicesConfig config,
            IClusteringConfig clusteringConfig,
            ISimulations simulations,
            IFactory factory,
            ILogger logger)
        {
            this.simulations = simulations;
            this.log         = logger;

            this.partitionsStorage = factory.Resolve <IStorageRecords>().Init(config.PartitionsStorage);
            this.maxPartitionSize  = clusteringConfig.MaxPartitionSize;
        }
 public SimulationsController(
     ISimulations simulationsService,
     IIotHubConnectionStringManager connectionStringManager,
     IIothubMetrics iothubMetrics,
     IPreprovisionedIotHub preprovisionedIotHub,
     ISimulationAgent simulationAgent,
     ILogger logger)
 {
     this.simulationsService      = simulationsService;
     this.connectionStringManager = connectionStringManager;
     this.iothubMetrics           = iothubMetrics;
     this.simulationAgent         = simulationAgent;
     this.log = logger;
 }
Пример #13
0
 public DevicePartitions(
     IServicesConfig config,
     IClusteringConfig clusteringConfig,
     ISimulations simulations,
     IClusterNodes clusterNodes,
     IEngines engines,
     ILogger logger)
 {
     this.simulations               = simulations;
     this.log                       = logger;
     this.partitionsStorage         = engines.Build(config.PartitionsStorage);
     this.clusterNodes              = clusterNodes;
     this.partitionLockDurationSecs = clusteringConfig.PartitionLockDurationMsecs / 1000;
     this.maxPartitionSize          = clusteringConfig.MaxPartitionSize;
 }
Пример #14
0
 public Agent(
     IClusterNodes clusterNodes,
     IDevicePartitions partitions,
     ISimulations simulations,
     IThreadWrapper thread,
     IClusteringConfig clusteringConfig,
     ILogger logger)
 {
     this.clusterNodes       = clusterNodes;
     this.partitions         = partitions;
     this.simulations        = simulations;
     this.thread             = thread;
     this.log                = logger;
     this.checkIntervalMsecs = clusteringConfig.CheckIntervalMsecs;
     this.running            = false;
 }
 public SimulationsController(
     ISimulations simulationsService,
     IConnectionStringValidation connectionStringValidation,
     IIothubMetrics iothubMetrics,
     IRateLimitingConfig defaultRatingConfig,
     IPreprovisionedIotHub preprovisionedIotHub,
     ISimulationAgent simulationAgent,
     IFactory factory,
     ILogger logger)
 {
     this.simulationsService         = simulationsService;
     this.connectionStringValidation = connectionStringValidation;
     this.iothubMetrics       = iothubMetrics;
     this.defaultRatingConfig = defaultRatingConfig;
     this.simulationAgent     = simulationAgent;
     this.factory             = factory;
     this.log = logger;
 }
Пример #16
0
        private void StartAgents()
        {
            // Temporary workaround to allow twin JSON deserialization in IoT SDK
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                CheckAdditionalContent = false
            };

            this.partitioningAgent = this.ApplicationContainer.Resolve <IPartitioningAgent>();
            this.partitioningAgent.StartAsync();

            this.simulationAgent = this.ApplicationContainer.Resolve <ISimulationAgent>();
            this.simulationAgent.StartAsync();

            // This creates sample simulations that will be shown on simulation dashboard by default
            this.simulationService = this.ApplicationContainer.Resolve <ISimulations>();
            this.simulationService.TrySeedAsync();
        }
Пример #17
0
 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 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;
 }
Пример #20
0
 public Agent(
     IClusterNodes clusterNodes,
     IDevicePartitions partitions,
     ISimulations simulations,
     IThreadWrapper thread,
     IClusteringConfig clusteringConfig,
     IFactory factory,
     ILogger logger,
     IAzureManagementAdapterClient azureManagementAdapter)
 {
     this.clusterNodes           = clusterNodes;
     this.partitions             = partitions;
     this.simulations            = simulations;
     this.thread                 = thread;
     this.factory                = factory;
     this.log                    = logger;
     this.azureManagementAdapter = azureManagementAdapter;
     this.clusteringConfig       = clusteringConfig;
     this.checkIntervalMsecs     = clusteringConfig.CheckIntervalMsecs;
     this.running                = false;
     this.currentNodeCount       = DEFAULT_NODE_COUNT;
 }