X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=applications%2Fforwardingrules-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fapplications%2Ffrm%2Fimpl%2FTableForwarder.java;h=ebfb2ae744c6f7c1b385ba1be65d33f1cab9c257;hb=49613603064b9a2cf2e13f76aa61793a0c8539b2;hp=8839cb6354efbc6b19e824fac17700b1e436d836;hpb=3c34de49abdc57fe13181e370e61e06a1e0ca658;p=openflowplugin.git diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/TableForwarder.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/TableForwarder.java index 8839cb6354..ebfb2ae744 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/TableForwarder.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/TableForwarder.java @@ -1,23 +1,18 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.applications.frm.impl; -import com.google.common.base.Preconditions; import com.google.common.util.concurrent.Futures; import java.util.Collections; -import java.util.concurrent.Callable; import java.util.concurrent.Future; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.infrautils.utils.concurrent.LoggingFutures; +import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager; -import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; @@ -28,7 +23,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.tab import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.table.update.UpdatedTableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures; -import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; @@ -38,104 +32,91 @@ public class TableForwarder extends AbstractListeningCommiter { private static final Logger LOG = LoggerFactory.getLogger(TableForwarder.class); - private ListenerRegistration listenerRegistration; - - public TableForwarder(final ForwardingRulesManager manager, final DataBroker db) { - super(manager, TableFeatures.class); - Preconditions.checkNotNull(db, "DataBroker can not be null!"); - final DataTreeIdentifier treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath()); - - try { - SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK, - ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES); - listenerRegistration = looper.loopUntilNoException(() -> db.registerDataTreeChangeListener(treeId, TableForwarder.this)); - } catch (final Exception e) { - LOG.warn("FRM Table DataChange listener registration fail!"); - LOG.debug("FRM Table DataChange listener registration fail ..", e); - throw new IllegalStateException("TableForwarder startup fail! System needs restart.", e); - } + public TableForwarder(final ForwardingRulesManager manager, final DataBroker db, + final ListenerRegistrationHelper registrationHelper) { + super(manager, db, registrationHelper); + } + + @Override + public void deregisterListener() { + close(); } @Override public void close() { if (listenerRegistration != null) { - try { - listenerRegistration.close(); - } catch (Exception e) { - LOG.warn("Error by stop FRM TableChangeListener: {}", e.getMessage()); - LOG.debug("Error by stop FRM TableChangeListener..", e); - } + listenerRegistration.close(); listenerRegistration = null; } } @Override protected InstanceIdentifier getWildCardPath() { - return InstanceIdentifier.create(Nodes.class).child(Node.class) - .augmentation(FlowCapableNode.class).child(TableFeatures.class); + return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class) + .child(TableFeatures.class); } @Override public void remove(final InstanceIdentifier identifier, final TableFeatures removeDataObj, - final InstanceIdentifier nodeIdent) { + final InstanceIdentifier nodeIdent) { // DO Nothing } @Override - public void update(final InstanceIdentifier identifier, - final TableFeatures original, final TableFeatures update, - final InstanceIdentifier nodeIdent) { - LOG.debug("Received the Table Update request [Tbl id, node Id, original, upd" + - " " + identifier + " " + nodeIdent + " " + original + " " + update); + public void update(final InstanceIdentifier identifier, final TableFeatures original, + final TableFeatures update, final InstanceIdentifier nodeIdent) { + LOG.debug("Received the Table Update request [Tbl id, node Id, original, upd {} {} {} {}", identifier, + nodeIdent, original, update); final TableFeatures originalTableFeatures = original; TableFeatures updatedTableFeatures; if (null == update) { updatedTableFeatures = original; - } - else { + } else { updatedTableFeatures = update; } final UpdateTableInputBuilder builder = new UpdateTableInputBuilder(); builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class))); - // TODO: reconsider model - this particular field is not used in service implementation + // TODO: reconsider model - this particular field is not used in service + // implementation builder.setTableRef(new TableRef(identifier)); builder.setTransactionUri(new Uri(provider.getNewTransactionId())); - builder.setUpdatedTable(new UpdatedTableBuilder().setTableFeatures( - Collections.singletonList(updatedTableFeatures)).build()); + builder.setUpdatedTable(new UpdatedTableBuilder() + .setTableFeatures(Collections.singletonMap(updatedTableFeatures.key(), updatedTableFeatures)) + .build()); - builder.setOriginalTable(new OriginalTableBuilder().setTableFeatures( - Collections.singletonList(originalTableFeatures)).build()); + builder.setOriginalTable(new OriginalTableBuilder() + .setTableFeatures(Collections.singletonMap(originalTableFeatures.key(), originalTableFeatures)) + .build()); LOG.debug("Invoking SalTableService "); - if (this.provider.getSalTableService() != null) - LOG.debug(" Handle to SalTableServices" + this.provider.getSalTableService()); - this.provider.getSalTableService().updateTable(builder.build()); + if (this.provider.getSalTableService() != null) { + LOG.debug(" Handle to SalTableServices {}", this.provider.getSalTableService()); + } + LoggingFutures.addErrorLogging(this.provider.getSalTableService().updateTable(builder.build()), LOG, + "updateTable"); } @Override - public Future add( - final InstanceIdentifier identifier, - final TableFeatures addDataObj, - final InstanceIdentifier nodeIdent) { + public Future> add(final InstanceIdentifier identifier, + final TableFeatures addDataObj, final InstanceIdentifier nodeIdent) { return Futures.immediateFuture(null); } @Override - public void createStaleMarkEntity(InstanceIdentifier identifier, TableFeatures del, InstanceIdentifier nodeIdent) { + public void createStaleMarkEntity(InstanceIdentifier identifier, TableFeatures del, + InstanceIdentifier nodeIdent) { LOG.debug("NO-OP"); - } @Override - public Future removeWithResult(InstanceIdentifier identifier, TableFeatures del, InstanceIdentifier nodeIdent) { + public Future> removeWithResult(InstanceIdentifier identifier, + TableFeatures del, InstanceIdentifier nodeIdent) { return null; } - - }