karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-5391) Add decanter:alert* commands and MBeans
Date Mon, 29 Jan 2018 15:23:01 GMT

    [ https://issues.apache.org/jira/browse/KARAF-5391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16343477#comment-16343477
] 

ASF GitHub Bot commented on KARAF-5391:
---------------------------------------

jbonofre closed pull request #31: [KARAF-5391] Add alert commands & MBean
URL: https://github.com/apache/karaf-decanter/pull/31
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/alerting/checker/pom.xml b/alerting/checker/pom.xml
index a975d3d..89f0ae0 100644
--- a/alerting/checker/pom.xml
+++ b/alerting/checker/pom.xml
@@ -35,6 +35,15 @@
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Export-Package>org.apache.karaf.decanter.alerting.checker</Export-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>build-helper-maven-plugin</artifactId>
diff --git a/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/AlertStore.java
b/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/AlertStore.java
index 4cbdd33..bbb71fe 100644
--- a/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/AlertStore.java
+++ b/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/AlertStore.java
@@ -16,12 +16,21 @@
  */
 package org.apache.karaf.decanter.alerting.checker;
 
+import java.util.Set;
+
 public interface AlertStore {
 
-    void add(String name, String level);
+    enum Level {
+        error,
+        warn
+    }
+
+    void add(String name, Level level);
+
+    void remove(String name, Level level);
 
-    void remove(String name, String level);
+    boolean known(String name, Level level);
 
-    boolean known(String name, String level);
+    Set<String> list(Level level);
 
 }
diff --git a/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/AlertStoreImpl.java
b/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/AlertStoreImpl.java
index 41e0caf..218d934 100644
--- a/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/AlertStoreImpl.java
+++ b/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/AlertStoreImpl.java
@@ -36,32 +36,42 @@ public void activate() {
         this.warnAlerts = new HashSet<>();
     }
 
