-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an avail data listener on the bus for hawkular kettle integration.
- Loading branch information
Showing
3 changed files
with
255 additions
and
0 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
108 changes: 108 additions & 0 deletions
108
hawkular-alerts-bus/src/main/java/org/hawkular/alerts/bus/listener/AvailDataListener.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,108 @@ | ||
/* | ||
* Copyright 2015 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.bus.listener; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.ejb.ActivationConfigProperty; | ||
import javax.ejb.EJB; | ||
import javax.ejb.MessageDriven; | ||
import javax.jms.MessageListener; | ||
|
||
import org.hawkular.alerts.api.model.data.Availability; | ||
import org.hawkular.alerts.api.model.data.Data; | ||
import org.hawkular.alerts.api.services.AlertsService; | ||
import org.hawkular.alerts.api.services.DefinitionsService; | ||
import org.hawkular.alerts.bus.messages.AvailDataMessage; | ||
import org.hawkular.alerts.bus.messages.AvailDataMessage.AvailData; | ||
import org.hawkular.alerts.bus.messages.AvailDataMessage.SingleAvail; | ||
import org.hawkular.bus.common.consumer.BasicMessageListener; | ||
import org.jboss.logging.Logger; | ||
|
||
import com.google.gson.GsonBuilder; | ||
|
||
/** | ||
* An adapter that processes Hawkular Availability data, extracts relevant avail datums, translates them to Alerting | ||
* Data format, and forwards them for Alert processing. | ||
* </p> | ||
* This is useful only when deploying into the Hawkular Bus with Hawkular Metrics. The expected format of the | ||
* data is JSON like: | ||
* </p> | ||
* <code> | ||
* { tenantId , List<org.rhq.metrics.client.common.SingleMetric> } | ||
* </code> | ||
* </p> | ||
* TODO: Add filtering of relevant Metric Ids. This means fetching the active triggers, running through the conditions, | ||
* and collecting the dataIds. Then using thise to filter the metricIds converted and forwarded to the engine. Note | ||
* that we will need a way to update that Id set as changes occur to the Trigger population. Changes are | ||
* rare so we don't want it to be too cumbersome. | ||
* | ||
* @author Jay Shaughnessy | ||
* @author Lucas Ponce | ||
*/ | ||
@MessageDriven(messageListenerInterface = MessageListener.class, activationConfig = { | ||
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"), | ||
@ActivationConfigProperty(propertyName = "destination", propertyValue = "HawkularAvailData") }) | ||
public class AvailDataListener extends BasicMessageListener<AvailDataMessage> { | ||
private final Logger log = Logger.getLogger(AvailDataListener.class); | ||
|
||
@EJB | ||
AlertsService alerts; | ||
|
||
@EJB | ||
DefinitionsService definitions; | ||
|
||
@PostConstruct | ||
public void postContruct() { | ||
|
||
} | ||
|
||
private boolean isNeeded(String metricId) { | ||
// TODO: probably a Map lookup | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void onBasicMessage(AvailDataMessage msg) { | ||
log.debugf("Message received: [%s]", msg); | ||
|
||
AvailData availData = msg.getAvailData(); | ||
|
||
List<SingleAvail> data = availData.getData(); | ||
List<Data> alertData = new ArrayList<>(data.size()); | ||
for (SingleAvail a : data) { | ||
if (isNeeded(a.getId())) { | ||
alertData.add(new Availability(a.getId(), a.getTimestamp(), a.getAvail())); | ||
} | ||
} | ||
|
||
log.debugf("Sending: [%s]", alertData); | ||
alerts.sendData(alertData); | ||
} | ||
|
||
// just dumps the expected json | ||
public static void main(String[] args) { | ||
AvailData d = new AvailData(); | ||
List<SingleAvail> sa = new ArrayList<>(1); | ||
sa.add(new SingleAvail("tenant", "Avail-01", 123L, "DOWN")); | ||
d.setData(sa); | ||
System.out.println(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(d).toString()); | ||
} | ||
|
||
} |
137 changes: 137 additions & 0 deletions
137
hawkular-alerts-bus/src/main/java/org/hawkular/alerts/bus/messages/AvailDataMessage.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,137 @@ | ||
/* | ||
* Copyright 2015 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.bus.messages; | ||
|
||
import java.util.List; | ||
|
||
import org.hawkular.bus.common.BasicMessage; | ||
|
||
import com.google.gson.annotations.Expose; | ||
|
||
/** | ||
* A bus message for messages on HawkularAvailData Topic. | ||
* | ||
* @author Jay Shaughnessy | ||
* @author Lucas Ponce | ||
*/ | ||
|
||
public class AvailDataMessage extends BasicMessage { | ||
|
||
// the basic message body - it will be exposed to the JSON output | ||
@Expose | ||
private AvailData availData; | ||
|
||
protected AvailDataMessage() { | ||
} | ||
|
||
public AvailDataMessage(AvailData metricData) { | ||
this.availData = metricData; | ||
} | ||
|
||
public AvailData getAvailData() { | ||
return availData; | ||
} | ||
|
||
public void setAvailData(AvailData availData) { | ||
this.availData = availData; | ||
} | ||
|
||
public static class AvailData { | ||
@Expose | ||
List<SingleAvail> data; | ||
|
||
public AvailData() { | ||
} | ||
|
||
public List<SingleAvail> getData() { | ||
return data; | ||
} | ||
|
||
public void setData(List<SingleAvail> data) { | ||
this.data = data; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AvailData [data=" + data + "]"; | ||
} | ||
} | ||
|
||
/** | ||
* This is meant to parse out an instance of <code>org.rhq.metrics.client.common.SingleMetric</code> | ||
*/ | ||
public static class SingleAvail { | ||
@Expose | ||
private String tenantId; | ||
@Expose | ||
private String id; | ||
@Expose | ||
private long timestamp; | ||
@Expose | ||
private String avail; | ||
|
||
public SingleAvail() { | ||
} | ||
|
||
public SingleAvail(String tenantId, String id, long timestamp, String avail) { | ||
this.tenantId = tenantId; | ||
this.id = id; | ||
this.timestamp = timestamp; | ||
this.avail = avail; | ||
} | ||
|
||
public String getTenantId() { | ||
return tenantId; | ||
} | ||
|
||
public void setTenantId(String tenantId) { | ||
this.tenantId = tenantId; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public long getTimestamp() { | ||
return timestamp; | ||
} | ||
|
||
public void setTimestamp(long timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
|
||
public String getAvail() { | ||
return avail; | ||
} | ||
|
||
public void setAvail(String avail) { | ||
this.avail = avail; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SingleAvail [tenantId=" + tenantId + ", id=" + id + ", timestamp=" + timestamp + ", avail=" | ||
+ avail + "]"; | ||
} | ||
|
||
} | ||
|
||
} |