2 * Copyright (c) 2015 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
8 package org.opendaylight.openflowplugin.test;
10 import java.util.Optional;
11 import java.util.concurrent.ExecutionException;
12 import org.opendaylight.mdsal.binding.api.ReadTransaction;
13 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Created by Martin Bobak mbobak@cisco.com on 8/20/14.
22 public final class TestProviderTransactionUtil {
24 private static final Logger LOG = LoggerFactory.getLogger(TestProviderTransactionUtil.class);
26 private TestProviderTransactionUtil() {
27 throw new AssertionError("TestProviderTransactionUtil was not meant to be instantiated.");
30 public static <T extends DataObject> T getDataObject(ReadTransaction readOnlyTransaction,
31 InstanceIdentifier<T> identifier) {
32 Optional<T> optionalData = null;
34 optionalData = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, identifier).get();
35 if (optionalData.isPresent()) {
36 return optionalData.get();
38 } catch (ExecutionException | InterruptedException e) {
39 LOG.error("Read transaction for identifier {} failed.", identifier, e);