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 @SuppressWarnings({ "unchecked", "deprecation" })
28 // deviceTx.put needs the "true" boolean parameter at the end in order to not compromise the Junit test suite
29 public static boolean writeTransaction(DeviceTransactionManager deviceTransactionManager,
31 LogicalDatastoreType logicalDatastoreType,
32 InstanceIdentifier instanceIdentifier,
34 throws ExecutionException, InterruptedException {
35 Future<Optional<DeviceTransaction>> deviceTxFuture =
36 deviceTransactionManager.getDeviceTransaction(nodeId);
37 if (!deviceTxFuture.get().isPresent()) {
40 DeviceTransaction deviceTx = deviceTxFuture.get().get();
41 deviceTx.merge(logicalDatastoreType, instanceIdentifier, object);
42 deviceTx.commit(Timeouts.DEVICE_WRITE_TIMEOUT, Timeouts.DEVICE_WRITE_TIMEOUT_UNIT).get();
46 public static DataObject readTransaction(DeviceTransactionManager deviceTransactionManager,
48 LogicalDatastoreType logicalDatastoreType,
49 InstanceIdentifier<? extends DataObject> instanceIdentifier)
50 throws ExecutionException, InterruptedException {
51 Future<Optional<DeviceTransaction>> deviceTxFuture =
52 deviceTransactionManager.getDeviceTransaction(nodeId);
53 if (!deviceTxFuture.get().isPresent()) {
56 DeviceTransaction deviceTx = deviceTxFuture.get().get();
57 Optional<? extends DataObject> readOpt
58 = deviceTx.read(logicalDatastoreType, instanceIdentifier).get();
59 if (!readOpt.isPresent()) {