db84128c2b5bd2c03052d92d5523ca9b0e8866d8
[netconf.git] / netconf / mdsal-netconf-connector / src / main / java / org / opendaylight / netconf / mdsal / connector / DOMDataTransactionValidator.java
1 /*
2  * Copyright (c) 2018 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.mdsal.connector;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
13 import org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
15 import org.opendaylight.mdsal.dom.api.DOMServiceExtension;
16 import org.opendaylight.yangtools.yang.common.OperationFailedException;
17 import org.opendaylight.yangtools.yang.common.RpcError;
18 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
19
20 /**
21  * A {@link DOMServiceExtension} which allows users to provide Validate capability for {@link DOMDataBroker}.
22  *
23  * <p> See <a href="https://tools.ietf.org/html/rfc4741#section-8.6">RFC4741 section 8.6</a> for details.
24  */
25 @Beta
26 public interface DOMDataTransactionValidator extends DOMDataBrokerExtension {
27     /**
28      * Validates state of the data tree associated with the provided {@link DOMDataTreeWriteTransaction}.
29      *
30      * <p>The operation should not have any side-effects on the transaction state.
31      *
32      * <p>It can be executed many times, providing the same results if the state of the transaction has not been
33      * changed.
34      *
35      * @param transaction
36      *     transaction to be validated
37      * @return
38      *     a CheckedFuture containing the result of the validate operation. The future blocks until the validation
39      *     operation is complete. A successful validate returns nothing. On failure, the Future will fail
40      *     with a {@link ValidationFailedException} or an exception derived from ValidationFailedException.
41      */
42     CheckedFuture<Void, ValidationFailedException> validate(DOMDataTreeWriteTransaction transaction);
43
44     /**
45      * Failed validation of asynchronous transaction. This exception is raised and returned when transaction validation
46      * failed.
47      */
48     class ValidationFailedException extends OperationFailedException {
49         private static final long serialVersionUID = 1L;
50
51         public ValidationFailedException(final String message, final Throwable cause) {
52             super(message, cause, RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "invalid-value", message,
53                 null, null, cause));
54         }
55
56         public ValidationFailedException(final String message) {
57             this(message, null);
58         }
59     }
60 }
61