Beispiel #1
0
        private async Task <IKeyValueStore> InitializeKeyValueStoreAsync(
            [NotNull] IEnumerable <IManagedProcess> managedProcesses,
            [NotNull] ClusterHeartBeat heartbeat)
        {
            string etcdAgentType = WellKnownAgentType.KeyValueStore.ToString();

            IEnumerable <IManagedProcess> kvsProcesses =
                managedProcesses.Where(m => m.AgentType.Equals(etcdAgentType));

            // For all well-known KVS agent processes...
            foreach (var kvsProcess in kvsProcesses)
            {
                // Check if they live (reviving them, if necessary):
                bool started = await heartbeat.CheckHeartBeatAsync(kvsProcess);

                if (started)
                {
                    // ... and try making contact
                    IServerProcess serverProcess = (IServerProcess)kvsProcess;

                    var keyValueStore = await EtcdKeyValueStore.TryConnectAsync(
                        serverProcess.HostName, serverProcess.Port, serverProcess.UseTls);

                    if (keyValueStore != null)
                    {
                        _logger.LogInformation("Using etcd based key-value store...");
                        return(keyValueStore);
                    }
                }
            }

            // None is configured or none is running or none is responding:
            _logger.LogInformation("Using in-memory key-value store...");
            return(new LocalKeyValueStore());
        }
Beispiel #2
0
        private static async Task <IKeyValueStore> TryGetEtcdKeyValueStore()
        {
            foreach (var kvsAgent in KnownAgents.Get(WellKnownAgentType.KeyValueStore))
            {
                IKeyValueStore keyValueStore = await EtcdKeyValueStore.TryConnectAsync(kvsAgent);

                if (keyValueStore != null)
                {
                    return(keyValueStore);
                }
            }

            // Do not just try the default address - Etcd might be running with a different purpose

            return(null);
        }