2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.applications.frm.impl;
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13 import com.google.common.collect.ImmutableList;
14 import com.google.common.collect.Iterables;
15 import com.google.common.collect.Lists;
16 import com.google.common.util.concurrent.CheckedFuture;
17 import com.google.common.util.concurrent.FutureCallback;
18 import com.google.common.util.concurrent.Futures;
19 import java.math.BigInteger;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.ListIterator;
25 import java.util.concurrent.Callable;
26 import java.util.concurrent.ExecutorService;
27 import java.util.concurrent.Executors;
28 import java.util.concurrent.atomic.AtomicInteger;
29 import javax.annotation.Nonnull;
30 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
31 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
32 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
33 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
34 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
35 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
36 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
37 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
38 import org.opendaylight.openflowplugin.applications.frm.FlowNodeReconciliation;
39 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
40 import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeter;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeterKey;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlowKey;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroup;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroupKey;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey;
71 import org.opendaylight.yangtools.concepts.ListenerRegistration;
72 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
73 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
74 import org.slf4j.Logger;
75 import org.slf4j.LoggerFactory;
79 * forwardingrules-manager
80 * org.opendaylight.openflowplugin.applications.frm
82 * FlowNode Reconciliation Listener
83 * Reconciliation for a new FlowNode
85 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
87 * Created: Jun 13, 2014
89 public class FlowNodeReconciliationImpl implements FlowNodeReconciliation {
91 private static final Logger LOG = LoggerFactory.getLogger(FlowNodeReconciliationImpl.class);
93 private final DataBroker dataBroker;
95 private final ForwardingRulesManager provider;
96 private static final String SEPARATOR = ":";
98 private ListenerRegistration<FlowNodeReconciliationImpl> listenerRegistration;
100 private final int THREAD_POOL_SIZE = 4;
101 ExecutorService executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
103 private static final InstanceIdentifier<FlowCapableNode> II_TO_FLOW_CAPABLE_NODE
104 = InstanceIdentifier.builder(Nodes.class)
106 .augmentation(FlowCapableNode.class)
109 public FlowNodeReconciliationImpl (final ForwardingRulesManager manager, final DataBroker db) {
110 this.provider = Preconditions.checkNotNull(manager, "ForwardingRulesManager can not be null!");
111 dataBroker = Preconditions.checkNotNull(db, "DataBroker can not be null!");
113 final InstanceIdentifier<FlowCapableNode> flowNodeWildCardIdentifier = InstanceIdentifier.create(Nodes.class)
114 .child(Node.class).augmentation(FlowCapableNode.class);
116 final DataTreeIdentifier<FlowCapableNode> treeId =
117 new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, flowNodeWildCardIdentifier);
120 SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK,
121 ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES);
123 listenerRegistration = looper.loopUntilNoException(new Callable<ListenerRegistration<FlowNodeReconciliationImpl>>() {
125 public ListenerRegistration<FlowNodeReconciliationImpl> call() throws Exception {
126 return dataBroker.registerDataTreeChangeListener(treeId, FlowNodeReconciliationImpl.this);
129 } catch (Exception e) {
130 LOG.warn("data listener registration failed: {}", e.getMessage());
131 LOG.debug("data listener registration failed.. ", e);
132 throw new IllegalStateException("FlowNodeReconciliation startup fail! System needs restart.", e);
137 public void close() {
138 if (listenerRegistration != null) {
140 listenerRegistration.close();
141 } catch (Exception e) {
142 LOG.warn("Error by stop FRM FlowNodeReconilListener: {}", e.getMessage());
143 LOG.debug("Error by stop FRM FlowNodeReconilListener..", e);
145 listenerRegistration = null;
150 public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<FlowCapableNode>> changes) {
151 Preconditions.checkNotNull(changes, "Changes may not be null!");
153 for (DataTreeModification<FlowCapableNode> change : changes) {
154 final InstanceIdentifier<FlowCapableNode> key = change.getRootPath().getRootIdentifier();
155 final DataObjectModification<FlowCapableNode> mod = change.getRootNode();
156 final InstanceIdentifier<FlowCapableNode> nodeIdent =
157 key.firstIdentifierOf(FlowCapableNode.class);
159 switch (mod.getModificationType()) {
161 if (mod.getDataAfter() == null) {
162 remove(key, mod.getDataBefore(), nodeIdent);
165 case SUBTREE_MODIFIED:
166 //NO-OP since we donot need to reconciliate on Node-updated
169 if (mod.getDataBefore() == null) {
170 add(key, mod.getDataAfter(), nodeIdent);
174 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
181 public void remove(InstanceIdentifier<FlowCapableNode> identifier, FlowCapableNode del,
182 InstanceIdentifier<FlowCapableNode> nodeIdent) {
183 if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE)){
184 if (LOG.isDebugEnabled()) {
185 LOG.debug("Node removed: {}",nodeIdent.firstKeyOf(Node.class).getId().getValue());
188 if ( ! nodeIdent.isWildcarded()) {
189 flowNodeDisconnected(nodeIdent);
195 public void add(InstanceIdentifier<FlowCapableNode> identifier, FlowCapableNode add,
196 InstanceIdentifier<FlowCapableNode> nodeIdent) {
197 if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE)){
198 if (LOG.isDebugEnabled()) {
199 LOG.debug("Node added: {}",nodeIdent.firstKeyOf(Node.class).getId().getValue());
202 if ( ! nodeIdent.isWildcarded()) {
203 flowNodeConnected(nodeIdent);
209 public void flowNodeDisconnected(InstanceIdentifier<FlowCapableNode> disconnectedNode) {
210 provider.unregistrateNode(disconnectedNode);
214 public void flowNodeConnected(InstanceIdentifier<FlowCapableNode> connectedNode) {
215 flowNodeConnected(connectedNode, false);
218 private void flowNodeConnected(InstanceIdentifier<FlowCapableNode> connectedNode, boolean force) {
219 if (force || !provider.isNodeActive(connectedNode)) {
220 provider.registrateNewNode(connectedNode);
222 if(!provider.isNodeOwner(connectedNode)) { return; }
224 if (provider.getConfiguration().isStaleMarkingEnabled()) {
225 LOG.info("Stale-Marking is ENABLED and proceeding with deletion of stale-marked entities on switch {}",
226 connectedNode.toString());
227 reconciliationPreProcess(connectedNode);
229 ReconciliationTask reconciliationTask = new ReconciliationTask(connectedNode);
230 executor.execute(reconciliationTask);
234 private class ReconciliationTask implements Runnable {
236 InstanceIdentifier<FlowCapableNode> nodeIdentity;
238 public ReconciliationTask(final InstanceIdentifier<FlowCapableNode> nodeIdent) {
239 nodeIdentity = nodeIdent;
245 String sNode = nodeIdentity.firstKeyOf(Node.class, NodeKey.class).getId().getValue();
246 BigInteger nDpId = getDpnIdFromNodeName(sNode);
248 ReadOnlyTransaction trans = provider.getReadTranaction();
249 Optional<FlowCapableNode> flowNode = Optional.absent();
251 AtomicInteger counter = new AtomicInteger();
252 //initialize the counter
255 flowNode = trans.read(LogicalDatastoreType.CONFIGURATION, nodeIdentity).get();
256 } catch (Exception e) {
257 LOG.error("Fail with read Config/DS for Node {} !", nodeIdentity, e);
260 if (flowNode.isPresent()) {
261 /* Tables - have to be pushed before groups */
262 // CHECK if while pusing the update, updateTableInput can be null to emulate a table add
263 List<TableFeatures> tableList = flowNode.get().getTableFeatures() != null
264 ? flowNode.get().getTableFeatures() : Collections.<TableFeatures>emptyList();
265 for (TableFeatures tableFeaturesItem : tableList) {
266 TableFeaturesKey tableKey = tableFeaturesItem.getKey();
267 KeyedInstanceIdentifier<TableFeatures, TableFeaturesKey> tableFeaturesII
268 = nodeIdentity.child(TableFeatures.class, new TableFeaturesKey(tableKey.getTableId()));
269 provider.getTableFeaturesCommiter().update(tableFeaturesII, tableFeaturesItem, null, nodeIdentity);
272 /* Groups - have to be first */
273 List<Group> groups = flowNode.get().getGroup() != null
274 ? flowNode.get().getGroup() : Collections.<Group>emptyList();
275 List<Group> toBeInstalledGroups = new ArrayList<>();
276 toBeInstalledGroups.addAll(groups);
277 List<Long> alreadyInstalledGroupids = new ArrayList<>();
278 //new list for suspected groups pointing to ports .. when the ports come up late
279 List<Group> suspectedGroups = new ArrayList<>();
281 while ((!(toBeInstalledGroups.isEmpty()) || !(suspectedGroups.isEmpty())) &&
282 (counter.get() <= provider.getConfiguration().getReconciliationRetryCount())) { //also check if the counter has not crossed the threshold
284 if (toBeInstalledGroups.isEmpty() && !suspectedGroups.isEmpty()) {
285 LOG.error("These Groups are pointing to node-connectors that are not up yet {}", suspectedGroups.toString());
286 toBeInstalledGroups.addAll(suspectedGroups);
290 ListIterator<Group> iterator = toBeInstalledGroups.listIterator();
291 while (iterator.hasNext()) {
292 Group group = iterator.next();
293 boolean okToInstall = true;
294 for (Bucket bucket : group.getBuckets().getBucket()) {
295 for (Action action : bucket.getAction()) {
297 if (action.getAction().getImplementedInterface().getName()
298 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase")) {
299 String nodeConnectorUri = ((OutputActionCase) (action.getAction()))
300 .getOutputAction().getOutputNodeConnector().getValue();
302 LOG.warn("Installing the group for node connector {}", nodeConnectorUri);
304 //check if the nodeconnector is there in the multimap
305 boolean isPresent = provider.getFlowNodeConnectorInventoryTranslatorImpl()
306 .isNodeConnectorUpdated(nDpId, nodeConnectorUri);
307 //if yes set okToInstall = true
311 }//else put it in a different list and still set okToInstall = true
313 suspectedGroups.add(group);
314 LOG.error("Not yet received the node-connector updated for {} " +
315 "for the group with id {}", nodeConnectorUri, group.getGroupId().toString());
322 else if (action.getAction().getImplementedInterface().getName()
323 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase")) {
324 Long groupId = ((GroupActionCase) (action.getAction())).getGroupAction().getGroupId();
325 if (!alreadyInstalledGroupids.contains(groupId)) {
332 //increment retry counter value
333 counter.incrementAndGet();
342 final KeyedInstanceIdentifier<Group, GroupKey> groupIdent =
343 nodeIdentity.child(Group.class, group.getKey());
344 provider.getGroupCommiter().add(groupIdent, group, nodeIdentity);
345 alreadyInstalledGroupids.add(group.getGroupId().getValue());
347 // resetting the counter to zero
353 /* installation of suspected groups*/
354 if (!toBeInstalledGroups.isEmpty()) {
355 for (Group group : toBeInstalledGroups) {
356 LOG.error("Installing the group {} finally although the port is not up after checking for {} times "
357 , group.getGroupId().toString(), provider.getConfiguration().getReconciliationRetryCount());
358 final KeyedInstanceIdentifier<Group, GroupKey> groupIdent =
359 nodeIdentity.child(Group.class, group.getKey());
360 provider.getGroupCommiter().add(groupIdent, group, nodeIdentity);
364 List<Meter> meters = flowNode.get().getMeter() != null
365 ? flowNode.get().getMeter() : Collections.<Meter>emptyList();
366 for (Meter meter : meters) {
367 final KeyedInstanceIdentifier<Meter, MeterKey> meterIdent =
368 nodeIdentity.child(Meter.class, meter.getKey());
369 provider.getMeterCommiter().add(meterIdent, meter, nodeIdentity);
372 List<Table> tables = flowNode.get().getTable() != null
373 ? flowNode.get().getTable() : Collections.<Table>emptyList();
374 for (Table table : tables) {
375 final KeyedInstanceIdentifier<Table, TableKey> tableIdent =
376 nodeIdentity.child(Table.class, table.getKey());
377 List<Flow> flows = table.getFlow() != null ? table.getFlow() : Collections.<Flow>emptyList();
378 for (Flow flow : flows) {
379 final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent =
380 tableIdent.child(Flow.class, flow.getKey());
381 provider.getFlowCommiter().add(flowIdent, flow, nodeIdentity);
385 /* clean transaction */
389 private BigInteger getDpnIdFromNodeName(String nodeName) {
390 String dpId = nodeName.substring(nodeName.lastIndexOf(SEPARATOR) + 1);
391 return new BigInteger(dpId);
394 private void reconciliationPreProcess(final InstanceIdentifier<FlowCapableNode> nodeIdent) {
396 List<InstanceIdentifier<StaleFlow>> staleFlowsToBeBulkDeleted = Lists.newArrayList();
397 List<InstanceIdentifier<StaleGroup>> staleGroupsToBeBulkDeleted = Lists.newArrayList();
398 List<InstanceIdentifier<StaleMeter>> staleMetersToBeBulkDeleted = Lists.newArrayList();
401 ReadOnlyTransaction trans = provider.getReadTranaction();
402 Optional<FlowCapableNode> flowNode = Optional.absent();
405 flowNode = trans.read(LogicalDatastoreType.CONFIGURATION, nodeIdent).get();
407 catch (Exception e) {
408 LOG.error("Reconciliation Pre-Processing Fail with read Config/DS for Node {} !", nodeIdent, e);
411 if (flowNode.isPresent()) {
413 LOG.debug("Proceeding with deletion of stale-marked Flows on switch {} using Openflow interface",
414 nodeIdent.toString());
415 /* Stale-Flows - Stale-marked Flows have to be removed first for safety */
416 List<Table> tables = flowNode.get().getTable() != null
417 ? flowNode.get().getTable() : Collections.<Table> emptyList();
418 for (Table table : tables) {
419 final KeyedInstanceIdentifier<Table, TableKey> tableIdent =
420 nodeIdent.child(Table.class, table.getKey());
421 List<StaleFlow> staleFlows = table.getStaleFlow() != null ? table.getStaleFlow() : Collections.<StaleFlow> emptyList();
422 for (StaleFlow staleFlow : staleFlows) {
424 FlowBuilder flowBuilder = new FlowBuilder(staleFlow);
425 Flow toBeDeletedFlow = flowBuilder.setId(staleFlow.getId()).build();
427 final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent =
428 tableIdent.child(Flow.class, toBeDeletedFlow.getKey());
431 this.provider.getFlowCommiter().remove(flowIdent, toBeDeletedFlow, nodeIdent);
433 staleFlowsToBeBulkDeleted.add(getStaleFlowInstanceIdentifier(staleFlow, nodeIdent));
438 LOG.debug("Proceeding with deletion of stale-marked Groups for switch {} using Openflow interface",
439 nodeIdent.toString());
441 // TODO: Should we collate the futures of RPC-calls to be sure that groups are Flows are fully deleted
442 // before attempting to delete groups - just in case there are references
444 /* Stale-marked Groups - Can be deleted after flows */
445 List<StaleGroup> staleGroups = flowNode.get().getStaleGroup() != null
446 ? flowNode.get().getStaleGroup() : Collections.<StaleGroup> emptyList();
447 for (StaleGroup staleGroup : staleGroups) {
449 GroupBuilder groupBuilder = new GroupBuilder(staleGroup);
450 Group toBeDeletedGroup = groupBuilder.setGroupId(staleGroup.getGroupId()).build();
452 final KeyedInstanceIdentifier<Group, GroupKey> groupIdent =
453 nodeIdent.child(Group.class, toBeDeletedGroup.getKey());
455 this.provider.getGroupCommiter().remove(groupIdent, toBeDeletedGroup, nodeIdent);
457 staleGroupsToBeBulkDeleted.add(getStaleGroupInstanceIdentifier(staleGroup, nodeIdent));
460 LOG.debug("Proceeding with deletion of stale-marked Meters for switch {} using Openflow interface",
461 nodeIdent.toString());
462 /* Stale-marked Meters - can be deleted anytime - so least priority */
463 List<StaleMeter> staleMeters = flowNode.get().getStaleMeter() != null
464 ? flowNode.get().getStaleMeter() : Collections.<StaleMeter> emptyList();
466 for (StaleMeter staleMeter : staleMeters) {
468 MeterBuilder meterBuilder = new MeterBuilder(staleMeter);
469 Meter toBeDeletedMeter = meterBuilder.setMeterId(staleMeter.getMeterId()).build();
471 final KeyedInstanceIdentifier<Meter, MeterKey> meterIdent =
472 nodeIdent.child(Meter.class, toBeDeletedMeter.getKey());
475 this.provider.getMeterCommiter().remove(meterIdent, toBeDeletedMeter, nodeIdent);
477 staleMetersToBeBulkDeleted.add(getStaleMeterInstanceIdentifier(staleMeter, nodeIdent));
481 /* clean transaction */
484 LOG.debug("Deleting all stale-marked flows/groups/meters of for switch {} in Configuration DS",
485 nodeIdent.toString());
486 // Now, do the bulk deletions
487 deleteDSStaleFlows(staleFlowsToBeBulkDeleted);
488 deleteDSStaleGroups(staleGroupsToBeBulkDeleted);
489 deleteDSStaleMeters(staleMetersToBeBulkDeleted);
494 private void deleteDSStaleFlows(List<InstanceIdentifier<StaleFlow>> flowsForBulkDelete){
495 ImmutableList.Builder<InstanceIdentifier<StaleFlow>> builder = ImmutableList.builder();
496 ImmutableList<InstanceIdentifier<StaleFlow>> bulkDelFlows = builder.addAll(flowsForBulkDelete.iterator()).build();
498 WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
500 for (InstanceIdentifier<StaleFlow> staleFlowIId : flowsForBulkDelete){
501 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, staleFlowIId);
504 CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTransaction.submit();
505 handleStaleEntityDeletionResultFuture(submitFuture);
508 private void deleteDSStaleGroups(List<InstanceIdentifier<StaleGroup>> groupsForBulkDelete){
509 ImmutableList.Builder<InstanceIdentifier<StaleGroup>> builder = ImmutableList.builder();
510 ImmutableList<InstanceIdentifier<StaleGroup>> bulkDelGroups = builder.addAll(groupsForBulkDelete.iterator()).build();
512 WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
514 for (InstanceIdentifier<StaleGroup> staleGroupIId : groupsForBulkDelete){
515 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, staleGroupIId);
518 CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTransaction.submit();
519 handleStaleEntityDeletionResultFuture(submitFuture);
523 private void deleteDSStaleMeters(List<InstanceIdentifier<StaleMeter>> metersForBulkDelete){
524 ImmutableList.Builder<InstanceIdentifier<StaleMeter>> builder = ImmutableList.builder();
525 ImmutableList<InstanceIdentifier<StaleMeter>> bulkDelGroups = builder.addAll(metersForBulkDelete.iterator()).build();
527 WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
529 for (InstanceIdentifier<StaleMeter> staleMeterIId : metersForBulkDelete){
530 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, staleMeterIId);
533 CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTransaction.submit();
534 handleStaleEntityDeletionResultFuture(submitFuture);
540 private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow> getStaleFlowInstanceIdentifier(StaleFlow staleFlow, InstanceIdentifier<FlowCapableNode> nodeIdent) {
542 .child(Table.class, new TableKey(staleFlow.getTableId()))
543 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow.class,
544 new StaleFlowKey(new FlowId(staleFlow.getId())));
547 private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroup> getStaleGroupInstanceIdentifier(StaleGroup staleGroup, InstanceIdentifier<FlowCapableNode> nodeIdent) {
549 .child(StaleGroup.class, new StaleGroupKey(new GroupId(staleGroup.getGroupId())));
553 private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeter> getStaleMeterInstanceIdentifier(StaleMeter staleMeter, InstanceIdentifier<FlowCapableNode> nodeIdent) {
555 .child(StaleMeter.class, new StaleMeterKey(new MeterId(staleMeter.getMeterId())));
559 private void handleStaleEntityDeletionResultFuture(CheckedFuture<Void, TransactionCommitFailedException> submitFuture) {
560 Futures.addCallback(submitFuture, new FutureCallback<Void>() {
562 public void onSuccess(Void result) { LOG.debug("Stale entity removal success");
566 public void onFailure(Throwable t) {
567 LOG.error("Stale entity removal failed {}", t);
574 private boolean compareInstanceIdentifierTail(InstanceIdentifier<?> identifier1,
575 InstanceIdentifier<?> identifier2) {
576 return Iterables.getLast(identifier1.getPathArguments()).equals(Iterables.getLast(identifier2.getPathArguments()));