Split listeners from data processors
authorStephen Kitt <skitt@redhat.com>
Fri, 1 Apr 2016 15:10:07 +0000 (17:10 +0200)
committerSam Hague <shague@redhat.com>
Mon, 4 Apr 2016 16:01:18 +0000 (12:01 -0400)
Listening for changes is different from processing them, so separate
the two concerns. This should make the data processors easier to
test.

Change-Id: I7a385b13c37ac2d02f12799042fc956084bd3670
Signed-off-by: Stephen Kitt <skitt@redhat.com>
Signed-off-by: Sam Hague <shague@redhat.com>
openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/AbstractDataTreeListener.java [deleted file]
openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/DelegatingDataTreeListener.java [new file with mode: 0644]
openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/INetvirtSfcDataProcessor.java
openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/NetvirtSfcAclDataProcessor.java [new file with mode: 0644]
openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/NetvirtSfcAclListener.java
openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/NetvirtSfcClassifierDataProcessor.java [new file with mode: 0644]
openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/NetvirtSfcClassifierListener.java
openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/NetvirtSfcProvider.java
openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/RspDataProcessor.java [new file with mode: 0644]
openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/RspListener.java

diff --git a/openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/AbstractDataTreeListener.java b/openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/AbstractDataTreeListener.java
deleted file mode 100644 (file)
index 11848db..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2013, 2015 Dell, 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.ovsdb.openstack.netvirt.sfc;
-
-import java.util.Collection;
-
-import com.google.common.base.Preconditions;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * AbstractChangeListner implemented basic {@link AsyncDataChangeEvent} processing for
- * netvirt-sfc data change listener.
- */
-public abstract class AbstractDataTreeListener<T extends DataObject> implements INetvirtSfcDataProcessor<T> {
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractDataTreeListener.class);
-    protected INetvirtSfcOF13Provider provider;
-    protected final Class<T> clazz;
-    private final ExecutorService executorService = Executors.newFixedThreadPool(1);
-
-    public AbstractDataTreeListener(INetvirtSfcOF13Provider provider, Class<T> clazz) {
-        this.provider = Preconditions.checkNotNull(provider, "provider can not be null!");
-        this.clazz = Preconditions.checkNotNull(clazz, "Class can not be null!");
-    }
-
-    private void processChanges(Collection<DataTreeModification<T>> changes) {
-        LOG.info("onDataTreeChanged: Received Data Tree Changed ...", changes);
-        for (DataTreeModification<T> change : changes) {
-            final InstanceIdentifier<T> key = change.getRootPath().getRootIdentifier();
-            final DataObjectModification<T> mod = change.getRootNode();
-            LOG.info("onDataTreeChanged: Received Data Tree Changed Update of Type={} for Key={}",
-                    mod.getModificationType(), key);
-            switch (mod.getModificationType()) {
-                case DELETE:
-                    remove(key, mod.getDataBefore());
-                    break;
-                case SUBTREE_MODIFIED:
-                    update(key, mod.getDataBefore(), mod.getDataAfter());
-                    break;
-                case WRITE:
-                    if (mod.getDataBefore() == null) {
-                        add(key, mod.getDataAfter());
-                    } else {
-                        update(key, mod.getDataBefore(), mod.getDataAfter());
-                    }
-                    break;
-                default:
-                    throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
-            }
-        }
-    }
-
-    @Override
-    public void onDataTreeChanged(final Collection<DataTreeModification<T>> changes) {
-        Preconditions.checkNotNull(changes, "Changes may not be null!");
-        executorService.submit(new Runnable() {
-            @Override
-            public void run() {
-                processChanges(changes);
-            }
-        });
-    }
-}
diff --git a/openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/DelegatingDataTreeListener.java b/openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/DelegatingDataTreeListener.java
new file mode 100644 (file)
index 0000000..b3f0f18
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2013, 2016 Dell, 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.ovsdb.openstack.netvirt.sfc;
+
+import java.util.Collection;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.annotation.Nonnull;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Data-tree listener which delegates data processing to a {@link INetvirtSfcDataProcessor}.
+ */
+public class DelegatingDataTreeListener<T extends DataObject> implements AutoCloseable, DataTreeChangeListener<T> {
+    private static final Logger LOG = LoggerFactory.getLogger(DelegatingDataTreeListener.class);
+    protected INetvirtSfcOF13Provider provider;
+    private final ExecutorService executorService = Executors.newFixedThreadPool(1);
+    private final INetvirtSfcDataProcessor<T> dataProcessor;
+    private ListenerRegistration<DelegatingDataTreeListener<T>> listenerRegistration;
+
+    public DelegatingDataTreeListener(INetvirtSfcOF13Provider provider, INetvirtSfcDataProcessor<T> dataProcessor,
+                                      DataBroker db, DataTreeIdentifier<T> treeId) {
+        this.provider = Preconditions.checkNotNull(provider, "provider can not be null!");
+        this.dataProcessor = Preconditions.checkNotNull(dataProcessor, "Data processor can not be null!");
+        registerListener(Preconditions.checkNotNull(db, "Data broker can not be null!"),
+                Preconditions.checkNotNull(treeId, "Tree identifier can not be null!"));
+    }
+
+    private void registerListener(final DataBroker db, DataTreeIdentifier<T> treeId) {
+        try {
+            LOG.info("Registering Data Change Listener for {}", getClass().getSimpleName());
+            listenerRegistration = db.registerDataTreeChangeListener(treeId, this);
+        } catch (final Exception e) {
+            LOG.warn("{} DataChange listener registration fail!", getClass().getSimpleName(), e);
+            throw new IllegalStateException("DataTreeListener startup fail! System needs restart.", e);
+        }
+    }
+
+    private void processChanges(Collection<DataTreeModification<T>> changes) {
+        LOG.info("onDataTreeChanged: Received Data Tree Changed ...", changes);
+        for (DataTreeModification<T> change : changes) {
+            final InstanceIdentifier<T> key = change.getRootPath().getRootIdentifier();
+            final DataObjectModification<T> mod = change.getRootNode();
+            LOG.info("onDataTreeChanged: Received Data Tree Changed Update of Type={} for Key={}",
+                    mod.getModificationType(), key);
+            switch (mod.getModificationType()) {
+                case DELETE:
+                    dataProcessor.remove(key, mod.getDataBefore());
+                    break;
+                case SUBTREE_MODIFIED:
+                    dataProcessor.update(key, mod.getDataBefore(), mod.getDataAfter());
+                    break;
+                case WRITE:
+                    if (mod.getDataBefore() == null) {
+                        dataProcessor.add(key, mod.getDataAfter());
+                    } else {
+                        dataProcessor.update(key, mod.getDataBefore(), mod.getDataAfter());
+                    }
+                    break;
+                default:
+                    throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
+            }
+        }
+    }
+
+    @Override
+    public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<T>> changes) {
+        Preconditions.checkNotNull(changes, "Changes may not be null!");
+        executorService.submit(new Runnable() {
+            @Override
+            public void run() {
+                processChanges(changes);
+            }
+        });
+    }
+
+    @Override
+    public void close() {
+        if (listenerRegistration != null) {
+            listenerRegistration.close();
+            listenerRegistration = null;
+        }
+    }
+}
index 5225b0309286ed7d7bf56ccf3bc0401651689776..04ef7ca6a38d8e5d59851d76d3ea92670eca4f18 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015 Dell, Inc. and others. All rights reserved.
+ * Copyright (c) 2013, 2016 Dell, 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,
@@ -8,7 +8,6 @@
 
 package org.opendaylight.ovsdb.openstack.netvirt.sfc;
 
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
@@ -16,7 +15,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
  * netvirt-sfc-dcl processor
  * org.opendaylight.ovsdb.openstack.netvirt.sfc
  */
