[WIFI-3056] Add API to get system event statistics

This commit is contained in:
Norm Traxler
2021-07-15 22:15:01 -04:00
parent 8834c33d90
commit 910a2cbe0c
9 changed files with 220 additions and 4 deletions

View File

@@ -33,6 +33,7 @@ import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse;
import com.telecominfraproject.wlan.core.server.cassandra.RowMapper;
import com.telecominfraproject.wlan.systemevent.datastore.SystemEventDatastore;
import com.telecominfraproject.wlan.systemevent.models.SystemEventRecord;
import com.telecominfraproject.wlan.systemevent.models.SystemEventStats;
/**
@@ -1031,4 +1032,9 @@ public class SystemEventDatastoreCassandra implements SystemEventDatastore {
return nextPagingState;
}
@Override
public SystemEventStats getSystemEventStats(String filterAttributeName, String filterAttributeValue, long fromTime, long toTime) {
return new SystemEventStats();
}
}

View File

@@ -3,6 +3,7 @@ package com.telecominfraproject.wlan.systemevent.datastore.inmemory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -20,8 +21,10 @@ import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse;
import com.telecominfraproject.wlan.core.model.pagination.SortOrder;
import com.telecominfraproject.wlan.datastore.inmemory.BaseInMemoryDatastore;
import com.telecominfraproject.wlan.systemevent.datastore.SystemEventDatastore;
import com.telecominfraproject.wlan.systemevent.models.EquipmentEventStats;
import com.telecominfraproject.wlan.systemevent.models.SystemEventRecord;
import com.telecominfraproject.wlan.systemevent.models.SystemEventRecordKey;
import com.telecominfraproject.wlan.systemevent.models.SystemEventStats;
/**
* @author dtoptygin
@@ -228,4 +231,38 @@ public class SystemEventDatastoreInMemory extends BaseInMemoryDatastore implemen
return clientMacAddresses.contains(macAddress);
}
@Override
public SystemEventStats getSystemEventStats(String filterAttributeName, String filterAttributeValue, long fromTime, long toTime) {
List<SystemEventRecord> items = new LinkedList<>();
// apply filters and build the full result list first - inefficient, but ok for testing
for (SystemEventRecord mdl : idToSystemEventRecordMap.values()) {
if (mdl.getEventTimestamp() >= fromTime && mdl.getEventTimestamp() <= toTime) {
items.add(mdl);
}
}
SystemEventStats stats = new SystemEventStats();
stats.setTotalCount(items.size());
Map<String, EquipmentEventStats> eqptStatsMap = new HashMap<>();
for (SystemEventRecord mdl : items) {
EquipmentEventStats eqptStats = eqptStatsMap.get(Long.toString(mdl.getEquipmentId()));
if (eqptStats == null) {
eqptStats = new EquipmentEventStats();
eqptStats.setEquipmentId(mdl.getEquipmentId());
eqptStatsMap.put(Long.toString(mdl.getEquipmentId()), eqptStats);
}
eqptStats.setTotalCount(eqptStats.getTotalCount() + 1);
if (mdl.getEventTimestamp() > eqptStats.getLastEventTime()) {
eqptStats.setLastEventTime(mdl.getEventTimestamp());
}
items.add(mdl);
}
List<EquipmentEventStats> equipmentStats = new ArrayList<>();
stats.setEquipmentStats(equipmentStats);
return stats;
}
}

View File

@@ -8,6 +8,7 @@ import com.telecominfraproject.wlan.core.model.pagination.ColumnAndSort;
import com.telecominfraproject.wlan.core.model.pagination.PaginationContext;
import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse;
import com.telecominfraproject.wlan.systemevent.models.SystemEventRecord;
import com.telecominfraproject.wlan.systemevent.models.SystemEventStats;
/**
* @author dtoptygin
@@ -60,4 +61,13 @@ public interface SystemEventDatastore {
List<ColumnAndSort> sortBy,
PaginationContext<SystemEventRecord> context);
/**
* @param filterAttributeName
* @param filterAttributeValue
* @param fromTime
* @param toTime
* @return Returns system event statistics for the given time range.
*/
SystemEventStats getSystemEventStats(String filterAttributeName, String filterAttributeValue, long fromTime, long toTime);
}

