X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fforwardingrules-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Ffrm%2Fimpl%2FFlowForwarder.java;h=698dbcb0d1593a912cc1caba527fb9a12e174cfd;hb=b3e553ce5b3d3e972cbe19465ab7af2fcb39934c;hp=e0c16a080676691080def9e86e12d22fe87883b0;hpb=796c92a53b69beda64657e355589284af48e95e3;p=controller.git diff --git a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/impl/FlowForwarder.java b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/impl/FlowForwarder.java index e0c16a0806..698dbcb0d1 100644 --- a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/impl/FlowForwarder.java +++ b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/impl/FlowForwarder.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.frm.impl; -import com.google.common.base.Preconditions; import org.opendaylight.controller.frm.ForwardingRulesManager; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; @@ -33,6 +32,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.Preconditions; + /** * GroupForwarder * It implements {@link org.opendaylight.controller.md.sal.binding.api.DataChangeListener}} @@ -52,8 +53,27 @@ public class FlowForwarder extends AbstractListeningCommiter { public FlowForwarder (final ForwardingRulesManager manager, final DataBroker db) { super(manager, Flow.class); Preconditions.checkNotNull(db, "DataBroker can not be null!"); - this.listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, - getWildCardPath(), FlowForwarder.this, DataChangeScope.SUBTREE); + registrationListener(db, 5); + } + + private void registrationListener(final DataBroker db, int i) { + try { + listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, + getWildCardPath(), FlowForwarder.this, DataChangeScope.SUBTREE); + } catch (final Exception e) { + if (i >= 1) { + try { + Thread.sleep(100); + } catch (InterruptedException e1) { + LOG.error("Thread interrupted '{}'", e1); + Thread.currentThread().interrupt(); + } + registrationListener(db, --i); + } else { + LOG.error("FRM Flow DataChange listener registration fail!", e); + throw new IllegalStateException("FlowForwarder registration Listener fail! System needs restart.", e); + } + } } @Override @@ -61,7 +81,7 @@ public class FlowForwarder extends AbstractListeningCommiter { if (listenerRegistration != null) { try { listenerRegistration.close(); - } catch (Exception e) { + } catch (final Exception e) { LOG.error("Error by stop FRM FlowChangeListener.", e); } listenerRegistration = null; @@ -77,10 +97,10 @@ public class FlowForwarder extends AbstractListeningCommiter { if (tableIdValidationPrecondition(tableKey, removeDataObj)) { final RemoveFlowInputBuilder builder = new RemoveFlowInputBuilder(removeDataObj); builder.setFlowRef(new FlowRef(identifier)); - builder.setNode(new NodeRef(nodeIdent)); + builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class))); builder.setFlowTable(new FlowTableRef(nodeIdent.child(Table.class, tableKey))); builder.setTransactionUri(new Uri(provider.getNewTransactionId())); - this.provider.getSalFlowService().removeFlow(builder.build()); + provider.getSalFlowService().removeFlow(builder.build()); } } @@ -93,13 +113,13 @@ public class FlowForwarder extends AbstractListeningCommiter { if (tableIdValidationPrecondition(tableKey, update)) { final UpdateFlowInputBuilder builder = new UpdateFlowInputBuilder(); - builder.setNode(new NodeRef(nodeIdent)); + builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class))); builder.setFlowRef(new FlowRef(identifier)); builder.setTransactionUri(new Uri(provider.getNewTransactionId())); builder.setUpdatedFlow((new UpdatedFlowBuilder(update)).build()); builder.setOriginalFlow((new OriginalFlowBuilder(original)).build()); - this.provider.getSalFlowService().updateFlow(builder.build()); + provider.getSalFlowService().updateFlow(builder.build()); } } @@ -112,11 +132,11 @@ public class FlowForwarder extends AbstractListeningCommiter { if (tableIdValidationPrecondition(tableKey, addDataObj)) { final AddFlowInputBuilder builder = new AddFlowInputBuilder(addDataObj); - builder.setNode(new NodeRef(nodeIdent)); + builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class))); builder.setFlowRef(new FlowRef(identifier)); builder.setFlowTable(new FlowTableRef(nodeIdent.child(Table.class, tableKey))); builder.setTransactionUri(new Uri(provider.getNewTransactionId())); - this.provider.getSalFlowService().addFlow(builder.build()); + provider.getSalFlowService().addFlow(builder.build()); } } @@ -129,7 +149,7 @@ public class FlowForwarder extends AbstractListeningCommiter { private boolean tableIdValidationPrecondition (final TableKey tableKey, final Flow flow) { Preconditions.checkNotNull(tableKey, "TableKey can not be null or empty!"); Preconditions.checkNotNull(flow, "Flow can not be null or empty!"); - if (flow.getTableId() != tableKey.getId()) { + if (! tableKey.getId().equals(flow.getTableId())) { LOG.error("TableID in URI tableId={} and in palyload tableId={} is not same.", flow.getTableId(), tableKey.getId()); return false;