Пример #1
0
 /// <summary> Initialize the private fields </summary>
 public TransactionManager(IEventBus eventBus,
                           ILogger <TransactionManager> logger,
                           IOptions <Configuration> options,
                           IMapper mapper,
                           IConfiguration configuration,
                           ITransactionQueueRepository transactionQueueRepository,
                           ITransactionQueueHistoryRepository transactionQueueHistoryRepository,
                           IFacilityManager facilityManager,
                           ITransactionPriorityManager transactionPriorityManager,
                           IFormularyManager formularyManager,
                           IAduTransactionManager aduTransactionManager,
                           IDestinationManager destinationManager)
 {
     _configuration                     = options.Value;
     _mapper                            = mapper;
     _eventBus                          = eventBus;
     _logger                            = logger;
     this.configuration                 = configuration;
     _transactionQueueRepository        = transactionQueueRepository;
     _transactionQueueHistoryRepository = transactionQueueHistoryRepository;
     _facilityManager                   = facilityManager;
     _transactionPriorityManager        = transactionPriorityManager;
     _formularyManager                  = formularyManager;
     _aduTransactionManager             = aduTransactionManager;
     _destinationManager                = destinationManager;
 }
Пример #2
0
        public ClusterInfo(string clusterId, IDestinationManager destinationManager)
        {
            ClusterId          = clusterId ?? throw new ArgumentNullException(nameof(clusterId));
            DestinationManager = destinationManager ?? throw new ArgumentNullException(nameof(destinationManager));

            DynamicState = CreateDynamicStateQuery();
        }
Пример #3
0
        public ClusterInfo(string clusterId, IDestinationManager destinationManager, IProxyHttpClientFactory proxyHttpClientFactory)
        {
            ClusterId              = clusterId ?? throw new ArgumentNullException(nameof(clusterId));
            DestinationManager     = destinationManager ?? throw new ArgumentNullException(nameof(destinationManager));
            ProxyHttpClientFactory = proxyHttpClientFactory ?? throw new ArgumentNullException(nameof(proxyHttpClientFactory));

            DynamicState = CreateDynamicStateQuery();
        }
Пример #4
0
        public BackendInfo(string backendId, IDestinationManager destinationManager, IProxyHttpClientFactory proxyHttpClientFactory)
        {
            Contracts.CheckNonEmpty(backendId, nameof(backendId));
            Contracts.CheckValue(destinationManager, nameof(destinationManager));
            Contracts.CheckValue(proxyHttpClientFactory, nameof(proxyHttpClientFactory));

            BackendId              = backendId;
            DestinationManager     = destinationManager;
            ProxyHttpClientFactory = proxyHttpClientFactory;

            DynamicState = CreateDynamicStateQuery();
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClusterProber"/> class.
        /// HealthProber is the unit that checks the health state for all destinations(replica) of a cluster(service)
        /// HealthProbe would query the health controller of the destination and update the health state for every destination
        /// periodically base on the time interval user specified in cluster.
        /// </summary>
        public ClusterProber(string clusterId, ClusterConfig config, IDestinationManager destinationManager, IMonotonicTimer timer, ILogger <ClusterProber> logger, IOperationLogger <ClusterProber> operationLogger, HttpClient httpClient, IRandomFactory randomFactory)
        {
            ClusterId               = clusterId ?? throw new ArgumentNullException(nameof(clusterId));
            Config                  = config ?? throw new ArgumentNullException(nameof(config));
            _destinationManager     = destinationManager ?? throw new ArgumentNullException(nameof(destinationManager));
            _timer                  = timer ?? throw new ArgumentNullException(nameof(timer));
            _logger                 = logger ?? throw new ArgumentNullException(nameof(logger));
            _operationLogger        = operationLogger ?? throw new ArgumentNullException(nameof(operationLogger));
            _randomFactory          = randomFactory ?? throw new ArgumentNullException(nameof(randomFactory));
            _clusterProbeHttpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));

            _healthControllerUrl = new Uri(Config.HealthCheckOptions.Path, UriKind.Relative);
            _healthCheckInterval = Config.HealthCheckOptions.Interval;
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BackendProber"/> class.
        /// HealthProber is the unit that checks the health state for all destinations(replica) of a backend(service)
        /// HealthProbe would query the health controller of the destination and update the health state for every destination
        /// periodically base on the time interval user specified in backend.
        /// </summary>
        public BackendProber(string backendId, BackendConfig config, IDestinationManager destinationManager, IMonotonicTimer timer, ILogger <BackendProber> logger, IOperationLogger <BackendProber> operationLogger, HttpClient httpClient, IRandomFactory randomFactory)
        {
            Contracts.CheckValue(backendId, nameof(backendId));
            Contracts.CheckValue(config, nameof(config));
            Contracts.CheckValue(destinationManager, nameof(destinationManager));
            Contracts.CheckValue(timer, nameof(timer));
            Contracts.CheckValue(logger, nameof(logger));
            Contracts.CheckValue(operationLogger, nameof(operationLogger));
            Contracts.CheckValue(httpClient, nameof(httpClient));
            Contracts.CheckValue(randomFactory, nameof(randomFactory));

            BackendId           = backendId;
            Config              = config;
            _destinationManager = destinationManager;
            _timer              = timer;
            _logger             = logger;
            _operationLogger    = operationLogger;
            _randomFactory      = randomFactory;

            _healthControllerUrl = new Uri(Config.HealthCheckOptions.Path, UriKind.Relative);
            _healthCheckInterval = Config.HealthCheckOptions.Interval;

            _backendProbeHttpClient = httpClient;
        }
        private void UpdateRuntimeDestinations(IDictionary <string, Destination> configDestinations, IDestinationManager destinationManager)
        {
            var desiredDestinations = new HashSet <string>(StringComparer.Ordinal);

            foreach (var configDestination in configDestinations)
            {
                desiredDestinations.Add(configDestination.Key);
                destinationManager.GetOrCreateItem(
                    itemId: configDestination.Key,
                    setupAction: destination =>
                {
                    if (destination.Config.Value?.Address != configDestination.Value.Address)
                    {
                        if (destination.Config.Value == null)
                        {
                            Log.DestinationAdded(_logger, configDestination.Key);
                        }
                        else
                        {
                            Log.DestinationChanged(_logger, configDestination.Key);
                        }
                        destination.Config.Value = new DestinationConfig(configDestination.Value.Address);
                    }
                });
            }

            foreach (var existingDestination in destinationManager.GetItems())
            {
                if (!desiredDestinations.Contains(existingDestination.DestinationId))
                {
                    // NOTE 1: This is safe to do within the `foreach` loop
                    // because `IDestinationManager.GetItems` returns a copy of the list of destinations.
                    //
                    // NOTE 2: Removing the endpoint from `IEndpointManager` is safe and existing
                    // backends will continue to work with their existing behavior (until those backends are updated)
                    // and the Garbage Collector won't destroy this backend object while it's referenced elsewhere.
                    Log.DestinationRemoved(_logger, existingDestination.DestinationId);
                    destinationManager.TryRemoveItem(existingDestination.DestinationId);
                }
            }
        }
