Do not use JdkFutureAdapters
[openflowplugin.git] / applications / forwardingrules-manager / src / main / java / org / opendaylight / openflowplugin / applications / frm / impl / TableForwarder.java
1 /*
2  * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowplugin.applications.frm.impl;
9
10 import com.google.common.util.concurrent.Futures;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.Collections;
13 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.OriginalTableBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.common.RpcResult;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class TableForwarder extends AbstractListeningCommiter<TableFeatures> {
32     private static final Logger LOG = LoggerFactory.getLogger(TableForwarder.class);
33
34     public TableForwarder(final ForwardingRulesManager manager, final DataBroker db,
35                           final ListenerRegistrationHelper registrationHelper) {
36         super(manager, db, registrationHelper);
37     }
38
39     @Override
40     protected InstanceIdentifier<TableFeatures> getWildCardPath() {
41         return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class)
42                 .child(TableFeatures.class);
43     }
44
45     @Override
46     public void remove(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures removeDataObj,
47             final InstanceIdentifier<FlowCapableNode> nodeIdent) {
48         // DO Nothing
49     }
50
51     @Override
52     public void update(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures original,
53             final TableFeatures update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
54         LOG.debug("Received the Table Update request [Tbl id, node Id, original, upd {} {} {} {}", identifier,
55                 nodeIdent, original, update);
56
57         final TableFeatures originalTableFeatures = original;
58         TableFeatures updatedTableFeatures;
59         if (null == update) {
60             updatedTableFeatures = original;
61         } else {
62             updatedTableFeatures = update;
63         }
64         final UpdateTableInputBuilder builder = new UpdateTableInputBuilder();
65
66         builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
67
68         // TODO: reconsider model - this particular field is not used in service
69         // implementation
70         builder.setTableRef(new TableRef(identifier));
71
72         builder.setTransactionUri(new Uri(provider.getNewTransactionId()));
73
74         builder.setUpdatedTable(new UpdatedTableBuilder()
75             .setTableFeatures(Collections.singletonMap(updatedTableFeatures.key(), updatedTableFeatures))
76             .build());
77
78         builder.setOriginalTable(new OriginalTableBuilder()
79             .setTableFeatures(Collections.singletonMap(originalTableFeatures.key(), originalTableFeatures))
80             .build());
81         LOG.debug("Invoking SalTableService ");
82
83         if (provider.getSalTableService() != null) {
84             LOG.debug(" Handle to SalTableServices {}", provider.getSalTableService());
85         }
86
87         LoggingFutures.addErrorLogging(provider.getSalTableService().updateTable(builder.build()), LOG,
88             "updateTable");
89     }
90
91     @Override
92     public ListenableFuture<RpcResult<?>> add(final InstanceIdentifier<TableFeatures> identifier,
93             final TableFeatures addDataObj, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
94         return Futures.immediateFuture(null);
95     }
96
97     @Override
98     public void createStaleMarkEntity(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures del,
99             final InstanceIdentifier<FlowCapableNode> nodeIdent) {
100         LOG.debug("NO-OP");
101     }
102
103     @Override
104     public ListenableFuture<RpcResult<?>> removeWithResult(final InstanceIdentifier<TableFeatures> identifier,
105             final TableFeatures del, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
106         return Futures.immediateFuture(null);
107     }
108 }