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
9 package org.opendaylight.openflowplugin.test;
11 import com.google.common.base.Optional;
12 import java.util.concurrent.ExecutionException;
13 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 * Created by Martin Bobak mbobak@cisco.com on 8/20/14.
23 public final class TestProviderTransactionUtil {
25 private static final Logger LOG = LoggerFactory.getLogger(TestProviderTransactionUtil.class);
27 private TestProviderTransactionUtil() {
28 throw new AssertionError("TestProviderTransactionUtil was not meant to be instantiated.");
31 public static <T extends DataObject> T getDataObject(ReadTransaction readOnlyTransaction,
32 InstanceIdentifier<T> identifier) {
33 Optional<T> optionalData = null;
35 optionalData = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, identifier).get();
36 if (optionalData.isPresent()) {
37 return optionalData.get();
39 } catch (ExecutionException | InterruptedException e) {
40 LOG.error("Read transaction for identifier {} failed.", identifier, e);