use of org.onosproject.net.group.GroupEvent in project onos by opennetworkinglab.
the class DistributedGroupStoreTest method testGroupOperationFailed.
/**
* Tests group operation failed interface.
*/
@Test
public void testGroupOperationFailed() {
TestDelegate delegate = new TestDelegate();
groupStore.setDelegate(delegate);
groupStore.deviceInitialAuditCompleted(deviceId1, true);
groupStore.deviceInitialAuditCompleted(deviceId2, true);
groupStore.storeGroupDescription(groupDescription1);
groupStore.storeGroupDescription(groupDescription2);
List<GroupEvent> eventsAfterAdds = delegate.eventsSeen();
assertThat(eventsAfterAdds, hasSize(2));
eventsAfterAdds.forEach(event -> assertThat(event.type(), is(GroupEvent.Type.GROUP_ADD_REQUESTED)));
delegate.resetEvents();
GroupOperation opAdd = GroupOperation.createAddGroupOperation(groupId1, INDIRECT, indirectGroupBuckets);
groupStore.groupOperationFailed(deviceId1, opAdd);
List<GroupEvent> eventsAfterAddFailed = delegate.eventsSeen();
assertThat(eventsAfterAddFailed, hasSize(2));
assertThat(eventsAfterAddFailed.get(0).type(), is(GroupEvent.Type.GROUP_ADD_FAILED));
assertThat(eventsAfterAddFailed.get(1).type(), is(GroupEvent.Type.GROUP_REMOVED));
delegate.resetEvents();
GroupOperation opModify = GroupOperation.createModifyGroupOperation(groupId2, INDIRECT, indirectGroupBuckets);
groupStore.groupOperationFailed(deviceId2, opModify);
List<GroupEvent> eventsAfterModifyFailed = delegate.eventsSeen();
assertThat(eventsAfterModifyFailed, hasSize(1));
assertThat(eventsAfterModifyFailed.get(0).type(), is(GroupEvent.Type.GROUP_UPDATE_FAILED));
delegate.resetEvents();
GroupOperation opDelete = GroupOperation.createDeleteGroupOperation(groupId2, INDIRECT);
groupStore.groupOperationFailed(deviceId2, opDelete);
List<GroupEvent> eventsAfterDeleteFailed = delegate.eventsSeen();
assertThat(eventsAfterDeleteFailed, hasSize(1));
assertThat(eventsAfterDeleteFailed.get(0).type(), is(GroupEvent.Type.GROUP_REMOVE_FAILED));
delegate.resetEvents();
}
use of org.onosproject.net.group.GroupEvent in project onos by opennetworkinglab.
the class DistributedGroupStore method removeGroupEntry.
/**
* Removes the group entry from store.
*
* @param group group entry
*/
@Override
public void removeGroupEntry(Group group) {
StoredGroupEntry existing = getStoredGroupEntry(group.deviceId(), group.id());
if (existing != null) {
log.debug("removeGroupEntry: removing group entry {} in device {}", group.id(), group.deviceId());
// Removal from groupid based map will happen in the
// map update listener
getGroupStoreKeyMap().remove(new GroupStoreKeyMapKey(existing.deviceId(), existing.appCookie()));
notifyDelegate(new GroupEvent(Type.GROUP_REMOVED, existing));
} else {
log.warn("removeGroupEntry for {} in device{} is " + "not existing in our maps", group.id(), group.deviceId());
}
}
use of org.onosproject.net.group.GroupEvent in project onos by opennetworkinglab.
the class DistributedGroupStore method addOrUpdateGroupEntry.
/**
* Stores a new group entry, or updates an existing entry.
*
* @param group group entry
*/
@Override
public void addOrUpdateGroupEntry(Group group) {
// check if this new entry is an update to an existing entry
StoredGroupEntry existing = getStoredGroupEntry(group.deviceId(), group.id());
GroupEvent event = null;
if (existing != null) {
log.trace("addOrUpdateGroupEntry: updating group entry {} in device {}", group.id(), group.deviceId());
// TODO is this really safe ?
synchronized (existing) {
// Update stats
updateGroupEntryStatsInternal(group, existing);
if ((existing.state() == GroupState.PENDING_ADD) || (existing.state() == GroupState.PENDING_ADD_RETRY)) {
log.trace("addOrUpdateGroupEntry: group entry {} in device {} moving from {} to ADDED", existing.id(), existing.deviceId(), existing.state());
existing.setState(GroupState.ADDED);
existing.setIsGroupStateAddedFirstTime(true);
event = new GroupEvent(Type.GROUP_ADDED, existing);
} else {
log.trace("addOrUpdateGroupEntry: group entry {} in device {} moving from {} to ADDED", existing.id(), existing.deviceId(), GroupState.PENDING_UPDATE);
existing.setState(GroupState.ADDED);
existing.setIsGroupStateAddedFirstTime(false);
event = new GroupEvent(Type.GROUP_UPDATED, existing);
}
// Re-PUT map entries to trigger map update events
getGroupStoreKeyMap().put(new GroupStoreKeyMapKey(existing.deviceId(), existing.appCookie()), existing);
}
} else {
log.warn("addOrUpdateGroupEntry: Group update {} " + "happening for a non-existing entry in the map", group);
}
// TODO if map is going to trigger event, is this one needed?
if (event != null) {
notifyDelegate(event);
}
}
use of org.onosproject.net.group.GroupEvent in project onos by opennetworkinglab.
the class SimpleVirtualGroupStore method storeGroupDescriptionInternal.
private void storeGroupDescriptionInternal(NetworkId networkId, GroupDescription groupDesc) {
// Check if a group is existing with the same key
if (getGroup(networkId, groupDesc.deviceId(), groupDesc.appCookie()) != null) {
return;
}
GroupId id = null;
if (groupDesc.givenGroupId() == null) {
// Get a new group identifier
id = new GroupId(getFreeGroupIdValue(networkId, groupDesc.deviceId()));
} else {
id = new GroupId(groupDesc.givenGroupId());
}
// Create a group entry object
StoredGroupEntry group = new DefaultGroup(id, groupDesc);
// Insert the newly created group entry into concurrent key and id maps
ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(networkId, groupDesc.deviceId());
keyTable.put(groupDesc.appCookie(), group);
ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(networkId, groupDesc.deviceId());
idTable.put(id, group);
notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group));
}
use of org.onosproject.net.group.GroupEvent in project onos by opennetworkinglab.
the class SimpleVirtualGroupStore method purgeGroupEntry.
@Override
public void purgeGroupEntry(NetworkId networkId, DeviceId deviceId) {
if (groupEntriesById.get(networkId) != null) {
Set<Map.Entry<GroupId, StoredGroupEntry>> entryPendingRemove = groupEntriesById.get(networkId).get(deviceId).entrySet();
groupEntriesById.get(networkId).remove(deviceId);
groupEntriesByKey.get(networkId).remove(deviceId);
entryPendingRemove.forEach(entry -> {
notifyDelegate(networkId, new GroupEvent(GroupEvent.Type.GROUP_REMOVED, entry.getValue()));
});
}
}
Aggregations