View File

@@ -0,0 +1,58 @@
package com.telecominfraproject.wlan.systemevent.models;
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
/**
* Total and per-oui/equipment/radio counts of the Client Sessions
*/
public class EquipmentEventStats extends BaseJsonModel {
private static final long serialVersionUID = 6630012772286577077L;
/**
* The equipment ID.
*/
private long equipmentId;
/**
* Count of system events for the equipment.
*/
private long totalCount;
/**
* Last event time.
*/
private long lastEventTime;
public long getEquipmentId() {
return equipmentId;
}
public void setEquipmentId(long equipmentId) {
this.equipmentId = equipmentId;
}
public long getTotalCount() {
return totalCount;
}
public void setTotalCount(long totalCount) {
this.totalCount = totalCount;
}
public long getLastEventTime() {
return lastEventTime;
}
public void setLastEventTime(long lastEventTime) {
this.lastEventTime = lastEventTime;
}
@Override
public EquipmentEventStats clone() {
EquipmentEventStats ret = (EquipmentEventStats) super.clone();
return ret;
}
}

View File

@@ -0,0 +1,51 @@
package com.telecominfraproject.wlan.systemevent.models;
import java.util.ArrayList;
import java.util.List;
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
/**
* Total and per equipment counts of the System Events
*/
public class SystemEventStats extends BaseJsonModel {
private static final long serialVersionUID = 6630012772286577077L;
/**
* Total count of all system events.
*/
private long totalCount;
/**
* Counts of system events per equipment Id.
*/
private List<EquipmentEventStats> equipmentStats = new ArrayList<>();
public long getTotalCount() {
return totalCount;
}
public void setTotalCount(long totalCount) {
this.totalCount = totalCount;
}
public List<EquipmentEventStats> getEquipmentStats() {
return equipmentStats;
}
public void setEquipmentStats(List<EquipmentEventStats> equipmentStats) {
this.equipmentStats = equipmentStats;
}
@Override
public SystemEventStats clone() {
SystemEventStats ret = (SystemEventStats) super.clone();
if (equipmentStats != null) {
ret.equipmentStats = new ArrayList<>(equipmentStats);
}
return ret;
}
}

View File

@@ -9,6 +9,7 @@ import com.telecominfraproject.wlan.core.model.pagination.ColumnAndSort;
import com.telecominfraproject.wlan.core.model.pagination.PaginationContext;
import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse;
import com.telecominfraproject.wlan.systemevent.models.SystemEventRecord;
import com.telecominfraproject.wlan.systemevent.models.SystemEventStats;
/**
@@ -70,4 +71,13 @@ public interface SystemEventServiceInterface {
return getForCustomer(fromTime, toTime, customerId, null, equipmentIds, null, dataTypes, sortBy, context);
}
/**
* @param filterAttributeName
* @param filterAttributeValue
* @param fromTime
* @param toTime
* @return Returns system event statistics for the given time range.
*/
SystemEventStats getSystemEventStats(String filterAttributeName, String filterAttributeValue, long fromTime, long toTime);
}

View File

