Add binding entity ownership interfaces 62/27662/13
authorTom Pantelis <tpanteli@brocade.com>
Mon, 28 Sep 2015 11:27:41 +0000 (07:27 -0400)
committerRobert Varga <robert.varga@pantheon.sk>
Tue, 24 Nov 2015 22:05:13 +0000 (23:05 +0100)
Change-Id: Ie79ae7a8a7df24b9f8869720dbe7ae6ae7555876
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
binding/mdsal-binding-api/pom.xml
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/Entity.java [new file with mode: 0644]
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipCandidateRegistration.java [new file with mode: 0644]
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipChange.java [new file with mode: 0644]
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipListener.java [new file with mode: 0644]
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipListenerRegistration.java [new file with mode: 0644]
binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipService.java [new file with mode: 0644]
binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/clustering/EntityTest.java [new file with mode: 0644]

index a6f3025fc821a3c12b07b42390043fd16571dae6..6dc2e329c5984314cf634b9863093956fa38291e 100644 (file)
       <artifactId>org.osgi.core</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <scm>
     <connection>scm:git:http://git.opendaylight.org/gerrit/controller.git</connection>
diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/Entity.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/Entity.java
new file mode 100644 (file)
index 0000000..b6bb79d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015 Brocade Communications 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.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntity;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding version of {@link GenericEntity}.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public class Entity extends GenericEntity<InstanceIdentifier<?>> {
+    private static final long serialVersionUID = 1L;
+
+    /** Constructs an instance.
+     *
+     * @param type the entity type
+     * @param id the entity id.
+     */
+    public Entity(@Nonnull final String type, @Nonnull final InstanceIdentifier<?> id) {
+        super(type, id);
+    }
+
+    /**
+     * Construct an Entity with an with a name. The general-entity schema is used to construct the
+     * InstanceIdentifier.
+     *
+     * @param type the type of the entity
+     * @param entityName the name of the entity used to construct a general-entity InstanceIdentifier
+     */
+    // FIXME: needs to be enabled in a follow-up
+//    public Entity(@Nonnull String type, @Nonnull String entityName) {
+//        super(type, InstanceIdentifier.builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.
+//                ns.yang.controller.md.sal.core.general.entity.rev150820.Entity.class,
+//                    new EntityKey(Preconditions.checkNotNull(entityName, "entityName should not be null"))).build());
+//    }
+}
diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipCandidateRegistration.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipCandidateRegistration.java
new file mode 100644 (file)
index 0000000..dedd6cf
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2015 Brocade Communications 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.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntityOwnershipCandidateRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding version of {@link GenericEntityOwnershipCandidateRegistration}.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public interface EntityOwnershipCandidateRegistration extends
+        GenericEntityOwnershipCandidateRegistration<InstanceIdentifier<?>, Entity> {
+}
diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipChange.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipChange.java
new file mode 100644 (file)
index 0000000..c5edfeb
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015 Brocade Communications 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.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import javax.annotation.Nonnull;
+import org.opendaylight.mdsal.common.api.clustering.EntityOwnershipChangeState;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntityOwnershipChange;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding version of {@link GenericEntityOwnershipChange}.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public class EntityOwnershipChange extends GenericEntityOwnershipChange<InstanceIdentifier<?>, Entity> {
+
+    /**
+     * {@inheritDoc}
+     */
+    public EntityOwnershipChange(@Nonnull final Entity entity, @Nonnull final EntityOwnershipChangeState state) {
+        super(entity, state);
+    }
+}
diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipListener.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipListener.java
new file mode 100644 (file)
index 0000000..47b3b9a
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 Brocade Communications 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.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntityOwnershipListener;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding interface for GenericEntityOwnershipListener.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public interface EntityOwnershipListener extends
+        GenericEntityOwnershipListener<InstanceIdentifier<?>, EntityOwnershipChange> {
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    void ownershipChanged(EntityOwnershipChange ownershipChange);
+}
diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipListenerRegistration.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipListenerRegistration.java
new file mode 100644 (file)
index 0000000..ca681b2
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2015 Brocade Communications 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.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntityOwnershipListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding interface for GenericEntityOwnershipCandidateRegistration.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public interface EntityOwnershipListenerRegistration extends
+        GenericEntityOwnershipListenerRegistration<InstanceIdentifier<?>, EntityOwnershipListener> {
+}
diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipService.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/clustering/EntityOwnershipService.java
new file mode 100644 (file)
index 0000000..f0a8a80
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015 Brocade Communications 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.mdsal.binding.api.clustering;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Optional;
+import javax.annotation.Nonnull;
+import org.opendaylight.mdsal.common.api.clustering.CandidateAlreadyRegisteredException;
+import org.opendaylight.mdsal.common.api.clustering.EntityOwnershipState;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntityOwnershipService;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Binding version of {@link GenericEntityOwnershipService}.
+ *
+ * @author Thomas Pantelis
+ */
+@Beta
+public interface EntityOwnershipService extends
+        GenericEntityOwnershipService<InstanceIdentifier<?>, Entity, EntityOwnershipListener> {
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    EntityOwnershipCandidateRegistration registerCandidate(@Nonnull Entity entity)
+            throws CandidateAlreadyRegisteredException;
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    EntityOwnershipListenerRegistration registerListener(@Nonnull String entityType,
+            @Nonnull EntityOwnershipListener listener);
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    Optional<EntityOwnershipState> getOwnershipState(@Nonnull Entity forEntity);
+}
diff --git a/binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/clustering/EntityTest.java b/binding/mdsal-binding-api/src/test/java/org/opendaylight/mdsal/binding/api/clustering/EntityTest.java
new file mode 100644 (file)
index 0000000..96efb40
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2015 Brocade Communications 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.mdsal.binding.api.clustering;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import org.apache.commons.lang3.SerializationUtils;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Unit tests for Entity.
+ *
+ * @author Thomas Pantelis
+ */
+public class EntityTest {
+    static String ENTITY_TYPE1 = "type1";
+    static String ENTITY_TYPE2 = "type2";
+    static final InstanceIdentifier<TestDataObject1> ID1 = InstanceIdentifier.create(TestDataObject1.class);
+    static final InstanceIdentifier<TestDataObject2> ID2 = InstanceIdentifier.create(TestDataObject2.class);
+
+    @Test
+    public void testHashCode() {
+        Entity entity1 = new Entity(ENTITY_TYPE1, ID1);
+
+        assertEquals("hashCode", entity1.hashCode(), new Entity(ENTITY_TYPE1, ID1).hashCode());
+        assertNotEquals("hashCode", entity1.hashCode(), new Entity(ENTITY_TYPE2, ID2).hashCode());
+    }
+
+    static class TestDataObject1 implements DataObject {
+        @Override
+        public Class<? extends DataContainer> getImplementedInterface() {
+            return null;
+        }
+    }
+
+    @Test
+    public void testEquals() {
+        Entity entity1 = new Entity(ENTITY_TYPE1, ID1);
+
+        assertEquals("Same", true, entity1.equals(entity1));
+        assertEquals("Same", true, entity1.equals(new Entity(ENTITY_TYPE1, ID1)));
+        assertEquals("Different entity type", false, entity1.equals(new Entity(ENTITY_TYPE2, ID1)));
+        assertEquals("Different yang ID", false, entity1.equals(new Entity(ENTITY_TYPE1, ID2)));
+        assertEquals("Different Object", false, entity1.equals(new Object()));
+        assertEquals("Equals null", false, entity1.equals(null));
+    }
+
+    @Test
+    public void testSerialization() {
+        Entity entity = new Entity(ENTITY_TYPE1, ID1);
+
+        Entity clone = SerializationUtils.clone(entity);
+
+        assertEquals("getType", entity.getType(), clone.getType());
+        assertEquals("getId", entity.getIdentifier(), clone.getIdentifier());
+    }
+
+    static class TestDataObject2 implements DataObject {
+        @Override
+        public Class<? extends DataContainer> getImplementedInterface() {
+            return null;
+        }
+    }
+}