itm and mdsal porting
[vpnservice.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / vpnservice / utils / clustering / ClusteringUtils.java
diff --git a/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/utils/clustering/ClusteringUtils.java b/mdsalutil/mdsalutil-api/src/main/java/org/opendaylight/vpnservice/utils/clustering/ClusteringUtils.java
new file mode 100644 (file)
index 0000000..ec90e2c
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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.vpnservice.utils.clustering;
+
+import com.google.common.base.Optional;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
+import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+public class ClusteringUtils {
+
+    public static boolean isNodeEntityOwner(EntityOwnershipService entityOwnershipService, String entityType,
+            String nodeId) {
+        Entity entity = new Entity(entityType, nodeId);
+        Optional<EntityOwnershipState> entityState = entityOwnershipService.getOwnershipState(entity);
+        if (entityState.isPresent()) {
+            return entityState.get().isOwner();
+        }
+        return false;
+    }
+
+    public static boolean isNodeEntityOwner(EntityOwnershipService entityOwnershipService, String entityType,
+            YangInstanceIdentifier nodeId) {
+        Entity entity = new Entity(entityType, nodeId);
+        Optional<EntityOwnershipState> entityState = entityOwnershipService.getOwnershipState(entity);
+        if (entityState.isPresent()) {
+            return entityState.get().isOwner();
+        }
+        return false;
+    }
+}