@Test public void testPushGroupMetrics() { groupStore.deviceInitialAuditCompleted(deviceId1, true); groupStore.deviceInitialAuditCompleted(deviceId2, true); GroupDescription groupDescription3 = new DefaultGroupDescription( deviceId1, GroupDescription.Type.SELECT, buckets, new DefaultGroupKey("aaa".getBytes()), null, APP_ID); groupStore.storeGroupDescription(groupDescription1); groupStore.storeGroupDescription(groupDescription2); groupStore.storeGroupDescription(groupDescription3); Group group1 = groupStore.getGroup(deviceId1, groupId1); assertThat(group1, instanceOf(DefaultGroup.class)); DefaultGroup defaultGroup1 = (DefaultGroup) group1; defaultGroup1.setPackets(55L); defaultGroup1.setBytes(66L); groupStore.pushGroupMetrics(deviceId1, ImmutableList.of(group1)); Group requeryGroup1 = groupStore.getGroup(deviceId1, groupId1); assertThat(requeryGroup1.packets(), is(55L)); assertThat(requeryGroup1.bytes(), is(66L)); }
@Override public void pushGroupMetrics(DeviceId deviceId, Collection<Group> groupEntries) { boolean deviceInitialAuditStatus = deviceInitialAuditStatus(deviceId); Set<Group> southboundGroupEntries = Sets.newHashSet(groupEntries); Set<StoredGroupEntry> storedGroupEntries = Sets.newHashSet(getStoredGroups(deviceId)); Set<Group> extraneousStoredEntries = Sets.newHashSet(getExtraneousGroups(deviceId)); log.trace("pushGroupMetrics: Displaying all ({}) southboundGroupEntries for device {}", southboundGroupEntries.size(), deviceId); for (Iterator<Group> it = southboundGroupEntries.iterator(); it.hasNext();) { Group group = it.next(); log.trace("Group {} in device {}", group, deviceId); } log.trace("Displaying all ({}) stored group entries for device {}", storedGroupEntries.size(), deviceId); for (Iterator<StoredGroupEntry> it1 = storedGroupEntries.iterator(); it1.hasNext();) { Group group = it1.next(); log.trace("Stored Group {} for device {}", group, deviceId); } garbageCollect(deviceId, southboundGroupEntries, storedGroupEntries); for (Iterator<Group> it2 = southboundGroupEntries.iterator(); it2.hasNext();) { Group group = it2.next(); if (storedGroupEntries.remove(group)) { log.trace("Group AUDIT: group {} exists in both planes for device {}", group.id(), deviceId); groupAdded(group); it2.remove(); } } for (Group group : southboundGroupEntries) { if (getGroup(group.deviceId(), group.id()) != null) { if (!storedGroupEntries.remove(getGroup( group.deviceId(), group.id()))) { log.warn("Group AUDIT: Inconsistent state:" + "Group exists in ID based table while " + "not present in key based table"); } } else { log.debug("Group AUDIT: extraneous group {} exists in data plane for device {}", group.id(), deviceId); extraneousStoredEntries.remove(group); extraneousGroup(group); } } for (Group group : storedGroupEntries) { log.debug("Group AUDIT: group {} missing in data plane for device {}", group.id(), deviceId); groupMissing(group); } for (Group group : extraneousStoredEntries) { log.debug("Group AUDIT: clearing extraneous group {} from store for device {}", group.id(), deviceId); removeExtraneousGroupEntry(group); } if (!deviceInitialAuditStatus) { log.info("Group AUDIT: Setting device {} initial AUDIT completed", deviceId); deviceInitialAuditCompleted(deviceId, true); } }
DistributedGroupStore extends AbstractStore<GroupEvent, GroupStoreDelegate> implements GroupStore { @Override public void pushGroupMetrics(DeviceId deviceId, Collection<Group> groupEntries) { boolean deviceInitialAuditStatus = deviceInitialAuditStatus(deviceId); Set<Group> southboundGroupEntries = Sets.newHashSet(groupEntries); Set<StoredGroupEntry> storedGroupEntries = Sets.newHashSet(getStoredGroups(deviceId)); Set<Group> extraneousStoredEntries = Sets.newHashSet(getExtraneousGroups(deviceId)); log.trace("pushGroupMetrics: Displaying all ({}) southboundGroupEntries for device {}", southboundGroupEntries.size(), deviceId); for (Iterator<Group> it = southboundGroupEntries.iterator(); it.hasNext();) { Group group = it.next(); log.trace("Group {} in device {}", group, deviceId); } log.trace("Displaying all ({}) stored group entries for device {}", storedGroupEntries.size(), deviceId); for (Iterator<StoredGroupEntry> it1 = storedGroupEntries.iterator(); it1.hasNext();) { Group group = it1.next(); log.trace("Stored Group {} for device {}", group, deviceId); } garbageCollect(deviceId, southboundGroupEntries, storedGroupEntries); for (Iterator<Group> it2 = southboundGroupEntries.iterator(); it2.hasNext();) { Group group = it2.next(); if (storedGroupEntries.remove(group)) { log.trace("Group AUDIT: group {} exists in both planes for device {}", group.id(), deviceId); groupAdded(group); it2.remove(); } } for (Group group : southboundGroupEntries) { if (getGroup(group.deviceId(), group.id()) != null) { if (!storedGroupEntries.remove(getGroup( group.deviceId(), group.id()))) { log.warn("Group AUDIT: Inconsistent state:" + "Group exists in ID based table while " + "not present in key based table"); } } else { log.debug("Group AUDIT: extraneous group {} exists in data plane for device {}", group.id(), deviceId); extraneousStoredEntries.remove(group); extraneousGroup(group); } } for (Group group : storedGroupEntries) { log.debug("Group AUDIT: group {} missing in data plane for device {}", group.id(), deviceId); groupMissing(group); } for (Group group : extraneousStoredEntries) { log.debug("Group AUDIT: clearing extraneous group {} from store for device {}", group.id(), deviceId); removeExtraneousGroupEntry(group); } if (!deviceInitialAuditStatus) { log.info("Group AUDIT: Setting device {} initial AUDIT completed", deviceId); deviceInitialAuditCompleted(deviceId, true); } } }
DistributedGroupStore extends AbstractStore<GroupEvent, GroupStoreDelegate> implements GroupStore { @Override public void pushGroupMetrics(DeviceId deviceId, Collection<Group> groupEntries) { boolean deviceInitialAuditStatus = deviceInitialAuditStatus(deviceId); Set<Group> southboundGroupEntries = Sets.newHashSet(groupEntries); Set<StoredGroupEntry> storedGroupEntries = Sets.newHashSet(getStoredGroups(deviceId)); Set<Group> extraneousStoredEntries = Sets.newHashSet(getExtraneousGroups(deviceId)); log.trace("pushGroupMetrics: Displaying all ({}) southboundGroupEntries for device {}", southboundGroupEntries.size(), deviceId); for (Iterator<Group> it = southboundGroupEntries.iterator(); it.hasNext();) { Group group = it.next(); log.trace("Group {} in device {}", group, deviceId); } log.trace("Displaying all ({}) stored group entries for device {}", storedGroupEntries.size(), deviceId); for (Iterator<StoredGroupEntry> it1 = storedGroupEntries.iterator(); it1.hasNext();) { Group group = it1.next(); log.trace("Stored Group {} for device {}", group, deviceId); } garbageCollect(deviceId, southboundGroupEntries, storedGroupEntries); for (Iterator<Group> it2 = southboundGroupEntries.iterator(); it2.hasNext();) { Group group = it2.next(); if (storedGroupEntries.remove(group)) { log.trace("Group AUDIT: group {} exists in both planes for device {}", group.id(), deviceId); groupAdded(group); it2.remove(); } } for (Group group : southboundGroupEntries) { if (getGroup(group.deviceId(), group.id()) != null) { if (!storedGroupEntries.remove(getGroup( group.deviceId(), group.id()))) { log.warn("Group AUDIT: Inconsistent state:" + "Group exists in ID based table while " + "not present in key based table"); } } else { log.debug("Group AUDIT: extraneous group {} exists in data plane for device {}", group.id(), deviceId); extraneousStoredEntries.remove(group); extraneousGroup(group); } } for (Group group : storedGroupEntries) { log.debug("Group AUDIT: group {} missing in data plane for device {}", group.id(), deviceId); groupMissing(group); } for (Group group : extraneousStoredEntries) { log.debug("Group AUDIT: clearing extraneous group {} from store for device {}", group.id(), deviceId); removeExtraneousGroupEntry(group); } if (!deviceInitialAuditStatus) { log.info("Group AUDIT: Setting device {} initial AUDIT completed", deviceId); deviceInitialAuditCompleted(deviceId, true); } }  }
DistributedGroupStore extends AbstractStore<GroupEvent, GroupStoreDelegate> implements GroupStore { @Override public void pushGroupMetrics(DeviceId deviceId, Collection<Group> groupEntries) { boolean deviceInitialAuditStatus = deviceInitialAuditStatus(deviceId); Set<Group> southboundGroupEntries = Sets.newHashSet(groupEntries); Set<StoredGroupEntry> storedGroupEntries = Sets.newHashSet(getStoredGroups(deviceId)); Set<Group> extraneousStoredEntries = Sets.newHashSet(getExtraneousGroups(deviceId)); log.trace("pushGroupMetrics: Displaying all ({}) southboundGroupEntries for device {}", southboundGroupEntries.size(), deviceId); for (Iterator<Group> it = southboundGroupEntries.iterator(); it.hasNext();) { Group group = it.next(); log.trace("Group {} in device {}", group, deviceId); } log.trace("Displaying all ({}) stored group entries for device {}", storedGroupEntries.size(), deviceId); for (Iterator<StoredGroupEntry> it1 = storedGroupEntries.iterator(); it1.hasNext();) { Group group = it1.next(); log.trace("Stored Group {} for device {}", group, deviceId); } garbageCollect(deviceId, southboundGroupEntries, storedGroupEntries); for (Iterator<Group> it2 = southboundGroupEntries.iterator(); it2.hasNext();) { Group group = it2.next(); if (storedGroupEntries.remove(group)) { log.trace("Group AUDIT: group {} exists in both planes for device {}", group.id(), deviceId); groupAdded(group); it2.remove(); } } for (Group group : southboundGroupEntries) { if (getGroup(group.deviceId(), group.id()) != null) { if (!storedGroupEntries.remove(getGroup( group.deviceId(), group.id()))) { log.warn("Group AUDIT: Inconsistent state:" + "Group exists in ID based table while " + "not present in key based table"); } } else { log.debug("Group AUDIT: extraneous group {} exists in data plane for device {}", group.id(), deviceId); extraneousStoredEntries.remove(group); extraneousGroup(group); } } for (Group group : storedGroupEntries) { log.debug("Group AUDIT: group {} missing in data plane for device {}", group.id(), deviceId); groupMissing(group); } for (Group group : extraneousStoredEntries) { log.debug("Group AUDIT: clearing extraneous group {} from store for device {}", group.id(), deviceId); removeExtraneousGroupEntry(group); } if (!deviceInitialAuditStatus) { log.info("Group AUDIT: Setting device {} initial AUDIT completed", deviceId); deviceInitialAuditCompleted(deviceId, true); } }  @Activate void activate(); @Deactivate void deactivate(); @Modified void modified(ComponentContext context); @Override int getGroupCount(DeviceId deviceId); @Override Iterable<Group> getGroups(DeviceId deviceId); @Override Group getGroup(DeviceId deviceId, GroupKey appCookie); @Override Group getGroup(DeviceId deviceId, GroupId groupId); @Override void storeGroupDescription(GroupDescription groupDesc); @Override void updateGroupDescription(DeviceId deviceId,
                                       GroupKey oldAppCookie,
                                       UpdateType type,
                                       GroupBuckets newBuckets,
                                       GroupKey newAppCookie); @Override void deleteGroupDescription(DeviceId deviceId,
                                       GroupKey appCookie); @Override void addOrUpdateGroupEntry(Group group); @Override void removeGroupEntry(Group group); @Override void purgeGroupEntry(DeviceId deviceId); @Override void deviceInitialAuditCompleted(DeviceId deviceId,
                                            boolean completed); @Override boolean deviceInitialAuditStatus(DeviceId deviceId); @Override void groupOperationFailed(DeviceId deviceId, GroupOperation operation); @Override void addOrUpdateExtraneousGroupEntry(Group group); @Override void removeExtraneousGroupEntry(Group group); @Override Iterable<Group> getExtraneousGroups(DeviceId deviceId); @Override void pushGroupMetrics(DeviceId deviceId,
                                 Collection<Group> groupEntries); }
