e7cfca516550937e42cd662e3833d534b0155a28
[netconf.git] /
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.server.mdsal;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.FluentFuture;
12 import java.io.Serial;
13 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
14 import org.opendaylight.mdsal.dom.api.DOMDataBrokerExtension;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
16 import org.opendaylight.mdsal.dom.api.DOMServiceExtension;
17 import org.opendaylight.yangtools.yang.common.ErrorTag;
18 import org.opendaylight.yangtools.yang.common.ErrorType;
19 import org.opendaylight.yangtools.yang.common.OperationFailedException;
20 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
21
22 /**
23  * A {@link DOMServiceExtension} which allows users to provide Validate capability for {@link DOMDataBroker}.
24  *
25  * <p> See <a href="https://tools.ietf.org/html/rfc4741#section-8.6">RFC4741 section 8.6</a> for details.
26  */
27 @Beta
28 public interface DOMDataTransactionValidator extends DOMDataBrokerExtension {
29     /**
30      * Validates state of the data tree associated with the provided {@link DOMDataTreeWriteTransaction}.
31      *
32      * <p>The operation should not have any side-effects on the transaction state.
33      *
34      * <p>It can be executed many times, providing the same results if the state of the transaction has not been
35      * changed.
36      *
37      * @param transaction
38      *     transaction to be validated
39      * @return
40      *     a FluentFuture containing the result of the validate operation. The future blocks until the validation
41      *     operation is complete. A successful validate returns nothing. On failure, the Future will fail
42      *     with a {@link ValidationFailedException} or an exception derived from ValidationFailedException.
43      */
44     FluentFuture<Void> validate(DOMDataTreeWriteTransaction transaction);
45
46     /**
47      * Failed validation of asynchronous transaction. This exception is raised and returned when transaction validation
48      * failed.
49      */
50     class ValidationFailedException extends OperationFailedException {
51         @Serial
52         private static final long serialVersionUID = 1L;
53
54         public ValidationFailedException(final String message, final Throwable cause) {
55             super(message, cause, RpcResultBuilder.newError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, message,
56                 null, null, cause));
57         }
58
59         public ValidationFailedException(final String message) {
60             this(message, null);
61         }
62     }
63 }
64