modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java | 35 ++++++---- modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java | 12 +-- 2 files changed, 27 insertions(+), 20 deletions(-)
New commits: commit dd6200e8a52d9d28ed4a57a8a1bff60b77e4a9d2 Author: Thomas Segismont tsegismo@redhat.com Date: Fri Dec 6 16:18:53 2013 +0100
Bug 1030063 - Clean up plugin update to work synchronously
Make a pause between plugin update attempts
diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java index 4f05315..b6cd741 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java @@ -18,6 +18,8 @@ */ package org.rhq.enterprise.agent;
+import static java.util.concurrent.TimeUnit.SECONDS; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -69,6 +71,7 @@ import org.apache.log4j.xml.DOMConfigurator; import org.jboss.remoting.invocation.NameBasedInvocation; import org.jboss.remoting.security.SSLSocketBuilder; import org.jboss.remoting.transport.http.ssl.HTTPSClientInvoker; +import org.jboss.util.file.FilenameSuffixFilter;
import org.rhq.core.clientapi.server.bundle.BundleServerService; import org.rhq.core.clientapi.server.configuration.ConfigurationServerService; @@ -1894,23 +1897,27 @@ public class AgentMain { // so allow this to be configurable via the "update plugins at startup" flag. m_pluginUpdate = new PluginUpdate(pc_config.getServerServices().getCoreServerService(), pc_config); if (m_configuration.isUpdatePluginsAtStartupEnabled()) { - boolean notified_user = false; - // this can block forever...perhaps exit after a few tries? - while (true) { - if (!notified_user) { - LOG.info(AgentI18NResourceKeys.WAITING_FOR_PLUGINS_WITH_DIR, plugin_dir); - getOut().println(MSG.getMsg(AgentI18NResourceKeys.WAITING_FOR_PLUGINS)); - notified_user = true; - } else { - // let's keep logging this at debug level so we don't look hung - LOG.debug(AgentI18NResourceKeys.WAITING_FOR_PLUGINS_WITH_DIR, plugin_dir); - } + LOG.info(AgentI18NResourceKeys.WAITING_FOR_PLUGINS_WITH_DIR, plugin_dir); + getOut().println(MSG.getMsg(AgentI18NResourceKeys.WAITING_FOR_PLUGINS)); + for (;;) { try { m_pluginUpdate.updatePlugins(); - break; } catch (Exception e) { LOG.error(e, AgentI18NResourceKeys.UPDATING_PLUGINS_FAILURE, e); } + if (pluginsDirHasJarFile(plugin_dir)) { + break; + } + try { + Thread.sleep(SECONDS.toMillis(30)); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + LOG.warn(AgentI18NResourceKeys.PLUGIN_CONTAINER_INITIALIZATION_INTERRUPTED); + getOut().println(MSG.getMsg(AgentI18NResourceKeys.PLUGIN_CONTAINER_INITIALIZATION_INTERRUPTED)); + return false; + } + // let's keep logging this at debug level so we don't look hung + LOG.debug(AgentI18NResourceKeys.WAITING_FOR_PLUGINS_WITH_DIR, plugin_dir); } } else if (plugin_dir.list().length == 0) { LOG.warn(AgentI18NResourceKeys.NO_PLUGINS); @@ -1934,6 +1941,10 @@ public class AgentMain { return plugin_container.isStarted(); }
+ private boolean pluginsDirHasJarFile(File plugin_dir) { + return plugin_dir.listFiles(new FilenameSuffixFilter(".jar")).length != 0; + } + /** * Tell the agent to immediately switch to another server. The given * server can be a simple hostname in which case, the current transport, diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java index 5e24b14..8b7f622 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/PluginUpdate.java @@ -123,15 +123,11 @@ public class PluginUpdate { List<Plugin> latest_plugins = coreServerService.getLatestPlugins();
if (LOG.isDebugEnabled()) { - if (LOG.isDebugEnabled()) { - LOG.debug(AgentI18NResourceKeys.LATEST_PLUGINS_COUNT, latest_plugins.size()); - } + LOG.debug(AgentI18NResourceKeys.LATEST_PLUGINS_COUNT, latest_plugins.size()); for (Plugin latest_plugin : latest_plugins) { - if (LOG.isDebugEnabled()) { - LOG.debug(AgentI18NResourceKeys.LATEST_PLUGIN, latest_plugin.getId(), latest_plugin.getName(), - latest_plugin.getDisplayName(), latest_plugin.getVersion(), latest_plugin.getPath(), - latest_plugin.getMd5(), latest_plugin.isEnabled(), latest_plugin.getDescription()); - } + LOG.debug(AgentI18NResourceKeys.LATEST_PLUGIN, latest_plugin.getId(), latest_plugin.getName(), + latest_plugin.getDisplayName(), latest_plugin.getVersion(), latest_plugin.getPath(), + latest_plugin.getMd5(), latest_plugin.isEnabled(), latest_plugin.getDescription()); } }
rhq-commits@lists.fedorahosted.org