Return-Path: X-Original-To: apmail-karaf-commits-archive@minotaur.apache.org Delivered-To: apmail-karaf-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 59B75174BC for ; Sat, 1 Aug 2015 17:19:22 +0000 (UTC) Received: (qmail 91210 invoked by uid 500); 1 Aug 2015 17:19:22 -0000 Delivered-To: apmail-karaf-commits-archive@karaf.apache.org Received: (qmail 91152 invoked by uid 500); 1 Aug 2015 17:19:22 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 91091 invoked by uid 99); 1 Aug 2015 17:19:22 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Aug 2015 17:19:22 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 0F094AC06FB for ; Sat, 1 Aug 2015 17:19:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1693744 [3/8] - in /karaf/site/production/manual/decanter/latest-1: ./ dev-guide/ user-guide/ Date: Sat, 01 Aug 2015 17:19:21 -0000 To: commits@karaf.apache.org From: jbonofre@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150801171922.0F094AC06FB@hades.apache.org> Added: karaf/site/production/manual/decanter/latest-1/custom-alerter.html URL: http://svn.apache.org/viewvc/karaf/site/production/manual/decanter/latest-1/custom-alerter.html?rev=1693744&view=auto ============================================================================== --- karaf/site/production/manual/decanter/latest-1/custom-alerter.html (added) +++ karaf/site/production/manual/decanter/latest-1/custom-alerter.html Sat Aug 1 17:19:21 2015 @@ -0,0 +1,658 @@ + + + + + + + +Custom SLA Alerter + + + + + + +
+
+

Custom SLA Alerter

+
+
+

A Decanter SLA Alerter is basically a special kind of appender.

+
+
+

It’s an OSGi EventAdmin EventHandler: it’s listening of decanter/alert/* EventAdmin topics, and +receives the alerting data coming from the SLA checker.

+
+
+

To enable a new Decanter Alerter, you just have to register an EventHandler OSGi service, like we do for an appender.

+
+
+

For instance, if you want to create a very simple SystemOutAlerter that displays the alert (coming from the +SLA checker) to System.out, you can create the following SystemOutAlerter class implementing EventHandler interface:

+
+
+
+
package org.apache.karaf.decanter.sample.alerter.systemout;
+
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventHandler;
+
+import java.util.HashMap;
+
+public class SystemOutAlerter implements EventHandler {
+
+    @Override
+    public void handleEvent(Event event) {
+        for (String name : event.getPropertyNames()) {
+            System.err.println(name + ":" + event.getProperty(name));
+        }
+    }
+
+}
+
+
+
+

Now, we create a BundleActivator that register our SystemOutAppender as an EventHandler OSGi service:

+
+
+
+
package org.apache.karaf.decanter.sample.alerter.systemout;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+import java.util.HashMap;
+import java.util.Dictionary;
+
+public class Activator implements BundleActivator {
+
+  private ServiceRegistration registration;
+
+  public void start(BundleContext bundleContext) {
+    SystemOutAlerter alerter = new SystemOutAlerter();
+    Dictionary<String, String> properties = new Hashtable<>();
+    properties.put(EventConstants.EVENT_TOPIC, "decanter/alert/*");
+    registration =  bundleContext.registerService(EventHandler.class, alerter, properties);
+  }
+
+  public void stop(BundleContext bundleContext) {
+    if (registration != null) registration.unregister();
+  }
+
+}
+
+
+
+

You can see that our SystemOutAlerter will listen on any decanter/alert/* topics.

+
+
+

We can now package our alerter bundle using the following Maven pom.xml:

+
+
+
+
<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">)
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.karaf.decanter.sample.alerter</groupId>
+    <artifactId>org.apache.karaf.decanter.sample.alerter.systemout</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Decanter :: Sample :: Alerter :: SystemOut</name>
+
+    <dependencies>
+
+        <!-- OSGi -->
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.3.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>4.3.1</version>
+        </dependency>
+
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.4.0</version>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Bundle-Version>${project.version}</Bundle-Version>
+                        <Bundle-Activator>org.apache.karaf.decanter.sample.alerter.systemout.Activator</Bundle-Activator>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
+
+
+
+

Once built, you can enable this alerter by deploying the bundle in Karaf (using the deploy folder or the bundle:install command).

+
+
+
+
+ + + \ No newline at end of file Added: karaf/site/production/manual/decanter/latest-1/custom-appender.html URL: http://svn.apache.org/viewvc/karaf/site/production/manual/decanter/latest-1/custom-appender.html?rev=1693744&view=auto ============================================================================== --- karaf/site/production/manual/decanter/latest-1/custom-appender.html (added) +++ karaf/site/production/manual/decanter/latest-1/custom-appender.html Sat Aug 1 17:19:21 2015 @@ -0,0 +1,658 @@ + + + + + + + +Custom Appender + + + + + + +
+
+

Custom Appender

+
+
+

A Decanter Appender is an OSGi EventAdmin EventHandler: it’s listening of decanter/collect/* EventAdmin topics, and +receives the monitoring data coming from the collectors.

+
+
+

It’s responsible to store the data into a target backend.

+
+
+

To enable a new Decanter Appender, you just have to register an EventHandler OSGi service.

+
+
+

For instance, if you want to create a very simple SystemOutAppender that displays the monitoring data (coming from the +collectors) to System.out, you can create the following SystemOutAppender class implementing EventHandler interface:

+
+
+
+
package org.apache.karaf.decanter.sample.appender.systemout;
+
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventHandler;
+
+import java.util.HashMap;
+
+public class SystemOutAppender implements EventHandler {
+
+    @Override
+    public void handleEvent(Event event) {
+        for (String name : event.getPropertyNames()) {
+            System.out.println(name + ":" + event.getProperty(name));
+        }
+    }
+
+}
+
+
+
+

Now, we create a BundleActivator that register our SystemOutAppender as an EventHandler OSGi service:

+
+
+
+
package org.apache.karaf.decanter.sample.appender.systemout;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.event.EventConstants;
+import org.osgi.service.event.EventHandler;
+import java.util.HashMap;
+import java.util.Dictionary;
+
+public class Activator implements BundleActivator {
+
+  private ServiceRegistration registration;
+
+  public void start(BundleContext bundleContext) {
+    SystemOutAppender appender = new SystemOutAppender();
+    Dictionary<String, String> properties = new Hashtable<>();
+    properties.put(EventConstants.EVENT_TOPIC, "decanter/collect/*");
+    registration =  bundleContext.registerService(EventHandler.class, appender, properties);
+  }
+
+  public void stop(BundleContext bundleContext) {
+    if (registration != null) registration.unregister();
+  }
+
+}
+
+
+
+

You can see that our SystemOutAppender will listen on any decanter/collect/* topics.

+
+
+

We can now package our appender bundle using the following Maven pom.xml:

+
+
+
+
<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">)
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.karaf.decanter.sample.appender</groupId>
+    <artifactId>org.apache.karaf.decanter.sample.appender.systemout</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Decanter :: Sample :: Appender :: SystemOut</name>
+
+    <dependencies>
+
+        <!-- OSGi -->
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.3.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>4.3.1</version>
+        </dependency>
+
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.4.0</version>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+                        <Bundle-Version>${project.version}</Bundle-Version>
+                        <Bundle-Activator>org.apache.karaf.decanter.sample.appender.systemout.Activator</Bundle-Activator>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
+
+
+
+

Once built, you can enable this appender by deploying the bundle in Karaf (using the deploy folder or the bundle:install command).

+
+
+
+
+ + + \ No newline at end of file