361be6800c41d22a4b02f9ed9441c1018b126c98
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / ModificationApplyOperation.java
1 /*
2  * Copyright (c) 2014 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.controller.md.sal.dom.store.impl;
9
10 import org.opendaylight.controller.md.sal.dom.store.impl.tree.NodeModification;
11 import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreMetadataNode;
12 import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreTreeNode;
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
15
16 import com.google.common.base.Optional;
17 import com.google.common.primitives.UnsignedLong;
18
19 /**
20  *
21  * Operation responsible for applying {@link NodeModification} on tree.
22  *
23  * Operation is composite - operation on top level node consists of
24  * suboperations on child nodes. This allows to walk operation hierarchy and
25  * invoke suboperations independently.
26  *
27  * <b>Implementation notes</b>
28  * <ul>
29  * <li>
30  * Implementations MUST expose all nested suboperations which operates on child
31  * nodes expose via {@link #getChild(PathArgument)} method.
32  * <li>Same suboperations SHOULD be used when invoked via
33  * {@link #apply(NodeModification, Optional)} if applicable.
34  *
35  *
36  * Hierarchical composite operation which is responsible for applying
37  * modification on particular subtree and creating updated subtree
38  *
39  *
40  */
41 public interface ModificationApplyOperation extends StoreTreeNode<ModificationApplyOperation> {
42
43     /**
44      *
45      * Implementation of this operation must be stateless and must not change
46      * state of this object.
47      *
48      * @param modification
49      *            NodeModification to be applied
50      * @param storeMeta
51      *            Store Metadata Node on which NodeModification should be
52      *            applied
53      * @param subtreeVersion New subtree version of parent node
54      * @throws IllegalArgumentException
55      *             If it is not possible to apply Operation on provided Metadata
56      *             node
57      * @return new {@link StoreMetadataNode} if operation resulted in updating
58      *         node, {@link Optional#absent()} if {@link NodeModification}
59      *         resulted in deletion of this node.
60      */
61     Optional<StoreMetadataNode> apply(NodeModification modification, Optional<StoreMetadataNode> storeMeta, UnsignedLong subtreeVersion);
62
63     /**
64      *
65      * Performs structural verification of NodeModification, such as writen values / types
66      * uses right structural elements.
67      *
68      * @param modification to be verified.
69      * @throws IllegalArgumentException If provided NodeModification does not adhere to the structure.
70      */
71     void verifyStructure(NodeModification modification) throws IllegalArgumentException;
72
73     /**
74      * Returns a suboperation for specified tree node
75      *
76      * @return Reference to suboperation for specified tree node, {@link Optional#absent()}
77      *    if suboperation is not supported for specified tree node.
78      */
79     @Override
80     Optional<ModificationApplyOperation> getChild(PathArgument child);
81
82     /**
83     *
84     * Checks if provided node modification could be applied to current metadata node.
85     *
86     * @param modification Modification
87     * @param current Metadata Node to which modification should be applied
88     * @return true if modification is applicable
89     *         false if modification is no applicable
90      * @throws DataPreconditionFailedException
91     */
92     void checkApplicable(InstanceIdentifier path, NodeModification modification, Optional<StoreMetadataNode> current) throws DataPreconditionFailedException;
93 }