2 * Copyright (c) 2016 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.binding.api;
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.FluentFuture;
12 import java.util.Collection;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.common.api.DataValidationFailedException;
15 import org.opendaylight.mdsal.common.api.PostCanCommitStep;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
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 DataTreeCommitCohort}s are hooked up into commit of data tree changes and MAY
26 * negatively affect performance of data broker / store.
29 * Implementations of this interface are discouraged, unless you really need ability to veto data
30 * 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 provided
35 * {@link DataTreeModification} for validation purposes.
38 * Use of any other external mutable state is discouraged, implementation MUST NOT use any
39 * transaction related APIs on same data broker / data store instance during invocation of
40 * callbacks, except ones provided as argument. Note that this MAY BE enforced by some
41 * implementations of {@link DataBroker} or Commit coordinator
44 * Note that this may be enforced by some implementations of {@link DataTreeCommitCohortRegistry}
45 * and such calls may fail.
47 * <h3>DataTreeCandidate assumptions</h3> Implementation SHOULD NOT make any assumptions on
48 * {@link DataTreeModification} being successfully committed until associated
49 * {@link PostCanCommitStep#preCommit()} and
50 * {@link org.opendaylight.mdsal.common.api.PostPreCommitStep#commit()} callback was invoked.
52 * <h2>Usage patterns</h2>
54 * <h3>Data Tree Validator</h3>
57 * Validator is implementation, which only validates {@link DataTreeModification} and does not
58 * retain any state derived from edited data - does not care if {@link DataTreeModification} was
59 * rejected afterwards or transaction was cancelled.
62 * Implementation may opt-out from receiving {@code preCommit()}, {@code commit()}, {@code abort()}
63 * callbacks by returning {@link PostCanCommitStep#NOOP}.
66 * TODO: Provide example and describe more usage patterns
68 * @author Tony Tkacik <ttkacik@cisco.com>
71 public interface DataTreeCommitCohort<T extends DataObject> {
73 * Validates the supplied data tree modifications and associates the cohort-specific steps with data broker
77 * If {@link DataValidationFailedException} is thrown by implementation, the commit of the supplied data
78 * will be prevented, with the DataBroker transaction providing the thrown exception as the cause of failure.
81 * Note the implementations are expected to do validation and processing asynchronous. Implementations SHOULD do
82 * processing fast, and are discouraged from blocking on any external resources. Implementation MUST NOT access
83 * any data transaction related APIs during invocation of the callback. Note that this may be enforced by some
84 * implementations of {@link DataTreeCommitCohortRegistry} and such calls may fail.
87 * Implementation MAY opt-out from implementing other steps by returning
88 * {@link PostCanCommitStep#NOOP}. Otherwise implementation MUST return instance of
89 * {@link PostCanCommitStep}, which will be used to invoke
90 * {@link org.opendaylight.mdsal.common.api.PostPreCommitStep#commit()} or
91 * {@link PostCanCommitStep#abort()} based on accepting data by data broker and or other commit cohorts.
93 * @param txId Transaction identifier. SHOULD be used only for reporting and correlation.
94 * Implementation MUST NOT use {@code txId} for validation.
95 * @param modifications the {@link DataTreeModification}s to be validated and committed.
96 * @return a FluentFuture which will successfully complete with the user-supplied implementation of
97 * {@link PostCanCommitStep} if all candidates are valid, or a failed future with a
98 * {@link DataValidationFailedException} if and only if a provided
99 * {@link DataTreeModification} instance did not pass validation. Users are encouraged to use
100 * more specific subclasses of this exception to provide additional information about
101 * validation failure reason.
103 FluentFuture<PostCanCommitStep> canCommit(@NonNull Object txId,
104 @NonNull Collection<DataTreeModification<T>> modifications);