Class PortMapping


  • public class PortMapping
    extends Object
    Entity holding port mappings which can be set through the configuration.
    Since:
    04.04.14
    Author:
    roland
    • Constructor Detail

      • PortMapping

        public PortMapping​(List<String> portMappings,
                           Properties projProperties)
        Create the mapping from a configuration. The configuration is list of port mapping specifications which has the format used by docker for port mapping (i.e. host_ip:host_port:container_port)
        • The "host_ip" part is optional. If not given, the all interfaces are used
        • If "host_port" is non numeric it is taken as a variable name. If this variable is given as value in variables, this number is used as host port. If no numeric value is given, it is considered to be filled with the real, dynamically created port value when updateProperties(Map) is called
        Parameters:
        portMappings - a list of configuration strings where each string hast the format host_ip:host_port:container_port. If the host-port is non-numeric it is assumed to be a variable (which later might be filled in with the dynamically created port).
        projProperties - project properties
        Throws:
        IllegalArgumentException - if the format doesn't fit
    • Method Detail

      • needsPropertiesUpdate

        public boolean needsPropertiesUpdate()
        Check whether property needs updates for dynamically obtained host ports and ip adresses.
        Returns:
        true if any property are used which need to be filled in, false otherwise
      • getContainerPorts

        public Set<String> getContainerPorts()
        Returns:
        Set of all mapped container ports
      • updateProperties

        public void updateProperties​(Map<String,​Container.PortBinding> dockerObtainedDynamicBindings)
        Update variable-to-port mappings with dynamically obtained ports and host ips. This should only be called once after this dynamically allocated parts has been be obtained.
        Parameters:
        dockerObtainedDynamicBindings - keys are the container ports, values are the dynamically mapped host ports and host ips.
      • toJson

        public com.google.gson.JsonArray toJson()
        Return the content of the mapping as an array with all specifications as given
        Returns:
        port mappings as JSON array or null if no mappings exist