-public interface INetvirtSfcDataProcessor<D extends DataObject> extends AutoCloseable, DataTreeChangeListener<D> {
+public interface INetvirtSfcDataProcessor<D extends DataObject> {
 
     /**
      * Method removes DataObject which is identified by InstanceIdentifier.
diff --git a/openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/NetvirtSfcAclDataProcessor.java b/openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/NetvirtSfcAclDataProcessor.java
new file mode 100644 (file)
index 0000000..2c66c25
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright © 2015, 2016 Dell, 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.ovsdb.openstack.netvirt.sfc;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.Acl;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Data processor for AccessList.
+ */
+public class NetvirtSfcAclDataProcessor implements INetvirtSfcDataProcessor<Acl> {
+    private final INetvirtSfcOF13Provider provider;
+
+    /**
+     * {@link NetvirtSfcAclDataProcessor} constructor.
+     * @param provider OpenFlow 1.3 Provider
+     */
+    public NetvirtSfcAclDataProcessor(final INetvirtSfcOF13Provider provider) {
+        this.provider = Preconditions.checkNotNull(provider, "Provider can not be null!");
+    }
+
+    @Override
+    public void remove(final InstanceIdentifier<Acl> identifier,
+                       final Acl change) {
+        Preconditions.checkNotNull(change, "Removed object can not be null!");
+        provider.removeClassifierRules(change);
+    }
+
+    @Override
+    public void update(final InstanceIdentifier<Acl> identifier,
+                       final Acl original, final Acl change) {
+        Preconditions.checkNotNull(original, "Updated original object can not be null!");
+        Preconditions.checkNotNull(original, "Updated update object can not be null!");
+        remove(identifier, original);
+        provider.addClassifierRules(change);
+    }
+
+    @Override
+    public void add(final InstanceIdentifier<Acl> identifier,
+                    final Acl change) {
+        Preconditions.checkNotNull(change, "Added object can not be null!");
+        provider.addClassifierRules(change);
+    }
+}
index 5fea53f33f8250557f16fcbc653a64faae4eea7e..e9d1862b3633a05595c8a727dbb1d8f0c8ed33ee 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2015 Dell, Inc. and others.  All rights reserved.
+ * Copyright © 2015, 2016 Dell, 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,
@@ -8,85 +8,25 @@
 
 package org.opendaylight.ovsdb.openstack.netvirt.sfc;
 
-import com.google.common.base.Preconditions;
 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.ovsdb.utils.mdsal.utils.MdsalUtils;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.AccessLists;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.Acl;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Data tree listener for AccessList.
  */
-public class NetvirtSfcAclListener extends AbstractDataTreeListener<Acl> {
-    private static final Logger LOG = LoggerFactory.getLogger(NetvirtSfcAclListener.class);
-    private ListenerRegistration<NetvirtSfcAclListener> listenerRegistration;
-
+public class NetvirtSfcAclListener extends DelegatingDataTreeListener<Acl> {
     /**
      * {@link NetvirtSfcAclListener} constructor.
      * @param provider OpenFlow 1.3 Provider
      * @param db MdSal {@link DataBroker}
      */
     public NetvirtSfcAclListener(final INetvirtSfcOF13Provider provider, final DataBroker db) {
-        super(provider, Acl.class);
-        Preconditions.checkNotNull(db, "DataBroker can not be null!");
-
-        registrationListener(db);
-    }
-
-    private void registrationListener(final DataBroker db) {
-        final DataTreeIdentifier<Acl> treeId =
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getIetfAclIid());
-        try {
-            LOG.info("Registering Data Change Listener for NetvirtSfc AccessList configuration.");
-            listenerRegistration = db.registerDataTreeChangeListener(treeId, this);
-        } catch (final Exception e) {
-            LOG.warn("Netvirt AccessList DataChange listener registration fail!", e);
-            throw new IllegalStateException("NetvirtSfcAccessListListener startup fail! System needs restart.", e);
-        }
-    }
-
-    @Override
-    public void close() {
-        if (listenerRegistration != null) {
-            try {
-                listenerRegistration.close();
-            } catch (final Exception e) {
-                LOG.warn("Error while stopping IETF ACL ChangeListener", e);
-            }
-            listenerRegistration = null;
-        }
-    }
-
-    @Override
-    public void remove(final InstanceIdentifier<Acl> identifier,
-                       final Acl change) {
-        Preconditions.checkNotNull(change, "Removed object can not be null!");
-        provider.removeClassifierRules(change);
-    }
-
-    @Override
-    public void update(final InstanceIdentifier<Acl> identifier,
-                       final Acl original, final Acl change) {
-        Preconditions.checkNotNull(original, "Updated original object can not be null!");
-        Preconditions.checkNotNull(original, "Updated update object can not be null!");
-        remove(identifier, original);
-        provider.addClassifierRules(change);
-    }
-
-    @Override
-    public void add(final InstanceIdentifier<Acl> identifier,
-                    final Acl change) {
-        Preconditions.checkNotNull(change, "Added object can not be null!");
-        provider.addClassifierRules(change);
-    }
-
-    public InstanceIdentifier<Acl> getIetfAclIid() {
-        return InstanceIdentifier.create(AccessLists.class).child(Acl.class);
+        super(provider, new NetvirtSfcAclDataProcessor(provider), db,
+                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+                        InstanceIdentifier.create(AccessLists.class).child(Acl.class)));
     }
 }
diff --git a/openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/NetvirtSfcClassifierDataProcessor.java b/openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/NetvirtSfcClassifierDataProcessor.java
new file mode 100644 (file)
index 0000000..87f81c9
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright © 2015, 2016 Dell, 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.ovsdb.openstack.netvirt.sfc;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.AccessLists;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.Acl;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.AclKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers
+        .Classifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Data processor for Classifier.
+ */
+public class NetvirtSfcClassifierDataProcessor implements INetvirtSfcDataProcessor<Classifier> {
+    private static final Logger LOG = LoggerFactory.getLogger(NetvirtSfcClassifierDataProcessor.class);
+    private final MdsalUtils mdsalUtils;
+    private final INetvirtSfcOF13Provider provider;
+
+    /**
+     * {@link NetvirtSfcClassifierDataProcessor} constructor.
+     * @param provider OpenFlow 1.3 Provider
+     * @param db MdSal {@link DataBroker}
+     */
+    public NetvirtSfcClassifierDataProcessor(final INetvirtSfcOF13Provider provider, final DataBroker db) {
+        this.provider = Preconditions.checkNotNull(provider, "Provider can not be null!");
+        Preconditions.checkNotNull(db, "DataBroker can not be null!");
+        mdsalUtils = new MdsalUtils(db);
+    }
+
+    @Override
+    public void remove(final InstanceIdentifier<Classifier> identifier,
+                       final Classifier change) {
+        Preconditions.checkNotNull(change, "Added object can not be null!");
+        String aclName = change.getAcl();
+        // Read the ACL information from data store and make sure it exists.
+        Acl acl = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, getIetfAclIid(aclName));
+        if (acl == null) {
+            LOG.debug("IETF ACL with name ={} is not yet configured. skip this operation", aclName);
+            return;
+        }
+
+        provider.removeClassifierRules(acl);
+    }
+
+    @Override
+    public void update(final InstanceIdentifier<Classifier> identifier,
+                       final Classifier original, final Classifier change) {
+        //TODO
+
+    }
+
+    @Override
+    public void add(final InstanceIdentifier<Classifier> identifier,
+                    final Classifier change) {
+        Preconditions.checkNotNull(change, "Added object can not be null!");
+        String aclName = change.getAcl();
+        // Read the ACL information from data store and make sure it exists.
+        Acl acl = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, getIetfAclIid(aclName));
+        if (acl == null) {
+            LOG.debug("IETF ACL with name ={} is not yet configured. skip this operation", aclName);
+            return;
+        }
+
+        provider.addClassifierRules(acl);
+    }
+
+    private InstanceIdentifier<Acl> getIetfAclIid(String aclName) {
+        return InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey(aclName));
+    }
+}
index 1ddfb948e8e75c8f8426cad86043f0207c1a7041..658338e19d685c9f164529a7fa5b3b94eee945f1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2015 Dell, Inc. and others.  All rights reserved.
+ * Copyright © 2015, 2016 Dell, 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,
 
 package org.opendaylight.ovsdb.openstack.netvirt.sfc;
 
