Sithara Punnassery | 589fac2 | 2016-10-03 11:51:53 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Sithara Punnassery | 589fac2 | 2016-10-03 11:51:53 -0700 | [diff] [blame] | 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.incubator.elasticcfg; |
| 17 | |
| 18 | import org.onosproject.event.ListenerService; |
| 19 | |
| 20 | import java.util.concurrent.CompletableFuture; |
| 21 | |
| 22 | /** |
| 23 | * Service for storing and distributing elastic configuration data. |
| 24 | */ |
| 25 | public interface ElasticConfigService |
| 26 | extends ListenerService<ElasticConfigEvent, ElasticConfigListener> { |
| 27 | /** |
| 28 | * Adds a new node to the elastic config store. |
| 29 | * |
| 30 | * @param store type of store to which the application wants to add the node to. |
| 31 | * @param path data structure with absolute path to the parent and relative |
| 32 | * path to the node |
| 33 | * @param node data structure with nodetype and value to be stored at the node |
| 34 | * @return future that is completed with {@code true} if the new node was successfully |
| 35 | * added. Future will be completed with {@code false} if a node already exists at |
| 36 | * the specified path. Future will be completed exceptionally with a |
| 37 | * {@code FailedException} if the parent node (for the node to create) does not exist. |
| 38 | */ |
| 39 | CompletableFuture<Boolean> addNode(ConfigStoreType store, |
| 40 | ConfigNodePath path, ConfigNode node); |
| 41 | |
| 42 | /** |
| 43 | * Removes a node from the elastic config store. |
| 44 | * |
| 45 | * @param store type of store which the application wants to access. |
| 46 | * @param path data structure with absolute path to the parent and |
| 47 | * relative path to the node |
| 48 | * @return future for the previous value. Future will be completed with a |
| 49 | * {@code FailedException} if the node to be removed is either the root |
| 50 | * node or has one or more children or if the node to be removed does not exist. |
| 51 | */ |
| 52 | CompletableFuture<ConfigNode> removeNode(ConfigStoreType store, ConfigNodePath path); |
| 53 | |
| 54 | /** |
| 55 | * Creates/Updates a node in the elastic config store. |
| 56 | * |
| 57 | * @param store type of store which the application wants to access. |
| 58 | * @param path data structure with absolute path to the parent and |
| 59 | * relative path to the node |
| 60 | * @param node data structure with nodetype and new value to be stored at the node |
| 61 | * @return future for the previous value. Future will be completed with {@code null} |
| 62 | * if there was no node previously at that path. |
| 63 | * Future will be completed with a {@code FailedException} |
| 64 | * if the parent node (for the node to create/update) does not exist. |
| 65 | */ |
| 66 | CompletableFuture<ConfigNode> updateNode(ConfigStoreType store, |
| 67 | ConfigNodePath path, ConfigNode node); |
| 68 | |
| 69 | /** |
| 70 | * Creates nodes in the elastic config store, recursively by creating |
| 71 | * all missing intermediate nodes in the path. |
| 72 | * |
| 73 | * @param store type of store which the application wants to access. |
| 74 | * @param path data structure with absolute path to the parent and relative |
| 75 | * path to the node |
| 76 | * @param node recursive data structure with nodetype and value to |
| 77 | * be stored at the node |
| 78 | * @return future that is completed with {@code true} if all the new |
| 79 | * nodes were successfully |
| 80 | * created. Future will be completed with {@code false} if any node |
| 81 | * already exists at the specified path |
| 82 | * //TODO |
| 83 | */ |
| 84 | CompletableFuture<Boolean> createRecursive(ConfigStoreType store, |
| 85 | ConfigNodePath path, ConfigNode node); |
| 86 | |
| 87 | /** |
| 88 | * Delete nodes in the elastic config store, recursively by deleting all |
| 89 | * intermediate nodes in the path. |
| 90 | * |
| 91 | * @param store type of store which the appplication wants to access. |
| 92 | * @param path data structure with absolute path to the parent and |
| 93 | * relative path to the node |
| 94 | * @return future that is completed with {@code true} if all the |
| 95 | * nodes under the given path including the node at the path could |
| 96 | * be successfully deleted. Future will be completed with {@code false} |
| 97 | * if the node at the given path or any parent node |
| 98 | * did not exist //TODO |
| 99 | */ |
| 100 | CompletableFuture<Boolean> deleteRecursive(ConfigStoreType store, ConfigNodePath path); |
| 101 | |
| 102 | /** |
| 103 | * Creates/Updates nodes in the elastic config store, recursively by creating |
| 104 | * all missing intermediate nodes in the path. |
| 105 | * |
| 106 | * @param store type of store which the appplication wants to access. |
| 107 | * @param path data structure with absolute path to the parent and |
| 108 | * relative path to the node |
| 109 | * @param node recursive data structure with nodetype and value to |
| 110 | * be stored at the node |
| 111 | * @return future that is completed with {@code true} if all the |
| 112 | * nodes under the given path |
| 113 | * including the node at the path could be successfully updated. |
| 114 | * Future will be completed with {@code false} if the node at the |
| 115 | * given path or any parent node |
| 116 | * did not exist //TODO |
| 117 | */ |
| 118 | CompletableFuture<Boolean> updateRecursive(ConfigStoreType store, |
| 119 | ConfigNodePath path, ConfigNode node); |
| 120 | |
| 121 | /** |
| 122 | * Returns a value node or subtree under the given path. |
| 123 | * |
| 124 | * @param store type of store which the application wants to access. |
| 125 | * @param path data structure with absolute path to the parent and |
| 126 | * relative path to the node |
| 127 | * @param mode whether to retrieve the nodes recursively or not |
| 128 | * @param filter filtering conditions to be applied on the result |
| 129 | * list of nodes. |
| 130 | * @return future that will be completed either with a value node |
| 131 | * or a recursive data structure containing the subtree; |
| 132 | * will be completed with {@code null} if |
| 133 | * after applying the filter, the result is an empty list of nodes. |
| 134 | * Future will be completed with a {@code FailedException} if path |
| 135 | * does not point to a valid node. |
Sithara Punnassery | 589fac2 | 2016-10-03 11:51:53 -0700 | [diff] [blame] | 136 | */ |
Sho SHIMIZU | 74e6463 | 2016-10-19 23:14:02 -0700 | [diff] [blame] | 137 | CompletableFuture<ConfigNode> getNode(ConfigStoreType store, |
| 138 | ConfigNodePath path, TraversalMode mode, |
| 139 | ConfigFilter filter); |
Sithara Punnassery | 589fac2 | 2016-10-03 11:51:53 -0700 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * Returns the number of children under the given path, excluding |
| 143 | * the node at the path. |
| 144 | * |
| 145 | * @param store type of store which the application wants to access. |
| 146 | * @param path data structure with absolute path to the parent and |
| 147 | * relative path to the node |
| 148 | * @param filter how the value nodes should be filtered |
| 149 | * @return future that will be completed with {@code Integer}, the |
| 150 | * count of the children |
| 151 | * after applying the filtering conditions as well. |
| 152 | * Future will be completed with a {@code FailedException} if path |
| 153 | * does not point to a valid node |
| 154 | */ |
| 155 | CompletableFuture<Integer> getNumberOfChildren(ConfigStoreType store, |
| 156 | ConfigNodePath path, ConfigFilter filter); |
| 157 | |
| 158 | //TODO |
| 159 | /** |
| 160 | * Filter |
| 161 | * What should be the filtering conditions? |
| 162 | * a list of keys? node attribute/s? level1 children? |
| 163 | * Merge Trees |
| 164 | * add sub tree |
| 165 | * delete subtree |
| 166 | * update sub tree |
| 167 | * get sub tree |
| 168 | * How to handle big subtrees? |
| 169 | * how many levels? how many results to limit? |
| 170 | */ |
| 171 | |
| 172 | /** |
| 173 | * Registers a listener to be notified when the subtree rooted at |
| 174 | * the specified path |
| 175 | * is modified. |
| 176 | * |
| 177 | * @param store type of store which the application wants to access. |
| 178 | * @param path data structure with absolute path to the parent and |
| 179 | * relative path to the node |
| 180 | * @param listener listener to be notified |
| 181 | * @return a future that is completed when the operation completes |
| 182 | */ |
| 183 | CompletableFuture<Void> addConfigListener(ConfigStoreType store, |
| 184 | ConfigNodePath path, |
| 185 | ElasticConfigListener listener); |
| 186 | |
| 187 | /** |
| 188 | * Unregisters a previously added listener. |
| 189 | * |
| 190 | * @param listener listener to unregister |
| 191 | * @return a future that is completed when the operation completes |
| 192 | */ |
Sho SHIMIZU | 74e6463 | 2016-10-19 23:14:02 -0700 | [diff] [blame] | 193 | CompletableFuture<Void> removeConfigListener(ElasticConfigListener listener); |
| 194 | } |