Exemplo n.º 1
0
        /// <summary>
        /// The handler for dea.find.droplet message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="reply">The reply.</param>
        /// <param name="subject">The subject.</param>
        private void DeaFindDropletHandler(string message, string reply, string subject)
        {
            if (this.shuttingDown)
            {
                return;
            }

            DeaFindDropletMessageRequest pmessage = new DeaFindDropletMessageRequest();
            pmessage.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(message));

            Logger.Debug(Strings.DeaReceivedFindDroplet, message);

            this.droplets.ForEach(delegate(DropletInstance instance)
            {
                try
                {
                    instance.Lock.EnterReadLock();

                    bool droplet_match = instance.Properties.DropletId == pmessage.DropletId;
                    bool version_match = pmessage.Version == null || pmessage.Version == instance.Properties.Version;
                    bool instace_match = pmessage.InstanceIds == null || pmessage.InstanceIds.Contains(instance.Properties.InstanceId);
                    bool index_match = pmessage.Indexes == null || pmessage.Indexes.Contains(instance.Properties.InstanceIndex);
                    bool state_match = pmessage.States == null || pmessage.States.Contains(instance.Properties.State);

                    DeaFindDropletMessageResponse response = new DeaFindDropletMessageResponse();

                    if (droplet_match && version_match && instace_match && index_match && state_match)
                    {
                        response.DeaId = UUID;
                        response.Version = instance.Properties.Version;
                        response.DropletId = instance.Properties.DropletId;
                        response.InstanceId = instance.Properties.InstanceId;
                        response.Index = instance.Properties.InstanceIndex;
                        response.State = instance.Properties.State;
                        response.StateTimestamp = instance.Properties.StateTimestamp;
                        response.FileUri = string.Format(CultureInfo.InvariantCulture, Strings.HttpDroplets, Host, this.directoryServerPort);

                        if (pmessage.Path != null)
                        {
                            string uri = string.Format(
                                CultureInfo.InvariantCulture,
                                "http://{0}/instance_paths/{1}?path={2}&timestamp={3}",
                                this.ExternalHost,
                                Uri.EscapeUriString(response.InstanceId),
                                Uri.EscapeUriString(pmessage.Path),
                                RubyCompatibility.DateTimeToEpochSeconds(DateTime.Now));

                            response.FileUriV2 = DEAUtilities.GetHmacedUri(uri, this.directoryServerHmacKey, new string[] { "path", "timestamp" }).ToString();
                        }
                        else
                        {
                            string uri = string.Format(
                                CultureInfo.InvariantCulture,
                                "http://{0}/instance_paths/{1}?path&timestamp={2}",
                                this.ExternalHost,
                                Uri.EscapeUriString(response.InstanceId),
                                RubyCompatibility.DateTimeToEpochSeconds(DateTime.Now));

                            response.FileUriV2 = DEAUtilities.GetHmacedUri(uri, this.directoryServerHmacKey, new string[] { "path", "timestamp" }).ToString();
                        }

                        Logger.Debug(Strings.DebugFileUriV2Path, response.FileUri);

                        response.FileAuth = new string[] { "una", "doua" };
                        response.Staged = instance.Properties.Staged;
                        response.DebugIP = instance.Properties.DebugIP;
                        response.DebugPort = instance.Properties.DebugPort;

                        if (pmessage.IncludeStates && instance.Properties.State == DropletInstanceState.Running)
                        {
                            response.Stats = instance.GenerateDropletStatusMessage();
                            response.Stats.Host = Host;
                            response.Stats.Cores = DEAUtilities.NumberOfCores();
                        }

                        this.deaReactor.SendReply(reply, response.SerializeToJson());
                    }
                }
                finally
                {
                    instance.Lock.ExitReadLock();
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// The handler for dea.find.droplet message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="reply">The reply.</param>
        /// <param name="subject">The subject.</param>
        private void DeaFindDropletHandler(string message, string reply, string subject)
        {
            if (this.shuttingDown)
            {
                return;
            }

            DeaFindDropletMessageRequest pmessage = new DeaFindDropletMessageRequest();
            pmessage.FromJsonIntermediateObject(JsonConvertibleObject.DeserializeFromJson(message));

            Logger.Debug(Strings.DeaReceivedFindDroplet, message);

            this.droplets.ForEach(delegate(DropletInstance instance)
            {
                try
                {
                    instance.Lock.EnterReadLock();

                    bool droplet_match = instance.Properties.DropletId == pmessage.DropletId;
                    bool version_match = pmessage.Version == null || pmessage.Version == instance.Properties.Version;
                    bool instace_match = pmessage.InstanceIds == null || pmessage.InstanceIds.Contains(instance.Properties.InstanceId);
                    bool index_match = pmessage.Indexes == null || pmessage.Indexes.Contains(instance.Properties.InstanceIndex);
                    bool state_match = pmessage.States == null || pmessage.States.Contains(instance.Properties.State);

                    DeaFindDropletMessageResponse response = new DeaFindDropletMessageResponse();

                    if (droplet_match && version_match && instace_match && index_match && state_match)
                    {
                        response.DeaId = UUID;
                        response.Version = instance.Properties.Version;
                        response.DropletId = instance.Properties.DropletId;
                        response.InstanceId = instance.Properties.InstanceId;
                        response.Index = instance.Properties.InstanceIndex;
                        response.State = instance.Properties.State;
                        response.StateTimestamp = instance.Properties.StateTimestamp;
                        response.FileUri = string.Format(CultureInfo.InvariantCulture, Strings.HttpDroplets, Host, this.fileViewer.Port);
                        response.FileAuth = this.fileViewer.Credentials;
                        response.Staged = instance.Properties.Staged;
                        response.DebugIP = instance.Properties.DebugIP;
                        response.DebugPort = instance.Properties.DebugPort;

                        if (pmessage.IncludeStates && instance.Properties.State == DropletInstanceState.Running)
                        {
                            response.Stats = instance.GenerateDropletStatusMessage();
                            response.Stats.Host = Host;
                            response.Stats.Cores = DEAUtilities.NumberOfCores();
                        }

                        this.deaReactor.SendReply(reply, response.SerializeToJson());
                    }
                }
                finally
                {
                    instance.Lock.ExitReadLock();
                }
            });
        }