2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.dom.api;
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.mdsal.common.api.DataValidationFailedException;
14 import org.opendaylight.mdsal.common.api.PostCanCommitStep;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 * Commit cohort participating in commit of data modification, which can validate data tree
20 * modifications, with option to reject supplied modification, and with callbacks describing state
23 * <h2>Performance implications</h2>
25 * {@link DOMDataTreeCommitCohort}s are hooked up into commit of data tree changes and MAY
26 * negatively affect performance of data broker / store.
28 * Implementations of this interface are discouraged, unless you really need ability to veto data
29 * tree changes, or to provide external state change in sync with visibility of commited data.
32 * <h2>Implementation requirements</h2>
34 * <h3>Correctness assumptions</h3> Implementation SHOULD use only {@link DOMDataTreeCandidate} and
35 * provided {@link SchemaContext} for validation purposes.
37 * Use of any other external mutable state is discouraged, implementation MUST NOT use any
38 * transaction related APIs on same data broker / data store instance during invocation of
39 * callbacks, except ones provided as argument. Note that this MAY BE enforced by some
40 * implementations of {@link DOMDataBroker} or DOMDataCommitCoordinator
42 * Note that this may be enforced by some implementations of {@link DOMDataTreeCommitCohortRegistry}
43 * and such calls may fail.
45 * <h3>Correct model usage</h3> If implementation is performing YANG-model driven validation
46 * implementation SHOULD use provided schema context.
48 * Any other instance of {@link SchemaContext} obtained by other means, may not be valid for
49 * associated DOMDataTreeCandidate and it may lead to incorrect validation or processing of provided
52 * <h3>DataTreeCandidate assumptions</h3> Implementation SHOULD NOT make any assumptions on
53 * {@link DOMDataTreeCandidate} being successfully committed until associated
54 * {@link PostCanCommitStep#preCommit()} and
55 * {@link org.opendaylight.mdsal.common.api.PostPreCommitStep#commit()} callback was invoked.
58 * <h2>Usage patterns</h2>
60 * <h3>Data Tree Validator</h3>
62 * Validator is implementation, which only validates {@link DOMDataTreeCandidate} and does not
63 * retain any state derived from edited data - does not care if {@link DOMDataTreeCandidate} was
64 * rejected afterwards or transaction was cancelled.
66 * Implementation may opt-out from receiving {@code preCommit()}, {@code commit()}, {@code abort()}
67 * callbacks by returning {@link PostCanCommitStep#NOOP}.
69 * TODO: Provide example and describe more usage patterns
71 * @author Tony Tkacik <ttkacik@cisco.com>
75 public interface DOMDataTreeCommitCohort {
78 * Validates supplied data tree candidate and associates cohort-specific steps with data broker
81 * If {@link DataValidationFailedException} is thrown by implementation, commit of supplied data
82 * will be prevented, with the DataBroker transaction providing the thrown exception as the
85 * Note the implementations are expected to do validation and processing asynchronous.
87 * Implementations SHOULD do processing fast, and are discouraged SHOULD NOT block on any
90 * Implementation MUST NOT access any data transaction related APIs during invocation of
91 * callback. Note that this may be enforced by some implementations of
92 * {@link DOMDataTreeCommitCohortRegistry} and such calls may fail.
94 * Implementation MAY opt-out from implementing other steps by returning
95 * {@link PostCanCommitStep#NOOP}. Otherwise implementation MUST return instance of
96 * {@link PostCanCommitStep}, which will be used to invoke
97 * {@link org.opendaylight.mdsal.common.api.PostPreCommitStep#commit()} or
98 * {@link PostCanCommitStep#abort()} based on accepting data by data broker and or other commit
101 * @param txId Transaction identifier. SHOULD be used only for reporting and correlation.
102 * Implementation MUST NOT use {@code txId} for validation.
103 * @param candidate Data Tree candidate to be validated and committed.
104 * @param ctx Schema Context to which Data Tree candidate should conform.
105 * @return Checked future which will successfully complete with user-supplied implementation of
106 * {@link PostCanCommitStep} if data are valid, or failed check future with
107 * {@link DataValidationFailedException} if and only if provided
108 * {@link DOMDataTreeCandidate} did not pass validation. Users are encouraged to use
109 * more specific subclasses of this exception to provide additional information about
110 * validation failure reason.
113 CheckedFuture<PostCanCommitStep, DataValidationFailedException> canCommit(@Nonnull Object txId,
114 @Nonnull DOMDataTreeCandidate candidate, @Nonnull SchemaContext ctx);