karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [2/3] karaf-decanter git commit: Avoid flooding of the log in case of repeated errors
Date Fri, 19 Feb 2016 08:40:36 GMT
Avoid flooding of the log in case of repeated errors


Project: http://git-wip-us.apache.org/repos/asf/karaf-decanter/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-decanter/commit/6b96900a
Tree: http://git-wip-us.apache.org/repos/asf/karaf-decanter/tree/6b96900a
Diff: http://git-wip-us.apache.org/repos/asf/karaf-decanter/diff/6b96900a

Branch: refs/heads/DS-target
Commit: 6b96900a2001d63835c94b574d2ae23c497c46b4
Parents: f2e56cf
Author: Christian Schneider <chris@die-schneider.net>
Authored: Fri Feb 19 09:37:54 2016 +0100
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Fri Feb 19 09:37:54 2016 +0100

----------------------------------------------------------------------
 .../decanter/collector/rest/RestCollector.java  | 27 ++++++++++++++++----
 1 file changed, 22 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/6b96900a/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
----------------------------------------------------------------------
diff --git a/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
b/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
index 9c2b078..b322644 100644
--- a/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
+++ b/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
@@ -45,14 +45,16 @@ import org.slf4j.LoggerFactory;
 public class RestCollector implements Runnable {
     private final static Logger LOGGER = LoggerFactory.getLogger(RestCollector.class);
 
-    private String type;
     private URL url;
     private String[] paths;
+    private String baseTopic;
     private Dictionary<String, Object> properties;
 
     private EventAdmin eventAdmin;
     private Unmarshaller unmarshaller;
 
+    private boolean repeatedError;
+
     @SuppressWarnings("unchecked")
     @Activate
     public void activate(ComponentContext context) throws MalformedURLException {
@@ -61,9 +63,11 @@ public class RestCollector implements Runnable {
         getProperty(props, "username", null);
         getProperty(props, "password", null);
         this.paths = getProperty(props, "paths", "").split(",");
+        this.baseTopic = getProperty(props, "topic", "decanter/collect");
         //props.remove("password");
         //props.remove("username");
         this.properties = props;
+        this.repeatedError = false;
     }
     
     private String getProperty(Dictionary<String, Object> properties, String key, String
defaultValue) {
@@ -74,8 +78,14 @@ public class RestCollector implements Runnable {
     public void run() {
         LOGGER.debug("Karaf Decanter REST Collector starts harvesting from {} ...", url);
         for (String path : paths) {
+            URL complete;
+            try {
+                complete = new URL(url, path);
+            } catch (MalformedURLException e) {
+                LOGGER.warn("Invalid URL. Stopping collector", e);
+                throw new IllegalArgumentException(e);
+            }
             try {
-                URL complete = new URL(url, path);
                 URLConnection connection = complete.openConnection();
                 Map<String, Object> data = unmarshaller.unmarshal(connection.getInputStream());
                 data.put("type", "rest");
@@ -83,15 +93,22 @@ public class RestCollector implements Runnable {
                 data.put("remote.url", complete);
                 addUserProperties(data);
                 eventAdmin.postEvent(new Event(toTopic(complete), data));
+                repeatedError = false;
             } catch (Exception e) {
-                LOGGER.warn("Error fetching", e);
+                if (repeatedError) {
+                    LOGGER.warn("Error fetching " + complete, e);
+                    repeatedError = true;
+                } else {
+                    LOGGER.debug("Repeated Error fetching " + complete, e);
+                }
+                
             }
         }
-        LOGGER.debug("Karaf Decanter JMX Collector harvesting {} done", type);
+        LOGGER.debug("Karaf Decanter REST Collector harvesting done");
     }
 
     private String toTopic(URL url) {
-        return "decanter/collect/rest/" + url.getHost() + url.getPath();
+        return baseTopic + "/" + url.getHost() + url.getPath();
     }
 
     private void addUserProperties(Map<String, Object> data) {


Mime
View raw message