-import com.google.common.base.Preconditions;
 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.ovsdb.utils.mdsal.utils.MdsalUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.AccessLists;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.Acl;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.AclKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.Classifiers;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.Classifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.sfc.classifier.rev150105.classifiers.classifier.sffs.Sff;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Data tree listener for Classifier.
  *
  * @author Arun Yerra
  */
-public class NetvirtSfcClassifierListener extends AbstractDataTreeListener<Classifier> {
-    private static final Logger LOG = LoggerFactory.getLogger(NetvirtSfcClassifierListener.class);
-    private MdsalUtils mdsalUtils;
-    private ListenerRegistration<NetvirtSfcClassifierListener> listenerRegistration;
-
+public class NetvirtSfcClassifierListener extends DelegatingDataTreeListener<Classifier> {
     /**
      * {@link NetvirtSfcClassifierListener} constructor.
      * @param provider OpenFlow 1.3 Provider
      * @param db MdSal {@link DataBroker}
      */
     public NetvirtSfcClassifierListener(final INetvirtSfcOF13Provider provider, final DataBroker db) {
-        super(provider, Classifier.class);
-        Preconditions.checkNotNull(db, "DataBroker can not be null!");
-        mdsalUtils = new MdsalUtils(db);
-        registrationListener(db);
-    }
-
-    private void registrationListener(final DataBroker db) {
-        final DataTreeIdentifier<Classifier> treeId =
-                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getClassifierIid());
-        try {
-            LOG.info("Registering Data Change Listener for NetvirtSfc Classifier configuration.");
-            listenerRegistration = db.registerDataTreeChangeListener(treeId, this);
-        } catch (final Exception e) {
-            LOG.warn("Netvirt Classifier DataChange listener registration fail!", e);
-            throw new IllegalStateException("NetvirtSfcClassifierListener startup fail! System needs restart.", e);
-        }
-    }
-
-    @Override
-    public void close() {
-        if (listenerRegistration != null) {
-            try {
-                listenerRegistration.close();
-            } catch (final Exception e) {
-                LOG.warn("Error to stop Netvirt Classifier DataChange listener", e);
-            }
-            listenerRegistration = null;
-        }
-    }
-
-    @Override
-    public void remove(final InstanceIdentifier<Classifier> identifier,
-                       final Classifier change) {
-        Preconditions.checkNotNull(change, "Added object can not be null!");
-        String aclName = change.getAcl();
-        // Read the ACL information from data store and make sure it exists.
-        Acl acl = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, getIetfAclIid(aclName));
-        if (acl == null) {
-            LOG.debug("IETF ACL with name ={} is not yet configured. skip this operation", aclName);
-            return;
-        }
-
-        provider.removeClassifierRules(acl);
-    }
-
-    @Override
-    public void update(final InstanceIdentifier<Classifier> identifier,
-                       final Classifier original, final Classifier change) {
-        //TODO
-
-    }
-
-    @Override
-    public void add(final InstanceIdentifier<Classifier> identifier,
-                    final Classifier change) {
-        Preconditions.checkNotNull(change, "Added object can not be null!");
-        String aclName = change.getAcl();
-        // Read the ACL information from data store and make sure it exists.
-        Acl acl = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, getIetfAclIid(aclName));
-        if (acl == null) {
-            LOG.debug("IETF ACL with name ={} is not yet configured. skip this operation", aclName);
-            return;
-        }
-
-        provider.addClassifierRules(acl);
-    }
-
-    public InstanceIdentifier<Classifier> getClassifierIid() {
-        return InstanceIdentifier.create(Classifiers.class).child(Classifier.class);
-    }
-
-    private InstanceIdentifier<Acl> getIetfAclIid(String aclName) {
-        return InstanceIdentifier.create(AccessLists.class).child(Acl.class, new AclKey(aclName));
+        super(provider, new NetvirtSfcClassifierDataProcessor(provider, db), db,
+                new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION,
+                        InstanceIdentifier.create(Classifiers.class).child(Classifier.class)));
     }
 }
