summaryrefslogtreecommitdiffstats
path: root/infra/data-impl/src
diff options
context:
space:
mode:
authorMichal Cmarada <mcmarada@cisco.com>2019-04-08 11:37:45 +0200
committerMichal Cmarada <mcmarada@cisco.com>2019-04-08 11:37:45 +0200
commitb16cea20258ba537db7c0755208c82ab93331ff7 (patch)
tree8a5a3c87069b9ce700c34323e75ff434e7acae97 /infra/data-impl/src
parent23979469bcf8cd312cb3ec9e9e548003110f68f4 (diff)
HONEYCOMB-443: ODL bump to Neon
- bumps ODL dependencies to neon - migrates guava optional to java.utils.optional Change-Id: Ibdaa365c7e21a341103aba88dfd67277e40d2969 Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Diffstat (limited to 'infra/data-impl/src')
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/DataBroker.java66
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegator.java38
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeManager.java25
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/Modification.java12
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModificationDiff.java2
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/NormalizedNodeUpdate.java9
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadOnlyTransaction.java28
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadWriteTransaction.java55
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadableDataTreeDelegator.java52
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ValidableTransaction.java18
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/WriteTransaction.java32
-rw-r--r--infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/DataBrokerTest.java34
-rw-r--r--infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorBaseTest.java8
-rw-r--r--infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java11
-rw-r--r--infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadOnlyTransactionTest.java12
-rw-r--r--infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadWriteTransactionTest.java18
-rw-r--r--infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadableDataTreeDelegatorTest.java44
-rw-r--r--infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/WriteTransactionTest.java15
18 files changed, 207 insertions, 272 deletions
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/DataBroker.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/DataBroker.java
index 1952f8778..8f20456ed 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/DataBroker.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/DataBroker.java
@@ -18,21 +18,22 @@ package io.fd.honeycomb.data.impl;
import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.ImmutableClassToInstanceMap;
import io.fd.honeycomb.data.DataModification;
import io.fd.honeycomb.data.ModifiableDataManager;
import io.fd.honeycomb.data.ReadableDataManager;
import java.io.Closeable;
import java.io.IOException;
-import java.util.Collections;
-import java.util.Map;
import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
+import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener;
import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
@@ -57,35 +58,32 @@ public class DataBroker implements DOMDataBroker, Closeable {
}
@Override
- public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
- LOG.trace("DataBroker({}).newReadOnlyTransaction()", this);
- return transactionFactory.newReadOnlyTransaction();
+ public DOMDataTreeReadTransaction newReadOnlyTransaction() {
+ LOG.trace("DataBroker({}).newReadTransaction()", this);
+ return transactionFactory.newReadTransaction();
}
@Override
- public DOMDataReadWriteTransaction newReadWriteTransaction() {
+ public DOMDataTreeReadWriteTransaction newReadWriteTransaction() {
LOG.trace("DataBroker({}).newReadWriteTransaction()", this);
return transactionFactory.newReadWriteTransaction();
}
@Override
- public DOMDataWriteTransaction newWriteOnlyTransaction() {
- LOG.trace("DataBroker({}).newWriteOnlyTransaction()", this);
- return transactionFactory.newWriteOnlyTransaction();
+ public DOMDataTreeWriteTransaction newWriteOnlyTransaction() {
+ LOG.trace("DataBroker({}).newWriteTransaction()", this);
+ return transactionFactory.newWriteTransaction();
}
@Override
- public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) {
+ public DOMTransactionChain createTransactionChain(final DOMTransactionChainListener listener) {
throw new UnsupportedOperationException("Not supported");
}
- @Nonnull
@Override
- public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
- return Collections.singletonMap(
- DOMDataTransactionValidator.class,
- (DOMDataTransactionValidator) tx -> ((ValidableTransaction)tx).validate()
- );
+ public @NonNull ClassToInstanceMap<DOMDataBrokerExtension> getExtensions() {
+ return ImmutableClassToInstanceMap.of(DOMDataTransactionValidator.class,
+ tx -> ((ValidableTransaction) tx).validate());
}
/**
@@ -118,11 +116,11 @@ public class DataBroker implements DOMDataBroker, Closeable {
*/
public interface TransactionFactory {
- DOMDataReadOnlyTransaction newReadOnlyTransaction();
+ DOMDataTreeReadTransaction newReadTransaction();
- DOMDataReadWriteTransaction newReadWriteTransaction();
+ DOMDataTreeReadWriteTransaction newReadWriteTransaction();
- DOMDataWriteTransaction newWriteOnlyTransaction();
+ DOMDataTreeWriteTransaction newWriteTransaction();
}
/**
@@ -139,12 +137,12 @@ public class DataBroker implements DOMDataBroker, Closeable {
}
@Override
- public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
+ public DOMDataTreeReadTransaction newReadTransaction() {
return ReadOnlyTransaction.create(configDataTree.newModification(), operationalDataTree);
}
@Override
- public DOMDataReadWriteTransaction newReadWriteTransaction() {
+ public DOMDataTreeReadWriteTransaction newReadWriteTransaction() {
final DataModification configModification = configDataTree.newModification();
return new ReadWriteTransaction(
ReadOnlyTransaction.create(configModification, operationalDataTree),
@@ -152,7 +150,7 @@ public class DataBroker implements DOMDataBroker, Closeable {
}
@Override
- public DOMDataWriteTransaction newWriteOnlyTransaction() {
+ public DOMDataTreeWriteTransaction newWriteTransaction() {
return WriteTransaction.createConfigOnly(configDataTree.newModification());
}
}
@@ -168,20 +166,20 @@ public class DataBroker implements DOMDataBroker, Closeable {
}
@Override
- public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
+ public DOMDataTreeReadTransaction newReadTransaction() {
return ReadOnlyTransaction.createOperationalOnly(operationalDataTree);
}
@Override
- public DOMDataReadWriteTransaction newReadWriteTransaction() {
+ public DOMDataTreeReadWriteTransaction newReadWriteTransaction() {
final DataModification dataModification = operationalDataTree.newModification();
return new ReadWriteTransaction(
- ReadOnlyTransaction.createOperationalOnly(dataModification),
- WriteTransaction.createOperationalOnly(dataModification));
+ ReadOnlyTransaction.createOperationalOnly(dataModification),
+ WriteTransaction.createOperationalOnly(dataModification));
}
@Override
- public DOMDataWriteTransaction newWriteOnlyTransaction() {
+ public DOMDataTreeWriteTransaction newWriteTransaction() {
return WriteTransaction.createOperationalOnly(operationalDataTree.newModification());
}
}
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegator.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegator.java
index b9246f3c4..094e621eb 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegator.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegator.java
@@ -17,15 +17,13 @@
package io.fd.honeycomb.data.impl;
import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.util.concurrent.Futures.immediateCheckedFuture;
import static io.fd.honeycomb.data.impl.ModifiableDataTreeDelegator.DataTreeWriteContextFactory.DataTreeWriteContext;
import static io.fd.honeycomb.data.impl.ModifiableDataTreeManager.DataTreeContextFactory.DataTreeContext;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
import io.fd.honeycomb.data.DataModification;
import io.fd.honeycomb.data.ReadableDataManager;
import io.fd.honeycomb.translate.MappingContext;
@@ -41,14 +39,17 @@ import io.fd.honeycomb.translate.write.registry.WriterRegistry;
import io.fd.honeycomb.translate.write.registry.WriterRegistry.DataObjectUpdates;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
+import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
+import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -67,7 +68,8 @@ import org.slf4j.LoggerFactory;
public final class ModifiableDataTreeDelegator extends ModifiableDataTreeManager {
private static final Logger LOG = LoggerFactory.getLogger(ModifiableDataTreeDelegator.class);
- private static final ReadableDataManager EMPTY_OPERATIONAL = p -> immediateCheckedFuture(Optional.absent());
+ private static final ReadableDataManager EMPTY_OPERATIONAL =
+ p -> FluentFutures.immediateFluentFuture(Optional.empty());
private final WriterRegistry writerRegistry;
private final DataBroker contextBroker;
@@ -163,10 +165,10 @@ public final class ModifiableDataTreeDelegator extends ModifiableDataTreeManager
try {
writerRegistry.processModifications(baUpdates, ctx);
- final CheckedFuture<Void, TransactionCommitFailedException> contextUpdateResult =
- ((TransactionMappingContext) mappingContext).submit();
+ final FluentFuture<? extends CommitInfo> contextUpdateResult =
+ ((TransactionMappingContext) mappingContext).commit();
// Blocking on context data update
- contextUpdateResult.checkedGet();
+ contextUpdateResult.get();
} catch (UpdateFailedException e) {
// TODO - HONEYCOMB-411
LOG.warn("Failed to apply all changes", e);
@@ -192,11 +194,11 @@ public final class ModifiableDataTreeDelegator extends ModifiableDataTreeManager
// not passing the cause,its logged above and it would be logged after transaction
// ended again(prevent double logging of same error
throw new Reverter.RevertSuccessException(getNonProcessedNodes(baUpdates, processed));
- } catch (TransactionCommitFailedException e) {
+ } catch (InterruptedException | ExecutionException ex) {
// TODO HONEYCOMB-162 revert should probably occur when context is not written successfully
final String msg = "Error while updating mapping context data";
- LOG.error(msg, e);
- throw new TranslationException(msg, e);
+ LOG.error(msg, ex);
+ throw new TranslationException(msg, ex);
} finally {
// Using finally instead of try-with-resources in order to leave ctx open for BulkUpdateException catch
// block. The context is needed there, but try-with-resources closes the resource before handling ex.
@@ -218,9 +220,10 @@ public final class ModifiableDataTreeDelegator extends ModifiableDataTreeManager
@SuppressWarnings("squid:S2095")
private TransactionWriteContext getRevertTransactionContext(final MappingContext affectedMappingContext) {
// Before Tx == after partial update
- final DOMDataReadOnlyTransaction beforeTx = ReadOnlyTransaction.create(this, EMPTY_OPERATIONAL);
+ final DOMDataTreeReadTransaction beforeTx = ReadOnlyTransaction.create(this, EMPTY_OPERATIONAL);
// After Tx == before partial update
- final DOMDataReadOnlyTransaction afterTx = ReadOnlyTransaction.create(untouchedModification, EMPTY_OPERATIONAL);
+ final DOMDataTreeReadTransaction afterTx =
+ ReadOnlyTransaction.create(untouchedModification, EMPTY_OPERATIONAL);
return new TransactionWriteContext(serializer, beforeTx, afterTx, affectedMappingContext);
}
@@ -229,9 +232,10 @@ public final class ModifiableDataTreeDelegator extends ModifiableDataTreeManager
@SuppressWarnings("squid:S2095")
private TransactionWriteContext getTransactionWriteContext() {
// Before Tx must use modification
- final DOMDataReadOnlyTransaction beforeTx = ReadOnlyTransaction.create(untouchedModification, EMPTY_OPERATIONAL);
+ final DOMDataTreeReadTransaction
+ beforeTx = ReadOnlyTransaction.create(untouchedModification, EMPTY_OPERATIONAL);
// After Tx must use current modification
- final DOMDataReadOnlyTransaction afterTx = ReadOnlyTransaction.create(this, EMPTY_OPERATIONAL);
+ final DOMDataTreeReadTransaction afterTx = ReadOnlyTransaction.create(this, EMPTY_OPERATIONAL);
final TransactionMappingContext mappingContext = new TransactionMappingContext(
contextBroker.newReadWriteTransaction());
return new TransactionWriteContext(serializer, beforeTx, afterTx, mappingContext);
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeManager.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeManager.java
index 4fa517c6e..f75ee64f5 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeManager.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModifiableDataTreeManager.java
@@ -18,19 +18,18 @@ package io.fd.honeycomb.data.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.util.concurrent.Futures.immediateCheckedFuture;
import static io.fd.honeycomb.data.impl.ModifiableDataTreeManager.DataTreeContextFactory.DataTreeContext;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
import io.fd.honeycomb.data.DataModification;
import io.fd.honeycomb.data.ModifiableDataManager;
-import io.fd.honeycomb.translate.ValidationFailedException;
import io.fd.honeycomb.translate.TranslationException;
+import io.fd.honeycomb.translate.ValidationFailedException;
+import java.util.Optional;
import javax.annotation.Nonnull;
import org.apache.commons.lang3.builder.RecursiveToStringStyle;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification;
@@ -69,7 +68,7 @@ public class ModifiableDataTreeManager implements ModifiableDataManager {
}
@Override
- public final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(@Nonnull final YangInstanceIdentifier path) {
+ public final FluentFuture<Optional<NormalizedNode<?, ?>>> read(@Nonnull final YangInstanceIdentifier path) {
return newModification().read(path);
}
@@ -83,14 +82,12 @@ public class ModifiableDataTreeManager implements ModifiableDataManager {
}
@Override
- public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
- @Nonnull final YangInstanceIdentifier path) {
- // TODO(HONEYCOMB-192): switch to java.util.Optional when rest of ODL infra does
- final Optional<NormalizedNode<?, ?>> node = Optional.fromNullable(modification.readNode(path).orElse(null));
+ public FluentFuture<Optional<NormalizedNode<?, ?>>> read(@Nonnull final YangInstanceIdentifier path) {
+ final Optional<NormalizedNode<?, ?>> node = modification.readNode(path);
if (LOG.isTraceEnabled() && node.isPresent()) {
LOG.trace("ConfigSnapshot.read: {}", node.get());
}
- return immediateCheckedFuture(node);
+ return FluentFutures.immediateFluentFuture(node);
}
@Override
@@ -145,9 +142,9 @@ public class ModifiableDataTreeManager implements ModifiableDataManager {
// Sealed modification cannot be altered, so create copy.
final CursorAwareDataTreeModification modificationCopy =
(CursorAwareDataTreeModification) snapshot.newModification();
- final DataTreeModificationCursor cursor = modificationCopy.createCursor(dataTree.getRootPath());
- checkState(cursor != null, "DataTreeModificationCursor for root path should not be null");
- modification.applyToCursor(cursor);
+ Optional<? extends DataTreeModificationCursor> cursor = modificationCopy.openCursor(dataTree.getRootPath());
+ checkState(cursor.isPresent(), "DataTreeModificationCursor for root path should not be empty");
+ modification.applyToCursor(cursor.get());
// Then validate it.
validateCandidate(prepareCandidateContext(modificationCopy));
}
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/Modification.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/Modification.java
index b95fc981d..358548ee4 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/Modification.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/Modification.java
@@ -88,14 +88,12 @@ final class Modification {
return dataCandidate.getModificationType();
}
- com.google.common.base.Optional<NormalizedNode<?, ?>> getDataBefore() {
- // TODO(HONEYCOMB-192): switch to java.util.Optional when rest of ODL infra does
- return com.google.common.base.Optional.fromNullable(dataCandidate.getDataBefore().orElse(null));
+ Optional<NormalizedNode<?, ?>> getDataBefore() {
+ return dataCandidate.getDataBefore();
}
- com.google.common.base.Optional<NormalizedNode<?, ?>> getDataAfter() {
- // TODO(HONEYCOMB-192): switch to java.util.Optional when rest of ODL infra does
- return com.google.common.base.Optional.fromNullable(dataCandidate.getDataAfter().orElse(null));
+ Optional<NormalizedNode<?, ?>> getDataAfter() {
+ return dataCandidate.getDataAfter();
}
Object getSchemaNode() {
@@ -216,7 +214,7 @@ final class Modification {
((SchemaNode) schemaNode).getQName().equals(identifier.getNodeType())) {
found = schemaNode;
} else {
- found = ((DataNodeContainer) schemaNode).getDataChildByName(identifier.getNodeType());
+ found = ((DataNodeContainer) schemaNode).findDataChildByName(identifier.getNodeType()).orElse(null);
}
} else if (schemaNode instanceof ChoiceSchemaNode) {
// For choices, iterate through all the cases
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModificationDiff.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModificationDiff.java
index 210408e39..b6adabdcc 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModificationDiff.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ModificationDiff.java
@@ -135,7 +135,7 @@ final class ModificationDiff {
private ModificationDiff detectUnderDisappearedNonPresenceContainer(
@Nonnull final Modification modification) {
- final com.google.common.base.Optional<NormalizedNode<?, ?>> dataBefore = modification.getDataBefore();
+ final java.util.Optional<NormalizedNode<?, ?>> dataBefore = modification.getDataBefore();
// is disappear case
if (dataBefore.isPresent()) {
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/NormalizedNodeUpdate.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/NormalizedNodeUpdate.java
index bfc8a1e2c..86e312834 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/NormalizedNodeUpdate.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/NormalizedNodeUpdate.java
@@ -19,6 +19,7 @@ package io.fd.honeycomb.data.impl;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
+import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -60,13 +61,11 @@ final class NormalizedNodeUpdate {
}
static NormalizedNodeUpdate create(@Nonnull final Modification modification) {
- final com.google.common.base.Optional<NormalizedNode<?, ?>> beforeData =
- modification.getDataBefore();
- final com.google.common.base.Optional<NormalizedNode<?, ?>> afterData =
- modification.getDataAfter();
+ final Optional<NormalizedNode<?, ?>> beforeData = modification.getDataBefore();
+ final Optional<NormalizedNode<?, ?>> afterData = modification.getDataAfter();
checkArgument(beforeData.isPresent() || afterData.isPresent(),
"Both before and after data are null for %s", modification.getId());
- return NormalizedNodeUpdate.create(modification.getId(), beforeData.orNull(), afterData.orNull());
+ return NormalizedNodeUpdate.create(modification.getId(), beforeData.orElse(null), afterData.orElse(null));
}
static NormalizedNodeUpdate create(@Nonnull final YangInstanceIdentifier id,
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadOnlyTransaction.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadOnlyTransaction.java
index dcd456a27..ed401eef9 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadOnlyTransaction.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadOnlyTransaction.java
@@ -21,23 +21,23 @@ import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
import io.fd.honeycomb.data.DataModification;
import io.fd.honeycomb.data.ReadableDataManager;
+import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-final class ReadOnlyTransaction implements DOMDataReadOnlyTransaction {
+final class ReadOnlyTransaction implements DOMDataTreeReadTransaction {
private static final Logger LOG = LoggerFactory.getLogger(ReadOnlyTransaction.class);
@@ -70,9 +70,8 @@ final class ReadOnlyTransaction implements DOMDataReadOnlyTransaction {
}
@Override
- public synchronized CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
- final LogicalDatastoreType store,
- final YangInstanceIdentifier path) {
+ public synchronized FluentFuture<Optional<NormalizedNode<?, ?>>> read(final LogicalDatastoreType store,
+ final YangInstanceIdentifier path) {
LOG.debug("ReadOnlyTransaction.read(), store={}, path={}", store, path);
checkState(!closed, "Transaction has been closed");
@@ -86,12 +85,13 @@ final class ReadOnlyTransaction implements DOMDataReadOnlyTransaction {
}
@Override
- public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
- final YangInstanceIdentifier path) {
+ public FluentFuture<Boolean> exists(final LogicalDatastoreType store,
+ final YangInstanceIdentifier path) {
LOG.debug("ReadOnlyTransaction.exists() store={}, path={}", store, path);
- ListenableFuture<Boolean> listenableFuture = Futures.transform(read(store, path), IS_NODE_PRESENT);
- return Futures.makeChecked(listenableFuture, ANY_EX_TO_READ_FAILED_EXCEPTION_MAPPER);
+ ListenableFuture<Boolean> listenableFuture = Futures.transform(read(store, path), IS_NODE_PRESENT,
+ MoreExecutors.directExecutor());
+ return FluentFuture.from(listenableFuture);
}
@Nonnull
@@ -119,6 +119,4 @@ final class ReadOnlyTransaction implements DOMDataReadOnlyTransaction {
private static final Function<? super Optional<NormalizedNode<?, ?>>, ? extends Boolean> IS_NODE_PRESENT =
(Function<Optional<NormalizedNode<?, ?>>, Boolean>) input -> input == null ? Boolean.FALSE : input.isPresent();
- private static final Function<? super Exception, ReadFailedException> ANY_EX_TO_READ_FAILED_EXCEPTION_MAPPER =
- (Function<Exception, ReadFailedException>) e -> new ReadFailedException("Exists failed", e);
} \ No newline at end of file
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadWriteTransaction.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadWriteTransaction.java
index c7d54f0ec..b2e7d38e1 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadWriteTransaction.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadWriteTransaction.java
@@ -16,39 +16,28 @@
package io.fd.honeycomb.data.impl;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FluentFuture;
+import java.util.Optional;
import javax.annotation.Nonnull;
-import org.apache.commons.lang3.builder.RecursiveToStringStyle;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.mdsal.common.api.CommitInfo;
-import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
- * Composite DOM transaction that delegates reads to a {@link DOMDataReadTransaction} delegate and writes to a {@link
- * DOMDataWriteTransaction} delegate.
+ * Composite DOM transaction that delegates reads to a {@link DOMDataTreeReadTransaction} delegate and writes to a {@link
+ * DOMDataTreeWriteTransaction} delegate.
*/
-final class ReadWriteTransaction implements DOMDataReadWriteTransaction, ValidableTransaction {
+final class ReadWriteTransaction implements DOMDataTreeReadWriteTransaction, ValidableTransaction {
- private static final Logger LOG = LoggerFactory.getLogger(ReadWriteTransaction.class);
-
- private final DOMDataReadOnlyTransaction delegateReadTx;
+ private final DOMDataTreeReadTransaction delegateReadTx;
private final ValidableTransaction delegateWriteTx;
- ReadWriteTransaction(@Nonnull final DOMDataReadOnlyTransaction delegateReadTx,
+ ReadWriteTransaction(@Nonnull final DOMDataTreeReadTransaction delegateReadTx,
@Nonnull final ValidableTransaction delegateWriteTx) {
this.delegateReadTx = Preconditions.checkNotNull(delegateReadTx, "delegateReadTx should not be null");
this.delegateWriteTx = Preconditions.checkNotNull(delegateWriteTx, "delegateWriteTx should not be null");
@@ -78,33 +67,19 @@ final class ReadWriteTransaction implements DOMDataReadWriteTransaction, Validab
}
@Override
- public CheckedFuture<Void, TransactionCommitFailedException> submit() {
- //TODO - remove after https://bugs.opendaylight.org/show_bug.cgi?id=7791 resolved
- if (LOG.isDebugEnabled()) {
- LOG.debug("Submitting transaction {}", ReflectionToStringBuilder.toString(
- delegateWriteTx,
- RecursiveToStringStyle.MULTI_LINE_STYLE,
- false,
- false
- ));
- }
- return delegateWriteTx.submit();
- }
-
- @Override
public FluentFuture<? extends CommitInfo> commit() {
return delegateWriteTx.commit();
}
@Override
- public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store,
- final YangInstanceIdentifier path) {
+ public FluentFuture<Optional<NormalizedNode<?, ?>>> read(final LogicalDatastoreType store,
+ final YangInstanceIdentifier path) {
return delegateReadTx.read(store, path);
}
@Override
- public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
- final YangInstanceIdentifier path) {
+ public FluentFuture<Boolean> exists(final LogicalDatastoreType store,
+ final YangInstanceIdentifier path) {
return delegateReadTx.exists(store, path);
}
@@ -114,7 +89,7 @@ final class ReadWriteTransaction implements DOMDataReadWriteTransaction, Validab
}
@Override
- public CheckedFuture<Void, DOMDataTransactionValidator.ValidationFailedException> validate() {
+ public FluentFuture<Void> validate() {
return delegateWriteTx.validate();
}
}
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadableDataTreeDelegator.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadableDataTreeDelegator.java
index de3cabde7..79188188e 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadableDataTreeDelegator.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadableDataTreeDelegator.java
@@ -21,12 +21,10 @@ import static com.google.common.collect.Iterables.getOnlyElement;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Collections2;
import com.google.common.collect.Multimap;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.FluentFuture;
import io.fd.honeycomb.data.ReadableDataManager;
import io.fd.honeycomb.translate.MappingContext;
import io.fd.honeycomb.translate.ModificationCache;
@@ -36,9 +34,12 @@ import io.fd.honeycomb.translate.read.registry.ReaderRegistry;
import io.fd.honeycomb.translate.util.TransactionMappingContext;
import java.util.Collection;
import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -67,7 +68,7 @@ public final class ReadableDataTreeDelegator implements ReadableDataManager {
private final BindingNormalizedNodeSerializer serializer;
private final ReaderRegistry readerRegistry;
private final SchemaContext globalContext;
- private final org.opendaylight.controller.md.sal.binding.api.DataBroker contextBroker;
+ private final org.opendaylight.mdsal.binding.api.DataBroker contextBroker;
/**
* Creates operational data tree instance.
@@ -80,7 +81,7 @@ public final class ReadableDataTreeDelegator implements ReadableDataManager {
public ReadableDataTreeDelegator(@Nonnull BindingNormalizedNodeSerializer serializer,
@Nonnull final SchemaContext globalContext,
@Nonnull final ReaderRegistry readerRegistry,
- @Nonnull final org.opendaylight.controller.md.sal.binding.api.DataBroker contextBroker) {
+ @Nonnull final org.opendaylight.mdsal.binding.api.DataBroker contextBroker) {
this.contextBroker = checkNotNull(contextBroker, "contextBroker should not be null");
this.globalContext = checkNotNull(globalContext, "globalContext should not be null");
this.serializer = checkNotNull(serializer, "serializer should not be null");
@@ -88,12 +89,12 @@ public final class ReadableDataTreeDelegator implements ReadableDataManager {
}
@Override
- public CheckedFuture<Optional<NormalizedNode<?, ?>>,
- org.opendaylight.controller.md.sal.common.api.data.ReadFailedException> read(
+ public FluentFuture<Optional<NormalizedNode<?, ?>>> read(
@Nonnull final YangInstanceIdentifier yangInstanceIdentifier) {
- try (TransactionMappingContext mappingContext = new TransactionMappingContext(contextBroker.newReadWriteTransaction());
- ReadContext ctx = new ReadContextImpl(mappingContext)) {
+ try (TransactionMappingContext mappingContext = new TransactionMappingContext(
+ contextBroker.newReadWriteTransaction());
+ ReadContext ctx = new ReadContextImpl(mappingContext)) {
final Optional<NormalizedNode<?, ?>> value;
if (checkNotNull(yangInstanceIdentifier).equals(YangInstanceIdentifier.EMPTY)) {
@@ -103,24 +104,17 @@ public final class ReadableDataTreeDelegator implements ReadableDataManager {
}
// Submit context mapping updates
- final CheckedFuture<Void, TransactionCommitFailedException> contextUpdateResult =
- ((TransactionMappingContext) ctx.getMappingContext()).submit();
+ final FluentFuture<? extends CommitInfo> contextUpdateResult =
+ ((TransactionMappingContext) ctx.getMappingContext()).commit();
// Blocking on context data update
- contextUpdateResult.checkedGet();
-
- return Futures.immediateCheckedFuture(value);
-
- } catch (ReadFailedException e) {
- return Futures.immediateFailedCheckedFuture(
- new org.opendaylight.controller.md.sal.common.api.data.ReadFailedException("Failed to read data", e));
- } catch (TransactionCommitFailedException e) {
- // Context write failed. This should not happen, but if it does, there's not much that can be done here
- // ... try to read again
- final String msg = "Error while updating mapping context data";
- LOG.error(msg, e);
- return Futures.immediateFailedCheckedFuture(
- new org.opendaylight.controller.md.sal.common.api.data.ReadFailedException(msg, e)
- );
+ contextUpdateResult.get();
+
+ return FluentFutures.immediateFluentFuture(value);
+
+ } catch (InterruptedException | ExecutionException | ReadFailedException ex) {
+ return FluentFutures.immediateFailedFluentFuture(
+ new org.opendaylight.controller.md.sal.common.api.data.ReadFailedException("Failed to read data",
+ ex));
}
}
@@ -138,9 +132,9 @@ public final class ReadableDataTreeDelegator implements ReadableDataManager {
if (dataObject.isPresent()) {
final NormalizedNode<?, ?> value = toNormalizedNodeFunction(path).apply(dataObject.get());
- return Optional.<NormalizedNode<?, ?>>fromNullable(value);
+ return Optional.ofNullable(value);
} else {
- return Optional.absent();
+ return Optional.empty();
}
}
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ValidableTransaction.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ValidableTransaction.java
index 0c67f863f..09dde4e70 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ValidableTransaction.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ValidableTransaction.java
@@ -17,19 +17,18 @@
package io.fd.honeycomb.data.impl;
import com.google.common.annotations.Beta;
-import com.google.common.util.concurrent.CheckedFuture;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import com.google.common.util.concurrent.FluentFuture;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator;
-import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator.ValidationFailedException;
/**
- * An {@link DOMDataWriteTransaction} than can be validated.
+ * An {@link DOMDataTreeWriteTransaction} than can be validated.
* @see DOMDataTransactionValidator
*/
@Beta
-interface ValidableTransaction extends DOMDataWriteTransaction {
+interface ValidableTransaction extends DOMDataTreeWriteTransaction {
/**
- * Validates state of the data tree associated with the provided {@link DOMDataWriteTransaction}.
+ * Validates state of the data tree associated with the provided {@link DOMDataTreeWriteTransaction}.
*
* <p>The operation should not have any side-effects on the transaction state.
*
@@ -37,9 +36,8 @@ interface ValidableTransaction extends DOMDataWriteTransaction {
* if the state of the transaction has not been changed.
*
* @return
- * a CheckedFuture containing the result of the validate operation. The future blocks until the validation
- * operation is complete. A successful validate returns nothing. On failure, the Future will fail
- * with a {@link ValidationFailedException} or an exception derived from ValidationFailedException.
+ * a FluentFuture containing the result of the validate operation. The future blocks until the validation
+ * operation is complete. A successful validate returns nothing. On failure, the Future will fail.
*/
- CheckedFuture<Void, ValidationFailedException> validate();
+ FluentFuture<Void> validate();
}
diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/WriteTransaction.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/WriteTransaction.java
index 91b48cc10..1ce7db74f 100644
--- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/WriteTransaction.java
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/WriteTransaction.java
@@ -20,7 +20,6 @@ import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.Futures;
import io.fd.honeycomb.data.DataModification;
@@ -30,10 +29,11 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator;
import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
+import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
@@ -113,23 +113,6 @@ final class WriteTransaction implements ValidableTransaction {
handleOperation(store, (modification) -> modification.delete(path));
}
- @Deprecated
- @Override
- public CheckedFuture<Void, TransactionCommitFailedException> submit() {
- LOG.trace("WriteTransaction.submit()");
- checkIsNew();
-
- try {
- doCommit();
- } catch (Exception e) {
- status = TransactionStatus.FAILED;
- LOG.error("Submit failed", e);
- return Futures.immediateFailedCheckedFuture(
- new TransactionCommitFailedException("Failed to validate DataTreeModification", e));
- }
- return Futures.immediateCheckedFuture(null);
- }
-
private void doCommit() throws TranslationException {
status = TransactionStatus.SUBMITED;
if (configModification != null) {
@@ -164,7 +147,7 @@ final class WriteTransaction implements ValidableTransaction {
}
@Override
- public CheckedFuture<Void, DOMDataTransactionValidator.ValidationFailedException> validate() {
+ public FluentFuture<Void> validate() {
try {
if (configModification != null) {
configModification.validate();
@@ -173,9 +156,10 @@ final class WriteTransaction implements ValidableTransaction {
operationalModification.validate();
}
} catch (Exception e) {
- return Futures.immediateFailedCheckedFuture(new DOMDataTransactionValidator.ValidationFailedException(e.getMessage(), e.getCause()));
+ return FluentFutures.immediateFailedFluentFuture(
+ new DOMDataTransactionValidator.ValidationFailedException(e.getMessage(), e.getCause()));
}
- return Futures.immediateCheckedFuture(null);
+ return FluentFutures.immediateNullFluentFuture();
}
diff --git a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/DataBrokerTest.java b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/DataBrokerTest.java
index 124179c79..56d333436 100644
--- a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/DataBrokerTest.java
+++ b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/DataBrokerTest.java
@@ -24,18 +24,19 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
+import com.google.common.collect.ClassToInstanceMap;
import io.fd.honeycomb.data.DataModification;
import io.fd.honeycomb.data.ModifiableDataManager;
import io.fd.honeycomb.data.ReadableDataManager;
-import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBrokerExtension;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
+import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener;
import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -58,7 +59,7 @@ public class DataBrokerTest {
@Test
public void testNewReadWriteTransaction() {
- final DOMDataReadWriteTransaction readWriteTx = broker.newReadWriteTransaction();
+ final DOMDataTreeReadWriteTransaction readWriteTx = broker.newReadWriteTransaction();
final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class);
readWriteTx.read(LogicalDatastoreType.CONFIGURATION, path);
@@ -77,7 +78,7 @@ public class DataBrokerTest {
@Test
public void testNewReadOnlyTransaction() {
- final DOMDataReadOnlyTransaction readTx = broker.newReadOnlyTransaction();
+ final DOMDataTreeReadTransaction readTx = broker.newReadOnlyTransaction();
final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class);
readTx.read(LogicalDatastoreType.CONFIGURATION, path);
@@ -88,14 +89,14 @@ public class DataBrokerTest {
@Test(expected = UnsupportedOperationException.class)
public void testCreateTransactionChain() {
- final TransactionChainListener listener = mock(TransactionChainListener.class);
+ final DOMTransactionChainListener listener = mock(DOMTransactionChainListener.class);
broker.createTransactionChain(listener);
}
@Test
public void testGetSupportedExtensions() {
- final Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> supportedExtensions =
- broker.getSupportedExtensions();
+ final @NonNull ClassToInstanceMap<DOMDataBrokerExtension> supportedExtensions =
+ broker.getExtensions();
assertEquals(1, supportedExtensions.size());
assertNotNull(supportedExtensions.get(DOMDataTransactionValidator.class));
}
@@ -117,7 +118,7 @@ public class DataBrokerTest {
@Test
public void testNewReadWriteTransaction() {
- final DOMDataReadWriteTransaction readWriteTx = broker.newReadWriteTransaction();
+ final DOMDataTreeReadWriteTransaction readWriteTx = broker.newReadWriteTransaction();
final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class);
readWriteTx.read(LogicalDatastoreType.OPERATIONAL, path);
@@ -133,7 +134,7 @@ public class DataBrokerTest {
@Test
public void testNewReadOnlyTransaction() {
- final DOMDataReadOnlyTransaction readTx = broker.newReadOnlyTransaction();
+ final DOMDataTreeReadTransaction readTx = broker.newReadOnlyTransaction();
final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class);
readTx.read(LogicalDatastoreType.OPERATIONAL, path);
@@ -143,7 +144,7 @@ public class DataBrokerTest {
@Test(expected = IllegalArgumentException.class)
public void testReadConfig() {
- final DOMDataReadOnlyTransaction readTx = broker.newReadOnlyTransaction();
+ final DOMDataTreeReadTransaction readTx = broker.newReadOnlyTransaction();
final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class);
readTx.read(LogicalDatastoreType.CONFIGURATION, path);
@@ -151,14 +152,13 @@ public class DataBrokerTest {
@Test(expected = UnsupportedOperationException.class)
public void testCreateTransactionChain() {
- final TransactionChainListener listener = mock(TransactionChainListener.class);
+ final DOMTransactionChainListener listener = mock(DOMTransactionChainListener.class);
broker.createTransactionChain(listener);
}
@Test
public void testGetSupportedExtensions() {
- final Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> supportedExtensions =
- broker.getSupportedExtensions();
+ final @NonNull ClassToInstanceMap<DOMDataBrokerExtension> supportedExtensions = broker.getExtensions();
assertTrue(supportedExtensions.isEmpty());
}
}
diff --git a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorBaseTest.java b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorBaseTest.java
index 5690e78c3..8f686333e 100644
--- a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorBaseTest.java
+++ b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorBaseTest.java
@@ -21,7 +21,6 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import com.google.common.util.concurrent.Futures;
import io.fd.honeycomb.translate.write.DataObjectUpdate;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.registry.WriterRegistry;
@@ -32,8 +31,9 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
@@ -52,7 +52,7 @@ abstract class ModifiableDataTreeDelegatorBaseTest extends ModificationBaseTest
@Mock
DataBroker contextBroker;
@Mock
- org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction tx;
+ org.opendaylight.mdsal.binding.api.ReadWriteTransaction tx;
@Captor
ArgumentCaptor<WriteContext> writeContextCaptor;
@@ -72,7 +72,7 @@ abstract class ModifiableDataTreeDelegatorBaseTest extends ModificationBaseTest
MockitoAnnotations.initMocks(this);
dataTree = getDataTree();
when(contextBroker.newReadWriteTransaction()).thenReturn(tx);
- when(tx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+ when(tx.commit()).thenReturn(FluentFutures.immediateNullFluentFuture());
when(serializer.fromYangInstanceIdentifier(any(YangInstanceIdentifier.class)))
.thenReturn(((InstanceIdentifier) DEFAULT_ID));
diff --git a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java
index b1e60c440..8ec18e4da 100644
--- a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java
+++ b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModifiableDataTreeDelegatorTest.java
@@ -28,19 +28,18 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
import io.fd.honeycomb.data.DataModification;
import io.fd.honeycomb.translate.write.DataObjectUpdate;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.registry.WriterRegistry;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import org.junit.Test;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -54,9 +53,9 @@ public class ModifiableDataTreeDelegatorTest extends ModifiableDataTreeDelegator
public void testRead() throws Exception {
final ContainerNode topContainer = getTopContainer("topContainer");
addNodeToTree(dataTree, topContainer, TOP_CONTAINER_ID);
- final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read =
+ final FluentFuture<Optional<NormalizedNode<?, ?>>> read =
configDataTree.read(TOP_CONTAINER_ID);
- final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read2 =
+ final FluentFuture<Optional<NormalizedNode<?, ?>>> read2 =
configDataTree.newModification().read(TOP_CONTAINER_ID);
final Optional<NormalizedNode<?, ?>> normalizedNodeOptional = read.get();
final Optional<NormalizedNode<?, ?>> normalizedNodeOptional2 = read2.get();
@@ -64,7 +63,7 @@ public class ModifiableDataTreeDelegatorTest extends ModifiableDataTreeDelegator
assertEquals(normalizedNodeOptional, normalizedNodeOptional2);
assertTrue(normalizedNodeOptional.isPresent());
assertEquals(topContainer, normalizedNodeOptional.get());
- assertEquals(dataTree.takeSnapshot().readNode(TOP_CONTAINER_ID), Optional.toJavaUtil(normalizedNodeOptional));
+ assertEquals(dataTree.takeSnapshot().readNode(TOP_CONTAINER_ID), normalizedNodeOptional);
}
@Test
diff --git a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadOnlyTransactionTest.java b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadOnlyTransactionTest.java
index 77470d17c..690a0deee 100644
--- a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadOnlyTransactionTest.java
+++ b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadOnlyTransactionTest.java
@@ -22,15 +22,14 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
-import io.fd.honeycomb.data.ReadableDataManager;
+import com.google.common.util.concurrent.FluentFuture;
import io.fd.honeycomb.data.DataModification;
+import io.fd.honeycomb.data.ReadableDataManager;
+import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -52,8 +51,7 @@ public class ReadOnlyTransactionTest {
@Test
public void testExists() {
final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class);
- final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>
- future = mock(CheckedFuture.class);
+ final FluentFuture<Optional<NormalizedNode<?, ?>>> future = mock(FluentFuture.class);
when(operationalData.read(path)).thenReturn(future);
readOnlyTx.exists(LogicalDatastoreType.OPERATIONAL, path);
diff --git a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadWriteTransactionTest.java b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadWriteTransactionTest.java
index bbe384289..cc744530f 100644
--- a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadWriteTransactionTest.java
+++ b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadWriteTransactionTest.java
@@ -23,15 +23,15 @@ import static org.mockito.MockitoAnnotations.initMocks;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
public class ReadWriteTransactionTest {
@Mock
- private DOMDataReadOnlyTransaction readTx;
+ private DOMDataTreeReadTransaction readTx;
@Mock
private ValidableTransaction writeTx;
@@ -78,15 +78,7 @@ public class ReadWriteTransactionTest {
}
@Test
- public void testSubmit() throws Exception {
- readWriteTx.submit();
- verify(writeTx).submit();
- }
-
-
- @SuppressWarnings("deprecation")
- @Test
- public void testCommit() throws Exception {
+ public void testCommit() {
readWriteTx.commit();
verify(writeTx).commit();
}
@@ -104,7 +96,7 @@ public class ReadWriteTransactionTest {
}
@Test
- public void testGetIdentifier() throws Exception {
+ public void testGetIdentifier() {
assertNotNull(readWriteTx.getIdentifier());
}
} \ No newline at end of file
diff --git a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadableDataTreeDelegatorTest.java b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadableDataTreeDelegatorTest.java
index 76b46dad6..6ff625d8e 100644
--- a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadableDataTreeDelegatorTest.java
+++ b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ReadableDataTreeDelegatorTest.java
@@ -30,29 +30,30 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.FluentFuture;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.registry.ReaderRegistry;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
+import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
import org.opendaylight.yangtools.util.UnmodifiableCollection;
+import org.opendaylight.yangtools.util.concurrent.FluentFutures;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
@@ -87,7 +88,7 @@ public class ReadableDataTreeDelegatorTest {
@Mock
private DOMDataBroker netconfMonitoringBroker;
@Mock
- private DOMDataReadOnlyTransaction domDataReadOnlyTransaction;
+ private DOMDataTreeReadTransaction domDataReadOnlyTransaction;
@Mock
private DataBroker contextBroker;
@@ -95,16 +96,16 @@ public class ReadableDataTreeDelegatorTest {
public void setUp() {
initMocks(this);
operationalData = new ReadableDataTreeDelegator(serializer, globalContext, reader, contextBroker);
- doReturn(schemaNode).when(globalContext).getDataChildByName(any(QName.class));
+ doReturn(Optional.of(schemaNode)).when(globalContext).findDataChildByName(any(QName.class));
doReturn(domDataReadOnlyTransaction).when(netconfMonitoringBroker).newReadOnlyTransaction();
- doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(domDataReadOnlyTransaction)
+ doReturn(FluentFutures.immediateFluentFuture(Optional.empty())).when(domDataReadOnlyTransaction)
.read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class));
- final org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction ctxTransaction = mock(
- org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction.class);
+ final org.opendaylight.mdsal.binding.api.ReadWriteTransaction ctxTransaction = mock(
+ org.opendaylight.mdsal.binding.api.ReadWriteTransaction.class);
doReturn(ctxTransaction).when(contextBroker).newReadWriteTransaction();
- doReturn(Futures.immediateCheckedFuture(null)).when(ctxTransaction).submit();
+ doReturn(FluentFutures.immediateNullFluentFuture()).when(ctxTransaction).commit();
}
@Test
@@ -124,7 +125,7 @@ public class ReadableDataTreeDelegatorTest {
final DataContainerChild<?, ?> expectedValue = mock(DataContainerChild.class);
doReturn(expectedValue).when(entry).getValue();
- final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> future = operationalData.read(yangId);
+ final FluentFuture<Optional<NormalizedNode<?, ?>>> future = operationalData.read(yangId);
verify(serializer).fromYangInstanceIdentifier(yangId);
verify(reader).read(same(id), any(ReadContext.class));
@@ -137,9 +138,9 @@ public class ReadableDataTreeDelegatorTest {
public void testReadNonExistingNode() throws Exception {
final YangInstanceIdentifier yangId = mock(YangInstanceIdentifier.class);
doReturn(id).when(serializer).fromYangInstanceIdentifier(yangId);
- doReturn(Optional.absent()).when(reader).read(same(id), any(ReadContext.class));
+ doReturn(Optional.empty()).when(reader).read(same(id), any(ReadContext.class));
- final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> future = operationalData.read(yangId);
+ final FluentFuture<Optional<NormalizedNode<?, ?>>> future = operationalData.read(yangId);
verify(serializer).fromYangInstanceIdentifier(yangId);
verify(reader).read(same(id), any(ReadContext.class));
@@ -151,13 +152,12 @@ public class ReadableDataTreeDelegatorTest {
public void testReadFailed() throws Exception {
doThrow(io.fd.honeycomb.translate.read.ReadFailedException.class).when(reader).readAll(any(ReadContext.class));
- final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> future =
- operationalData.read( YangInstanceIdentifier.EMPTY);
+ final FluentFuture<Optional<NormalizedNode<?, ?>>> future = operationalData.read(YangInstanceIdentifier.EMPTY);
try {
- future.checkedGet();
- } catch (ReadFailedException e) {
- assertTrue(e.getCause() instanceof io.fd.honeycomb.translate.read.ReadFailedException);
+ future.get();
+ } catch (ExecutionException e) {
+ assertTrue(e.getCause() instanceof ReadFailedException);
return;
}
fail("ReadFailedException was expected");
@@ -181,7 +181,7 @@ public class ReadableDataTreeDelegatorTest {
doReturn(vppYangId.getLastPathArgument()).when(vppStateContainer).getIdentifier();
// Read root
- final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> future =
+ final FluentFuture<Optional<NormalizedNode<?, ?>>> future =
operationalData.read(YangInstanceIdentifier.EMPTY);
verify(reader).readAll(any(ReadContext.class));
diff --git a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/WriteTransactionTest.java b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/WriteTransactionTest.java
index 74313a1ba..8bda219cb 100644
--- a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/WriteTransactionTest.java
+++ b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/WriteTransactionTest.java
@@ -25,15 +25,16 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
import io.fd.honeycomb.data.DataModification;
import io.fd.honeycomb.translate.TranslationException;
import io.fd.honeycomb.translate.ValidationFailedException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -68,7 +69,7 @@ public class WriteTransactionTest {
@Test(expected = IllegalStateException.class)
public void testOnFinishedTx() {
- writeTx.submit();
+ writeTx.commit();
writeTx.put(LogicalDatastoreType.CONFIGURATION, path, data);
verify(configSnapshot).write(path, data);
}
@@ -86,7 +87,7 @@ public class WriteTransactionTest {
@Test
public void testCancelFinished() {
- writeTx.submit();
+ writeTx.commit();
assertFalse(writeTx.cancel());
}
@@ -98,14 +99,14 @@ public class WriteTransactionTest {
@Test
public void testSubmit() throws Exception {
- writeTx.submit();
+ writeTx.commit();
verify(configSnapshot).commit();
}
@Test
public void testSubmitFailed() throws Exception {
doThrow(mock(ValidationFailedException.class)).when(configSnapshot).commit();
- final CheckedFuture<Void, TransactionCommitFailedException> future = writeTx.submit();
+ final FluentFuture<? extends CommitInfo> future = writeTx.commit();
try {
future.get();
} catch (Exception e) {