modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventPoller.java
| 66 +++++-----
modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventResourceComponentHelper.java
| 18 +-
2 files changed, 42 insertions(+), 42 deletions(-)
New commits:
commit b4c048f8dfe3aab6f4c8347e856b80f40e66f29a
Author: Thomas Segismont <tsegismo(a)redhat.com>
Date: Thu Jan 30 18:15:50 2014 +0100
Bug 977350 - Log events will not be collected if target log file doesn't exist at
the time the resource is started by the plug-in container
Changed the warning message to indicate that the poller will be started even if the
file does not exist
Changed the poller implementation to support "bad" files (non existing or
file is a directory): event polling will start as soon as a regular file is found
diff --git
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventPoller.java
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventPoller.java
index b4e19c4..6a2c774 100644
---
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventPoller.java
+++
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventPoller.java
@@ -1,25 +1,22 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2012 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2, as
- * published by the Free Software Foundation, and/or the GNU Lesser
- * General Public License, version 2.1, also as published by the Free
- * Software Foundation.
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
*
* 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 and the GNU Lesser General Public License
- * for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
+
package org.rhq.core.pluginapi.event.log;
import java.io.BufferedReader;
@@ -47,7 +44,7 @@ import org.rhq.core.pluginapi.event.EventPoller;
* @author Ian Springer
*/
public class LogFileEventPoller implements EventPoller {
- private final Log log = LogFactory.getLog(this.getClass());
+ private static final Log LOG = LogFactory.getLog(LogFileEventPoller.class);
private String eventType;
private File logFile;
@@ -76,24 +73,27 @@ public class LogFileEventPoller implements EventPoller {
@Nullable
public Set<Event> poll() {
- if (!this.initialized) {
- init();
- }
- if (this.logFileInfo == null) {
- // This means SIGAR, which we require, is unavailable, so just return null.
- return null;
- }
-
if (!this.logFile.exists()) {
- log.warn("Log file [" + this.logFile + "] being polled does
not exist.");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Log file [" + this.logFile + "] being polled
does not exist.");
+ }
return null;
}
if (this.logFile.isDirectory()) {
- log.error("Log file [" + this.logFile + "] being polled is a
directory, not a regular file.");
+ LOG.error("Log file [" + this.logFile + "] being polled is a
directory, not a regular file.");
return null;
}
-
- try {
+ if (!this.initialized) {
+ init();
+ }
+ if (this.logFileInfo == null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Cannot poll log file [" + this.logFile
+ + "] because native integration is either disabled or
unavailable.");
+ }
+ return null;
+ }
+ try {
if (!this.logFileInfo.changed()) {
return null;
}
@@ -118,7 +118,7 @@ public class LogFileEventPoller implements EventPoller {
throw new RuntimeException("Failed to obtain file info for log file
[" + this.logFile + "].", e);
}
} else {
- log.warn("SIGAR is unavailable - cannot poll log file [" +
this.logFile + "] for events.");
+ LOG.warn("SIGAR is unavailable - cannot poll log file [" +
this.logFile + "] for events.");
}
this.initialized = true;
@@ -138,7 +138,7 @@ public class LogFileEventPoller implements EventPoller {
BufferedReader bufferedReader = new BufferedReader(reader);
events = this.entryProcessor.processLines(bufferedReader);
} catch (IOException e) {
- log.error("Failed to read log file being tailed: " + this.logFile,
e);
+ LOG.error("Failed to read log file being tailed: " + this.logFile,
e);
} finally {
if (reader != null) {
//noinspection EmptyCatchBlock
@@ -155,29 +155,29 @@ public class LogFileEventPoller implements EventPoller {
FileInfo previousFileInfo = fileInfo.getPreviousInfo();
if (previousFileInfo == null) {
- if (log.isDebugEnabled()) {
- log.debug(this.logFile + ": first stat");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(this.logFile + ": first stat");
}
return fileInfo.getSize();
}
if (fileInfo.getInode() != previousFileInfo.getInode()) {
- if (log.isDebugEnabled()) {
- log.debug(this.logFile + ": file inode changed");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(this.logFile + ": file inode changed");
}
return -1;
}
if (fileInfo.getSize() < previousFileInfo.getSize()) {
- if (log.isDebugEnabled()) {
- log.debug(this.logFile + ": file truncated");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(this.logFile + ": file truncated");
}
return -1;
}
- if (log.isDebugEnabled()) {
+ if (LOG.isDebugEnabled()) {
long diff = fileInfo.getSize() - previousFileInfo.getSize();
- log.debug(this.logFile + ": " + diff + " new bytes");
+ LOG.debug(this.logFile + ": " + diff + " new bytes");
}
return previousFileInfo.getSize();
diff --git
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventResourceComponentHelper.java
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventResourceComponentHelper.java
index 37a99eb..147b423 100644
---
a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventResourceComponentHelper.java
+++
b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/event/log/LogFileEventResourceComponentHelper.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2012 Red Hat, Inc.
+ * Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -13,9 +13,10 @@
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
+
package org.rhq.core.pluginapi.event.log;
import java.io.File;
@@ -49,6 +50,8 @@ import org.rhq.core.system.SystemInfoFactory;
* @author Ian Springer
*/
public class LogFileEventResourceComponentHelper {
+ private static final Log LOG =
LogFactory.getLog(LogFileEventResourceComponentHelper.class);
+
public static final String LOG_ENTRY_EVENT_TYPE = "logEntry";
public static final String LOG_EVENT_SOURCES_CONFIG_PROP =
"logEventSources";
@@ -65,8 +68,6 @@ public class LogFileEventResourceComponentHelper {
// TODO: Make this configurable via a plugin config prop.
private static final int POLLING_INTERVAL_IN_SECONDS = 60;
- private final Log log = LogFactory.getLog(this.getClass());
-
private ResourceContext<?> resourceContext;
private List<PropertyMap> startedEventSources = new
ArrayList<PropertyMap>();
@@ -105,7 +106,7 @@ public class LogFileEventResourceComponentHelper {
boolean nativeSystemInfoDisabled =
SystemInfoFactory.isNativeSystemInfoDisabled();
ResourceType resourceType = this.resourceContext.getResourceType();
List<String> logFilePaths = getLogFilePaths(enabledEventSources);
- log.warn("Log files " + logFilePaths + " for [" +
resourceType.getPlugin() + ":"
+ LOG.warn("Log files " + logFilePaths + " for [" +
resourceType.getPlugin() + ":"
+ resourceType.getName() + "] Resource with key [" +
this.resourceContext.getResourceKey()
+ "] cannot be polled, because log file polling requires RHQ native
support, which "
+ ((nativeSystemInfoDisabled) ? "has been disabled for this
Agent" : "is not available on this platform") + ".");
@@ -121,9 +122,8 @@ public class LogFileEventResourceComponentHelper {
}
File logFile = new File(logFilePath);
if (!logFile.canRead()) {
- log.error("LOGFILE: Logfile at location " + logFilePath
- + " does not exist or is not readable. Can not start watching
the event log.");
- continue;
+ LOG.warn("LOGFILE: Logfile at location " + logFilePath + "
does not exist or is not readable. "
+ + "The poller will be started but no events will be polled until
the file is created.");
}
Log4JLogEntryProcessor processor = new
Log4JLogEntryProcessor(LOG_ENTRY_EVENT_TYPE, logFile);