Mercurial > hg > release > thermostat-1.4
changeset 1531:cbbf264033b4
Add an AgentInformation.getRequestQueueAddress() method
Reviewed-by: jerboaa
line wrap: on
line diff
--- a/client/command/src/main/java/com/redhat/thermostat/client/command/cli/PingCommand.java Tue Oct 28 14:11:59 2014 -0400 +++ b/client/command/src/main/java/com/redhat/thermostat/client/command/cli/PingCommand.java Tue Oct 28 14:12:32 2014 -0400 @@ -137,11 +137,9 @@ ServiceReference agentInfoDaoRef = context.getServiceReference(AgentInfoDAO.class.getName()); requireNonNull(agentInfoDaoRef, translator.localize(LocaleResources.COMMAND_PING_NO_AGENT_INFO_DAO)); AgentInfoDAO agentInfoDao = (AgentInfoDAO) context.getService(agentInfoDaoRef); - String address = agentInfoDao.getAgentInformation(targetHostRef).getConfigListenAddress(); + InetSocketAddress target = agentInfoDao.getAgentInformation(targetHostRef).getRequestQueueAddress(); context.ungetService(agentInfoDaoRef); - String [] host = address.split(":"); - InetSocketAddress target = new InetSocketAddress(host[0], Integer.parseInt(host[1])); Request ping = new Request(RequestType.RESPONSE_EXPECTED, target); ping.setParameter(Request.ACTION, PING_ACTION_NAME); ping.setReceiver("com.redhat.thermostat.agent.command.internal.PingReceiver");
--- a/killvm/common/src/main/java/com/redhat/thermostat/killvm/common/KillVMRequest.java Tue Oct 28 14:11:59 2014 -0400 +++ b/killvm/common/src/main/java/com/redhat/thermostat/killvm/common/KillVMRequest.java Tue Oct 28 14:12:32 2014 -0400 @@ -55,10 +55,8 @@ } public void sendKillVMRequestToAgent(VmRef vmRef, AgentInfoDAO agentInfoDAO, RequestResponseListener listener) { - String address = agentInfoDAO.getAgentInformation(vmRef.getHostRef()).getConfigListenAddress(); + InetSocketAddress target = agentInfoDAO.getAgentInformation(vmRef.getHostRef()).getRequestQueueAddress(); - String [] host = address.split(":"); - InetSocketAddress target = new InetSocketAddress(host[0], Integer.parseInt(host[1])); Request murderer = getKillRequest(target); murderer.setParameter(Request.ACTION, CMD_CHANNEL_ACTION_NAME); murderer.setParameter("vm-pid", String.valueOf(vmRef.getPid()));
--- a/killvm/common/src/test/java/com/redhat/thermostat/killvm/common/KillVMRequestTest.java Tue Oct 28 14:11:59 2014 -0400 +++ b/killvm/common/src/test/java/com/redhat/thermostat/killvm/common/KillVMRequestTest.java Tue Oct 28 14:12:32 2014 -0400 @@ -78,7 +78,7 @@ when(vm.getPid()).thenReturn(123456); AgentInformation info = mock(AgentInformation.class); - when(info.getConfigListenAddress()).thenReturn("0.0.42.42:42"); + when(info.getRequestQueueAddress()).thenReturn(new InetSocketAddress("0.0.42.42", 42)); when(agentDAO.getAgentInformation(ref)).thenReturn(info);
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/model/AgentInformation.java Tue Oct 28 14:11:59 2014 -0400 +++ b/storage/core/src/main/java/com/redhat/thermostat/storage/model/AgentInformation.java Tue Oct 28 14:12:32 2014 -0400 @@ -36,6 +36,7 @@ package com.redhat.thermostat.storage.model; +import java.net.InetSocketAddress; import java.util.Objects; import com.redhat.thermostat.storage.core.Entity; @@ -98,6 +99,13 @@ this.address = address; } + public InetSocketAddress getRequestQueueAddress() { + String address = getConfigListenAddress(); + String [] host = address.split(":"); + InetSocketAddress target = new InetSocketAddress(host[0], Integer.parseInt(host[1])); + return target; + } + @Override public String toString() { return "agent " + getAgentId();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/storage/core/src/test/java/com/redhat/thermostat/storage/model/AgentInformationTest.java Tue Oct 28 14:12:32 2014 -0400 @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2014 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.storage.model; + +import static org.junit.Assert.assertEquals; + +import java.net.InetSocketAddress; + +import org.junit.Test; + +public class AgentInformationTest { + + @Test + public void configurationAddressIsParsedCorrectly() { + final String HOST = "example.com"; + final int PORT = 80; + + AgentInformation info = new AgentInformation(); + info.setConfigListenAddress(HOST + ":" + PORT); + + assertEquals(new InetSocketAddress(HOST, PORT), info.getRequestQueueAddress()); + } +}
--- a/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/collector/impl/ThreadMXBeanCollector.java Tue Oct 28 14:11:59 2014 -0400 +++ b/thread/client-common/src/main/java/com/redhat/thermostat/thread/client/common/collector/impl/ThreadMXBeanCollector.java Tue Oct 28 14:12:32 2014 -0400 @@ -90,10 +90,7 @@ Request createRequest() { HostRef targetHostRef = ref.getHostRef(); - String address = agentDao.getAgentInformation(targetHostRef).getConfigListenAddress(); - String [] host = address.split(":"); - - InetSocketAddress target = new InetSocketAddress(host[0], Integer.parseInt(host[1])); + InetSocketAddress target = agentDao.getAgentInformation(targetHostRef).getRequestQueueAddress(); Request harvester = new Request(RequestType.RESPONSE_EXPECTED, target); harvester.setReceiver(HarvesterCommand.RECEIVER);
--- a/vm-gc/remote-collector-client-common/src/main/java/com/redhat/thermostat/gc/remote/common/GCRequest.java Tue Oct 28 14:11:59 2014 -0400 +++ b/vm-gc/remote-collector-client-common/src/main/java/com/redhat/thermostat/gc/remote/common/GCRequest.java Tue Oct 28 14:12:32 2014 -0400 @@ -60,11 +60,8 @@ HostRef targetHostRef = vm.getHostRef(); - String address = agentDAO.getAgentInformation(targetHostRef).getConfigListenAddress(); - String [] host = address.split(":"); - - InetSocketAddress target = new InetSocketAddress(host[0], Integer.parseInt(host[1])); - Request gcRequest = createRequest(target); + InetSocketAddress address = agentDAO.getAgentInformation(targetHostRef).getRequestQueueAddress(); + Request gcRequest = createRequest(address); gcRequest.setReceiver(GCAction.RECEIVER);
--- a/vm-gc/remote-collector-client-common/src/test/java/com/redhat/thermostat/gc/remote/common/GCRequestTest.java Tue Oct 28 14:11:59 2014 -0400 +++ b/vm-gc/remote-collector-client-common/src/test/java/com/redhat/thermostat/gc/remote/common/GCRequestTest.java Tue Oct 28 14:12:32 2014 -0400 @@ -79,7 +79,7 @@ when(vm.getPid()).thenReturn(123456); AgentInformation info = mock(AgentInformation.class); - when(info.getConfigListenAddress()).thenReturn("0.0.42.42:42"); + when(info.getRequestQueueAddress()).thenReturn(new InetSocketAddress("0.0.42.42", 42)); when(agentDAO.getAgentInformation(ref)).thenReturn(info);
--- a/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/DumpHeapHelper.java Tue Oct 28 14:11:59 2014 -0400 +++ b/vm-heap-analysis/command/src/main/java/com/redhat/thermostat/vm/heap/analysis/command/internal/DumpHeapHelper.java Tue Oct 28 14:12:32 2014 -0400 @@ -90,10 +90,7 @@ int pid = info.getVmPid(); HostRef targetHostRef = reference.getHostRef(); - String address = agentInfoDAO.getAgentInformation(targetHostRef).getConfigListenAddress(); - - String [] host = address.split(":"); - InetSocketAddress target = new InetSocketAddress(host[0], Integer.parseInt(host[1])); + InetSocketAddress target = agentInfoDAO.getAgentInformation(targetHostRef).getRequestQueueAddress(); Request req = new Request(RequestType.RESPONSE_EXPECTED, target); req.setReceiver(RECEIVER_CLASS_NAME); req.setParameter(Request.ACTION, CMD_CHANNEL_ACTION_NAME);
--- a/vm-heap-analysis/command/src/test/java/com/redhat/thermostat/vm/heap/analysis/command/internal/DumpHeapHelperTest.java Tue Oct 28 14:11:59 2014 -0400 +++ b/vm-heap-analysis/command/src/test/java/com/redhat/thermostat/vm/heap/analysis/command/internal/DumpHeapHelperTest.java Tue Oct 28 14:12:32 2014 -0400 @@ -82,7 +82,7 @@ HostRef host = mock(HostRef.class); AgentInformation agentInfo = mock(AgentInformation.class); - when(agentInfo.getConfigListenAddress()).thenReturn("test:123"); + when(agentInfo.getRequestQueueAddress()).thenReturn(new InetSocketAddress("test", 123)); agentInfoDao = mock(AgentInfoDAO.class); when(agentInfoDao.getAgentInformation(host)).thenReturn(agentInfo);
--- a/vm-jmx/client-core/src/main/java/com/redhat/thermostat/vm/jmx/client/core/internal/JmxToggleNotificationRequest.java Tue Oct 28 14:11:59 2014 -0400 +++ b/vm-jmx/client-core/src/main/java/com/redhat/thermostat/vm/jmx/client/core/internal/JmxToggleNotificationRequest.java Tue Oct 28 14:12:32 2014 -0400 @@ -75,10 +75,7 @@ public void sendEnableNotificationsRequestToAgent(VmRef vm, boolean enable) { HostRef targetHostRef = vm.getHostRef(); - String address = agentDAO.getAgentInformation(targetHostRef).getConfigListenAddress(); - String[] host = address.split(":"); - - InetSocketAddress target = new InetSocketAddress(host[0], Integer.parseInt(host[1])); + InetSocketAddress target = agentDAO.getAgentInformation(targetHostRef).getRequestQueueAddress(); Request req = new Request(RequestType.RESPONSE_EXPECTED, target); req.setReceiver(JmxCommand.RECEIVER);
--- a/vm-jmx/client-core/src/test/java/com/redhat/thermostat/vm/jmx/client/core/internal/JmxToggleNotificationRequestTest.java Tue Oct 28 14:11:59 2014 -0400 +++ b/vm-jmx/client-core/src/test/java/com/redhat/thermostat/vm/jmx/client/core/internal/JmxToggleNotificationRequestTest.java Tue Oct 28 14:12:32 2014 -0400 @@ -95,7 +95,7 @@ agentDAO = mock(AgentInfoDAO.class); agentInfo = mock(AgentInformation.class); - when(agentInfo.getConfigListenAddress()).thenReturn(HOST + ":" + PORT); + when(agentInfo.getRequestQueueAddress()).thenReturn(new InetSocketAddress(HOST, PORT)); when(agentDAO.getAgentInformation(host)).thenReturn(agentInfo); factory = mock(JmxToggleResponseListenerFactory.class);