package org.opendaylight.openflowplugin.applications.frsync.util;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.JdkFutureAdapters;
-import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
-import javax.annotation.Nullable;
-import org.opendaylight.openflowplugin.applications.frsync.markandsweep.SwitchFlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
/**
* Util methods for group reconcil task (future chaining, transforms).
*/
-public class ReconcileUtil {
+public final class ReconcileUtil {
private static final Logger LOG = LoggerFactory.getLogger(ReconcileUtil.class);
+ private ReconcileUtil() {
+ throw new IllegalStateException("This class should not be instantiated.");
+ }
+
/**
* @param previousItemAction description for case when the triggering future contains failure
* @param <D> type of rpc output (gathered in list)
* @return single rpc result of type Void honoring all partial rpc results
*/
public static <D> Function<List<RpcResult<D>>, RpcResult<Void>> createRpcResultCondenser(final String previousItemAction) {
- return new Function<List<RpcResult<D>>, RpcResult<Void>>() {
- @Nullable
- @Override
- public RpcResult<Void> apply(@Nullable final List<RpcResult<D>> input) {
- final RpcResultBuilder<Void> resultSink;
- if (input != null) {
- List<RpcError> errors = new ArrayList<>();
- for (RpcResult<D> rpcResult : input) {
- if (!rpcResult.isSuccessful()) {
- errors.addAll(rpcResult.getErrors());
- }
- }
- if (errors.isEmpty()) {
- resultSink = RpcResultBuilder.success();
- } else {
- resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
+ return input -> {
+ final RpcResultBuilder<Void> resultSink;
+ if (input != null) {
+ List<RpcError> errors = new ArrayList<>();
+ for (RpcResult<D> rpcResult : input) {
+ if (!rpcResult.isSuccessful()) {
+ errors.addAll(rpcResult.getErrors());
}
+ }
+ if (errors.isEmpty()) {
+ resultSink = RpcResultBuilder.success();
} else {
- resultSink = RpcResultBuilder.<Void>failed()
- .withError(RpcError.ErrorType.APPLICATION, "previous " + previousItemAction + " failed");
-
+ resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
}
-
- return resultSink.build();
+ } else {
+ resultSink = RpcResultBuilder.<Void>failed()
+ .withError(RpcError.ErrorType.APPLICATION, "previous " + previousItemAction + " failed");
}
+ return resultSink.build();
};
}
* @return single rpc result of type Void honoring all partial rpc results
*/
public static <D> Function<RpcResult<D>, RpcResult<Void>> createRpcResultToVoidFunction(final String actionDescription) {
- return new Function<RpcResult<D>, RpcResult<Void>>() {
- @Nullable
- @Override
- public RpcResult<Void> apply(@Nullable final RpcResult<D> input) {
- final RpcResultBuilder<Void> resultSink;
- if (input != null) {
- List<RpcError> errors = new ArrayList<>();
- if (!input.isSuccessful()) {
- errors.addAll(input.getErrors());
- resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
- } else {
- resultSink = RpcResultBuilder.success();
- }
+ return input -> {
+ final RpcResultBuilder<Void> resultSink;
+ if (input != null) {
+ List<RpcError> errors = new ArrayList<>();
+ if (!input.isSuccessful()) {
+ errors.addAll(input.getErrors());
+ resultSink = RpcResultBuilder.<Void>failed().withRpcErrors(errors);
} else {
- resultSink = RpcResultBuilder.<Void>failed()
- .withError(RpcError.ErrorType.APPLICATION, "action of " + actionDescription + " failed");
-
+ resultSink = RpcResultBuilder.success();
}
-
- return resultSink.build();
+ } else {
+ resultSink = RpcResultBuilder.<Void>failed()
+ .withError(RpcError.ErrorType.APPLICATION, "action of " + actionDescription + " failed");
}
+ return resultSink.build();
};
}
public static AsyncFunction<RpcResult<Void>, RpcResult<Void>> chainBarrierFlush(
final InstanceIdentifier<Node> nodeIdent,
final FlowCapableTransactionService flowCapableTransactionService) {
- return new AsyncFunction<RpcResult<Void>, RpcResult<Void>>() {
- @Override
- public ListenableFuture<RpcResult<Void>> apply(final RpcResult<Void> input) throws Exception {
- final SendBarrierInput barrierInput = new SendBarrierInputBuilder()
- .setNode(new NodeRef(nodeIdent))
- .build();
- return JdkFutureAdapters.listenInPoolThread(flowCapableTransactionService.sendBarrier(barrierInput));
- }
+ return input -> {
+ final SendBarrierInput barrierInput = new SendBarrierInputBuilder()
+ .setNode(new NodeRef(nodeIdent))
+ .build();
+ return JdkFutureAdapters.listenInPoolThread(flowCapableTransactionService.sendBarrier(barrierInput));
};
}
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<>();
final Map<MeterId, Meter> meterOperationalMap,
final List<Meter> metersConfigured,
final boolean gatherUpdates) {
- LOG.trace("resolving meters for {}", nodeId);
+ LOG.trace("resolving meters for {}", nodeId.getValue());
final ItemSyncBox<Meter> syncBox = new ItemSyncBox<>();
for (Meter meter : metersConfigured) {
final Meter existingMeter = meterOperationalMap.get(meter.getMeterId());
* @param gatherUpdates check content of pending item if present on device (and create update task eventually)
* @return list of safe synchronization steps
*/
- @VisibleForTesting
- static ItemSyncBox<Flow> resolveFlowDiffsInTable(final List<Flow> flowsConfigured,
+ public static ItemSyncBox<Flow> resolveFlowDiffsInTable(final List<Flow> flowsConfigured,
final Map<SwitchFlowId, Flow> flowOperationalMap,
final boolean gatherUpdates) {
final ItemSyncBox<Flow> flowsSyncBox = new ItemSyncBox<>();
final Map<Short, Table> tableOperationalMap,
final List<Table> tablesConfigured,
final boolean gatherUpdates) {
- LOG.trace("resolving flows in tables for {}", nodeId);
+ LOG.trace("resolving flows in tables for {}", nodeId.getValue());
final Map<TableKey, ItemSyncBox<Flow>> tableFlowSyncBoxes = new HashMap<>();
for (final Table tableConfigured : tablesConfigured) {
final List<Flow> flowsConfigured = tableConfigured.getFlow();