Browse Source

cleaned up server-side stats service, UI now uses per-client calls

pull/1161/merge
Justin Richer 8 years ago
parent
commit
a926a8f0ab
  1. 7
      openid-connect-common/src/main/java/org/mitre/openid/connect/service/StatsService.java
  2. 63
      openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultStatsService.java

7
openid-connect-common/src/main/java/org/mitre/openid/connect/service/StatsService.java

@ -39,13 +39,6 @@ public interface StatsService {
*/
public Map<String, Integer> getSummaryStats();
/**
* Calculate usage count for all clients
*
* @return a map of id of client object to number of approvals
*/
public Map<String, Integer> getByClientId();
/**
* Calculate the usage count for a single client
*

63
openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/DefaultStatsService.java

@ -50,9 +50,6 @@ public class DefaultStatsService implements StatsService {
@Autowired
private ApprovedSiteService approvedSiteService;
@Autowired
private ClientDetailsEntityService clientService;
// stats cache
private Supplier<Map<String, Integer>> summaryCache = createSummaryCache();
@ -66,18 +63,6 @@ public class DefaultStatsService implements StatsService {
}, 10, TimeUnit.MINUTES);
}
private Supplier<Map<String, Integer>> byClientIdCache = createByClientIdCache();
private Supplier<Map<String, Integer>> createByClientIdCache() {
return Suppliers.memoizeWithExpiration(new Supplier<Map<String, Integer>>() {
@Override
public Map<String, Integer> get() {
return computeByClientId();
}
}, 10, TimeUnit.MINUTES);
}
@Override
public Map<String, Integer> getSummaryStats() {
return summaryCache.get();
@ -104,66 +89,26 @@ public class DefaultStatsService implements StatsService {
return e;
}
/* (non-Javadoc)
* @see org.mitre.openid.connect.service.StatsService#calculateByClientId()
*/
@Override
public Map<String, Integer> getByClientId() {
return byClientIdCache.get();
}
private Map<String, Integer> computeByClientId() {
// get all approved sites
Collection<ApprovedSite> allSites = approvedSiteService.getAll();
Multiset<String> clientIds = HashMultiset.create();
for (ApprovedSite approvedSite : allSites) {
clientIds.add(approvedSite.getClientId());
}
Map<String, Integer> counts = getEmptyClientCountMap();
for (String clientId : clientIds) {
ClientDetailsEntity client = clientService.loadClientByClientId(clientId);
counts.put(client.getClientId(), clientIds.count(clientId));
}
return counts;
}
/* (non-Javadoc)
* @see org.mitre.openid.connect.service.StatsService#countForClientId(java.lang.String)
*/
@Override
public ClientStat getCountForClientId(String id) {
public ClientStat getCountForClientId(String clientId) {
Map<String, Integer> counts = getByClientId();
Collection<ApprovedSite> approvedSites = approvedSiteService.getByClientId(clientId);
ClientStat stat = new ClientStat();
stat.setApprovedSiteCount(counts.get(id));
stat.setApprovedSiteCount(approvedSites.size());
return stat;
}
/**
* Create a new map of all client ids set to zero
* @return
*/
private Map<String, Integer> getEmptyClientCountMap() {
Map<String, Integer> counts = new HashMap<>();
Collection<ClientDetailsEntity> clients = clientService.getAllClients();
for (ClientDetailsEntity client : clients) {
counts.put(client.getClientId(), 0);
}
return counts;
}
/**
* Reset both stats caches on a trigger (before the timer runs out). Resets the timers.
*/
@Override
public void resetCache() {
summaryCache = createSummaryCache();
byClientIdCache = createByClientIdCache();
}
}

Loading…
Cancel
Save