mirror of
https://github.com/Telecominfraproject/wlan-cloud-services.git
synced 2026-01-27 10:23:02 +00:00
[WIFI-2670] Client Session API support OUI attribute and count query
This commit is contained in:
@@ -12,6 +12,7 @@ import com.telecominfraproject.wlan.core.model.pagination.PaginationContext;
|
||||
import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse;
|
||||
|
||||
import com.telecominfraproject.wlan.client.datastore.ClientDatastore;
|
||||
import com.telecominfraproject.wlan.client.info.models.ClientSessionCounts;
|
||||
import com.telecominfraproject.wlan.client.models.Client;
|
||||
import com.telecominfraproject.wlan.client.session.models.ClientSession;
|
||||
|
||||
@@ -108,6 +109,13 @@ public class ClientDatastoreCassandra implements ClientDatastore {
|
||||
|
||||
return clientSessionDAO.getSessionsForCustomer(customerId, equipmentIds, locationIds, macSubstring, sortBy, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientSessionCounts getSessionCounts(int customerId) {
|
||||
// Not yet supported.
|
||||
ClientSessionCounts counts = new ClientSessionCounts();
|
||||
return counts;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.telecominfraproject.wlan.client.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;
|
||||
@@ -15,6 +16,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.telecominfraproject.wlan.client.datastore.ClientDatastore;
|
||||
import com.telecominfraproject.wlan.client.info.models.ClientInfoDetails;
|
||||
import com.telecominfraproject.wlan.client.info.models.ClientSessionCounts;
|
||||
import com.telecominfraproject.wlan.client.models.Client;
|
||||
import com.telecominfraproject.wlan.client.session.models.ClientSession;
|
||||
import com.telecominfraproject.wlan.core.model.equipment.MacAddress;
|
||||
@@ -512,4 +514,30 @@ public class ClientDatastoreInMemory extends BaseInMemoryDatastore implements Cl
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientSessionCounts getSessionCounts(int customerId) {
|
||||
ClientSessionCounts counts = new ClientSessionCounts();
|
||||
int totalCount = 0;
|
||||
Map<String, Integer> perOuiMap = new HashMap<>();
|
||||
|
||||
for (ClientSession session : idToClientSessionMap.values()) {
|
||||
if (session.getCustomerId() == customerId) {
|
||||
totalCount++;
|
||||
if (session.getOui() != null) {
|
||||
Integer cnt = perOuiMap.get(session.getOui());
|
||||
if (cnt == null) {
|
||||
cnt = 0;
|
||||
} else {
|
||||
cnt++;
|
||||
}
|
||||
perOuiMap.put(session.getOui(), cnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
counts.setTotalCount(totalCount);
|
||||
counts.setOuiCounts(perOuiMap);
|
||||
return counts;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.telecominfraproject.wlan.client.info.models.ClientSessionCounts;
|
||||
import com.telecominfraproject.wlan.client.models.Client;
|
||||
import com.telecominfraproject.wlan.client.session.models.ClientSession;
|
||||
import com.telecominfraproject.wlan.core.model.equipment.MacAddress;
|
||||
@@ -105,5 +106,12 @@ public interface ClientDatastore {
|
||||
*/
|
||||
PaginationResponse<ClientSession> getSessionsForCustomer(int customerId, Set<Long> equipmentIds, Set<Long> locationIds, String macSubstring, List<ColumnAndSort> sortBy, PaginationContext<ClientSession> context);
|
||||
|
||||
/**
|
||||
* Get Client Session counts for the given customerId.
|
||||
*
|
||||
* @param customerId
|
||||
* @return
|
||||
*/
|
||||
ClientSessionCounts getSessionCounts(int customerId);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
package com.telecominfraproject.wlan.client.info.models;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
|
||||
/**
|
||||
* Total and per-oui counts of the Client Sessions
|
||||
*/
|
||||
public class ClientSessionCounts extends BaseJsonModel {
|
||||
|
||||
private static final long serialVersionUID = 7697349699510565184L;
|
||||
|
||||
private int totalCount;
|
||||
private Map<String, Integer> ouiCounts = new HashMap<>();
|
||||
|
||||
public Map<String, Integer> getOuiCounts() {
|
||||
return ouiCounts;
|
||||
}
|
||||
|
||||
public void setOuiCounts(Map<String, Integer> ouiCounts) {
|
||||
this.ouiCounts = ouiCounts;
|
||||
}
|
||||
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientSessionCounts clone() {
|
||||
ClientSessionCounts ret = (ClientSessionCounts) super.clone();
|
||||
if (ouiCounts != null) {
|
||||
ret.ouiCounts = new HashMap<>(ouiCounts);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import com.telecominfraproject.wlan.core.model.json.interfaces.HasCustomerId;
|
||||
|
||||
public class ClientSession extends BaseJsonModel implements HasCustomerId {
|
||||
|
||||
private static final String UNKNOWN_OUI = "ffffff";
|
||||
|
||||
private static final long serialVersionUID = -7714023056859882994L;
|
||||
|
||||
private MacAddress macAddress;
|
||||
@@ -16,6 +18,7 @@ public class ClientSession extends BaseJsonModel implements HasCustomerId {
|
||||
private long locationId;
|
||||
private ClientSessionDetails details;
|
||||
private long lastModifiedTimestamp;
|
||||
private String oui;
|
||||
|
||||
public long getEquipmentId() {
|
||||
return equipmentId;
|
||||
@@ -47,6 +50,12 @@ public class ClientSession extends BaseJsonModel implements HasCustomerId {
|
||||
|
||||
public void setMacAddress(MacAddress macAddress) {
|
||||
this.macAddress = macAddress;
|
||||
if (macAddress != null && macAddress.isGlobalAddress()) {
|
||||
this.oui = macAddress.toOuiString();
|
||||
}
|
||||
else {
|
||||
this.oui = UNKNOWN_OUI;
|
||||
}
|
||||
}
|
||||
|
||||
public long getLastModifiedTimestamp() {
|
||||
@@ -65,6 +74,14 @@ public class ClientSession extends BaseJsonModel implements HasCustomerId {
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
public String getOui() {
|
||||
return oui;
|
||||
}
|
||||
|
||||
public void setOui(String oui) {
|
||||
this.oui = oui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientSession clone() {
|
||||
ClientSession ret = (ClientSession) super.clone();
|
||||
@@ -79,7 +96,7 @@ public class ClientSession extends BaseJsonModel implements HasCustomerId {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(customerId, details, equipmentId, locationId, lastModifiedTimestamp, macAddress);
|
||||
return Objects.hash(customerId, details, equipmentId, locationId, lastModifiedTimestamp, macAddress, oui);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,7 +112,8 @@ public class ClientSession extends BaseJsonModel implements HasCustomerId {
|
||||
&& equipmentId == other.equipmentId
|
||||
&& locationId == other.locationId
|
||||
&& lastModifiedTimestamp == other.lastModifiedTimestamp
|
||||
&& Objects.equals(macAddress, other.macAddress);
|
||||
&& Objects.equals(macAddress, other.macAddress)
|
||||
&& Objects.equals(oui, other.oui);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.telecominfraproject.wlan.core.model.json.GenericResponse;
|
||||
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.client.info.models.ClientSessionCounts;
|
||||
import com.telecominfraproject.wlan.client.models.Client;
|
||||
import com.telecominfraproject.wlan.client.session.models.ClientSession;
|
||||
|
||||
@@ -144,4 +144,12 @@ public interface ClientServiceInterface {
|
||||
*/
|
||||
PaginationResponse<ClientSession> getSessionsForCustomer(int customerId, Set<Long> equipmentIds, Set<Long> locationIds, String macSubstring, List<ColumnAndSort> sortBy, PaginationContext<ClientSession> context);
|
||||
|
||||
/**
|
||||
* Get Client Session counts for the given customerId.
|
||||
*
|
||||
* @param customerId
|
||||
* @return
|
||||
*/
|
||||
ClientSessionCounts getSessionCounts(int customerId);
|
||||
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@ package com.telecominfraproject.wlan.client;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.telecominfraproject.wlan.client.controller.ClientController;
|
||||
import com.telecominfraproject.wlan.client.controller.ClientController.ListOfClientSessions;
|
||||
import com.telecominfraproject.wlan.client.info.models.ClientSessionCounts;
|
||||
import com.telecominfraproject.wlan.client.models.Client;
|
||||
import com.telecominfraproject.wlan.client.session.models.ClientSession;
|
||||
import com.telecominfraproject.wlan.core.model.equipment.MacAddress;
|
||||
@@ -26,7 +25,6 @@ import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse;
|
||||
public class ClientServiceLocal implements ClientServiceInterface {
|
||||
|
||||
@Autowired private ClientController clientController;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ClientServiceLocal.class);
|
||||
|
||||
@Override
|
||||
public Client create(Client client) {
|
||||
@@ -109,5 +107,10 @@ public class ClientServiceLocal implements ClientServiceInterface {
|
||||
public GenericResponse deleteSessions(long createdBeforeTimestamp) {
|
||||
return clientController.deleteSessions(createdBeforeTimestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientSessionCounts getSessionCounts(int customerId) {
|
||||
return clientController.getSessionCounts(customerId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.telecominfraproject.wlan.client.info.models.ClientSessionCounts;
|
||||
import com.telecominfraproject.wlan.client.models.Client;
|
||||
import com.telecominfraproject.wlan.client.session.models.ClientSession;
|
||||
import com.telecominfraproject.wlan.core.client.BaseRemoteClient;
|
||||
@@ -365,5 +366,21 @@ public class ClientServiceRemote extends BaseRemoteClient implements ClientServi
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientSessionCounts getSessionCounts(int customerId) {
|
||||
LOG.debug("calling getSessionCounts( {} )", customerId);
|
||||
|
||||
try {
|
||||
ResponseEntity<ClientSessionCounts> responseEntity = restTemplate.exchange(getBaseUrl() + "/session/countsForCustomer?customerId={customerId}",
|
||||
HttpMethod.GET, null, ClientSessionCounts.class, customerId);
|
||||
|
||||
ClientSessionCounts result = responseEntity.getBody();
|
||||
LOG.debug("getSessionCounts({}) returns {} ", customerId, result);
|
||||
return result;
|
||||
} catch (Exception exp) {
|
||||
LOG.error("getSessionCounts({}) exception ", customerId, exp);
|
||||
throw exp;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,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;
|
||||
@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.telecominfraproject.wlan.client.datastore.ClientDatastore;
|
||||
import com.telecominfraproject.wlan.client.info.models.ClientSessionCounts;
|
||||
import com.telecominfraproject.wlan.client.models.Client;
|
||||
import com.telecominfraproject.wlan.client.models.events.ClientAddedEvent;
|
||||
import com.telecominfraproject.wlan.client.models.events.ClientBlockListChangedEvent;
|
||||
@@ -430,6 +432,13 @@ public class ClientController {
|
||||
|
||||
return new GenericResponse(true, "");
|
||||
}
|
||||
|
||||
@GetMapping("/session/countsForCustomer")
|
||||
public ClientSessionCounts getSessionCounts(@RequestParam int customerId) {
|
||||
ClientSessionCounts ret = clientDatastore.getSessionCounts(customerId);
|
||||
LOG.debug("countsForCustomer({}) {}", customerId, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void publishEvent(SystemEvent event) {
|
||||
if (event == null) {
|
||||
|
||||
Reference in New Issue
Block a user