@@ -15,6 +15,7 @@ import com.telecominfraproject.wlan.core.model.pagination.PaginationContext;
import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse;
import com.telecominfraproject.wlan.systemevent.controller.SystemEventController;
import com.telecominfraproject.wlan.systemevent.models.SystemEventRecord;
import com.telecominfraproject.wlan.systemevent.models.SystemEventStats;
/**
* @author dtoptygin
@@ -56,11 +57,17 @@ public class SystemEventServiceLocal implements SystemEventServiceInterface {
Set<Long> locationIds, Set<Long> equipmentIds, Set<MacAddress> clientMacAdresses, Set<String> dataTypes, List<ColumnAndSort> sortBy,
PaginationContext<SystemEventRecord> context) {
LOG.debug("calling serviceMetricController.getForCustomer {} {} {} ", fromTime, toTime, customerId);
LOG.debug("calling systemEventController.getForCustomer {} {} {} ", fromTime, toTime, customerId);
return systemEventController.getForCustomer(fromTime, toTime, customerId,
locationIds, equipmentIds, clientMacAdresses, dataTypes, sortBy, context);
}
@Override
public SystemEventStats getSystemEventStats(String filterAttributeName, String filterAttributeValue, long fromTime, long toTime) {
LOG.debug("calling systemEventController.getSystemEventStats {} {} {} {}", filterAttributeName, filterAttributeValue, fromTime, toTime);
return systemEventController.getSystemEventStats(filterAttributeName, filterAttributeValue, fromTime, toTime);
}
}

View File

@@ -20,6 +20,7 @@ import com.telecominfraproject.wlan.core.model.pagination.PaginationContext;
import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse;
import com.telecominfraproject.wlan.datastore.exceptions.DsDataValidationException;
import com.telecominfraproject.wlan.systemevent.models.SystemEventRecord;
import com.telecominfraproject.wlan.systemevent.models.SystemEventStats;
/**
* @author dtoptygin
@@ -175,5 +176,22 @@ public class SystemEventServiceRemote extends BaseRemoteClient implements System
return baseUrl;
}
@Override
public SystemEventStats getSystemEventStats(String filterAttributeName, String filterAttributeValue, long fromTime, long toTime) {
LOG.debug("calling getSystemEventStats( {}, {}, {}, {} )", filterAttributeName, filterAttributeValue, fromTime, toTime);
try {
ResponseEntity<SystemEventStats> responseEntity = restTemplate.exchange(getBaseUrl() +
"/stats?filterAttributeName={filterAttributeName}&filterAttributeValue={filterAttributeValue}&fromTime={fromTime}&toTime={toTime}",
HttpMethod.GET, null, SystemEventStats.class, filterAttributeName, filterAttributeValue, fromTime, toTime);
SystemEventStats result = responseEntity.getBody();
LOG.debug("getSessionCounts({}, {}, {}, {}) returns {} ", filterAttributeName, filterAttributeValue, fromTime, toTime, result);
return result;
} catch (Exception exp) {
LOG.error("getSessionCounts({}, {}, {}, {}) exception ", filterAttributeName, filterAttributeValue, fromTime, toTime, exp);
throw exp;
}
}
}

View File

@@ -7,6 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -22,6 +23,7 @@ import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse;
import com.telecominfraproject.wlan.datastore.exceptions.DsDataValidationException;
import com.telecominfraproject.wlan.systemevent.datastore.SystemEventDatastore;
import com.telecominfraproject.wlan.systemevent.models.SystemEventRecord;
import com.telecominfraproject.wlan.systemevent.models.SystemEventStats;
/**
@@ -141,7 +143,6 @@ public class SystemEventController {
return ret;
}
/**
* Deletes SystemEventRecord records
*
@@ -173,5 +174,23 @@ public class SystemEventController {
return new GenericResponse(true, "");
}
/**
* @param filterAttributeName
* @param filterAttributeValue
* @param fromTime
* @param toTime
* @return Returns system event statistics for the given time range.
*/
@GetMapping("/stats")
public SystemEventStats getSystemEventStats(
@RequestParam String filterAttributeName,
@RequestParam String filterAttributeValue,
@RequestParam long fromTime,
@RequestParam long toTime) {
SystemEventStats ret = systemEventDatastore.getSystemEventStats(filterAttributeName, filterAttributeValue, fromTime, toTime);
LOG.debug("getSystemEventStats({},{},{},{}) {}", filterAttributeName, filterAttributeName, fromTime, toTime, ret);
return ret;
}
}