Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.config; |
| 17 | |
Sithara Punnassery | 0620879 | 2017-02-10 16:25:29 -0800 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 19 | import org.onosproject.yang.model.DataNode; |
| 20 | import org.onosproject.yang.model.ResourceId; |
Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 21 | import org.onosproject.store.Store; |
| 22 | |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame^] | 23 | import java.util.Collection; |
Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 24 | import java.util.concurrent.CompletableFuture; |
| 25 | |
| 26 | /** |
| 27 | * Store interface for storing and distributing dynamic configuration data. |
| 28 | */ |
Sithara Punnassery | 0620879 | 2017-02-10 16:25:29 -0800 | [diff] [blame] | 29 | @Beta |
Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 30 | public interface DynamicConfigStore |
| 31 | extends Store<DynamicConfigEvent, DynamicConfigStoreDelegate> { |
| 32 | /** |
| 33 | * Adds a new node in the dynamic config store. The new node will not be |
| 34 | * added if there is a node with the same identifier, already present at |
| 35 | * the specified path or any of the parent nodes were not present in the |
| 36 | * path leading up to the requested node. |
| 37 | * |
| 38 | * @param path data structure with absolute path to the parent |
| 39 | * @param node recursive data structure, holding a leaf node or a subtree |
| 40 | * @return future that is completed with {@code true} if the new node was |
| 41 | * successfully added or completed exceptionally with |
| 42 | * {@code FailedException} if node addition failed |
| 43 | */ |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 44 | CompletableFuture<Boolean> addNode(ResourceId path, DataNode node); |
Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 45 | |
| 46 | /** |
| 47 | * Adds a new node in the dynamic config store. |
| 48 | * Creates any missing parent nodes, leading up to the given node. Node |
| 49 | * will not be added if there is a node with the same identifier, already |
| 50 | * present at the specified path. |
| 51 | * |
| 52 | * @param path data structure with absolute path to the parent |
| 53 | * @param node recursive data structure, holding a leaf node or a subtree |
| 54 | * @return future that is completed with {@code true} if the node was |
| 55 | * successfully added or completed exceptionally with |
| 56 | * {@code FailedException} if the node addition failed |
| 57 | */ |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 58 | CompletableFuture<Boolean> addRecursive(ResourceId path, DataNode node); |
Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * Reads the requested node from the dynamic config store. |
| 62 | * This operation would get translated to reading a leaf node or a subtree. |
| 63 | * This would fail if the requested node was not present or any parent nodes |
| 64 | * in the path were not present. |
| 65 | * |
| 66 | * @param path data structure with absolute path to the intended node |
| 67 | * @param filter filtering conditions to be applied on the result list of nodes |
| 68 | * @return future that will be completed with a DataNode (will be an empty |
| 69 | * DataNode if after applying the filter, the result is an empty list of nodes) |
| 70 | * or completed with {@code FailedException} if the node could not be read |
| 71 | */ |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 72 | CompletableFuture<DataNode> readNode(ResourceId path, Filter filter); |
Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Updates an existing node in the dynamic config store. |
| 76 | * This request would fail if the requested node, any of its children or |
| 77 | * any parent nodes in the path were not present. |
| 78 | * |
| 79 | * @param path data structure with absolute path to the parent |
| 80 | * @param node recursive data structure, holding a leaf node or a subtree |
| 81 | * @return future that is completed with {@code true} if the node was |
| 82 | * successfully updated or completed exceptionally with |
| 83 | * {@code FailedException} if the update request failed |
| 84 | */ |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 85 | CompletableFuture<Boolean> updateNode(ResourceId path, DataNode node); |
Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * Updates an existing node in the dynamic config store. |
| 89 | * Any missing children will be created with this request. The update will |
| 90 | * fail if the requested node or any of the parent nodes in the path |
| 91 | * were not present. |
| 92 | * |
| 93 | * @param path data structure with absolute path to the parent |
| 94 | * @param node recursive data structure, holding a leaf node or a subtree |
| 95 | * @return future that is completed with {@code true} if the node was |
| 96 | * successfully updated or completed exceptionally with |
| 97 | * {@code FailedException} if the update request failed |
| 98 | */ |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 99 | CompletableFuture<Boolean> updateNodeRecursive(ResourceId path, DataNode node); |
Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * Replaces nodes in the dynamic config store. |
| 103 | * This will ensure that only the tree structure in the given DataNode will |
| 104 | * be in place after a replace. This would fail if the requested node or |
| 105 | * any of the parent nodes in the path were not present. |
| 106 | * |
| 107 | * @param path data structure with absolute path to the parent |
| 108 | * @param node recursive data structure, holding a leaf node or a subtree |
| 109 | * @return future that is completed with {@code true} if the node was |
| 110 | * successfully replaced or completed exceptionally with |
| 111 | * {@code FailedException} if the replace request failed |
| 112 | */ |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 113 | CompletableFuture<Boolean> replaceNode(ResourceId path, DataNode node); |
Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * Removes a node from the dynamic config store. |
| 117 | * This would fail if the requested node or any of the parent nodes in the |
| 118 | * path were not present or the specified node is the root node or has one |
| 119 | * or more children. |
| 120 | * |
| 121 | * @param path data structure with absolute path to the intended node |
| 122 | * @return future that is completed with {@code true} if the node was |
| 123 | * successfully deleted or completed exceptionally with |
| 124 | * {@code FailedException} if the delete request failed |
| 125 | */ |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 126 | CompletableFuture<Boolean> deleteNode(ResourceId path); |
Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * Removes a subtree from the dynamic config store. |
| 130 | * This will delete all the children recursively, under the given node. |
| 131 | * Will fail if the requested node or any of the parent nodes in |
| 132 | * the path were not present. |
| 133 | * |
| 134 | * @param path data structure with absolute path to the intended node |
| 135 | * @return future that is completed with {@code true} if the delete was |
| 136 | * successful or completed exceptionally with |
| 137 | * {@code FailedException} if the delete request failed |
| 138 | */ |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 139 | CompletableFuture<Boolean> deleteNodeRecursive(ResourceId path); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame^] | 140 | |
| 141 | /** |
| 142 | * Adds a listener to be notified when a leaf or subtree rooted at the |
| 143 | * specified path is modified. |
| 144 | * |
| 145 | * @param path data structure with absolute path to the node being listened to |
| 146 | * @param listener listener to be notified |
| 147 | * @throws FailedException if the listener could not be added |
| 148 | */ |
| 149 | void addConfigListener(ResourceId path, DynamicConfigListener listener); |
| 150 | |
| 151 | /** |
| 152 | * Removes a previously added listener. |
| 153 | * |
| 154 | * @param path data structure with absolute path to the node being listened to |
| 155 | * @param listener listener to unregister |
| 156 | * @throws FailedException if the listener could not be removed |
| 157 | */ |
| 158 | void removeConfigListener(ResourceId path, DynamicConfigListener listener); |
| 159 | |
| 160 | /** |
| 161 | * Returns a collection of previously added listeners. |
| 162 | * |
| 163 | * @param path data structure with absolute path to the node being listened to |
| 164 | * @return a collection of previously added listeners |
| 165 | */ |
| 166 | Collection<? extends DynamicConfigListener> getConfigListener(ResourceId path); |
| 167 | //DynamicConfigListener getConfigListener(ResourceId path); |
Sithara Punnassery | ff11455 | 2017-01-10 11:40:55 -0800 | [diff] [blame] | 168 | } |