Exemple #1
0
        private void ProcessDeaFindDroplet(string message, string reply)
        {
            if (shutting_down)
            {
                return;
            }

            log.Debug(Resources.Agent_ProcessDeaFindDroplet_Fmt, message);

            FindDroplet findDroplet = Message.FromJson <FindDroplet>(message);

            dropletManager.ForAllInstances((instance) =>
            {
                if (instance.DropletID == findDroplet.DropletID)
                {
                    if (instance.Version == findDroplet.Version)
                    {
                        if (findDroplet.States.Contains(instance.State))
                        {
                            var startDate = DateTime.ParseExact(instance.Start, Constants.JsonDateFormat, CultureInfo.InvariantCulture);
                            var span      = DateTime.Now - startDate;

                            var response = new FindDropletResponse(messagingProvider.UniqueIdentifier, instance, span)
                            {
                                FileUri     = String.Format(CultureInfo.InvariantCulture, Resources.Agent_Droplets_Fmt, config.LocalIPAddress, config.FilesServicePort),
                                Credentials = config.FilesCredentials.ToArray(),
                            };

                            if (response.State != VcapStates.RUNNING)
                            {
                                response.Stats = null;
                            }

                            messagingProvider.Publish(reply, response);
                        }
                    }
                }
            });
        }
        private void ProcessDeaFindDroplet(string message, string reply)
        {
            if (shutting_down)
            {
                return;
            }

            log.Debug(Resources.Agent_ProcessDeaFindDroplet_Fmt, message);

            FindDroplet findDroplet = Message.FromJson <FindDroplet>(message);

            dropletManager.ForAllInstances(findDroplet.DropletID, (instance) =>
            {
                bool versionMatched  = findDroplet.Version.IsNullOrWhiteSpace() || instance.Version == findDroplet.Version;
                bool instanceMatched = null == findDroplet.InstanceIds || findDroplet.InstanceIds.Contains(instance.InstanceID);
                bool indexMatched    = null == findDroplet.Indices || findDroplet.Indices.Contains(instance.InstanceIndex);
                bool stateMatched    = null == findDroplet.States || findDroplet.States.Contains(instance.State);

                if (versionMatched && instanceMatched && indexMatched && stateMatched)
                {
                    var response = new FindDropletResponse(natsClient.UniqueIdentifier, instance)
                    {
                        FileUri = String.Format(CultureInfo.InvariantCulture,
                                                Resources.Agent_Droplets_Fmt, config.LocalIPAddress, config.FilesServicePort),
                        Credentials = config.FilesCredentials.ToArray(),
                    };

                    if (findDroplet.IncludeStats && instance.IsRunning)
                    {
                        response.Stats = new Stats(instance);
                    }

                    natsClient.Publish(reply, response);
                }
            });
        }