-    public void add(String name, String level) {
-        if (level.equals("error")) {
+    public void add(String name, Level level) {
+        if (level == Level.error) {
             this.errorAlerts.add(name);
         }
-        if (level.equals("warn")) {
+        if (level == Level.warn) {
             this.warnAlerts.add(name);
         }
     }
 
-    public void remove(String name, String level) {
-        if (level.equals("error")) {
+    public void remove(String name, Level level) {
+        if (level == Level.error) {
             this.errorAlerts.remove(name);
         }
-        if (level.equals("warn")) {
+        if (level == Level.warn) {
             this.warnAlerts.remove(name);
         }
     }
 
-    public boolean known(String name, String level) {
-        if (level.equals("error")) {
+    public boolean known(String name, Level level) {
+        if (level == Level.error) {
             return this.errorAlerts.contains(name);
         }
-        if (level.equals("warn")) {
+        if (level == Level.warn) {
             return this.warnAlerts.contains(name);
         }
         return false;
     }
 
+    public Set<String> list(Level level) {
+        if (level == Level.error) {
+            return this.errorAlerts;
+        }
+        if (level == Level.warn) {
+            return this.warnAlerts;
+        }
+        return null;
+    }
+
 }
diff --git a/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/Checker.java
b/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/Checker.java
index 3c85b24..8228a03 100644
--- a/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/Checker.java
+++ b/alerting/checker/src/main/java/org/apache/karaf/decanter/alerting/checker/Checker.java
@@ -73,19 +73,19 @@ public void handleEvent(Event collectEvent) {
             if (errorPattern != null) {
                 Object value = collectEvent.getProperty(name);
                 if (!validate(errorPattern, value)) {
-                    if (!alertStore.known(name, "error")) {
-                        alertStore.add(name, "error");
+                    if (!alertStore.known(name, AlertStore.Level.error)) {
+                        alertStore.add(name, AlertStore.Level.error);
                         Event alertEvent = populateAlertEvent("error", collectEvent, name,
errorPattern, false);
                         dispatcher.postEvent(alertEvent);
                     }
                 } else {
-                    if (alertStore.known(name, "error")) {
+                    if (alertStore.known(name, AlertStore.Level.error)) {
                         dispatcher.postEvent(populateAlertEvent("error", collectEvent, name,
errorPattern, true));
-                        alertStore.remove(name, "error");
+                        alertStore.remove(name, AlertStore.Level.error);
                     }
                 }
             } else {
-                if (alertStore.known(name, "error")) {
+                if (alertStore.known(name, AlertStore.Level.error)) {
                     dispatcher.postEvent(populateAlertEvent("error", collectEvent, name,
"REMOVED", true));
                 }
             }
@@ -100,21 +100,21 @@ public void handleEvent(Event collectEvent) {
             if (warnPattern != null) {
                 Object value = collectEvent.getProperty(name);
                 if (!validate(warnPattern, value)) {
-                    if (!alertStore.known(name, "warn")) {
-                        alertStore.add(name, "warn");
+                    if (!alertStore.known(name, AlertStore.Level.warn)) {
+                        alertStore.add(name, AlertStore.Level.warn);
                         Event alertEvent = populateAlertEvent("warn", collectEvent, name,
warnPattern, false);
                         dispatcher.postEvent(alertEvent);
                     }
                 } else {
-                    if (alertStore.known(name, "warn")) {
+                    if (alertStore.known(name, AlertStore.Level.warn)) {
                         dispatcher.postEvent(populateAlertEvent("warn", collectEvent, name,
warnPattern, true));
-                        alertStore.remove(name, "warn");
+                        alertStore.remove(name, AlertStore.Level.warn);
                     }
                 }
             } else {
-                if (alertStore.known(name, "warn")) {
+                if (alertStore.known(name, AlertStore.Level.warn)) {
                     dispatcher.postEvent(populateAlertEvent("warn", collectEvent, name, "REMOVED",
true));
-                    alertStore.remove(name, "warn");
+                    alertStore.remove(name, AlertStore.Level.warn);
                 }
             }
         }
diff --git a/alerting/command/pom.xml b/alerting/command/pom.xml
new file mode 100644
index 0000000..c6e0653
--- /dev/null
+++ b/alerting/command/pom.xml
@@ -0,0 +1,83 @@
+<?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">
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.decanter</groupId>
+        <artifactId>alerting</artifactId>
+        <version>2.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.karaf.decanter.alerting</groupId>
+    <artifactId>org.apache.karaf.decanter.alerting.command</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Decanter :: Alerting :: Command</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.alerting</groupId>
+            <artifactId>org.apache.karaf.decanter.alerting.checker</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.core</artifactId>
+            <optional>true</optional>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.karaf.tooling</groupId>
+                <artifactId>karaf-services-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>process-classes</phase>
+                        <goals>
+                            <goal>service-metadata-generate</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Private-Package>
+                            org.apache.karaf.decanter.alerting.command,
+                            org.apache.karaf.decanter.alerting.command.completers
+                        </Private-Package>
+                        <Import-Package>
+                            org.apache.karaf.decanter.alerting.checker,
+                            org.apache.karaf.shell*;version="[4,5)",
+                            *
+                        </Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file
diff --git a/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/AddAlert.java
b/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/AddAlert.java
new file mode 100644
index 0000000..68568a6
--- /dev/null
+++ b/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/AddAlert.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.decanter.alerting.command;
+
+import org.apache.karaf.decanter.alerting.checker.AlertStore;
+import org.apache.karaf.decanter.alerting.command.completers.LevelCompleter;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+@Service
+@Command(scope = "decanter", name = "alert-add", description = "Add an alert manually")
+public class AddAlert implements Action {
+
+    @Reference
+    private AlertStore store;
+
+    @Argument(index = 0, name = "level", description = "Alert level", required = true, multiValued
= false)
+    @Completion(LevelCompleter.class)
+    String level;
+
+    @Argument(index = 1, name = "name", description = "Alert name", required = true, multiValued
= false)
+    String name;
+
+    @Override
+    public Object execute() throws Exception {
+        store.add(name, AlertStore.Level.valueOf(level));
+        return null;
+    }
+
+}
diff --git a/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/ListAlerts.java
b/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/ListAlerts.java
new file mode 100644
index 0000000..330141b
--- /dev/null
+++ b/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/ListAlerts.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.decanter.alerting.command;
+
+import org.apache.karaf.decanter.alerting.checker.AlertStore;
+import org.apache.karaf.decanter.alerting.command.completers.LevelCompleter;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+import java.util.Set;
+
+@Command(scope = "decanter", name = "alerts", description = "List the current alerts")
+@Service
+public class ListAlerts implements Action {
+
+    @Reference
+    private AlertStore store;
+
+    @Argument(index = 0, name = "Alert level", description = "The level of the alerts", required
= true, multiValued = false)
+    @Completion(LevelCompleter.class)
+    String level;
+
+    @Override
+    public Object execute() throws Exception {
+        AlertStore.Level alertLevel = AlertStore.Level.valueOf(level);
+        Set<String> alerts = store.list(alertLevel);
+        for (String alert : alerts) {
+            System.out.println(alert);
+        }
+        return null;
+    }
+}
diff --git a/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/RemoveAlert.java
b/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/RemoveAlert.java
new file mode 100644
index 0000000..01113f9
--- /dev/null
+++ b/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/RemoveAlert.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.decanter.alerting.command;
+
+import org.apache.karaf.decanter.alerting.checker.AlertStore;
+import org.apache.karaf.decanter.alerting.command.completers.AlertCompleter;
+import org.apache.karaf.decanter.alerting.command.completers.LevelCompleter;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+@Service
+@Command(scope = "decanter", name = "alert-remove", description = "Remove an alert")
+public class RemoveAlert implements Action {
+
+    @Reference
+    private AlertStore store;
+
+    @Argument(index = 0, name = "level", description = "Alert level", required = true, multiValued
= false)
+    @Completion(LevelCompleter.class)
+    String level;
+
+    @Argument(index = 1, name = "name", description = "Alert name", required = true, multiValued
= false)
+    @Completion(AlertCompleter.class)
+    String name;
+
+    @Override
+    public Object execute() throws Exception {
+        store.remove(name, AlertStore.Level.valueOf(level));
+        return null;
+    }
+
+}
diff --git a/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/completers/AlertCompleter.java
b/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/completers/AlertCompleter.java
new file mode 100644
index 0000000..e536e68
--- /dev/null
+++ b/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/completers/AlertCompleter.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.decanter.alerting.command.completers;
+
+import org.apache.karaf.decanter.alerting.checker.AlertStore;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+
+import java.util.List;
+import java.util.Set;
+
+@Service
+public class AlertCompleter implements Completer {
+
+    @Reference
+    private AlertStore store;
+
+    @Override
+    public int complete(Session session, CommandLine commandLine, List<String> candidates)
{
+        StringsCompleter delegate = new StringsCompleter();
+        Set<String> errorAlerts = store.list(AlertStore.Level.error);
+        for (String alert : errorAlerts) {
+            delegate.getStrings().add(alert);
+        }
+        Set<String> warnAlerts = store.list(AlertStore.Level.warn);
+        for (String alert : warnAlerts) {
+            delegate.getStrings().add(alert);
+        }
+        return delegate.complete(session, commandLine, candidates);
+    }
+
+}
diff --git a/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/completers/LevelCompleter.java
b/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/completers/LevelCompleter.java
new file mode 100644
index 0000000..6949621
--- /dev/null
+++ b/alerting/command/src/main/java/org/apache/karaf/decanter/alerting/command/completers/LevelCompleter.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.decanter.alerting.command.completers;
+
+import org.apache.karaf.decanter.alerting.checker.AlertStore;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+
+import java.util.List;
+
+@Service
+public class LevelCompleter implements Completer {
+
+    @Override
+    public int complete(Session session, CommandLine commandLine, List<String> candidates)
{
+        StringsCompleter delegate = new StringsCompleter();
+        delegate.getStrings().add(AlertStore.Level.error.toString());
+        delegate.getStrings().add(AlertStore.Level.warn.toString());
+        return delegate.complete(session, commandLine, candidates);
+    }
+
+}
diff --git a/alerting/management/pom.xml b/alerting/management/pom.xml
new file mode 100644
index 0000000..10e7cdd
--- /dev/null
+++ b/alerting/management/pom.xml
@@ -0,0 +1,44 @@
+<?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">
+
+    <!--
+
+        Licensed to the Apache Software Foundation (ASF) under one or more
+        contributor license agreements.  See the NOTICE file distributed with
+        this work for additional information regarding copyright ownership.
+        The ASF licenses this file to You under the Apache License, Version 2.0
+        (the "License"); you may not use this file except in compliance with
+        the License.  You may obtain a copy of the License at
+
+           http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.decanter</groupId>
+        <artifactId>alerting</artifactId>
+        <version>2.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.karaf.decanter.alerting</groupId>
+    <artifactId>org.apache.karaf.decanter.alerting.management</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: Decanter :: Alerting :: Management</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.decanter.alerting</groupId>
+            <artifactId>org.apache.karaf.decanter.alerting.checker</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/alerting/management/src/main/java/org/apache/karaf/decanter/alerting/management/AlertMBean.java
b/alerting/management/src/main/java/org/apache/karaf/decanter/alerting/management/AlertMBean.java
new file mode 100644
index 0000000..d73821b
--- /dev/null
+++ b/alerting/management/src/main/java/org/apache/karaf/decanter/alerting/management/AlertMBean.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.decanter.alerting.management;
+
+import javax.management.MBeanException;
+import java.util.Set;
+
+public interface AlertMBean {
+
+    Set<String> getAlerts(String level) throws MBeanException;
+
+    void add(String name, String level) throws MBeanException;
+
+    void remove(String name, String level) throws MBeanException;
+
+}
diff --git a/alerting/management/src/main/java/org/apache/karaf/decanter/alerting/management/AlertMBeanImpl.java
b/alerting/management/src/main/java/org/apache/karaf/decanter/alerting/management/AlertMBeanImpl.java
new file mode 100644
index 0000000..1dfc866
--- /dev/null
+++ b/alerting/management/src/main/java/org/apache/karaf/decanter/alerting/management/AlertMBeanImpl.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.decanter.alerting.management;
+
+import org.apache.karaf.decanter.alerting.checker.AlertStore;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import javax.management.MBeanException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+import java.util.Set;
+
+@Component(
+        name = "org.apache.karaf.decanter.alerting.management",
+        immediate = true,
+        property = "jmx.objectname=org.apache.karaf.decanter:type=alerting,name=default"
+)
+public class AlertMBeanImpl extends StandardMBean implements AlertMBean {
+
+    @Reference
+    AlertStore store;
+
+    public AlertMBeanImpl() throws NotCompliantMBeanException {
+        super(AlertMBean.class);
+    }
+
+    @Override
+    public Set<String> getAlerts(String level) throws MBeanException {
+        return store.list(AlertStore.Level.valueOf(level));
+    }
+
+    @Override
+    public void add(String name, String level) throws MBeanException {
+        store.add(name, AlertStore.Level.valueOf(level));
+    }
+
+    @Override
+    public void remove(String name, String level) throws MBeanException {
+        store.remove(name, AlertStore.Level.valueOf(level));
+    }
+}
diff --git a/alerting/pom.xml b/alerting/pom.xml
index bb5fbc0..7bc74fe 100644
--- a/alerting/pom.xml
+++ b/alerting/pom.xml
@@ -35,6 +35,8 @@
 
     <modules>
         <module>checker</module>
+        <module>command</module>
+        <module>management</module>
         <module>alerter</module>
     </modules>
 
diff --git a/assembly/src/main/feature/feature.xml b/assembly/src/main/feature/feature.xml
index 591e4b3..a440b21 100644
--- a/assembly/src/main/feature/feature.xml
+++ b/assembly/src/main/feature/feature.xml
@@ -392,7 +392,15 @@
     </feature>
     
     <feature name="decanter-alerting" version="${project.version}" description="Karaf
Decanter Alerting">
-        <feature>decanter-alerting-core</feature>
+        <feature prerequisite="true">decanter-alerting-core</feature>
+        <conditional>
+            <condition>shell</condition>
+            <bundle>mvn:org.apache.karaf.decanter.alerting/org.apache.karaf.decanter.alerting.command/${project.version}</bundle>
+        </conditional>
+        <conditional>
+            <condition>management</condition>
+            <bundle>mvn:org.apache.karaf.decanter.alerting/org.apache.karaf.decanter.alerting.management/${project.version}</bundle>
+        </conditional>
         <configfile finalname="/etc/org.apache.karaf.decanter.alerting.checker.cfg">mvn:org.apache.karaf.decanter.alerting/org.apache.karaf.decanter.alerting.checker/${project.version}/cfg</configfile>
     </feature>
 
diff --git a/pom.xml b/pom.xml
index 96897ff..c65f201 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,6 +53,7 @@
         <glassfish-json.version>1.0.4</glassfish-json.version>
         <json-api.version>1.0</json-api.version>
         <kafka.version>0.11.0.0</kafka.version>
+        <karaf.version>4.1.4</karaf.version>
         <kibana.version>3.1.1</kibana.version>
         <kibana4.version>4.1.2</kibana4.version>
         <kibana6.version>6.1.1</kibana6.version>
@@ -137,6 +138,11 @@
     <build>
         <pluginManagement>
             <plugins>
+                <plugin>
+                    <groupId>org.apache.karaf.tooling</groupId>
+                    <artifactId>karaf-services-maven-plugin</artifactId>
+                    <version>${karaf.version}</version>
+                </plugin>
                 <plugin>
                     <groupId>org.apache.felix</groupId>
                     <artifactId>maven-bundle-plugin</artifactId>
@@ -296,6 +302,13 @@
                 <version>6.0.0</version>
             </dependency>
 
+            <!-- Karaf -->
+            <dependency>
+                <groupId>org.apache.karaf.shell</groupId>
+                <artifactId>org.apache.karaf.shell.core</artifactId>
+                <version>${karaf.version}</version>
+            </dependency>
+
             <!-- ActiveMQ -->
             <dependency>
                 <groupId>org.apache.activemq</groupId>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Add decanter:alert* commands and MBeans
> ---------------------------------------
>
>                 Key: KARAF-5391
>                 URL: https://issues.apache.org/jira/browse/KARAF-5391
>             Project: Karaf
>          Issue Type: New Feature
>          Components: decanter
>            Reporter: Jean-Baptiste Onofré
>            Assignee: Jean-Baptiste Onofré
>            Priority: Major
>             Fix For: decanter-2.0.0
>
>
> It would be convenient to be able to ne able to manipulate the alerts store (list, remove,
...).



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message