2 * Copyright (c) 2016, 2017 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
9 package org.opendaylight.netvirt.sfc.translator;
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;
20 public class MdsalUtils {
21 private static final Logger LOG = LoggerFactory.getLogger(MdsalUtils.class);
22 private DataBroker databroker = null;
25 * Class constructor setting the data broker.
27 * @param dataBroker the {@link DataBroker}
29 public MdsalUtils(DataBroker dataBroker) {
30 this.databroker = dataBroker;
34 * Executes put as a blocking transaction.
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
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();
50 } catch (TransactionCommitFailedException e) {
51 LOG.warn("Failed to put {} ", path, e);