2 * Copyright (c) 2016 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netvirt.openstack.netvirt;
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;
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
21 * Created by vishnoianil on 1/11/16.
24 public class ClusterAwareMdsalUtils {
26 private static final Logger LOG = LoggerFactory.getLogger(ClusterAwareMdsalUtils.class);
27 private final MdsalUtils mdsalUtils;
30 * Class constructor setting the MdsalUtils instance.
32 * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
34 public ClusterAwareMdsalUtils(DataBroker dataBroker) {
35 mdsalUtils = new MdsalUtils(dataBroker);
39 * Wrapper method to execute delete as a blocking transaction.
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
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);
55 * Wrapper method to execute merge as a blocking transaction.
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
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);
71 * Wrapper method to execute put as a blocking transaction.
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
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);
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.
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
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);