static public void execute(Map<String, String> infoMap) throws Exception {
int conditionId = Integer.valueOf(infoMap.get(DATAMAP_CONDITION_ID));
int resourceId = Integer.valueOf(infoMap.get(DATAMAP_RESOURCE_ID));
long duration = Long.valueOf(infoMap.get(DATAMAP_DURATION)); // in seconds
long durationStart = Long.valueOf(infoMap.get(DATAMAP_START_TIME)); // in milliseconds
AlertConditionOperator operator = AlertConditionOperator.valueOf(infoMap.get(DATAMAP_OPERATOR));
// get the availabilities for the duration period, one consistent duration will indicate a duration condition
AvailabilityCriteria criteria = new AvailabilityCriteria();
criteria.addFilterResourceId(resourceId);
long durationEnd = durationStart + (duration * 1000);
criteria.addFilterInterval((durationStart + 1), (durationEnd - 1)); // reduced 1ms to fake exclusive interval filter.
criteria.addSortStartTime(PageOrdering.ASC);
List<Availability> avails = LookupUtil.getAvailabilityManager().findAvailabilityByCriteria(
LookupUtil.getSubjectManager().getOverlord(), criteria);
// Although unlikely, it's possible the resource has actually gone away while we waited out the duration period.
// If we can't find any resource avail assume the resource is gone and just end the job.
if (avails.isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug("AlertAvailabilityDurationJob: No alert. Assuming resource has been uninventoried ["
+ resourceId + "]");
}
return;
}
// If there are multiple duration records for the duration period then the avail did not stay constant.
// Therefore, the alert should not fire as the semantics are "goes down and stays down".
if (avails.size() > 1) {
if (LOG.isDebugEnabled()) {
LOG.debug("AlertAvailabilityDurationJob: No alert. Resource avail for [" + resourceId
+ "] has fluctuated. " + avails);
}
return;
}
// At this point we should be able to just checkConditions because if there is only one avail record for the
// duration period it means nothing has changed. But, we'll perform a sanity check just to ensure the avail
// type is what we think it should be...
Availability avail = avails.get(0);
AvailabilityType availType = avail.getAvailabilityType();
boolean checkConditions = false;
switch (operator) {
case AVAIL_DURATION_DOWN:
checkConditions = (AvailabilityType.DOWN == availType);
break;
case AVAIL_DURATION_NOT_UP:
checkConditions = (AvailabilityType.UP != availType);
break;
default:
LOG.error("AlertAvailabilityDurationJob: unexpected operator [" + operator.name() + "]");
}
// the call to checkConditions will probably result in an alert, as the actual condition satisfaction was
// just done. but we need to actually hook into the alerting chassis to ensure any other conditions are
// still satisfied and to make sure all the alert processing is performed.