Beispiel #1
0
 public Task UpdateMemberStatusValueAsync(Cluster cluster, IMemberStatusValue statusValue)
 {
     cluster.System.Root.Send(_clusterMonitor, new Messages.UpdateStatusValue {
         StatusValue = statusValue
     });
     return(Actor.Done);
 }
        public Task RegisterMemberAsync(
            Cluster cluster, string clusterName, string host, int port, string[] kinds,
            IMemberStatusValue statusValue, IMemberStatusValueSerializer serializer
            )
        {
            var props = Props.FromFunc(
                ctx =>
            {
                if (ctx.Message is GetKinds && ctx.Sender != null)
                {
                    ctx.Respond(new GetKindsResponse {
                        Kinds = { _kinds }
                    });
                }

                return(Actor.Done);
            }
                );

            cluster.Remote.Serialization.RegisterFileDescriptor(ProtosReflection.Descriptor);

            cluster.Remote.RegisterKnownKind(KindsResponder, props);

            _kinds    = kinds;
            _okStatus = serializer.Deserialize("Ok!");
            _koStatus = serializer.Deserialize("Ko!");

            _isServer = host == _serverHost && port == _serverPort;

            return(Actor.Done);
        }
        public async Task UpdateMemberStatusValueAsync(IMemberStatusValue statusValue)
        {
            _statusValue = statusValue;

            if (_statusValue == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(_id))
            {
                return;
            }

            //register a semi unique ID for the current process
            var kvKey = $"{_clusterName}/{_address}:{_port}/StatusValue"; //slash should be present
            var value = _statusValueSerializer.ToValueBytes(statusValue);
            await _client.KV.Put(new KVPair(kvKey)
            {
                //Write the ID for this member.
                //the value is later used to see if an existing node have changed its ID over time
                //meaning that it has Re-joined the cluster.
                Value = value
            }, new WriteOptions());
        }
        private Task RegisterService(IMemberStatusValue statusValue, ISpawnerContext context)
        {
            var registration = new AgentServiceRegistration
            {
                ID      = _id,
                Name    = _clusterName,
                Tags    = _kinds,
                Address = _address,
                Port    = _port,
                Meta    = new Dictionary <string, string>
                {
                    { "StatusValue", _statusValueSerializer.Serialize(statusValue) },
                    { "DeregisterInterval", _options.DeregisterCritical.TotalSeconds.ToString(CultureInfo.InvariantCulture) }
                },
                Check = new AgentServiceCheck
                {
                    DeregisterCriticalServiceAfter = _options.DeregisterCritical,
                    TTL = _options.ServiceTtl
                }
            };

            Logger.LogDebug("Registering service {Service}", _id);

            _registered  = true;
            _statusValue = statusValue;

            var ttlCheckProps = Props.FromProducer(() => new ConsulCheckin(_client, _id, _options.RefreshTtl));

            _ttlCheck = context.Spawn(ttlCheckProps);

            return(_client.Agent.ServiceRegister(registration));
        }
Beispiel #5
0
 public MemberStatus(string memberId, string host, int port, IReadOnlyCollection <string> kinds, bool alive, IMemberStatusValue statusValue)
 {
     MemberId    = memberId;
     Host        = host ?? throw new ArgumentNullException(nameof(host));
     Kinds       = kinds ?? throw new ArgumentNullException(nameof(kinds));
     Port        = port;
     Alive       = alive;
     StatusValue = statusValue;
 }
Beispiel #6
0
        public bool IsSame(IMemberStatusValue val)
        {
            if (val is SeededLocalClusterProviderMemberStatusValue statusValue)
            {
                return(statusValue._memberId.Equals(_memberId));
            }

            return(false);
        }
Beispiel #7
0
        public Task RegisterMemberAsync(string clusterName, string host, int port, string[] kinds, IMemberStatusValue statusValue, IMemberStatusValueSerializer serializer)
        {
            _kinds    = kinds;
            _okStatus = serializer.FromValueBytes(Encoding.UTF8.GetBytes("Ok!"));
            _koStatus = serializer.FromValueBytes(Encoding.UTF8.GetBytes("Ko!"));

            _isServer = host == _serverHost && port == _serverPort;

            return(Actor.Done);
        }
        public async Task RegisterMemberAsync(string clusterName, string address, int port, string[] kinds, IMemberStatusValue statusValue, IMemberStatusValueSerializer statusValueSerializer)
        {
            _id                    = $"{clusterName}@{address}:{port}";
            _clusterName           = clusterName;
            _address               = address;
            _port                  = port;
            _kinds                 = kinds;
            _index                 = 0;
            _statusValue           = statusValue;
            _statusValueSerializer = statusValueSerializer;

            await RegisterServiceAsync();
            await RegisterMemberValsAsync();

            UpdateTtl();
        }
 public Task UpdateMemberStatusValueAsync(Cluster cluster, IMemberStatusValue statusValue) => Actor.Done;
        public byte[] ToValueBytes(IMemberStatusValue val)
        {
            var dVal = (WeightedMemberStatusValue)val;

            return(Encoding.UTF8.GetBytes(dVal.Weight.ToString()));
        }
 public ClusterConfig WithInitialMemberStatusValue(IMemberStatusValue statusValue)
 {
     InitialMemberStatusValue = statusValue;
     return(this);
 }
Beispiel #12
0
        public Task RegisterMemberAsync(Cluster cluster,
                                        string clusterName, string address, int port, string[] kinds, IMemberStatusValue statusValue,
                                        IMemberStatusValueSerializer statusValueSerializer
                                        )
        {
            var props = Props
                        .FromProducer(() => new ConsulClusterMonitor(cluster.System, _options, _consulConfig))
                        .WithGuardianSupervisorStrategy(Supervision.AlwaysRestartStrategy)
                        .WithDispatcher(Mailbox.Dispatchers.SynchronousDispatcher);

            _clusterMonitor = cluster.System.Root.SpawnNamed(props, "ClusterMonitor");

            cluster.System.Root.Send(
                _clusterMonitor, new Messages.RegisterMember
            {
                ClusterName           = clusterName,
                Address               = address,
                Port                  = port,
                Kinds                 = kinds,
                StatusValue           = statusValue,
                StatusValueSerializer = statusValueSerializer
            }
                );

            return(Actor.Done);
        }
Beispiel #13
0
 public byte[] ToValueBytes(IMemberStatusValue val)
 {
     return(null);
 }
Beispiel #14
0
 public Task UpdateMemberStatusValueAsync(IMemberStatusValue statusValue) => Actor.Done;
        public string Serialize(IMemberStatusValue val)
        {
            var dVal = (WeightedMemberStatusValue)val;

            return(dVal.Weight.ToString());
        }
Beispiel #16
0
 public Task RegisterMemberAsync(string clusterName, string h, int p, string[] kinds, IMemberStatusValue statusValue, IMemberStatusValueSerializer serializer)
 {
     return(Task.FromResult(0));
 }
 public bool IsSame(IMemberStatusValue val)
 {
     return(Weight == (val as WeightedMemberStatusValue)?.Weight);
 }
 public bool IsSame(IMemberStatusValue val) => Weight == (val as WeightedMemberStatusValue)?.Weight;
Beispiel #19
0
 public Task UpdateMemberStatusValueAsync(IMemberStatusValue statusValue)
 {
     return(Task.FromResult(0));
 }