2 * Copyright © 2018 Orange 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.transportpce.renderer.utils;
11 import java.util.Optional;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.Future;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.transportpce.common.Timeouts;
16 import org.opendaylight.transportpce.common.device.DeviceTransaction;
17 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 public final class TransactionUtils {
23 private TransactionUtils() {
27 public static boolean writeTransaction(DeviceTransactionManager deviceTransactionManager,
29 LogicalDatastoreType logicalDatastoreType,
30 InstanceIdentifier instanceIdentifier,
32 throws ExecutionException, InterruptedException {
33 Future<Optional<DeviceTransaction>> deviceTxFuture =
34 deviceTransactionManager.getDeviceTransaction(nodeId);
35 if (!deviceTxFuture.get().isPresent()) {
38 DeviceTransaction deviceTx = deviceTxFuture.get().get();
39 deviceTx.put(logicalDatastoreType, instanceIdentifier, object, true);
40 deviceTx.commit(Timeouts.DEVICE_WRITE_TIMEOUT, Timeouts.DEVICE_WRITE_TIMEOUT_UNIT).get();
44 public static DataObject readTransaction(DeviceTransactionManager deviceTransactionManager,
46 LogicalDatastoreType logicalDatastoreType,
47 InstanceIdentifier<? extends DataObject> instanceIdentifier)
48 throws ExecutionException, InterruptedException {
49 Future<Optional<DeviceTransaction>> deviceTxFuture =
50 deviceTransactionManager.getDeviceTransaction(nodeId);
51 if (!deviceTxFuture.get().isPresent()) {
54 DeviceTransaction deviceTx = deviceTxFuture.get().get();
55 Optional<? extends DataObject> readOpt
56 = deviceTx.read(logicalDatastoreType, instanceIdentifier).get();
57 if (!readOpt.isPresent()) {