Mercurial > hg > release > thermostat-0.11
changeset 110:ed7314b03796
Remove NetworkInfo
Reviewed-by: vanaltj
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-March/000290.html
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Fri, 09 Mar 2012 11:55:41 -0500 |
parents | 9e701016aeca |
children | 528b79d1ee35 |
files | agent/src/main/java/com/redhat/thermostat/backend/system/NetworkInfoBuilder.java agent/src/main/java/com/redhat/thermostat/backend/system/SystemBackend.java agent/src/test/java/com/redhat/thermostat/backend/system/NetworkInfoBuilderTest.java client/src/main/java/com/redhat/thermostat/client/ui/HostOverviewController.java common/src/main/java/com/redhat/thermostat/common/NetworkInfo.java |
diffstat | 5 files changed, 80 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/agent/src/main/java/com/redhat/thermostat/backend/system/NetworkInfoBuilder.java Fri Mar 09 11:13:19 2012 -0500 +++ b/agent/src/main/java/com/redhat/thermostat/backend/system/NetworkInfoBuilder.java Fri Mar 09 11:55:41 2012 -0500 @@ -41,12 +41,13 @@ import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; +import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import com.redhat.thermostat.common.NetworkInfo; import com.redhat.thermostat.common.NetworkInterfaceInfo; import com.redhat.thermostat.common.utils.LoggingUtils; @@ -54,8 +55,8 @@ private static final Logger logger = LoggingUtils.getLogger(NetworkInfoBuilder.class); - public static NetworkInfo build() { - NetworkInfo info = new NetworkInfo(); + public static List<NetworkInterfaceInfo> build() { + List<NetworkInterfaceInfo> info = new ArrayList<NetworkInterfaceInfo>(); try { Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface iface : Collections.list(ifaces)) { @@ -67,7 +68,7 @@ iInfo.setIp6Addr(fixAddr(addr.toString())); } } - info.addNetworkInterfaceInfo(iInfo); + info.add(iInfo); } } catch (SocketException e) { logger.log(Level.WARNING, "error enumerating network interfaces");
--- a/agent/src/main/java/com/redhat/thermostat/backend/system/SystemBackend.java Fri Mar 09 11:13:19 2012 -0500 +++ b/agent/src/main/java/com/redhat/thermostat/backend/system/SystemBackend.java Fri Mar 09 11:55:41 2012 -0500 @@ -146,7 +146,7 @@ @Override public void run() { store(new CpuStatConverter().cpuStatToChunk(new CpuStatBuilder().build())); - for (NetworkInterfaceInfo info: NetworkInfoBuilder.build().getInterfaces()) { + for (NetworkInterfaceInfo info: NetworkInfoBuilder.build()) { store(new NetworkInterfaceInfoConverter().networkInfoToChunk(info)); } store(new MemoryStatConverter().memoryStatToChunk(new MemoryStatBuilder().build()));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/agent/src/test/java/com/redhat/thermostat/backend/system/NetworkInfoBuilderTest.java Fri Mar 09 11:55:41 2012 -0500 @@ -0,0 +1,67 @@ +/* + * Copyright 2012 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.backend.system; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; + +import com.redhat.thermostat.common.NetworkInterfaceInfo; + +public class NetworkInfoBuilderTest { + + @Test + public void testBuilder() { + + List<NetworkInterfaceInfo> info = NetworkInfoBuilder.build(); + assertNotNull(info); + for (NetworkInterfaceInfo iface: info) { + assertNotNull(iface); + assertNotNull(iface.getInterfaceName()); + if (iface.getIp4Addr() != null) { + // ipv4 address matches the form XX.XX.XX.XX + assertTrue(iface.getIp4Addr().matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}")); + } + // TODO check for sane ipv6 address + } + + } + +}
--- a/client/src/main/java/com/redhat/thermostat/client/ui/HostOverviewController.java Fri Mar 09 11:13:19 2012 -0500 +++ b/client/src/main/java/com/redhat/thermostat/client/ui/HostOverviewController.java Fri Mar 09 11:55:41 2012 -0500 @@ -59,7 +59,6 @@ import com.redhat.thermostat.client.AsyncUiFacade; import com.redhat.thermostat.client.locale.LocaleResources; import com.redhat.thermostat.common.HostInfo; -import com.redhat.thermostat.common.NetworkInfo; import com.redhat.thermostat.common.NetworkInterfaceInfo; import com.redhat.thermostat.common.dao.HostInfoConverter; import com.redhat.thermostat.common.dao.HostRef; @@ -103,19 +102,19 @@ new NetworkTableModelUpdater().execute(); } - private class NetworkTableModelUpdater extends SwingWorker<NetworkInfo, Void> { + private class NetworkTableModelUpdater extends SwingWorker<List<NetworkInterfaceInfo>, Void> { @Override - protected NetworkInfo doInBackground() throws Exception { + protected List<NetworkInterfaceInfo> doInBackground() throws Exception { return getNetworkInfo(); } - private NetworkInfo getNetworkInfo() { - NetworkInfo network = new NetworkInfo(); + private List<NetworkInterfaceInfo> getNetworkInfo() { + List<NetworkInterfaceInfo> network = new ArrayList<NetworkInterfaceInfo>(); DBCursor cursor = networkInfoCollection.find(new BasicDBObject("agent-id", hostRef.getAgentId())); while (cursor.hasNext()) { NetworkInterfaceInfo info = new NetworkInterfaceInfoConverter().fromDBObject(cursor.next()); - network.addNetworkInterfaceInfo(info); + network.add(info); } return network; @@ -125,10 +124,10 @@ protected void done() { List<Object[]> data = new ArrayList<Object[]>(); - NetworkInfo networkInfo; + List<NetworkInterfaceInfo> networkInfo; try { networkInfo = get(); - for (NetworkInterfaceInfo info: networkInfo.getInterfaces()) { + for (NetworkInterfaceInfo info: networkInfo) { String ifaceName = info.getInterfaceName(); String ipv4 = info.getIp4Addr(); String ipv6 = info.getIp6Addr();
--- a/common/src/main/java/com/redhat/thermostat/common/NetworkInfo.java Fri Mar 09 11:13:19 2012 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * Copyright 2012 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.common; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public class NetworkInfo { - - private Map<String, NetworkInterfaceInfo> interfaces = new HashMap<String, NetworkInterfaceInfo>(); - - public NetworkInfo() { - - } - - public synchronized void addNetworkInterfaceInfo(NetworkInterfaceInfo info) { - interfaces.put(info.getInterfaceName(), info); - } - - public synchronized void removeNetworkInterfaceInfo(NetworkInterfaceInfo info) { - interfaces.remove(info.getInterfaceName()); - } - - public Collection<NetworkInterfaceInfo> getInterfaces() { - return Collections.unmodifiableCollection(interfaces.values()); - } -}