index bc20f4bbc00c31a38d97e1eb940996f316ce4673..f92dd61688e13345ab019587d496b516fc4d26c5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2015 Dell, Inc. and others.  All rights reserved.
+ * Copyright © 2015, 2016 Dell, 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,
@@ -28,9 +28,9 @@ import org.slf4j.LoggerFactory;
 
 public class NetvirtSfcProvider implements BindingAwareProvider, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(NetvirtSfcProvider.class);
-    private NetvirtSfcAclListener aclListener;
-    private NetvirtSfcClassifierListener classifierListener;
-    private RspListener rspListener;
+    private AutoCloseable aclListener;
+    private AutoCloseable classifierListener;
+    private AutoCloseable rspListener;
     private Boolean addSfFlows;
 
     public void setOf13Provider(String of13Provider) {
diff --git a/openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/RspDataProcessor.java b/openstack/net-virt-sfc/impl/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/sfc/RspDataProcessor.java
new file mode 100644 (file)
index 0000000..e88427e
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2015, 2016 Red Hat, 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.ovsdb.openstack.netvirt.sfc;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Data processor for {@link RenderedServicePath}
+ */
+public class RspDataProcessor implements INetvirtSfcDataProcessor<RenderedServicePath> {
+    private final INetvirtSfcOF13Provider provider;
+
+    public RspDataProcessor(final INetvirtSfcOF13Provider provider) {
+        this.provider = Preconditions.checkNotNull(provider, "Provider can not be null!");
+    }
+
+    @Override
+    public void remove(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath change) {
+        Preconditions.checkNotNull(change, "Removed object can not be null!");
+        provider.removeRsp(change);
+    }
+
+    @Override
+    public void update(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath original,
+                       RenderedServicePath change) {
+        Preconditions.checkNotNull(original, "Updated original object can not be null!");
+        Preconditions.checkNotNull(original, "Updated update object can not be null!");
+        remove(identifier, original);
+        provider.addRsp(change);
+    }
+
+    @Override
+    public void add(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath change) {
+        Preconditions.checkNotNull(change, "Created object can not be null!");
+        provider.addRsp(change);
+    }
+}
index 996c1662bf640faa153dd0942789f71c63890d96..c808fb563939e42fd0bfd3ac180002592fc86dea 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2015 Red Hat, Inc. and others.  All rights reserved.
+ * Copyright © 2015, 2016 Red Hat, 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,
@@ -7,70 +7,19 @@
  */
 package org.opendaylight.ovsdb.openstack.netvirt.sfc;
 
-import com.google.common.base.Preconditions;
 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.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.RenderedServicePaths;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Data tree listener for {@link RenderedServicePath}
  */
-public class RspListener extends AbstractDataTreeListener<RenderedServicePath> {
-    private static final Logger LOG = LoggerFactory.getLogger(RspListener.class);
-    private ListenerRegistration<RspListener> listenerRegistration;
-
+public class RspListener extends DelegatingDataTreeListener<RenderedServicePath> {
     public RspListener(final INetvirtSfcOF13Provider provider, final DataBroker db) {
-        super(provider, RenderedServicePath.class);
-        Preconditions.checkNotNull(db, "DataBroker can not be null!");
-
-        registrationListener(db);
-    }
-
-    public InstanceIdentifier<RenderedServicePath> getRspIid() {
-        return InstanceIdentifier.create(RenderedServicePaths.class).child(RenderedServicePath.class);
-    }
-
-    private void registrationListener(final DataBroker db) {
-        final DataTreeIdentifier<RenderedServicePath> treeId =
-                new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, getRspIid());
-        try {
-            LOG.info("Registering Data Change Listener for NetvirtSfc RenderedServicePath configuration.");
-            listenerRegistration = db.registerDataTreeChangeListener(treeId, this);
-        } catch (final Exception e) {
-            LOG.warn("Netvirt RenderedServicePath DataChange listener registration failed!", e);
-            throw new IllegalStateException("RspListener startup failed! System needs restart.", e);
-        }
-    }
-
-    @Override
-    public void remove(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath change) {
-        Preconditions.checkNotNull(change, "Removed object can not be null!");
-        provider.removeRsp(change);
-    }
-
-    @Override
-    public void update(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath original,
-                       RenderedServicePath change) {
-        Preconditions.checkNotNull(original, "Updated original object can not be null!");
-        Preconditions.checkNotNull(original, "Updated update object can not be null!");
-        remove(identifier, original);
-        provider.addRsp(change);
-    }
-
-    @Override
-    public void add(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath change) {
-        Preconditions.checkNotNull(change, "Created object can not be null!");
-        provider.addRsp(change);
-    }
-
-    @Override
-    public void close() throws Exception {
-
+        super(provider, new RspDataProcessor(provider), db, new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.create(RenderedServicePaths.class).child(RenderedServicePath.class)));
     }
 }