Пример #8
0
 internal ClusterInfo(string clusterId, IDestinationManager destinationManager)
 {
     ClusterId          = clusterId ?? throw new ArgumentNullException(nameof(clusterId));
     DestinationManager = destinationManager ?? throw new ArgumentNullException(nameof(destinationManager));
 }
Пример #9
0
 public UpgraderBuilder To(IDestinationManager destination)
 {
     this.DestinationManager = destination;
     return(this);
 }
Пример #10
0
 /// <inheritdoc/>
 public IClusterProber CreateClusterProber(string clusterId, ClusterConfig config, IDestinationManager destinationManager)
 {
     return(new ClusterProber(clusterId, config, destinationManager, _timer, _logger, _operationLogger, _httpClientFactory.CreateHttpClient(), _randomFactory));
 }
Пример #11
0
 public Destination(IMapper mapper, IDestinationManager destinationManager)
 {
     _mapper             = mapper;
     _destinationManager = destinationManager;
 }
Пример #12
0
 /// <inheritdoc/>
 public IBackendProber CreateBackendProber(string backendId, BackendConfig config, IDestinationManager destinationManager)
 {
     return(new BackendProber(backendId, config, destinationManager, _timer, _logger, _operationLogger, _httpClientFactory.CreateHttpClient(), _randomFactory));
 }
Пример #13
0
 public HomeController(IDestinationManager destinationManager, IHostingEnvironment hostingEnvironment,
                       IMapper mapper) : base(hostingEnvironment)
 {
     this._destinationManager = destinationManager;
     this._mapper             = mapper;
 }
Пример #14
0
        public static bool Init(ISettings settings)
        {
            if (loaded == true)
            {
                throw new Exception("Please only call this method once.");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            Core.Settings = settings;

            string pidFilePath = Path.Combine(Core.Settings.DataPath, "meshwork.pid");

            if (File.Exists(pidFilePath))
            {
                int processId = -1;
                Int32.TryParse(File.ReadAllText(pidFilePath), out processId);
                try
                {
                    Process.GetProcessById(processId);
                    Console.Error.WriteLine("Meshwork is already running (PID {0})!", processId);
                    return(false);
                }
                catch (ArgumentException)
                {
                    File.Delete(pidFilePath);
                }
            }
            File.WriteAllText(pidFilePath, Process.GetCurrentProcess().Id.ToString());

            if (settings.KeyEncrypted)
            {
                PasswordPrompt(null, EventArgs.Empty);
                if (!settings.KeyUnlocked)
                {
                    // Quit!
                    return(false);
                }
            }

            rsaProvider = new RSACryptoServiceProvider();
            rsaProvider.ImportParameters(settings.EncryptionParameters);
            nodeID = Common.SHA512Str(rsaProvider.ToXmlString(false));

            fileSystem = Container.GetExportedValue <IFileSystemProvider>();

            shareBuilder = Container.GetExportedValue <IShareBuilder>();
            shareBuilder.FinishedIndexing += ShareBuilder_FinishedIndexing;

            shareWatcher        = Container.GetExportedValue <IShareWatcher>();
            shareHasher         = Container.GetExportedValue <IShareHasher>();
            transportManager    = Container.GetExportedValue <ITransportManager>();
            fileTransferManager = Container.GetExportedValue <IFileTransferManager>();
            fileSearchManager   = Container.GetExportedValue <IFileSearchManager>();
            destinationManager  = Container.GetExportedValue <IDestinationManager>();

            // XXX: Use reflection to load these:
            destinationManager.RegisterSource(new TCPIPv4DestinationSource());
            destinationManager.RegisterSource(new TCPIPv6DestinationSource());

            MonoTorrent.Client.Tracker.TrackerFactory.Register("meshwork", typeof(MeshworkTracker));

            ITransportListener tcpListener = new TcpTransportListener(Core.Settings.TcpListenPort);

            transportListeners.Add(tcpListener);

            loaded = true;

            if (FinishedLoading != null)
            {
                FinishedLoading(null, EventArgs.Empty);
            }

            return(true);
        }