/* * Copyright (c) 2016, 2017 Brocade Communications Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.netvirt.sfc.translator; import com.google.common.util.concurrent.CheckedFuture; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MdsalUtils { private static final Logger LOG = LoggerFactory.getLogger(MdsalUtils.class); private DataBroker databroker = null; /** * Class constructor setting the data broker. * * @param dataBroker the {@link DataBroker} */ public MdsalUtils(DataBroker dataBroker) { this.databroker = dataBroker; } /** * Executes put as a blocking transaction. * * @param logicalDatastoreType {@link LogicalDatastoreType} which should be modified * @param path {@link InstanceIdentifier} for path to read * @param the data object type * @return the result of the request */ public boolean put( final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier path, D data) { boolean result = false; final WriteTransaction transaction = databroker.newWriteOnlyTransaction(); transaction.put(logicalDatastoreType, path, data, WriteTransaction.CREATE_MISSING_PARENTS); CheckedFuture future = transaction.submit(); try { future.checkedGet(); result = true; } catch (TransactionCommitFailedException e) { LOG.warn("Failed to put {} ", path, e); } return result; } }