BUG 7264 Fix missing flows for Remote SG rule
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / netvirt / openstack / netvirt / ClusterAwareMdsalUtils.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. 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.netvirt.openstack.netvirt;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.netvirt.utils.mdsal.utils.MdsalUtils;
13 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16 /**
17  * Class is a wrapper for MdsalUtils.java class. It wrap all the methods
18  * from MdsalUtils and call it only when *this* instance is net-virt master
19  * instances.
20  *
21  * Created by vishnoianil on 1/11/16.
22  */
23
24 public class ClusterAwareMdsalUtils {
25
26     private static final Logger LOG = LoggerFactory.getLogger(ClusterAwareMdsalUtils.class);
27     private final MdsalUtils mdsalUtils;
28
29     /**
30      * Class constructor setting the MdsalUtils instance.
31      *
32      * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
33      */
34     public ClusterAwareMdsalUtils(DataBroker dataBroker) {
35         mdsalUtils = new MdsalUtils(dataBroker);
36     }
37
38     /**
39      * Wrapper method to execute delete as a blocking transaction.
40      *
41      * @param store {@link LogicalDatastoreType} which should be modified
42      * @param path {@link InstanceIdentifier} to read from
43      * @param <D> the data object type
44      * @return the result of the request
45      */
46     public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean delete(
47             final LogicalDatastoreType store, final InstanceIdentifier<D> path)  {
48         if (NetvirtProvider.isMasterProviderInstance()) {
49             return mdsalUtils.delete(store,path);
50         }
51         return true;
52     }
53
54     /**
55      * Wrapper method to execute merge as a blocking transaction.
56      *
57      * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
58      * @param path {@link InstanceIdentifier} for path to read
59      * @param <D> the data object type
60      * @return the result of the request
61      */
62     public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean merge(
63             final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data) {
64         if (NetvirtProvider.isMasterProviderInstance()) {
65             return mdsalUtils.merge(logicalDatastoreType,path, data);
66         }
67         return true;
68     }
69
70     /**
71      * Wrapper method to execute put as a blocking transaction.
72      *
73      * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
74      * @param path {@link InstanceIdentifier} for path to read
75      * @param <D> the data object type
76      * @return the result of the request
77      */
78     public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean put(
79             final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data) {
80         if (NetvirtProvider.isMasterProviderInstance()) {
81             return mdsalUtils.put(logicalDatastoreType,path, data);
82         }
83         return true;
84     }
85
86     /**
87      * Wrapper method to executes read as a blocking transaction.
88      * Read is open for all instances to execute their normal
89      * control flow. Because with current implementation all the
90      * net-virt instances execute in similar way, because they want
91      * to build their local caches so that all the instances has same
92      * state of internal cache.
93      *
94      * @param store {@link LogicalDatastoreType} to read
95      * @param path {@link InstanceIdentifier} for path to read
96      * @param <D> the data object type
97      * @return the result as the data object requested
98      */
99     public <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(
100             final LogicalDatastoreType store, final InstanceIdentifier<D> path)  {
101         return mdsalUtils.read(store,path);
102     }
103 }