[ONOS-5170] GroupStore: add purgeGroupEntries
The GroupStore exposes purgeGroupEntry, which purges from the store by a specific device. Add purgeGroupEntries, to purge entries from all devices from the GroupStore, and expose purgeGroupEntries to allow applications to purge all group entries from the GroupStore without specifying a device. Change-Id: I735f011a1fbbfa3ce8f1dd57a591a81c4377b012
Showing
7 changed files
with
58 additions
and
7 deletions
| ... | @@ -113,6 +113,11 @@ public interface GroupService | ... | @@ -113,6 +113,11 @@ public interface GroupService |
| 113 | void purgeGroupEntries(DeviceId deviceId); | 113 | void purgeGroupEntries(DeviceId deviceId); |
| 114 | 114 | ||
| 115 | /** | 115 | /** |
| 116 | + * Purges all group entries. | ||
| 117 | + */ | ||
| 118 | + default void purgeGroupEntries() {}; | ||
| 119 | + | ||
| 120 | + /** | ||
| 116 | * Deletes a group associated to an application cookie. | 121 | * Deletes a group associated to an application cookie. |
| 117 | * GROUP_DELETED or GROUP_DELETE_FAILED notifications would be | 122 | * GROUP_DELETED or GROUP_DELETE_FAILED notifications would be |
| 118 | * provided along with cookie depending on the result of the | 123 | * provided along with cookie depending on the result of the | ... | ... |
| ... | @@ -125,6 +125,11 @@ public interface GroupStore extends Store<GroupEvent, GroupStoreDelegate> { | ... | @@ -125,6 +125,11 @@ public interface GroupStore extends Store<GroupEvent, GroupStoreDelegate> { |
| 125 | void purgeGroupEntry(DeviceId deviceId); | 125 | void purgeGroupEntry(DeviceId deviceId); |
| 126 | 126 | ||
| 127 | /** | 127 | /** |
| 128 | + * Removes all group entries from store. | ||
| 129 | + */ | ||
| 130 | + default void purgeGroupEntries() {}; | ||
| 131 | + | ||
| 132 | + /** | ||
| 128 | * A group entry that is present in switch but not in the store. | 133 | * A group entry that is present in switch but not in the store. |
| 129 | * | 134 | * |
| 130 | * @param group group entry | 135 | * @param group group entry | ... | ... |
| ... | @@ -482,6 +482,18 @@ public class SimpleGroupStore | ... | @@ -482,6 +482,18 @@ public class SimpleGroupStore |
| 482 | } | 482 | } |
| 483 | 483 | ||
| 484 | @Override | 484 | @Override |
| 485 | + public void purgeGroupEntries() { | ||
| 486 | + groupEntriesById.values().forEach(groupEntries -> { | ||
| 487 | + groupEntries.entrySet().forEach(entry -> { | ||
| 488 | + notifyDelegate(new GroupEvent(Type.GROUP_REMOVED, entry.getValue())); | ||
| 489 | + }); | ||
| 490 | + }); | ||
| 491 | + | ||
| 492 | + groupEntriesById.clear(); | ||
| 493 | + groupEntriesByKey.clear(); | ||
| 494 | + } | ||
| 495 | + | ||
| 496 | + @Override | ||
| 485 | public void deviceInitialAuditCompleted(DeviceId deviceId, | 497 | public void deviceInitialAuditCompleted(DeviceId deviceId, |
| 486 | boolean completed) { | 498 | boolean completed) { |
| 487 | synchronized (deviceAuditStatus) { | 499 | synchronized (deviceAuditStatus) { | ... | ... |
| ... | @@ -214,10 +214,15 @@ public class SimpleGroupStoreTest { | ... | @@ -214,10 +214,15 @@ public class SimpleGroupStoreTest { |
| 214 | // Testing removeGroupEntry operation from southbound | 214 | // Testing removeGroupEntry operation from southbound |
| 215 | testRemoveGroupFromSB(currKey); | 215 | testRemoveGroupFromSB(currKey); |
| 216 | 216 | ||
| 217 | - // Testing removing all groups on the given device | 217 | + // Testing removing all groups on the given device by deviceid |
| 218 | newKey = new DefaultGroupKey("group1".getBytes()); | 218 | newKey = new DefaultGroupKey("group1".getBytes()); |
| 219 | testStoreAndGetGroup(newKey); | 219 | testStoreAndGetGroup(newKey); |
| 220 | testDeleteGroupOnDevice(newKey); | 220 | testDeleteGroupOnDevice(newKey); |
| 221 | + | ||
| 222 | + // Testing removing all groups on the given device | ||
| 223 | + newKey = new DefaultGroupKey("group1".getBytes()); | ||
| 224 | + testStoreAndGetGroup(newKey); | ||
| 225 | + testPurgeGroupEntries(); | ||
| 221 | } | 226 | } |
| 222 | 227 | ||
| 223 | // Testing storeGroup operation | 228 | // Testing storeGroup operation |
| ... | @@ -432,6 +437,13 @@ public class SimpleGroupStoreTest { | ... | @@ -432,6 +437,13 @@ public class SimpleGroupStoreTest { |
| 432 | assertThat(simpleGroupStore.getGroupCount(D1), is(0)); | 437 | assertThat(simpleGroupStore.getGroupCount(D1), is(0)); |
| 433 | } | 438 | } |
| 434 | 439 | ||
| 440 | + // Testing purgeGroupEntries | ||
| 441 | + private void testPurgeGroupEntries() { | ||
| 442 | + assertThat(simpleGroupStore.getGroupCount(D1), is(1)); | ||
| 443 | + simpleGroupStore.purgeGroupEntries(); | ||
| 444 | + assertThat(simpleGroupStore.getGroupCount(D1), is(0)); | ||
| 445 | + } | ||
| 446 | + | ||
| 435 | // Testing removeGroupEntry operation from southbound | 447 | // Testing removeGroupEntry operation from southbound |
| 436 | private void testRemoveGroupFromSB(GroupKey currKey) { | 448 | private void testRemoveGroupFromSB(GroupKey currKey) { |
| 437 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); | 449 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); | ... | ... |
| ... | @@ -230,6 +230,11 @@ public class GroupManager | ... | @@ -230,6 +230,11 @@ public class GroupManager |
| 230 | store.purgeGroupEntry(deviceId); | 230 | store.purgeGroupEntry(deviceId); |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | + @Override | ||
| 234 | + public void purgeGroupEntries() { | ||
| 235 | + checkPermission(GROUP_WRITE); | ||
| 236 | + store.purgeGroupEntries(); | ||
| 237 | + } | ||
| 233 | 238 | ||
| 234 | /** | 239 | /** |
| 235 | * Delete a group associated to an application cookie. | 240 | * Delete a group associated to an application cookie. | ... | ... |
| ... | @@ -931,19 +931,27 @@ public class DistributedGroupStore | ... | @@ -931,19 +931,27 @@ public class DistributedGroupStore |
| 931 | } | 931 | } |
| 932 | } | 932 | } |
| 933 | 933 | ||
| 934 | + private void purgeGroupEntries(Set<Entry<GroupStoreKeyMapKey, StoredGroupEntry>> entries) { | ||
| 935 | + entries.forEach(entry -> { | ||
| 936 | + groupStoreEntriesByKey.remove(entry.getKey()); | ||
| 937 | + }); | ||
| 938 | + } | ||
| 939 | + | ||
| 934 | @Override | 940 | @Override |
| 935 | public void purgeGroupEntry(DeviceId deviceId) { | 941 | public void purgeGroupEntry(DeviceId deviceId) { |
| 936 | - Set<Entry<GroupStoreKeyMapKey, StoredGroupEntry>> entryPendingRemove = | 942 | + Set<Entry<GroupStoreKeyMapKey, StoredGroupEntry>> entriesPendingRemove = |
| 937 | new HashSet<>(); | 943 | new HashSet<>(); |
| 938 | 944 | ||
| 939 | getGroupStoreKeyMap().entrySet().stream() | 945 | getGroupStoreKeyMap().entrySet().stream() |
| 940 | .filter(entry -> entry.getKey().deviceId().equals(deviceId)) | 946 | .filter(entry -> entry.getKey().deviceId().equals(deviceId)) |
| 941 | - .forEach(entryPendingRemove::add); | 947 | + .forEach(entriesPendingRemove::add); |
| 942 | 948 | ||
| 943 | - entryPendingRemove.forEach(entry -> { | 949 | + purgeGroupEntries(entriesPendingRemove); |
| 944 | - groupStoreEntriesByKey.remove(entry.getKey()); | 950 | + } |
| 945 | - notifyDelegate(new GroupEvent(Type.GROUP_REMOVED, entry.getValue())); | 951 | + |
| 946 | - }); | 952 | + @Override |
| 953 | + public void purgeGroupEntries() { | ||
| 954 | + purgeGroupEntries(getGroupStoreKeyMap().entrySet()); | ||
| 947 | } | 955 | } |
| 948 | 956 | ||
| 949 | @Override | 957 | @Override | ... | ... |
| ... | @@ -236,6 +236,10 @@ public class DistributedGroupStoreTest { | ... | @@ -236,6 +236,10 @@ public class DistributedGroupStoreTest { |
| 236 | groupStore.purgeGroupEntry(deviceId2); | 236 | groupStore.purgeGroupEntry(deviceId2); |
| 237 | assertThat(groupStore.getGroupCount(deviceId1), is(1)); | 237 | assertThat(groupStore.getGroupCount(deviceId1), is(1)); |
| 238 | assertThat(groupStore.getGroupCount(deviceId2), is(0)); | 238 | assertThat(groupStore.getGroupCount(deviceId2), is(0)); |
| 239 | + | ||
| 240 | + groupStore.purgeGroupEntries(); | ||
| 241 | + assertThat(groupStore.getGroupCount(deviceId1), is(0)); | ||
| 242 | + assertThat(groupStore.getGroupCount(deviceId2), is(0)); | ||
| 239 | } | 243 | } |
| 240 | 244 | ||
| 241 | /** | 245 | /** | ... | ... |
-
Please register or login to post a comment