summaryrefslogtreecommitdiffstats
path: root/infra/data-impl/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'infra/data-impl/src/main/java')
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/DataBroker.java6
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ReadWriteTransaction.java12
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ValidableTransaction.java45
-rw-r--r--infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/WriteTransaction.java35
4 files changed, 80 insertions, 18 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 a60bf3415..1952f8778 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
@@ -33,6 +33,7 @@ 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.netconf.mdsal.connector.DOMDataTransactionValidator;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -81,7 +82,10 @@ public class DataBroker implements DOMDataBroker, Closeable {
@Nonnull
@Override
public Map<Class<? extends DOMDataBrokerExtension>, DOMDataBrokerExtension> getSupportedExtensions() {
- return Collections.emptyMap();
+ return Collections.singletonMap(
+ DOMDataTransactionValidator.class,
+ (DOMDataTransactionValidator) tx -> ((ValidableTransaction)tx).validate()
+ );
}
/**
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 f26810e15..c7d54f0ec 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
@@ -31,6 +31,7 @@ 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.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.Logger;
@@ -40,15 +41,15 @@ import org.slf4j.LoggerFactory;
* Composite DOM transaction that delegates reads to a {@link DOMDataReadTransaction} delegate and writes to a {@link
* DOMDataWriteTransaction} delegate.
*/
-final class ReadWriteTransaction implements DOMDataReadWriteTransaction {
+final class ReadWriteTransaction implements DOMDataReadWriteTransaction, ValidableTransaction {
private static final Logger LOG = LoggerFactory.getLogger(ReadWriteTransaction.class);
private final DOMDataReadOnlyTransaction delegateReadTx;
- private final DOMDataWriteTransaction delegateWriteTx;
+ private final ValidableTransaction delegateWriteTx;
ReadWriteTransaction(@Nonnull final DOMDataReadOnlyTransaction delegateReadTx,
- @Nonnull final DOMDataWriteTransaction delegateWriteTx) {
+ @Nonnull final ValidableTransaction delegateWriteTx) {
this.delegateReadTx = Preconditions.checkNotNull(delegateReadTx, "delegateReadTx should not be null");
this.delegateWriteTx = Preconditions.checkNotNull(delegateWriteTx, "delegateWriteTx should not be null");
}
@@ -111,5 +112,10 @@ final class ReadWriteTransaction implements DOMDataReadWriteTransaction {
public Object getIdentifier() {
return this;
}
+
+ @Override
+ public CheckedFuture<Void, DOMDataTransactionValidator.ValidationFailedException> validate() {
+ return delegateWriteTx.validate();
+ }
}
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
new file mode 100644
index 000000000..0c67f863f
--- /dev/null
+++ b/infra/data-impl/src/main/java/io/fd/honeycomb/data/impl/ValidableTransaction.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2018 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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 org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator;
+import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator.ValidationFailedException;
+
+/**
+ * An {@link DOMDataWriteTransaction} than can be validated.
+ * @see DOMDataTransactionValidator
+ */
+@Beta
+interface ValidableTransaction extends DOMDataWriteTransaction {
+ /**
+ * Validates state of the data tree associated with the provided {@link DOMDataWriteTransaction}.
+ *
+ * <p>The operation should not have any side-effects on the transaction state.
+ *
+ * <p>It can be executed many times, providing the same results
+ * 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.
+ */
+ CheckedFuture<Void, ValidationFailedException> 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 b2ed5265f..91b48cc10 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
@@ -32,7 +32,7 @@ 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.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.netconf.mdsal.connector.DOMDataTransactionValidator;
import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -40,7 +40,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@NotThreadSafe
-final class WriteTransaction implements DOMDataWriteTransaction {
+final class WriteTransaction implements ValidableTransaction {
private static final Logger LOG = LoggerFactory.getLogger(WriteTransaction.class);
@@ -120,7 +120,7 @@ final class WriteTransaction implements DOMDataWriteTransaction {
checkIsNew();
try {
- validateAndCommit();
+ doCommit();
} catch (Exception e) {
status = TransactionStatus.FAILED;
LOG.error("Submit failed", e);
@@ -130,16 +130,8 @@ final class WriteTransaction implements DOMDataWriteTransaction {
return Futures.immediateCheckedFuture(null);
}
- private void validateAndCommit() throws TranslationException {
+ private void doCommit() 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();
}
@@ -155,7 +147,7 @@ final class WriteTransaction implements DOMDataWriteTransaction {
LOG.trace("WriteTransaction.commit()");
checkIsNew();
try {
- validateAndCommit();
+ doCommit();
} catch (Exception e) {
status = TransactionStatus.FAILED;
LOG.error("Submit failed", e);
@@ -171,6 +163,21 @@ final class WriteTransaction implements DOMDataWriteTransaction {
return this;
}
+ @Override
+ public CheckedFuture<Void, DOMDataTransactionValidator.ValidationFailedException> validate() {
+ try {
+ if (configModification != null) {
+ configModification.validate();
+ }
+ if (operationalModification != null) {
+ operationalModification.validate();
+ }
+ } catch (Exception e) {
+ return Futures.immediateFailedCheckedFuture(new DOMDataTransactionValidator.ValidationFailedException(e.getMessage(), e.getCause()));
+ }
+ return Futures.immediateCheckedFuture(null);
+ }
+
@Nonnull
static WriteTransaction createOperationalOnly(@Nonnull final DataModification operationalData) {
@@ -188,7 +195,7 @@ final class WriteTransaction implements DOMDataWriteTransaction {
return new WriteTransaction(requireNonNull(configData), requireNonNull(operationalData));
}
- // TODO consider removing because original class was deprecated and removed, this is just temporary fix.
+ // TODO consider refactor based on implemented contract.
enum TransactionStatus {
/**
* The transaction has been freshly allocated. The user is still accessing