public string GenerateEndpointCreationNotificationMsg(Manifest cart, Endpoint endpoint, string privateIpValue, string publicPortValue)
        {

            Dictionary<string, object> endpointCreateHash = new Dictionary<string, object>()
            {
                { "cartridge_name", string.Format("{0}-{1}", cart.Name, cart.Version) },
                { "external_address", NodeConfig.Values["PUBLIC_IP"] },
                { "external_port", publicPortValue },
                { "internal_address", privateIpValue },
                { "internal_port", endpoint.PrivatePort },
                { "protocols", endpoint.Protocols },
                { "description", endpoint.Description },
                { "type", new string[0] }
            };

            if (cart.Categories.Contains("web_framework"))
            {
                endpointCreateHash["type"] = new string[] { "web_framework" };
            }
            else if (cart.Categories.Contains("database"))
            {
                endpointCreateHash["type"] = new string[] { "database" };
            }
            else if (cart.Categories.Contains("plugin"))
            {
                endpointCreateHash["type"] = new string[] { "plugin" };
            }
            else
            {
                endpointCreateHash["type"] = new string[] { "other" };
            }

            if (endpoint.Mappings != null)
            {
                endpointCreateHash["mappings"] = endpoint.Mappings.Select(m =>
                {
                    return new Dictionary<string, string>()
                    {
                        { "frontend", m.Frontend },
                        { "backend", m.Backend }
                    };
                }).ToArray();
            }

            return string.Format("NOTIFY_ENDPOINT_CREATE: {0}\n", JsonConvert.SerializeObject(endpointCreateHash));
        }
Example #2
0
        public static Endpoint FromDescriptor(dynamic spec, string tag)
        {
            Endpoint endpoint = new Endpoint();
            endpoint.PrivateIpName = spec.ContainsKey("Private-IP-Name") ? Endpoint.BuildName(tag, spec["Private-IP-Name"]) : null;
            endpoint.PrivatePortName = spec.ContainsKey("Private-Port-Name") ? Endpoint.BuildName(tag, spec["Private-Port-Name"]) : null;
            endpoint.PrivatePort = spec.ContainsKey("Private-Port") ? spec["Private-Port"] : null;
            endpoint.PublicPortName = spec.ContainsKey("Public-Port-Name") ? Endpoint.BuildName(tag, spec["Public-Port-Name"]) : null;
            endpoint.WebsocketPortName = spec.ContainsKey("WebSocket-Port-Name") ? Endpoint.BuildName(tag, spec["WebSocket-Port-Name"]) : null;
            endpoint.WebsocketPort = spec.ContainsKey("WebSocket-Port") ? spec["WebSocket-Port"] : null;
            endpoint.Options = spec.ContainsKey("Options") ? spec["Options"] : null;
            endpoint.Description = spec.ContainsKey("Description") ? spec["Description"] : null;
            endpoint.Protocols = spec.ContainsKey("Protocols") ? ((List<object>)spec["Protocols"]).Select(p => p.ToString()).ToArray() : new string[0];
            if (((Dictionary<object, object>)spec).ContainsKey("Mappings"))
            {
                foreach (dynamic c in spec["Mappings"])
                {
                    endpoint.Mappings.Add(Mapping.FromDescriptor(c));
                }
            }

            return endpoint;
        }