Merge "Provide callback feature when modal is visible"
authorAndrew Kim <andrekim@cisco.com>
Thu, 23 Jan 2014 23:33:23 +0000 (23:33 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 23 Jan 2014 23:33:23 +0000 (23:33 +0000)
opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java

index 83db4144007963a94e503a33345b1e641eadc2a0..e34eb329330d2e1b30ee72aac6950f2084894777 100644 (file)
@@ -13,6 +13,8 @@ import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.net.UnknownHostException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.Enumeration;
@@ -95,9 +97,20 @@ public class ClusterManager implements IClusterServices {
         InetAddress gossipRouterAddress = null;
         String supernodes_list = System.getProperty("supernodes",
                 loopbackAddress);
-        StringBuilder sanitized_supernodes_list = new StringBuilder();
+        /*
+         * Check the environment for the "container" variable, if this is set
+         * and is equal to "lxc", then ODL is running inside an lxc
+         * container, and address resolution of supernodes will be modified
+         * accordingly.
+         */
+        boolean inContainer = "lxc".equals(System.getenv("container"));
+        StringBuffer sanitized_supernodes_list = new StringBuffer();
         List<InetAddress> myAddresses = new ArrayList<InetAddress>();
 
+        if (inContainer) {
+            logger.trace("DOCKER: Resolving supernode host names using docker container semantics");
+        }
+
         StringTokenizer supernodes = new StringTokenizer(supernodes_list, ":");
         if (supernodes.hasMoreTokens()) {
             // Populate the list of my addresses
@@ -131,6 +144,34 @@ public class ClusterManager implements IClusterServices {
             }
             host = host_port.nextToken();
             InetAddress hostAddr;
+            /*
+             * If we are in a container and the hostname begins with a '+', this is
+             * an indication that we should resolve this host name in the context
+             * of a docker container.
+             *
+             * Specifically this means:
+             * '+self'   : self reference and the host will be mapped to the value of
+             *             HOSTNAME in the environment
+             * '+<name>' : references another container by its name. The docker established
+             *             environment variables will be used to resolve the host to an
+             *             IP address.
+             */
+            if (inContainer && host != null && host.charAt(0) == '+') {
+                if ("+self".equals(host)) {
+                    host = System.getenv("HOSTNAME");
+                } else {
+                    String link = System.getenv(host.substring(1).toUpperCase() + "_PORT");
+                    if (link != null) {
+                        try {
+                            host = new URI(link).getHost();
+                        } catch (URISyntaxException e) {
+                            logger.error("DOCKER: Unable to translate container reference ({}) to host IP Address, will attempt using normal host name",
+                                host.substring(1));
+                        }
+                    }
+                }
+            }
+
             try {
                 hostAddr = InetAddress.getByName(host);
             } catch (UnknownHostException ue) {