diff options
author | Michal Cmarada <mcmarada@cisco.com> | 2019-04-08 11:37:45 +0200 |
---|---|---|
committer | Michal Cmarada <mcmarada@cisco.com> | 2019-04-08 11:37:45 +0200 |
commit | b16cea20258ba537db7c0755208c82ab93331ff7 (patch) | |
tree | 8a5a3c87069b9ce700c34323e75ff434e7acae97 /infra/data-impl/src/main/java/io/fd | |
parent | 23979469bcf8cd312cb3ec9e9e548003110f68f4 (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/main/java/io/fd')
11 files changed, 141 insertions, 196 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(); } |