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", "rawtypes" })
28 // deviceTx.put needs the "true" boolean parameter at the end in order to not compromise the Junit test suite
29 // FIXME check if the InstanceIdentifier raw type can be avoided
30 // Raw types use are discouraged since they lack type safety.
31 // Resulting Problems are observed at run time and not at compile time
32 public static boolean writeTransaction(DeviceTransactionManager deviceTransactionManager,
34 LogicalDatastoreType logicalDatastoreType,
35 InstanceIdentifier instanceIdentifier,
37 throws ExecutionException, InterruptedException {
38 Future<Optional<DeviceTransaction>> deviceTxFuture =
39 deviceTransactionManager.getDeviceTransaction(nodeId);
40 if (!deviceTxFuture.get().isPresent()) {
43 DeviceTransaction deviceTx = deviceTxFuture.get().get();
44 deviceTx.merge(logicalDatastoreType, instanceIdentifier, object);
45 deviceTx.commit(Timeouts.DEVICE_WRITE_TIMEOUT, Timeouts.DEVICE_WRITE_TIMEOUT_UNIT).get();
49 public static DataObject readTransaction(DeviceTransactionManager deviceTransactionManager,
51 LogicalDatastoreType logicalDatastoreType,
52 InstanceIdentifier<? extends DataObject> instanceIdentifier)
53 throws ExecutionException, InterruptedException {
54 Future<Optional<DeviceTransaction>> deviceTxFuture =
55 deviceTransactionManager.getDeviceTransaction(nodeId);
56 if (!deviceTxFuture.get().isPresent()) {
59 DeviceTransaction deviceTx = deviceTxFuture.get().get();
60 Optional<? extends DataObject> readOpt
61 = deviceTx.read(logicalDatastoreType, instanceIdentifier).get();
62 if (!readOpt.isPresent()) {