2 * Copyright (c) 2016 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.applications.frsync.dao;
11 import com.google.common.base.Optional;
12 import java.util.concurrent.TimeUnit;
13 import java.util.concurrent.TimeoutException;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Implementation of data access object for ODL {@link FlowCapableNode}.
31 public class FlowCapableNodeOdlDao implements FlowCapableNodeDao {
33 private static final Logger LOG = LoggerFactory.getLogger(FlowCapableNodeOdlDao.class);
35 private static final InstanceIdentifier<Nodes> NODES_IID = InstanceIdentifier.create(Nodes.class);
36 private final DataBroker dataBroker;
37 private final LogicalDatastoreType logicalDatastoreType;
39 public FlowCapableNodeOdlDao(DataBroker dataBroker, LogicalDatastoreType logicalDatastoreType) {
40 this.dataBroker = dataBroker;
41 this.logicalDatastoreType = logicalDatastoreType;
44 public Optional<FlowCapableNode> loadByNodeId(@Nonnull NodeId nodeId) {
45 try (final ReadOnlyTransaction roTx = dataBroker.newReadOnlyTransaction()) {
46 final InstanceIdentifier<FlowCapableNode> path =
47 NODES_IID.child(Node.class, new NodeKey(nodeId)).augmentation(FlowCapableNode.class);
48 return roTx.read(logicalDatastoreType, path).checkedGet(5000, TimeUnit.MILLISECONDS);
49 } catch (ReadFailedException | TimeoutException e) {
50 LOG.error("error reading {} -> {}", nodeId.getValue(), e);
53 return Optional.absent();