From: <do...@hy...> - 2008-09-24 05:22:03
|
Author: dougm Date: 2008-09-23 22:21:46 -0700 (Tue, 23 Sep 2008) New Revision: 11273 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=11273 Modified: trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimConnection.java trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimHostEventPlugin.java trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimUtil.java Log: [HHQ-2495] refresh ServiceInstance wrapper if session is invalid (reviewed by clee) Modified: trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimConnection.java =================================================================== --- trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimConnection.java 2008-09-24 03:05:35 UTC (rev 11272) +++ trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimConnection.java 2008-09-24 05:21:46 UTC (rev 11273) @@ -68,9 +68,11 @@ _log.debug("Creating cache for: " + url); } else { + boolean requiresReconnect = false; boolean usernameChanged = !username.equals(conn._user); boolean passwordChanged = !password.equals(conn._pass); if (usernameChanged || passwordChanged) { + requiresReconnect = true; if (_log.isDebugEnabled()) { String diff = ""; if (usernameChanged) { @@ -85,6 +87,11 @@ _log.debug("Credentials changed (" + diff + ") reconnecting cached connection for: " + url); } + } + else { + requiresReconnect = !conn.vim.isSessionValid(); + } + if (requiresReconnect) { VimUtil.dispose(conn.vim); _log.debug("Closed previous connection (" + address(conn.vim) + ") for: " + url); Modified: trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimHostEventPlugin.java =================================================================== --- trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimHostEventPlugin.java 2008-09-24 03:05:35 UTC (rev 11272) +++ trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimHostEventPlugin.java 2008-09-24 05:21:46 UTC (rev 11273) @@ -64,6 +64,11 @@ super.configure(config); _props = config.toProperties(); + setup(); + getManager().addRunnableTracker(this); + } + + private void setup() throws PluginException { _lastCheck = System.currentTimeMillis(); try { _vim = VimUtil.getInstance(_props); @@ -83,8 +88,6 @@ _vim = null; throw new PluginException(e.getMessage(), e); } - - getManager().addRunnableTracker(this); } public void shutdown() throws PluginException { @@ -104,6 +107,10 @@ } _log.debug("Checking for events"); + if (!_vim.isSessionValid()) { + VimUtil.dispose(_vim); + setup(); + } Event[] events; try { events = _history.getLastPage(); Modified: trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimUtil.java =================================================================== --- trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimUtil.java 2008-09-24 03:05:35 UTC (rev 11272) +++ trunk/plugins/vim/src/org/hyperic/hq/plugin/vim/VimUtil.java 2008-09-24 05:21:46 UTC (rev 11273) @@ -27,10 +27,14 @@ import java.net.URL; import java.rmi.RemoteException; +import java.util.Calendar; +import java.util.Date; import java.util.Properties; import javax.xml.rpc.ServiceException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.hyperic.hq.product.PluginException; import org.hyperic.util.config.ConfigResponse; @@ -50,11 +54,15 @@ static final String PROP_USERNAME = VimCollector.PROP_USERNAME; static final String PROP_PASSWORD = VimCollector.PROP_PASSWORD; + private static final Log _log = + LogFactory.getLog(VimUtil.class.getName()); private InventoryNavigator _nav; + private String _url; public VimUtil(URL url, String username, String password, boolean ignoreCert) throws ServiceException, RemoteException { super(url, username, password, ignoreCert); + _url = url.toString(); } public static VimUtil getInstance(Properties props) @@ -84,6 +92,25 @@ return getInstance(config.toProperties()); } + public boolean isSessionValid() { + try { + //make sure session is still valid. XXX better way? + Calendar clock = getServerClock(); + if (clock == null) { + _log.debug(_url + " session invalid, clock=NULL"); + return false; + } + else { + _log.debug(_url + " session valid, clock=" + + new Date(clock.getTimeInMillis())); + return true; + } + } catch (Exception e) { + _log.debug(_url + " session invalid, clock=" + e, e); + return false; + } + } + public boolean isESX() { return !"gsx".equals(getAboutInfo().getProductLineId()); } |