2 * Copyright (c) 2014 Cisco 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.groupbasedpolicy.renderer.ofoverlay.sfcutils;
11 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
12 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
15 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 import com.google.common.base.Optional;
22 import com.google.common.util.concurrent.CheckedFuture;
25 * @author Martin Sunal
27 public class SfcDataStoreHelper {
29 private static final Logger LOG = LoggerFactory.getLogger(SfcDataStoreHelper.class);
32 * Reads data from datastore as synchrone call.
33 * @return {@link Optional#isPresent()} is {@code true} if reading was successful and data exists in datastore; {@link Optional#isPresent()} is {@code false} otherwise
35 public static <U extends DataObject> U readFromDs(LogicalDatastoreType store,InstanceIdentifier<U> iid, ReadTransaction rTx) {
37 Optional<U> optionalDataObject;
38 CheckedFuture<Optional<U>, ReadFailedException> submitFuture = rTx.read(store, iid);
40 optionalDataObject = submitFuture.checkedGet();
41 if (optionalDataObject != null && optionalDataObject.isPresent()) {
42 ret = optionalDataObject.get();
44 LOG.debug("{}: Failed to read", Thread.currentThread().getStackTrace()[1]);
46 } catch (ReadFailedException e) {
47 LOG.warn("failed to ....", e);
53 * Calls {@link WriteTransaction#submit()} on write transaction.
54 * @param wTx write transaction
55 * @return {@code true} if transaction commit was successful; {@code false} otherwise
57 public static boolean submitToDs(WriteTransaction wTx) {
58 CheckedFuture<Void, TransactionCommitFailedException> submitFuture = wTx.submit();
60 submitFuture.checkedGet();
62 } catch (TransactionCommitFailedException e) {
63 LOG.warn("Transaction commit failed to DS.", e);