diff --git a/src/lib/wm_resource_utils.erl b/src/lib/wm_resource_utils.erl index 762be9e..281fd32 100644 --- a/src/lib/wm_resource_utils.erl +++ b/src/lib/wm_resource_utils.erl @@ -1,6 +1,6 @@ -module(wm_resource_utils). --export([get_ingres_ports_map/1, get_ingres_ports_str/1, get_port_tuples/1]). +-export([get_ingres_ports_map/2, get_ingres_ports_str/1, get_port_tuples/1]). -include("wm_entity.hrl"). -include("wm_log.hrl"). @@ -15,10 +15,10 @@ get_ingres_port_with_proto(Port) -> {error, not_found} end. --spec get_ingres_ports_map([#resource{}]) -> map(). -get_ingres_ports_map([]) -> +-spec get_ingres_ports_map([#resource{}], atom()) -> map(). +get_ingres_ports_map([], _) -> #{}; -get_ingres_ports_map([#resource{name = "ports", properties = Properties} | T]) -> +get_ingres_ports_map([#resource{name = "ports", properties = Properties} | T], KeyType) -> case proplists:get_value(value, Properties) of Value when is_list(Value) -> Ports = string:split(Value, ",", all), @@ -26,7 +26,12 @@ get_ingres_ports_map([#resource{name = "ports", properties = Properties} | T]) - case get_ingres_port_with_proto(Port) of {ok, PortAndProto} -> PortNumberStr = hd(string:split(PortAndProto, "/")), - maps:put(list_to_binary(PortNumberStr), #{}, Map); + case KeyType of + binaries -> + maps:put(list_to_binary(PortNumberStr), #{}, Map); + strings -> + maps:put(PortNumberStr, #{}, Map) + end; {error, not_found} -> Map end @@ -34,16 +39,16 @@ get_ingres_ports_map([#resource{name = "ports", properties = Properties} | T]) - #{}, Ports); _ -> - get_ingres_ports_map(T) + get_ingres_ports_map(T, KeyType) end; -get_ingres_ports_map([_ | T]) -> - get_ingres_ports_map(T). +get_ingres_ports_map([_ | T], KeyType) -> + get_ingres_ports_map(T, KeyType). -spec get_ingres_ports_str([#resource{}]) -> [string()]. get_ingres_ports_str(Resources) -> - Ports = maps:keys(get_ingres_ports_map(Resources)), - string:join(Ports, ","). + Ports = maps:keys(get_ingres_ports_map(Resources, strings)), + lists:flatten(string:join(Ports, ",")). -spec get_port_tuples([#resource{}]) -> {[{string(), integer(), integer()}], []}. get_port_tuples([]) -> diff --git a/src/srv/cloud/wm_virtres_handler.erl b/src/srv/cloud/wm_virtres_handler.erl index 266a75a..cb6f156 100644 --- a/src/srv/cloud/wm_virtres_handler.erl +++ b/src/srv/cloud/wm_virtres_handler.erl @@ -125,7 +125,7 @@ spawn_partition(Job, Remote) -> JobIngresPorts = wm_resource_utils:get_ingres_ports_str(wm_entity:get(request, Job)), ApiPort = integer_to_list(wm_entity:get(api_port, SelfNode)), SshPort = wm_conf:g(ssh_daemon_listen_port, {?DEFAULT_SSH_DAEMON_PORT, integer}), - IngresPorts = JobIngresPorts ++ "," ++ ApiPort ++ "," ++ SshPort, + IngresPorts = JobIngresPorts ++ "," ++ ApiPort ++ "," ++ integer_to_list(SshPort), Options = #{name => PartName, image_name => get_resource_value_property(image, "cloud-image", Job, Remote, fun get_default_image_name/1), diff --git a/src/srv/container/wm_docker.erl b/src/srv/container/wm_docker.erl index a08a6f6..c3b6cd7 100644 --- a/src/srv/container/wm_docker.erl +++ b/src/srv/container/wm_docker.erl @@ -172,7 +172,7 @@ generate_container_json(#job{request = Request}, Porter) -> Term9 = jwalk:set({"HostConfig"}, Term8, get_host_config(Request)), Term10 = jwalk:set({"StdinOnce"}, Term9, false), Term11 = jwalk:set({"VolumesFrom"}, Term10, get_volumes_from()), - Term12 = jwalk:set({"ExposedPorts"}, Term11, wm_resource_utils:get_ingres_ports_map(Request)), + Term12 = jwalk:set({"ExposedPorts"}, Term11, wm_resource_utils:get_ingres_ports_map(Request, binaries)), Term13 = jwalk:set({"WorkingDir"}, Term12, <<"/tmp">>), Term14 = jwalk:set({"AutoRemove"}, Term13, true), Term15 = jwalk:set({"User"}, Term14, <<"root">>),