use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group in project openflowplugin by opendaylight.
the class SyncPlanPushStrategyIncrementalImpl method flushAddGroupPortionAndBarrier.
private ListenableFuture<RpcResult<Void>> flushAddGroupPortionAndBarrier(final InstanceIdentifier<FlowCapableNode> nodeIdent, final ItemSyncBox<Group> groupsPortion) {
final List<ListenableFuture<RpcResult<AddGroupOutput>>> allResults = new ArrayList<>();
final List<ListenableFuture<RpcResult<UpdateGroupOutput>>> allUpdateResults = new ArrayList<>();
for (Group group : groupsPortion.getItemsToPush()) {
final KeyedInstanceIdentifier<Group, GroupKey> groupIdent = nodeIdent.child(Group.class, group.getKey());
allResults.add(JdkFutureAdapters.listenInPoolThread(groupForwarder.add(groupIdent, group, nodeIdent)));
}
for (ItemSyncBox.ItemUpdateTuple<Group> groupTuple : groupsPortion.getItemsToUpdate()) {
final Group existingGroup = groupTuple.getOriginal();
final Group group = groupTuple.getUpdated();
final KeyedInstanceIdentifier<Group, GroupKey> groupIdent = nodeIdent.child(Group.class, group.getKey());
allUpdateResults.add(JdkFutureAdapters.listenInPoolThread(groupForwarder.update(groupIdent, existingGroup, group, nodeIdent)));
}
final ListenableFuture<RpcResult<Void>> singleVoidAddResult = Futures.transform(Futures.allAsList(allResults), ReconcileUtil.<AddGroupOutput>createRpcResultCondenser("group add"), MoreExecutors.directExecutor());
final ListenableFuture<RpcResult<Void>> singleVoidUpdateResult = Futures.transform(Futures.allAsList(allUpdateResults), ReconcileUtil.<UpdateGroupOutput>createRpcResultCondenser("group update"), MoreExecutors.directExecutor());
final ListenableFuture<RpcResult<Void>> summaryResult = Futures.transform(Futures.allAsList(singleVoidAddResult, singleVoidUpdateResult), ReconcileUtil.<Void>createRpcResultCondenser("group add/update"), MoreExecutors.directExecutor());
return Futures.transformAsync(summaryResult, ReconcileUtil.chainBarrierFlush(PathUtil.digNodePath(nodeIdent), transactionService), MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group in project openflowplugin by opendaylight.
the class SyncReactorImpl method syncup.
@Override
public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> nodeIdent, final SyncupEntry syncupEntry) {
final NodeId nodeId = PathUtil.digNodeId(nodeIdent);
FlowCapableNode configTree = syncupEntry.getAfter();
FlowCapableNode operationalTree = syncupEntry.getBefore();
final SyncCrudCounters counters = new SyncCrudCounters();
/**
* instructions:
* - extract diff changes and prepare change steps in safe order
* - optimization: decide if updates needed
* - execute chosen implementation (e.g. conventional API, bulk API, flat bulk API)
* - recommended order follows:
* reconciliation strategy - phase 1: - add/update missing objects in following order:
* - table features - groups (reordered) - meters - flows
* reconciliation strategy - phase 2: - remove redundant objects in following order:
* - flows - meters - groups (reordered)
*/
final List<ItemSyncBox<Group>> groupsToAddOrUpdate = extractGroupsToAddOrUpdate(nodeId, configTree, operationalTree);
final ItemSyncBox<Meter> metersToAddOrUpdate = extractMetersToAddOrUpdate(nodeId, configTree, operationalTree);
final Map<TableKey, ItemSyncBox<Flow>> flowsToAddOrUpdate = extractFlowsToAddOrUpdate(nodeId, configTree, operationalTree);
final Map<TableKey, ItemSyncBox<Flow>> flowsToRemove = extractFlowsToRemove(nodeId, configTree, operationalTree);
final ItemSyncBox<Meter> metersToRemove = extractMetersToRemove(nodeId, configTree, operationalTree);
final List<ItemSyncBox<Group>> groupsToRemove = extractGroupsToRemove(nodeId, configTree, operationalTree);
final SynchronizationDiffInput input = new SynchronizationDiffInput(nodeIdent, groupsToAddOrUpdate, metersToAddOrUpdate, flowsToAddOrUpdate, flowsToRemove, metersToRemove, groupsToRemove);
final ListenableFuture<RpcResult<Void>> bootstrapResultFuture = RpcResultBuilder.<Void>success().buildFuture();
final ListenableFuture<RpcResult<Void>> resultVehicle = syncPlanPushStrategy.executeSyncStrategy(bootstrapResultFuture, input, counters);
return Futures.transform(resultVehicle, input1 -> {
if (input1 == null) {
return false;
}
if (LOG.isDebugEnabled()) {
final CrudCounts flowCrudCounts = counters.getFlowCrudCounts();
final CrudCounts meterCrudCounts = counters.getMeterCrudCounts();
final CrudCounts groupCrudCounts = counters.getGroupCrudCounts();
LOG.debug("Syncup outcome[{}] (added/updated/removed): flow={}/{}/{}, group={}/{}/{}, " + "meter={}/{}/{}, errors={}", nodeId.getValue(), flowCrudCounts.getAdded(), flowCrudCounts.getUpdated(), flowCrudCounts.getRemoved(), groupCrudCounts.getAdded(), groupCrudCounts.getUpdated(), groupCrudCounts.getRemoved(), meterCrudCounts.getAdded(), meterCrudCounts.getUpdated(), meterCrudCounts.getRemoved(), Arrays.toString(input1.getErrors().toArray()));
}
return input1.isSuccessful();
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group in project openflowplugin by opendaylight.
the class FlowCapableNodeLookups method wrapGroupsToMap.
@Nonnull
public static Map<Long, Group> wrapGroupsToMap(@Nullable final List<Group> groups) {
final Map<Long, Group> groupMap;
if (groups == null) {
groupMap = Collections.emptyMap();
} else {
LOG.trace("groups found: {}", groups.size());
groupMap = new HashMap<>();
for (Group group : groups) {
groupMap.put(group.getGroupId().getValue(), group);
}
}
return groupMap;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group in project openflowplugin by opendaylight.
the class ReconcileUtil method resolveAndDivideGroupDiffs.
/**
* Returns a list of safe synchronization steps.
*
* @param nodeId target node
* @param installedGroupsArg groups resent on device
* @param pendingGroups groups configured for device
* @param gatherUpdates check content of pending item if present on device (and create update task eventually)
* @return list of safe synchronization steps
*/
public static List<ItemSyncBox<Group>> resolveAndDivideGroupDiffs(final NodeId nodeId, final Map<Long, Group> installedGroupsArg, final Collection<Group> pendingGroups, final boolean gatherUpdates) {
final Map<Long, Group> installedGroups = new HashMap<>(installedGroupsArg);
final List<ItemSyncBox<Group>> plan = new ArrayList<>();
while (!Iterables.isEmpty(pendingGroups)) {
final ItemSyncBox<Group> stepPlan = new ItemSyncBox<>();
final Iterator<Group> iterator = pendingGroups.iterator();
final Map<Long, Group> installIncrement = new HashMap<>();
while (iterator.hasNext()) {
final Group group = iterator.next();
final Group existingGroup = installedGroups.get(group.getGroupId().getValue());
if (existingGroup != null) {
if (!gatherUpdates) {
iterator.remove();
} else {
// check buckets and eventually update
if (group.equals(existingGroup)) {
iterator.remove();
} else {
if (checkGroupPrecondition(installedGroups.keySet(), group)) {
iterator.remove();
LOG.trace("Group {} on device {} differs - planned for update", group.getGroupId(), nodeId);
stepPlan.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(existingGroup, group));
}
}
}
} else if (checkGroupPrecondition(installedGroups.keySet(), group)) {
iterator.remove();
installIncrement.put(group.getGroupId().getValue(), group);
stepPlan.getItemsToPush().add(group);
}
}
if (!stepPlan.isEmpty()) {
// atomic update of installed flows in order to keep plan portions clean of local group dependencies
installedGroups.putAll(installIncrement);
plan.add(stepPlan);
} else if (!pendingGroups.isEmpty()) {
LOG.warn("Failed to resolve and divide groups into preconditions-match based ordered plan: {}, " + "resolving stuck at level {}", nodeId.getValue(), plan.size());
throw new IllegalStateException("Failed to resolve and divide groups when matching preconditions");
}
}
return plan;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group in project openflowplugin by opendaylight.
the class GroupDirectStatisticsServiceTest method testBuildRequestBody.
@Override
public void testBuildRequestBody() throws Exception {
final GetGroupStatisticsInput input = mock(GetGroupStatisticsInput.class);
when(input.getNode()).thenReturn(createNodeRef(NODE_ID));
when(input.getGroupId()).thenReturn(new GroupId(GROUP_NO));
final MultipartRequestGroupCase body = (MultipartRequestGroupCase) ((MultipartRequestInput) service.buildRequest(new Xid(42L), input)).getMultipartRequestBody();
final MultipartRequestGroup group = body.getMultipartRequestGroup();
assertEquals(GROUP_NO, group.getGroupId().getValue());
}
Aggregations