DistributedGroupStore extends AbstractStore<GroupEvent, GroupStoreDelegate> implements GroupStore { @Override public void pushGroupMetrics(DeviceId deviceId, Collection<Group> groupEntries) { boolean deviceInitialAuditStatus = deviceInitialAuditStatus(deviceId); Set<Group> southboundGroupEntries = Sets.newHashSet(groupEntries); Set<StoredGroupEntry> storedGroupEntries = Sets.newHashSet(getStoredGroups(deviceId)); Set<Group> extraneousStoredEntries = Sets.newHashSet(getExtraneousGroups(deviceId)); log.trace("pushGroupMetrics: Displaying all ({}) southboundGroupEntries for device {}", southboundGroupEntries.size(), deviceId); for (Iterator<Group> it = southboundGroupEntries.iterator(); it.hasNext();) { Group group = it.next(); log.trace("Group {} in device {}", group, deviceId); } log.trace("Displaying all ({}) stored group entries for device {}", storedGroupEntries.size(), deviceId); for (Iterator<StoredGroupEntry> it1 = storedGroupEntries.iterator(); it1.hasNext();) { Group group = it1.next(); log.trace("Stored Group {} for device {}", group, deviceId); } garbageCollect(deviceId, southboundGroupEntries, storedGroupEntries); for (Iterator<Group> it2 = southboundGroupEntries.iterator(); it2.hasNext();) { Group group = it2.next(); if (storedGroupEntries.remove(group)) { log.trace("Group AUDIT: group {} exists in both planes for device {}", group.id(), deviceId); groupAdded(group); it2.remove(); } } for (Group group : southboundGroupEntries) { if (getGroup(group.deviceId(), group.id()) != null) { if (!storedGroupEntries.remove(getGroup( group.deviceId(), group.id()))) { log.warn("Group AUDIT: Inconsistent state:" + "Group exists in ID based table while " + "not present in key based table"); } } else { log.debug("Group AUDIT: extraneous group {} exists in data plane for device {}", group.id(), deviceId); extraneousStoredEntries.remove(group); extraneousGroup(group); } } for (Group group : storedGroupEntries) { log.debug("Group AUDIT: group {} missing in data plane for device {}", group.id(), deviceId); groupMissing(group); } for (Group group : extraneousStoredEntries) { log.debug("Group AUDIT: clearing extraneous group {} from store for device {}", group.id(), deviceId); removeExtraneousGroupEntry(group); } if (!deviceInitialAuditStatus) { log.info("Group AUDIT: Setting device {} initial AUDIT completed", deviceId); deviceInitialAuditCompleted(deviceId, true); } }  @Activate void activate(); @Deactivate void deactivate(); @Modified void modified(ComponentContext context); @Override int getGroupCount(DeviceId deviceId); @Override Iterable<Group> getGroups(DeviceId deviceId); @Override Group getGroup(DeviceId deviceId, GroupKey appCookie); @Override Group getGroup(DeviceId deviceId, GroupId groupId); @Override void storeGroupDescription(GroupDescription groupDesc); @Override void updateGroupDescription(DeviceId deviceId,
                                       GroupKey oldAppCookie,
                                       UpdateType type,
                                       GroupBuckets newBuckets,
                                       GroupKey newAppCookie); @Override void deleteGroupDescription(DeviceId deviceId,
                                       GroupKey appCookie); @Override void addOrUpdateGroupEntry(Group group); @Override void removeGroupEntry(Group group); @Override void purgeGroupEntry(DeviceId deviceId); @Override void deviceInitialAuditCompleted(DeviceId deviceId,
                                            boolean completed); @Override boolean deviceInitialAuditStatus(DeviceId deviceId); @Override void groupOperationFailed(DeviceId deviceId, GroupOperation operation); @Override void addOrUpdateExtraneousGroupEntry(Group group); @Override void removeExtraneousGroupEntry(Group group); @Override Iterable<Group> getExtraneousGroups(DeviceId deviceId); @Override void pushGroupMetrics(DeviceId deviceId,
                                 Collection<Group> groupEntries);  }