ec90e2c59fbe37125321fc3a27e2f2c0ea7f5157
[vpnservice.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / vpnservice / utils / clustering / ClusteringUtils.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.vpnservice.utils.clustering;
9
10 import com.google.common.base.Optional;
11 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
12 import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
13 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15
16 public class ClusteringUtils {
17
18     public static boolean isNodeEntityOwner(EntityOwnershipService entityOwnershipService, String entityType,
19             String nodeId) {
20         Entity entity = new Entity(entityType, nodeId);
21         Optional<EntityOwnershipState> entityState = entityOwnershipService.getOwnershipState(entity);
22         if (entityState.isPresent()) {
23             return entityState.get().isOwner();
24         }
25         return false;
26     }
27
28     public static boolean isNodeEntityOwner(EntityOwnershipService entityOwnershipService, String entityType,
29             YangInstanceIdentifier nodeId) {
30         Entity entity = new Entity(entityType, nodeId);
31         Optional<EntityOwnershipState> entityState = entityOwnershipService.getOwnershipState(entity);
32         if (entityState.isPresent()) {
33             return entityState.get().isOwner();
34         }
35         return false;
36     }
37 }