changeset 1543:87c0133216f6

PR2056: AgentInformation.getRequestQueueAddress() should handle IPv6 addresse Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2014-November/011534.html
author Omair Majid <omajid@redhat.com>
date Thu, 13 Nov 2014 11:38:01 -0500
parents f2dcec9f38e1
children d318a5be8867
files distribution/config/agent.properties storage/core/src/main/java/com/redhat/thermostat/storage/model/AgentInformation.java storage/core/src/test/java/com/redhat/thermostat/storage/model/AgentInformationTest.java
diffstat 3 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/distribution/config/agent.properties	Thu Nov 13 11:36:25 2014 -0500
+++ b/distribution/config/agent.properties	Thu Nov 13 11:38:01 2014 -0500
@@ -6,6 +6,8 @@
 # requests from the client will listen for connections on the address
 # configured here.
 # If this is removed or commented out, the default port is 127.0.0.1:12000
+# If this includes an IPv6 address, enclose it in [ and ] like:
+# [1fff:0:a88:85a3::ac1f]:12000
 CONFIG_LISTEN_ADDRESS=127.0.0.1:12000
 
 # Connection URL to storage. This can be overridden with the -d option
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/model/AgentInformation.java	Thu Nov 13 11:36:25 2014 -0500
+++ b/storage/core/src/main/java/com/redhat/thermostat/storage/model/AgentInformation.java	Thu Nov 13 11:38:01 2014 -0500
@@ -37,8 +37,11 @@
 package com.redhat.thermostat.storage.model;
 
 import java.net.InetSocketAddress;
+import java.util.List;
 import java.util.Objects;
 
+import com.redhat.thermostat.common.utils.HostPortPair;
+import com.redhat.thermostat.common.utils.HostPortsParser;
 import com.redhat.thermostat.storage.core.Entity;
 import com.redhat.thermostat.storage.core.Persist;
 
@@ -101,8 +104,11 @@
 
     public InetSocketAddress getRequestQueueAddress() {
         String address = getConfigListenAddress();
-        String [] host = address.split(":");
-        InetSocketAddress target = new InetSocketAddress(host[0], Integer.parseInt(host[1]));
+        HostPortsParser parser = new HostPortsParser(address);
+        parser.parse();
+        List<HostPortPair> result = parser.getHostsPorts();
+        HostPortPair hostAndPort = result.get(0);
+        InetSocketAddress target = new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort());
         return target;
     }
 
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/model/AgentInformationTest.java	Thu Nov 13 11:36:25 2014 -0500
+++ b/storage/core/src/test/java/com/redhat/thermostat/storage/model/AgentInformationTest.java	Thu Nov 13 11:38:01 2014 -0500
@@ -54,4 +54,15 @@
 
         assertEquals(new InetSocketAddress(HOST, PORT), info.getRequestQueueAddress());
     }
+
+    @Test
+    public void configurationIPv6AddressIsParsedCorrectly() {
+        final String HOST = "[1fff:0:a88:85a3::ac1f]";
+        final int PORT = 80;
+
+        AgentInformation info = new AgentInformation();
+        info.setConfigListenAddress(HOST + ":" + PORT);
+
+        assertEquals(new InetSocketAddress(HOST, PORT), info.getRequestQueueAddress());
+    }
 }