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;
12 import java.util.concurrent.atomic.AtomicInteger;
13 import com.google.common.base.Optional;
14 import com.google.common.base.Preconditions;
15 import com.google.common.collect.ImmutableList;
16 import com.google.common.collect.Iterables;
17 import com.google.common.collect.Lists;
18 import com.google.common.util.concurrent.CheckedFuture;
19 import com.google.common.util.concurrent.FutureCallback;
20 import com.google.common.util.concurrent.Futures;
22 import java.util.concurrent.Callable;
24 import org.opendaylight.controller.md.sal.binding.api.*;
25 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
26 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
27 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
28 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
29 import org.opendaylight.openflowplugin.applications.frm.FlowNodeReconciliation;
30 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
31 import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeter;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeterKey;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlowKey;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroup;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroupKey;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey;
65 import org.opendaylight.yangtools.concepts.ListenerRegistration;
66 import org.opendaylight.yangtools.yang.binding.DataObject;
67 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
68 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
69 import org.slf4j.Logger;
70 import org.slf4j.LoggerFactory;
72 import javax.annotation.Nonnull;
76 * forwardingrules-manager
77 * org.opendaylight.openflowplugin.applications.frm
79 * FlowNode Reconciliation Listener
80 * Reconciliation for a new FlowNode
82 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
84 * Created: Jun 13, 2014
86 public class FlowNodeReconciliationImpl implements FlowNodeReconciliation {
88 private static final Logger LOG = LoggerFactory.getLogger(FlowNodeReconciliationImpl.class);
90 private final DataBroker dataBroker;
92 private final ForwardingRulesManager provider;
93 public static final String SEPARATOR = ":";
95 private ListenerRegistration<FlowNodeReconciliationImpl> listenerRegistration;
97 private static final InstanceIdentifier<FlowCapableNode> II_TO_FLOW_CAPABLE_NODE
98 = InstanceIdentifier.builder(Nodes.class)
100 .augmentation(FlowCapableNode.class)
103 public FlowNodeReconciliationImpl (final ForwardingRulesManager manager, final DataBroker db) {
104 this.provider = Preconditions.checkNotNull(manager, "ForwardingRulesManager can not be null!");
105 dataBroker = Preconditions.checkNotNull(db, "DataBroker can not be null!");
107 final InstanceIdentifier<FlowCapableNode> flowNodeWildCardIdentifier = InstanceIdentifier.create(Nodes.class)
108 .child(Node.class).augmentation(FlowCapableNode.class);
110 final DataTreeIdentifier<FlowCapableNode> treeId =
111 new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, flowNodeWildCardIdentifier);
114 SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK,
115 ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES);
117 listenerRegistration = looper.loopUntilNoException(new Callable<ListenerRegistration<FlowNodeReconciliationImpl>>() {
119 public ListenerRegistration<FlowNodeReconciliationImpl> call() throws Exception {
120 return dataBroker.registerDataTreeChangeListener(treeId, FlowNodeReconciliationImpl.this);
123 } catch (Exception e) {
124 LOG.warn("data listener registration failed: {}", e.getMessage());
125 LOG.debug("data listener registration failed.. ", e);
126 throw new IllegalStateException("FlowNodeReconciliation startup fail! System needs restart.", e);
131 public void close() {
132 if (listenerRegistration != null) {
134 listenerRegistration.close();
135 } catch (Exception e) {
136 LOG.warn("Error by stop FRM FlowNodeReconilListener: {}", e.getMessage());
137 LOG.debug("Error by stop FRM FlowNodeReconilListener..", e);
139 listenerRegistration = null;
144 public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<FlowCapableNode>> changes) {
145 Preconditions.checkNotNull(changes, "Changes may not be null!");
147 for (DataTreeModification<FlowCapableNode> change : changes) {
148 final InstanceIdentifier<FlowCapableNode> key = change.getRootPath().getRootIdentifier();
149 final DataObjectModification<FlowCapableNode> mod = change.getRootNode();
150 final InstanceIdentifier<FlowCapableNode> nodeIdent =
151 key.firstIdentifierOf(FlowCapableNode.class);
153 switch (mod.getModificationType()) {
155 if (mod.getDataAfter() == null) {
156 remove(key, mod.getDataBefore(), nodeIdent);
159 case SUBTREE_MODIFIED:
160 //NO-OP since we donot need to reconciliate on Node-updated
163 if (mod.getDataBefore() == null) {
164 add(key, mod.getDataAfter(), nodeIdent);
168 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
175 public void remove(InstanceIdentifier<FlowCapableNode> identifier, FlowCapableNode del,
176 InstanceIdentifier<FlowCapableNode> nodeIdent) {
177 if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE)){
178 if (LOG.isDebugEnabled()) {
179 LOG.debug("Node removed: {}",nodeIdent.firstKeyOf(Node.class).getId().getValue());
182 if ( ! nodeIdent.isWildcarded()) {
183 flowNodeDisconnected(nodeIdent);
189 public void add(InstanceIdentifier<FlowCapableNode> identifier, FlowCapableNode add,
190 InstanceIdentifier<FlowCapableNode> nodeIdent) {
191 if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE)){
192 if (LOG.isDebugEnabled()) {
193 LOG.debug("Node added: {}",nodeIdent.firstKeyOf(Node.class).getId().getValue());
196 if ( ! nodeIdent.isWildcarded()) {
197 flowNodeConnected(nodeIdent);
203 public void flowNodeDisconnected(InstanceIdentifier<FlowCapableNode> disconnectedNode) {
204 provider.unregistrateNode(disconnectedNode);
208 public void flowNodeConnected(InstanceIdentifier<FlowCapableNode> connectedNode) {
209 flowNodeConnected(connectedNode, false);
212 private void flowNodeConnected(InstanceIdentifier<FlowCapableNode> connectedNode, boolean force) {
213 if (force || !provider.isNodeActive(connectedNode)) {
214 provider.registrateNewNode(connectedNode);
216 if(!provider.isNodeOwner(connectedNode)) { return; }
218 if (provider.getConfiguration().isStaleMarkingEnabled()) {
219 LOG.info("Stale-Marking is ENABLED and proceeding with deletion of stale-marked entities on switch {}",
220 connectedNode.toString());
221 reconciliationPreProcess(connectedNode);
223 reconciliation(connectedNode);
227 private void reconciliation(final InstanceIdentifier<FlowCapableNode> nodeIdent) {
229 String sNode = nodeIdent.firstKeyOf(Node.class, NodeKey.class).getId().getValue();
230 long nDpId = getDpnIdFromNodeName(sNode);
232 ReadOnlyTransaction trans = provider.getReadTranaction();
233 Optional<FlowCapableNode> flowNode = Optional.absent();
235 AtomicInteger counter = new AtomicInteger();
236 //initialize the counter
239 flowNode = trans.read(LogicalDatastoreType.CONFIGURATION, nodeIdent).get();
241 catch (Exception e) {
242 LOG.error("Fail with read Config/DS for Node {} !", nodeIdent, e);
245 if (flowNode.isPresent()) {
246 /* Tables - have to be pushed before groups */
247 // CHECK if while pusing the update, updateTableInput can be null to emulate a table add
248 List<TableFeatures> tableList = flowNode.get().getTableFeatures() != null
249 ? flowNode.get().getTableFeatures() : Collections.<TableFeatures> emptyList() ;
250 for (TableFeatures tableFeaturesItem : tableList) {
251 TableFeaturesKey tableKey = tableFeaturesItem.getKey();
252 KeyedInstanceIdentifier<TableFeatures, TableFeaturesKey> tableFeaturesII
253 = nodeIdent.child(TableFeatures.class, new TableFeaturesKey(tableKey.getTableId()));
254 provider.getTableFeaturesCommiter().update(tableFeaturesII, tableFeaturesItem, null, nodeIdent);
257 /* Groups - have to be first */
258 List<Group> groups = flowNode.get().getGroup() != null
259 ? flowNode.get().getGroup() : Collections.<Group>emptyList();
260 List<Group> toBeInstalledGroups = new ArrayList<>();
261 toBeInstalledGroups.addAll(groups);
262 List<Long> alreadyInstalledGroupids = new ArrayList<>();
263 //new list for suspected groups pointing to ports .. when the ports come up late
264 List<Group> suspectedGroups = new ArrayList<>();
266 while ((!(toBeInstalledGroups.isEmpty()) || !(suspectedGroups.isEmpty())) &&
267 (counter.get()<=provider.getConfiguration().getReconciliationRetryCount())) { //also check if the counter has not crossed the threshold
269 if(toBeInstalledGroups.isEmpty() && ! suspectedGroups.isEmpty()){
270 LOG.error("These Groups are pointing to node-connectors that are not up yet {}",suspectedGroups.toString());
271 toBeInstalledGroups.addAll(suspectedGroups);
275 ListIterator<Group> iterator = toBeInstalledGroups.listIterator();
276 while (iterator.hasNext()) {
277 Group group = iterator.next();
278 boolean okToInstall = true;
279 for (Bucket bucket : group.getBuckets().getBucket()) {
280 for (Action action : bucket.getAction()) {
282 if (action.getAction().getImplementedInterface().getName()
283 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase")){
284 String nodeConnectorUri = ((OutputActionCase)(action.getAction()))
285 .getOutputAction().getOutputNodeConnector().getValue();
287 LOG.warn("Installing the group for node connector {}",nodeConnectorUri);
289 //check if the nodeconnector is there in the multimap
290 boolean isPresent = provider.getFlowNodeConnectorInventoryTranslatorImpl()
291 .isNodeConnectorUpdated(nDpId, nodeConnectorUri);
292 //if yes set okToInstall = true
296 }//else put it in a different list and still set okToInstall = true
298 suspectedGroups.add(group);
299 LOG.error("Not yet received the node-connector updated for {} " +
300 "for the group with id {}",nodeConnectorUri,group.getGroupId().toString());
307 else if (action.getAction().getImplementedInterface().getName()
308 .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase")) {
309 Long groupId = ((GroupActionCase) (action.getAction())).getGroupAction().getGroupId();
310 if (!alreadyInstalledGroupids.contains(groupId)) {
317 //increment retry counter value
318 counter.incrementAndGet();
328 final KeyedInstanceIdentifier<Group, GroupKey> groupIdent =
329 nodeIdent.child(Group.class, group.getKey());
330 this.provider.getGroupCommiter().add(groupIdent, group, nodeIdent);
331 alreadyInstalledGroupids.add(group.getGroupId().getValue());
333 // resetting the counter to zero
339 /* installation of suspected groups*/
340 if(!toBeInstalledGroups.isEmpty()){
341 for(Group group :toBeInstalledGroups){
342 LOG.error("Installing the group {} finally although the port is not up after checking for {} times "
343 ,group.getGroupId().toString(),provider.getConfiguration().getReconciliationRetryCount());
344 final KeyedInstanceIdentifier<Group, GroupKey> groupIdent =
345 nodeIdent.child(Group.class, group.getKey());
346 this.provider.getGroupCommiter().add(groupIdent, group, nodeIdent);
350 List<Meter> meters = flowNode.get().getMeter() != null
351 ? flowNode.get().getMeter() : Collections.<Meter> emptyList();
352 for (Meter meter : meters) {
353 final KeyedInstanceIdentifier<Meter, MeterKey> meterIdent =
354 nodeIdent.child(Meter.class, meter.getKey());
355 this.provider.getMeterCommiter().add(meterIdent, meter, nodeIdent);
358 List<Table> tables = flowNode.get().getTable() != null
359 ? flowNode.get().getTable() : Collections.<Table> emptyList();
360 for (Table table : tables) {
361 final KeyedInstanceIdentifier<Table, TableKey> tableIdent =
362 nodeIdent.child(Table.class, table.getKey());
363 List<Flow> flows = table.getFlow() != null ? table.getFlow() : Collections.<Flow> emptyList();
364 for (Flow flow : flows) {
365 final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent =
366 tableIdent.child(Flow.class, flow.getKey());
367 this.provider.getFlowCommiter().add(flowIdent, flow, nodeIdent);
371 /* clean transaction */
374 private long getDpnIdFromNodeName(String nodeName) {
375 String dpId = nodeName.substring(nodeName.lastIndexOf(SEPARATOR) + 1);
376 return Long.parseLong(dpId);
379 private void reconciliationPreProcess(final InstanceIdentifier<FlowCapableNode> nodeIdent) {
382 List<InstanceIdentifier<StaleFlow>> staleFlowsToBeBulkDeleted = Lists.newArrayList();
383 List<InstanceIdentifier<StaleGroup>> staleGroupsToBeBulkDeleted = Lists.newArrayList();
384 List<InstanceIdentifier<StaleMeter>> staleMetersToBeBulkDeleted = Lists.newArrayList();
387 ReadOnlyTransaction trans = provider.getReadTranaction();
388 Optional<FlowCapableNode> flowNode = Optional.absent();
391 flowNode = trans.read(LogicalDatastoreType.CONFIGURATION, nodeIdent).get();
393 catch (Exception e) {
394 LOG.error("Reconciliation Pre-Processing Fail with read Config/DS for Node {} !", nodeIdent, e);
397 if (flowNode.isPresent()) {
399 LOG.debug("Proceeding with deletion of stale-marked Flows on switch {} using Openflow interface",
400 nodeIdent.toString());
401 /* Stale-Flows - Stale-marked Flows have to be removed first for safety */
402 List<Table> tables = flowNode.get().getTable() != null
403 ? flowNode.get().getTable() : Collections.<Table> emptyList();
404 for (Table table : tables) {
405 final KeyedInstanceIdentifier<Table, TableKey> tableIdent =
406 nodeIdent.child(Table.class, table.getKey());
407 List<StaleFlow> staleFlows = table.getStaleFlow() != null ? table.getStaleFlow() : Collections.<StaleFlow> emptyList();
408 for (StaleFlow staleFlow : staleFlows) {
410 FlowBuilder flowBuilder = new FlowBuilder(staleFlow);
411 Flow toBeDeletedFlow = flowBuilder.setId(staleFlow.getId()).build();
413 final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent =
414 tableIdent.child(Flow.class, toBeDeletedFlow.getKey());
417 this.provider.getFlowCommiter().remove(flowIdent, toBeDeletedFlow, nodeIdent);
419 staleFlowsToBeBulkDeleted.add(getStaleFlowInstanceIdentifier(staleFlow, nodeIdent));
424 LOG.debug("Proceeding with deletion of stale-marked Groups for switch {} using Openflow interface",
425 nodeIdent.toString());
427 // TODO: Should we collate the futures of RPC-calls to be sure that groups are Flows are fully deleted
428 // before attempting to delete groups - just in case there are references
430 /* Stale-marked Groups - Can be deleted after flows */
431 List<StaleGroup> staleGroups = flowNode.get().getStaleGroup() != null
432 ? flowNode.get().getStaleGroup() : Collections.<StaleGroup> emptyList();
433 for (StaleGroup staleGroup : staleGroups) {
435 GroupBuilder groupBuilder = new GroupBuilder(staleGroup);
436 Group toBeDeletedGroup = groupBuilder.setGroupId(staleGroup.getGroupId()).build();
438 final KeyedInstanceIdentifier<Group, GroupKey> groupIdent =
439 nodeIdent.child(Group.class, toBeDeletedGroup.getKey());
441 this.provider.getGroupCommiter().remove(groupIdent, toBeDeletedGroup, nodeIdent);
443 staleGroupsToBeBulkDeleted.add(getStaleGroupInstanceIdentifier(staleGroup, nodeIdent));
446 LOG.debug("Proceeding with deletion of stale-marked Meters for switch {} using Openflow interface",
447 nodeIdent.toString());
448 /* Stale-marked Meters - can be deleted anytime - so least priority */
449 List<StaleMeter> staleMeters = flowNode.get().getStaleMeter() != null
450 ? flowNode.get().getStaleMeter() : Collections.<StaleMeter> emptyList();
452 for (StaleMeter staleMeter : staleMeters) {
454 MeterBuilder meterBuilder = new MeterBuilder(staleMeter);
455 Meter toBeDeletedMeter = meterBuilder.setMeterId(staleMeter.getMeterId()).build();
457 final KeyedInstanceIdentifier<Meter, MeterKey> meterIdent =
458 nodeIdent.child(Meter.class, toBeDeletedMeter.getKey());
461 this.provider.getMeterCommiter().remove(meterIdent, toBeDeletedMeter, nodeIdent);
463 staleMetersToBeBulkDeleted.add(getStaleMeterInstanceIdentifier(staleMeter, nodeIdent));
467 /* clean transaction */
470 LOG.debug("Deleting all stale-marked flows/groups/meters of for switch {} in Configuration DS",
471 nodeIdent.toString());
472 // Now, do the bulk deletions
473 deleteDSStaleFlows(staleFlowsToBeBulkDeleted);
474 deleteDSStaleGroups(staleGroupsToBeBulkDeleted);
475 deleteDSStaleMeters(staleMetersToBeBulkDeleted);
480 private void deleteDSStaleFlows(List<InstanceIdentifier<StaleFlow>> flowsForBulkDelete){
481 ImmutableList.Builder<InstanceIdentifier<StaleFlow>> builder = ImmutableList.builder();
482 ImmutableList<InstanceIdentifier<StaleFlow>> bulkDelFlows = builder.addAll(flowsForBulkDelete.iterator()).build();
484 WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
486 for (InstanceIdentifier<StaleFlow> staleFlowIId : flowsForBulkDelete){
487 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, staleFlowIId);
490 CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTransaction.submit();
491 handleStaleEntityDeletionResultFuture(submitFuture);
494 private void deleteDSStaleGroups(List<InstanceIdentifier<StaleGroup>> groupsForBulkDelete){
495 ImmutableList.Builder<InstanceIdentifier<StaleGroup>> builder = ImmutableList.builder();
496 ImmutableList<InstanceIdentifier<StaleGroup>> bulkDelGroups = builder.addAll(groupsForBulkDelete.iterator()).build();
498 WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
500 for (InstanceIdentifier<StaleGroup> staleGroupIId : groupsForBulkDelete){
501 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, staleGroupIId);
504 CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTransaction.submit();
505 handleStaleEntityDeletionResultFuture(submitFuture);
509 private void deleteDSStaleMeters(List<InstanceIdentifier<StaleMeter>> metersForBulkDelete){
510 ImmutableList.Builder<InstanceIdentifier<StaleMeter>> builder = ImmutableList.builder();
511 ImmutableList<InstanceIdentifier<StaleMeter>> bulkDelGroups = builder.addAll(metersForBulkDelete.iterator()).build();
513 WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
515 for (InstanceIdentifier<StaleMeter> staleMeterIId : metersForBulkDelete){
516 writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, staleMeterIId);
519 CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTransaction.submit();
520 handleStaleEntityDeletionResultFuture(submitFuture);
526 private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow> getStaleFlowInstanceIdentifier(StaleFlow staleFlow, InstanceIdentifier<FlowCapableNode> nodeIdent) {
528 .child(Table.class, new TableKey(staleFlow.getTableId()))
529 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow.class,
530 new StaleFlowKey(new FlowId(staleFlow.getId())));
533 private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.StaleGroup> getStaleGroupInstanceIdentifier(StaleGroup staleGroup, InstanceIdentifier<FlowCapableNode> nodeIdent) {
535 .child(StaleGroup.class, new StaleGroupKey(new GroupId(staleGroup.getGroupId())));
539 private InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeter> getStaleMeterInstanceIdentifier(StaleMeter staleMeter, InstanceIdentifier<FlowCapableNode> nodeIdent) {
541 .child(StaleMeter.class, new StaleMeterKey(new MeterId(staleMeter.getMeterId())));
545 private void handleStaleEntityDeletionResultFuture(CheckedFuture<Void, TransactionCommitFailedException> submitFuture) {
546 Futures.addCallback(submitFuture, new FutureCallback<Void>() {
548 public void onSuccess(Void result) { LOG.debug("Stale entity removal success");
552 public void onFailure(Throwable t) {
553 LOG.error("Stale entity removal failed {}", t);
560 private boolean compareInstanceIdentifierTail(InstanceIdentifier<?> identifier1,
561 InstanceIdentifier<?> identifier2) {
562 return Iterables.getLast(identifier1.getPathArguments()).equals(Iterables.getLast(identifier2.getPathArguments()));