Remove sfc-translator MdsalUtils::merge()
[netvirt.git] / vpnservice / sfc / translator / src / main / java / org / opendaylight / netvirt / sfc / translator / MdsalUtils.java
1 /*
2  * Copyright (c) 2016, 2017 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
9 package org.opendaylight.netvirt.sfc.translator;
10
11 import com.google.common.util.concurrent.CheckedFuture;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class MdsalUtils {
21     private static final Logger LOG = LoggerFactory.getLogger(MdsalUtils.class);
22     private DataBroker databroker = null;
23
24     /**
25      * Class constructor setting the data broker.
26      *
27      * @param dataBroker the {@link DataBroker}
28      */
29     public MdsalUtils(DataBroker dataBroker) {
30         this.databroker = dataBroker;
31     }
32
33     /**
34      * Executes put as a blocking transaction.
35      *
36      * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified
37      * @param path {@link InstanceIdentifier} for path to read
38      * @param <D> the data object type
39      * @return the result of the request
40      */
41     public <D extends org.opendaylight.yangtools.yang.binding.DataObject> boolean put(
42             final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data)  {
43         boolean result = false;
44         final WriteTransaction transaction = databroker.newWriteOnlyTransaction();
45         transaction.put(logicalDatastoreType, path, data, WriteTransaction.CREATE_MISSING_PARENTS);
46         CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
47         try {
48             future.checkedGet();
49             result = true;
50         } catch (TransactionCommitFailedException e) {
51             LOG.warn("Failed to put {} ", path, e);
52         }
53         return result;
54     }
55 }