|
From: <jt...@hy...> - 2007-03-13 00:22:52
|
Author: jtravis Date: 2007-03-12 16:22:47 -0800 (Mon, 12 Mar 2007) New Revision: 3719 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=3719 Added: trunk/src/org/hyperic/hq/common/server/session/GUIDGenerator.java Modified: trunk/src/org/hyperic/hq/common/server/session/ServerConfigManagerEJBImpl.java Log: Fix build problems by moving sigar stuff to a non ejb-impl class Added: trunk/src/org/hyperic/hq/common/server/session/GUIDGenerator.java =================================================================== --- trunk/src/org/hyperic/hq/common/server/session/GUIDGenerator.java (rev 0) +++ trunk/src/org/hyperic/hq/common/server/session/GUIDGenerator.java 2007-03-13 00:22:47 UTC (rev 3719) @@ -0,0 +1,80 @@ +/* + * NOTE: This copyright does *not* cover user programs that use HQ + * program services by normal system calls through the application + * program interfaces provided as part of the Hyperic Plug-in Development + * Kit or the Hyperic Client Development Kit - this is merely considered + * normal use of the program, and does *not* fall under the heading of + * "derived work". + * + * Copyright (C) [2004, 2005, 2006], Hyperic, Inc. + * This file is part of HQ. + * + * HQ is free software; you can redistribute it and/or modify + * it under the terms version 2 of the GNU General Public License as + * published by the Free Software Foundation. This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + */ +package org.hyperic.hq.common.server.session; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hyperic.sigar.NetFlags; +import org.hyperic.sigar.NetInterfaceConfig; +import org.hyperic.sigar.Sigar; +import org.safehaus.uuid.EthernetAddress; +import org.safehaus.uuid.UUIDGenerator; + +class GUIDGenerator { + private static final Log _log = LogFactory.getLog(GUIDGenerator.class); + + static String createGUID() { + Sigar sigar = null; + + try { + EthernetAddress eAddr; + sigar = new Sigar(); + String[] ifaces = sigar.getNetInterfaceList(); + String hwaddr = null; + + for (int i=0; i<ifaces.length; i++) { + NetInterfaceConfig cfg = + sigar.getNetInterfaceConfig(ifaces[i]); + + if (NetFlags.LOOPBACK_ADDRESS.equals(cfg.getAddress()) || + (cfg.getFlags() & NetFlags.IFF_LOOPBACK) != 0 || + NetFlags.NULL_HWADDR.equals(cfg.getHwaddr())) + { + continue; + } + + hwaddr = cfg.getHwaddr(); + break; + } + + if (hwaddr == null) { + _log.warn("Unable to get MAC hardware address -- none found"); + return null; + } + + _log.debug("Obtained HW MAC: " + hwaddr); + eAddr = new EthernetAddress(hwaddr); + return UUIDGenerator.getInstance() + .generateTimeBasedUUID(eAddr) + .toString(); + } catch(Exception e) { + _log.warn("Error while creating GUID", e); + return null; + } finally { + if (sigar != null) + sigar.close(); + } + } +} Modified: trunk/src/org/hyperic/hq/common/server/session/ServerConfigManagerEJBImpl.java =================================================================== --- trunk/src/org/hyperic/hq/common/server/session/ServerConfigManagerEJBImpl.java 2007-03-12 23:54:10 UTC (rev 3718) +++ trunk/src/org/hyperic/hq/common/server/session/ServerConfigManagerEJBImpl.java 2007-03-13 00:22:47 UTC (rev 3719) @@ -49,11 +49,6 @@ import org.hyperic.hq.common.shared.ServerConfigManagerLocal; import org.hyperic.hq.common.shared.ServerConfigManagerUtil; import org.hyperic.hq.dao.ConfigPropertyDAO; -import org.hyperic.sigar.NetFlags; -import org.hyperic.sigar.NetInterfaceConfig; -import org.hyperic.sigar.Sigar; -import org.hyperic.sigar.SigarProxy; -import org.hyperic.sigar.SigarProxyCache; import org.hyperic.util.ConfigPropertyException; import org.hyperic.util.StringUtil; import org.hyperic.util.jdbc.DBUtil; @@ -414,7 +409,7 @@ res = p.getProperty("HQ-GUID"); if (res == null || res.trim().length() == 0) { - if ((res = createGUID()) == null) + if ((res = GUIDGenerator.createGUID()) == null) return "unknown"; p.setProperty("HQ-GUID", res); try { @@ -426,45 +421,6 @@ return res; } - private String createGUID() { - try { - EthernetAddress eAddr; - Sigar sigar = new Sigar(); - SigarProxy proxy = SigarProxyCache.newInstance(sigar); - String[] ifaces = proxy.getNetInterfaceList(); - String hwaddr = null; - - for (int i=0; i<ifaces.length; i++) { - NetInterfaceConfig cfg = - sigar.getNetInterfaceConfig(ifaces[i]); - - if (NetFlags.LOOPBACK_ADDRESS.equals(cfg.getAddress()) || - (cfg.getFlags() & NetFlags.IFF_LOOPBACK) != 0 || - NetFlags.NULL_HWADDR.equals(cfg.getHwaddr())) - { - continue; - } - - hwaddr = cfg.getHwaddr(); - break; - } - - if (hwaddr == null) { - _log.warn("Unable to get MAC hardware address -- none found"); - return null; - } - - _log.debug("Obtained HW MAC: " + hwaddr); - eAddr = new EthernetAddress(hwaddr); - return UUIDGenerator.getInstance() - .generateTimeBasedUUID(eAddr) - .toString(); - } catch(Exception e) { - _log.warn("Error while creating GUID", e); - return null; - } - } - private static InitialContext ic = null; protected InitialContext getInitialContext() { if (ic == null) { |