Skip to content

Commit

Permalink
HWKALERTS-99 Unify addEvents() logic
Browse files Browse the repository at this point in the history
Maintain persisEvents() for Java API
  • Loading branch information
lucasponce committed Nov 4, 2015
1 parent b5b0fde commit 022506a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ public interface AlertsService {
void addAlerts(Collection<Alert> alerts) throws Exception;

/**
* Persist the provided events.
* Persist the provided events and sent to the engine for alerts evaluation.
* @param events Set of unpersisted Events.
* @throws Exception any problem
*/
void addEvents(Collection<Event> events) throws Exception;

/**
* Only persist the provided events.
* @param events Set of unpersisted Events.
* @throws Exception any problem
*/
void persistEvents(Collection<Event> events) throws Exception;

/**
* Add a note on an existing Alert.
* If alertId doesn't exist then the note is ignored.
Expand Down Expand Up @@ -170,25 +177,4 @@ void resolveAlertsForTrigger(String tenantId, String triggerId, String resolvedB
* @throws Exception any problem.
*/
void sendData(Collection<Data> data) throws Exception;

/**
* Send event into the alerting system for evaluation.
* Events are persisted after inference.
* addEvents() only persist events but not put it on the engine for evaluation.
*
* @param event Not Null. The events to be avaluated and persisted by the alerting engine.
* @throws Exception any problem
*/
void sendEvent(Event event) throws Exception;

/**
* Send event into the alerting system for evaluation.
* Events are persisted after inference.
* addEvents() only persist events but not put it on the engine for evaluation.
*
* @param events Not Null. The events to be avaluated and persisted by the alerting engine.
* @throws Exception any problem
*/
void sendEvents(Collection<Event> events) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public void run() {
rules.fire();
alertsService.addAlerts(alerts);
alerts.clear();
alertsService.addEvents(events);
alertsService.persistEvents(events);
events.clear();
handleDisabledTriggers();
handleAutoResolvedTriggers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ public void addAlerts(Collection<Alert> alerts) throws Exception {
List<Event> events = alerts.stream()
.map(Event::new)
.collect(Collectors.toList());
addEvents(events);
persistEvents(events);
}

@Override
public void addEvents(Collection<Event> events) throws Exception {
public void persistEvents(Collection<Event> events) throws Exception {
if (events == null) {
throw new IllegalArgumentException("Events must be not null");
}
Expand Down Expand Up @@ -1297,23 +1297,11 @@ public void sendData(Collection<Data> data) throws Exception {
}

@Override
public void sendEvent(Event event) throws Exception {
if (null == event) {
return;
}
addEvents(Collections.singletonList(event));
if (!isEmpty(event.getDataId())
&& eventsCacheManager.getActiveDataIds().contains(event.getDataId())) {
alertsEngine.sendEvent(event);
}
}

@Override
public void sendEvents(Collection<Event> events) throws Exception {
public void addEvents(Collection<Event> events) throws Exception {
if (null == events || events.isEmpty()) {
return;
}
addEvents(events);
persistEvents(events);
Set<String> activeDataIds = eventsCacheManager.getActiveDataIds();
Collection<Event> withConditions = new ArrayList<>();
for (Event e : events) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ public void test0060BasicEvent() throws Exception {
List<Event> events = new ArrayList<>();
events.add(event);

alertsService.addEvents(events);
alertsService.persistEvents(events);

// No filter
List<Event> result = alertsService.getEvents(TEST_TENANT, null, null);
Expand Down Expand Up @@ -1554,7 +1554,7 @@ public void test0070PagingEvents() throws Exception {
Thread.sleep(2); // events for the same trigger must not come in at the same exact ms.
}

alertsService.addEvents(events);
alertsService.persistEvents(events);

List<Event> result = alertsService.getEvents(TEST_TENANT, null, null);
assertEquals(107, result.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -100,7 +101,7 @@ public Response createEvent(
New events are sent directly to the engine for inference process.
Input events and new ones generated by the alerts engine are persisted at the end of the process.
*/
alertsService.sendEvent(event);
alertsService.addEvents(Collections.singletonList(event));
log.debugf("Event: %s ", event.toString());
return ResponseUtil.ok(event);
} else {
Expand Down

0 comments on commit 022506a

Please sign in to comment.