Github user sjcorbett commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/353#discussion_r21027748
--- Diff:
core/src/main/java/brooklyn/location/access/PortForwardManager.java ---
@@ -20,87 +20,71 @@
import java.util.Collection;
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.basic.ConfigKeys;
import brooklyn.location.Location;
import com.google.common.annotations.Beta;
import com.google.common.net.HostAndPort;
/**
- * Records port mappings against public IP addresses with given
identifiers.
- * <p>
- * To use, create a new authoritative instance (e.g. {@link
PortForwardManagerAuthority}) which will live in one
- * canonical place, then set config to be a client (e.g. {@link
PortForwardManagerClient} which delegates to the
- * primary instance) so the authority is shared among all communicating
parties but only persisted in one place.
- * <p>
- * One Location side (e.g. a software process in a VM) can request ({@link
#acquirePublicPort(String, Location, int)})
- * an unused port on a firewall / public IP address. It may then go on
actually to talk to that firewall/IP to
- * provision the forwarding rule.
- * <p>
- * Subsequently the other side can use this class {@link #lookup(Location,
int)} if it knows the
- * location and private port it wishes to talk to.
- * <p>
+ * Acts as a registry for existing port mappings (e.g. the public
endpoints for accessing specific
+ * ports on private VMs). This could be using DNAT, or iptables
port-forwarding, or Docker port-mapping
+ * via the host, or any other port mapping approach.
+ *
+ * Also controls the allocation of ports via {@link
#acquirePublicPort(String)}
+ * (e.g. for port-mapping with DNAT, then which port to use for the public
side).
+ *
+ * Implementations typically will not know anything about what the
firewall/IP actually is, they just
+ * handle a unique identifier for it.
+ *
+ * To use, see {@link PortForwardManagerLocationResolver}, with code such
as
+ * {@code
managementContext.getLocationRegistry().resolve("portForwardManager(scope=global)")}.
+ *
* Implementations typically will not know anything about what the
firewall/IP actually is, they just handle a
* unique identifier for it. It is recommended, however, to {@link
#recordPublicIpHostname(String, String)} an
* accessible hostname with the identifier. This is required in order to
use {@link #lookup(Location, int)}.
*/
@Beta
-public interface PortForwardManager {
+public interface PortForwardManager extends Location {
- /**
- * Reserves a unique public port on the given publicIpId.
- * <p>
- * Often followed by {@link #associate(String, int, Location, int)}
- * to enable {@link #lookup(Location, int)}.
- */
- public int acquirePublicPort(String publicIpId);
+ public static final ConfigKey<String> SCOPE =
ConfigKeys.newStringConfigKey(
+ "scope",
+ "The scope that this applies to, defaulting to global",
+ "global");
- /** Returns old mapping if it existed, null if it is new. */
- public PortMapping acquirePublicPortExplicit(String publicIpId, int
port);
+ @Beta
+ public static final ConfigKey<Integer>
PORT_FORWARD_MANAGER_STARTING_PORT = ConfigKeys.newIntegerConfigKey(
+ "brooklyn.portForwardManager.startingPort",
+ "The starting port for assigning port numbers, such as for
DNAT",
+ 11000);
- /** Returns the port mapping for a given publicIpId and public port. */
- public PortMapping getPortMappingWithPublicSide(String publicIpId, int
publicPort);
+ public String getScope();
- /** Returns the subset of port mappings associated with a given public
IP ID. */
- public Collection<PortMapping> getPortMappingWithPublicIpId(String
publicIpId);
-
- /** Clears the given port mapping, returning the mapping if there was
one. */
- public PortMapping forgetPortMapping(String publicIpId, int
publicPort);
-
- /** @see #forgetPortMapping(String, int) */
- public boolean forgetPortMapping(PortMapping m);
-
- // -----------------
-
/**
- * Records a public hostname or address to be associated with the
given publicIpId for lookup purposes.
+ * Reserves a unique public port on the given publicIpId.
* <p>
- * Conceivably this may have to be access-location specific.
+ * Often followed by {@link #associate(String, HostAndPort, int)} or
{@link #associate(String, HostAndPort, Location, int)}
+ * to enable {@link #lookup(String, int)} or {@link #lookup(Location,
int)} respectively.
*/
- public void recordPublicIpHostname(String publicIpId, String
hostnameOrPublicIpAddress);
-
- /** Returns a recorded public hostname or address. */
- public String getPublicIpHostname(String publicIpId);
-
- /** Clears a previous call to {@link #recordPublicIpHostname(String,
String)}. */
- public boolean forgetPublicIpHostname(String publicIpId);
+ public int acquirePublicPort(String publicIpId);
/**
- * Returns the public host and port for use accessing the given
mapping.
+ * Records a location and private port against a public endpoint (ip
and port),
+ * to support {@link #lookup(Location, int)}.
* <p>
- * Conceivably this may have to be access-location specific.
+ * Superfluous if {@link #acquirePublicPort(String, Location, int)}
was used,
+ * but strongly recommended if {@link
#acquirePublicPortExplicit(String, int)} was used
+ * e.g. if the location is not known ahead of time.
*/
- public HostAndPort getPublicHostAndPort(PortMapping m);
+ public void associate(String publicIpId, HostAndPort publicEndpoint,
Location l, int privatePort);
- // -----------------
-
/**
- * Reserves a unique public port for the purpose of forwarding to the
given target,
- * associated with a given location for subsequent lookup purpose.
- * <p>
- * If already allocated, returns the previously allocated.
+ * Records a mapping for pubilcIpId:privatePort to a public endpoint,
such that it can
--- End diff --
Typo pubilcIpId
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---