Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a06d125
commit 32a6d1f
Showing
37 changed files
with
7,608 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2015-2017 Red Hat, Inc. and/or its affiliates | ||
and other contributors as indicated by the @author tags. | ||
Licensed 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. | ||
--> | ||
<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> | ||
|
||
<parent> | ||
<groupId>org.hawkular.alerts</groupId> | ||
<artifactId>hawkular-alerts-alerters</artifactId> | ||
<version>2.0.0.Final-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>hawkular-alerts-alerters-api</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Hawkular Alerting: Alerters Api</name> | ||
|
||
</project> |
20 changes: 20 additions & 0 deletions
20
alerters/alerters-api/src/main/java/org/hawkular/alerts/alerters/api/Alerter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.hawkular.alerts.alerters.api; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Define an alerters plugin implementation | ||
* Plugin must have a unique name that will be used at registration phase | ||
* Plugin must implement AlerterPlugin interface | ||
* | ||
* @author Jay Shaughnessy | ||
* @author Lucas Ponce | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface Alerter { | ||
String name(); | ||
} |
16 changes: 16 additions & 0 deletions
16
alerters/alerters-api/src/main/java/org/hawkular/alerts/alerters/api/AlerterPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.hawkular.alerts.alerters.api; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
|
||
import org.hawkular.alerts.api.services.AlertsService; | ||
import org.hawkular.alerts.api.services.DefinitionsService; | ||
|
||
/** | ||
* @author Jay Shaughnessy | ||
* @author Lucas Ponce | ||
*/ | ||
public interface AlerterPlugin { | ||
|
||
void init(DefinitionsService definitions, AlertsService alerts, ExecutorService executor); | ||
void stop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2015-2017 Red Hat, Inc. and/or its affiliates | ||
and other contributors as indicated by the @author tags. | ||
Licensed 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. | ||
--> | ||
<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> | ||
|
||
<parent> | ||
<groupId>org.hawkular.alerts</groupId> | ||
<artifactId>hawkular-alerts-alerters</artifactId> | ||
<version>2.0.0.Final-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>hawkular-alerts-alerters-impl</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Hawkular Alerting: Alerters Implementation</name> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.hawkular.alerts</groupId> | ||
<artifactId>hawkular-alerts-alerters-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hawkular.alerts</groupId> | ||
<artifactId>hawkular-alerts-engine</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
105 changes: 105 additions & 0 deletions
105
...s/alerters-impl/src/main/java/org/hawkular/alerts/alerters/standalone/AlerterPlugins.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright 2015-2016 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed 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.hawkular.alerts.alerters.standalone; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipInputStream; | ||
|
||
import org.hawkular.alerts.alerters.api.Alerter; | ||
import org.hawkular.alerts.alerters.api.AlerterPlugin; | ||
import org.hawkular.alerts.api.services.AlertsService; | ||
import org.hawkular.alerts.api.services.DefinitionsService; | ||
import org.hawkular.alerts.engine.StandaloneAlerts; | ||
import org.hawkular.commons.log.MsgLogger; | ||
import org.hawkular.commons.log.MsgLogging; | ||
|
||
/** | ||
* Helper class to find the classes annotated with ActionPlugin and instantiate them. | ||
* | ||
* @author Lucas Ponce | ||
*/ | ||
public class AlerterPlugins { | ||
private static final MsgLogger log = MsgLogging.getMsgLogger(AlerterPlugins.class); | ||
private static AlerterPlugins instance; | ||
private Map<String, AlerterPlugin> plugins; | ||
private ClassLoader cl = Thread.currentThread().getContextClassLoader(); | ||
|
||
DefinitionsService definitions; | ||
AlertsService alerts; | ||
ExecutorService executor; | ||
|
||
public static synchronized Map<String, AlerterPlugin> getPlugins() { | ||
if (instance == null) { | ||
instance = new AlerterPlugins(); | ||
} | ||
return Collections.unmodifiableMap(instance.plugins); | ||
} | ||
|
||
private AlerterPlugins() { | ||
try { | ||
plugins = new HashMap<>(); | ||
definitions = StandaloneAlerts.getDefinitionsService(); | ||
alerts = StandaloneAlerts.getAlertsService(); | ||
executor = StandaloneAlerts.getExecutor(); | ||
scan(); | ||
} catch (Exception e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private void scan() throws IOException { | ||
String[] classpath = System.getProperty("java.class.path").split(":"); | ||
for (int i=0; i<classpath.length; i++) { | ||
if (classpath[i].contains("hawkular") && classpath[i].endsWith("jar")) { | ||
ZipInputStream zip = new ZipInputStream(new FileInputStream(classpath[i])); | ||
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) { | ||
if (!entry.isDirectory() && entry.getName().endsWith(".class")) { | ||
String className = entry.getName().replace('/', '.'); // including ".class" | ||
className = className.substring(0, className.length() - 6); | ||
try { | ||
Class clazz = cl.loadClass(className); | ||
if (clazz.isAnnotationPresent(Alerter.class)) { | ||
Alerter alerter = (Alerter)clazz.getAnnotation(Alerter.class); | ||
String name = alerter.name(); | ||
Object newInstance = clazz.newInstance(); | ||
log.infof("Scanning %s", clazz.getName()); | ||
if (newInstance instanceof AlerterPlugin) { | ||
AlerterPlugin pluginInstance = (AlerterPlugin)newInstance; | ||
pluginInstance.init(definitions, alerts, executor); | ||
plugins.put(name, pluginInstance); | ||
} else { | ||
throw new IllegalStateException("Alerter [" + name + "] is not instance of " + | ||
"AlerterPlugin"); | ||
} | ||
} | ||
} catch (Exception e) { | ||
log.errorf("Error loading AlerterPlugin %s. Reason: %s", className, e.toString()); | ||
System.exit(1); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...rc/main/java/org/hawkular/alerts/alerters/standalone/StandaloneAlerterPluginRegister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.hawkular.alerts.alerters.standalone; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
import org.hawkular.alerts.alerters.api.AlerterPlugin; | ||
import org.hawkular.commons.log.MsgLogger; | ||
import org.hawkular.commons.log.MsgLogging; | ||
|
||
/** | ||
* @author Jay Shaughnessy | ||
* @author Lucas Ponce | ||
*/ | ||
public class StandaloneAlerterPluginRegister { | ||
private static final MsgLogger log = MsgLogging.getMsgLogger(StandaloneAlerterPluginRegister.class); | ||
|
||
private static StandaloneAlerterPluginRegister instance; | ||
private static ExecutorService executor; | ||
|
||
Map<String, AlerterPlugin> plugins; | ||
|
||
private StandaloneAlerterPluginRegister() { | ||
init(); | ||
} | ||
|
||
public static void setExecutor(ExecutorService executor) { | ||
StandaloneAlerterPluginRegister.executor = executor; | ||
} | ||
|
||
public void init() { | ||
plugins = AlerterPlugins.getPlugins(); | ||
log.info("Alerter Plugins load finished"); | ||
} | ||
|
||
public static synchronized void start() { | ||
if (instance == null) { | ||
instance = new StandaloneAlerterPluginRegister(); | ||
} | ||
} | ||
|
||
public static synchronized void stop() { | ||
if (instance != null && instance.plugins != null) { | ||
instance.plugins.entrySet().stream().forEach(pluginEntry -> { | ||
log.infof("Stopping Alerter %s", pluginEntry.getKey()); | ||
pluginEntry.getValue().stop(); | ||
}); | ||
} | ||
instance = null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2015-2017 Red Hat, Inc. and/or its affiliates | ||
and other contributors as indicated by the @author tags. | ||
Licensed 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. | ||
--> | ||
<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> | ||
|
||
<parent> | ||
<groupId>org.hawkular.alerts</groupId> | ||
<artifactId>hawkular-alerts-alerters-plugins</artifactId> | ||
<version>2.0.0.Final-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>hawkular-alerts-alerters-elasticsearch</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Hawkular Alerting: Alerter Elasticsearch Plugin</name> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.elasticsearch.client</groupId> | ||
<artifactId>rest</artifactId> | ||
<version>${version.org.elasticsearch.client}</version> | ||
</dependency> | ||
|
||
<!-- Tests --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
<version>${version.junit}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
Oops, something went wrong.