2 * Copyright (c) 2017 Cisco Systems, Inc. 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.lispflowmapping.neutron.intenthandler.util;
10 import static java.util.Objects.requireNonNull;
12 import java.util.Optional;
13 import java.util.concurrent.ExecutionException;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.mdsal.binding.api.ReadTransaction;
16 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Created by Shakib Ahmed on 1/12/17.
25 public final class VppNetconfTrasaction {
26 private static final Logger LOG = LoggerFactory.getLogger(VppNetconfTrasaction.class);
28 public static final byte RETRY_COUNT = 5;
30 private VppNetconfTrasaction() {
33 public static synchronized <T extends DataObject> Optional<T> read(DataBroker dataBroker,
34 LogicalDatastoreType datastoreType,
35 InstanceIdentifier<T> instanceIdentifier) {
36 LOG.trace("Started Netconf transaction on VPP Node");
37 requireNonNull(dataBroker);
39 Optional<T> returnData;
41 int retryCounter = RETRY_COUNT;
43 while (retryCounter > 0) {
44 ReadTransaction readTransaction = dataBroker.newReadOnlyTransaction();
46 returnData = readTransaction(instanceIdentifier, datastoreType, readTransaction);
47 LOG.trace("Netconf READ transaction SUCCESSFUL. Data present: {}", returnData.isPresent());
48 readTransaction.close();
50 } catch (IllegalStateException e) {
52 LOG.warn("Assuming that netconf read-transaction failed, retrying. Retry Count: " + retryCounter,
54 readTransaction.close();
55 } catch (InterruptedException | ExecutionException e) {
56 LOG.warn("Exception while reading data. Retry Aborted.", e.getMessage());
57 readTransaction.close();
62 return Optional.empty();
65 private static <T extends DataObject> Optional<T> readTransaction(InstanceIdentifier<T> instanceIdentifier,
66 LogicalDatastoreType datastoreType,
67 ReadTransaction readTransaction)
68 throws IllegalStateException, InterruptedException, ExecutionException {
69 return readTransaction.read(datastoreType, instanceIdentifier).get();