diff options
author | Michal Cmarada <michal.cmarada@pantheon.tech> | 2018-09-25 11:15:35 +0200 |
---|---|---|
committer | Michal Cmarada <michal.cmarada@pantheon.tech> | 2018-09-25 11:22:18 +0200 |
commit | 556a0f59abc9b09005d40945bc20948d69e4f98e (patch) | |
tree | 76d795ae59aba49521fc4fdc7d65062c946147be /infra/data-impl | |
parent | 46bcceb927b1bce07c1c9517f45470703293eb84 (diff) |
Bump ODL dependencies to Fluorine (HONEYCOMB-433)
Change-Id: I142ebd2899272feff00abe7d4bae708f093ee3ec
Signed-off-by: Michal Cmarada <michal.cmarada@pantheon.tech>
Diffstat (limited to 'infra/data-impl')
8 files changed, 89 insertions, 69 deletions
diff --git a/infra/data-impl/pom.xml b/infra/data-impl/pom.xml index fa3d976d8..6abc1892d 100644 --- a/infra/data-impl/pom.xml +++ b/infra/data-impl/pom.xml @@ -47,6 +47,10 @@ <artifactId>guava</artifactId> </dependency> <dependency> + <groupId>org.eclipse.jdt</groupId> + <artifactId>org.eclipse.jdt.annotation</artifactId> + </dependency> + <dependency> <groupId>org.opendaylight.mdsal</groupId> <artifactId>mdsal-binding-dom-codec</artifactId> </dependency> 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 5246ca15b..a60bf3415 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 @@ -26,17 +26,13 @@ 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.LogicalDatastoreType; 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.DOMDataChangeListener; 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.opendaylight.yangtools.concepts.ListenerRegistration; -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; @@ -78,14 +74,6 @@ public class DataBroker implements DOMDataBroker, Closeable { } @Override - public ListenerRegistration<DOMDataChangeListener> registerDataChangeListener(final LogicalDatastoreType store, - final YangInstanceIdentifier path, - final DOMDataChangeListener listener, - final DataChangeScope triggeringScope) { - throw new UnsupportedOperationException("Not supported"); - } - - @Override public DOMTransactionChain createTransactionChain(final TransactionChainListener listener) { throw new UnsupportedOperationException("Not supported"); } diff --git a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapter.java b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapter.java index df6f199b6..65889d4fc 100644 --- a/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapter.java +++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapter.java @@ -29,7 +29,7 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.Optional; import javax.annotation.Nonnull; -import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; 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.DataTree; @@ -62,7 +62,7 @@ public class PersistingDataTreeAdapter implements DataTree { * @param schemaService schemaContext provier */ public PersistingDataTreeAdapter(@Nonnull final DataTree delegate, - @Nonnull final SchemaService schemaService, + @Nonnull final DOMSchemaService schemaService, @Nonnull final Path persistPath) { this(delegate, new JsonPersister(persistPath, schemaService)); } @@ -102,9 +102,9 @@ public class PersistingDataTreeAdapter implements DataTree { static class JsonPersister { private final Path path; - private final SchemaService schemaServiceDependency; + private final DOMSchemaService schemaServiceDependency; - JsonPersister(final Path persistPath, final SchemaService schemaService) { + JsonPersister(final Path persistPath, final DOMSchemaService schemaService) { this.path = testPersistPath(checkNotNull(persistPath, "persistPath is null")); this.schemaServiceDependency = checkNotNull(schemaService, "schemaService is null"); } 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 f2301d77a..f26810e15 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 @@ -19,11 +19,10 @@ 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.ListenableFuture; +import com.google.common.util.concurrent.FluentFuture; 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.TransactionStatus; 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; @@ -31,7 +30,7 @@ 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.yangtools.yang.common.RpcResult; +import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.slf4j.Logger; @@ -92,7 +91,7 @@ final class ReadWriteTransaction implements DOMDataReadWriteTransaction { } @Override - public ListenableFuture<RpcResult<TransactionStatus>> commit() { + public FluentFuture<? extends CommitInfo> commit() { return delegateWriteTx.commit(); } 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 cd47c65db..b2ed5265f 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 @@ -18,26 +18,22 @@ package io.fd.honeycomb.data.impl; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; -import static org.opendaylight.controller.md.sal.common.api.TransactionStatus.CANCELED; -import static org.opendaylight.controller.md.sal.common.api.TransactionStatus.COMMITED; -import static org.opendaylight.controller.md.sal.common.api.TransactionStatus.FAILED; -import static org.opendaylight.controller.md.sal.common.api.TransactionStatus.NEW; -import static org.opendaylight.controller.md.sal.common.api.TransactionStatus.SUBMITED; 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 com.google.common.util.concurrent.ListenableFuture; import io.fd.honeycomb.data.DataModification; +import io.fd.honeycomb.translate.TranslationException; import java.util.function.Consumer; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; -import org.opendaylight.controller.md.sal.common.api.TransactionStatus; +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.controller.md.sal.dom.api.DOMDataWriteTransaction; -import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.slf4j.Logger; @@ -52,7 +48,7 @@ final class WriteTransaction implements DOMDataWriteTransaction { private DataModification operationalModification; @Nullable private DataModification configModification; - private TransactionStatus status = NEW; + private TransactionStatus status = TransactionStatus.NEW; private WriteTransaction(@Nullable final DataModification configModification, @Nullable final DataModification operationalModification) { @@ -61,7 +57,7 @@ final class WriteTransaction implements DOMDataWriteTransaction { } private void checkIsNew() { - Preconditions.checkState(status == NEW, "Transaction was submitted or canceled"); + Preconditions.checkState(status == TransactionStatus.NEW, "Transaction was submitted or canceled"); } @Override @@ -98,14 +94,14 @@ final class WriteTransaction implements DOMDataWriteTransaction { @Override public boolean cancel() { - if (status != NEW) { + if (status != TransactionStatus.NEW) { // only NEW transactions can be cancelled return false; } else { if (configModification != null) { configModification.close(); } - status = CANCELED; + status = TransactionStatus.CANCELED; return true; } } @@ -117,35 +113,57 @@ final class WriteTransaction implements DOMDataWriteTransaction { handleOperation(store, (modification) -> modification.delete(path)); } + @Deprecated @Override public CheckedFuture<Void, TransactionCommitFailedException> submit() { LOG.trace("WriteTransaction.submit()"); checkIsNew(); try { - status = SUBMITED; - - if(configModification != null) { - configModification.commit(); - } - if(operationalModification != null) { - operationalModification.commit(); - } - - status = COMMITED; + validateAndCommit(); } catch (Exception e) { - status = FAILED; + status = TransactionStatus.FAILED; LOG.error("Submit failed", e); return Futures.immediateFailedCheckedFuture( - new TransactionCommitFailedException("Failed to validate DataTreeModification", e)); + new TransactionCommitFailedException("Failed to validate DataTreeModification", e)); } return Futures.immediateCheckedFuture(null); } + private void validateAndCommit() throws TranslationException { + status = TransactionStatus.SUBMITED; + // Validate first to catch any issues before attempting commit + if (configModification != null) { + configModification.validate(); + } + if (operationalModification != null) { + operationalModification.validate(); + } + + if (configModification != null) { + configModification.commit(); + } + if (operationalModification != null) { + operationalModification.commit(); + } + + status = TransactionStatus.COMMITED; + } + @Override - @Deprecated - public ListenableFuture<RpcResult<TransactionStatus>> commit() { - throw new UnsupportedOperationException("deprecated"); + public @NonNull FluentFuture<? extends CommitInfo> commit() { + LOG.trace("WriteTransaction.commit()"); + checkIsNew(); + try { + validateAndCommit(); + } catch (Exception e) { + status = TransactionStatus.FAILED; + LOG.error("Submit failed", e); + return FluentFuture + .from(Futures.immediateFailedFuture( + new TransactionCommitFailedException("Failed to validate DataTreeModification", e))); + } + return FluentFuture.from(Futures.immediateFuture(null)); } @Override @@ -169,4 +187,30 @@ final class WriteTransaction implements DOMDataWriteTransaction { @Nonnull final DataModification operationalData) { return new WriteTransaction(requireNonNull(configData), requireNonNull(operationalData)); } + + // TODO consider removing because original class was deprecated and removed, this is just temporary fix. + enum TransactionStatus { + /** + * The transaction has been freshly allocated. The user is still accessing + * it and it has not been sealed. + */ + NEW, + /** + * The transaction has been completed by the user and sealed. It is currently + * awaiting execution. + */ + SUBMITED, + /** + * The transaction has been successfully committed to backing store. + */ + COMMITED, + /** + * The transaction has failed to commit due to some underlying issue. + */ + FAILED, + /** + * Currently unused. + */ + CANCELED, + } } 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 4a0fb11a9..14d32784f 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 @@ -29,11 +29,9 @@ import java.util.Map; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; 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.DOMDataChangeListener; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -86,14 +84,6 @@ public class DataBrokerTest { } @Test(expected = UnsupportedOperationException.class) - public void testRegisterDataChangeListener() { - final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class); - final DOMDataChangeListener listener = mock(DOMDataChangeListener.class); - broker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, path, listener, - AsyncDataBroker.DataChangeScope.BASE); - } - - @Test(expected = UnsupportedOperationException.class) public void testCreateTransactionChain() { final TransactionChainListener listener = mock(TransactionChainListener.class); broker.createTransactionChain(listener); @@ -156,14 +146,6 @@ public class DataBrokerTest { } @Test(expected = UnsupportedOperationException.class) - public void testRegisterDataChangeListener() { - final YangInstanceIdentifier path = mock(YangInstanceIdentifier.class); - final DOMDataChangeListener listener = mock(DOMDataChangeListener.class); - broker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, path, listener, - AsyncDataBroker.DataChangeScope.BASE); - } - - @Test(expected = UnsupportedOperationException.class) public void testCreateTransactionChain() { final TransactionChainListener listener = mock(TransactionChainListener.class); broker.createTransactionChain(listener); diff --git a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapterTest.java b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapterTest.java index dba707785..487b84d22 100644 --- a/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapterTest.java +++ b/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/PersistingDataTreeAdapterTest.java @@ -35,7 +35,7 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; @@ -47,7 +47,7 @@ public class PersistingDataTreeAdapterTest { @Mock private DataTree delegatingDataTree; @Mock - private SchemaService schemaService; + private DOMSchemaService schemaService; @Mock private DataTreeSnapshot snapshot; @Mock 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 86521f39b..d0cbb3235 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 @@ -27,6 +27,7 @@ import static org.mockito.MockitoAnnotations.initMocks; import com.google.common.util.concurrent.CheckedFuture; 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; @@ -115,9 +116,11 @@ public class WriteTransactionTest { } - @Test(expected = UnsupportedOperationException.class) - public void testCommit() { + @Test + public void testCommit() throws TranslationException { writeTx.commit(); + verify(configSnapshot).validate(); + verify(configSnapshot).commit(); } @Test |