blob: 659718441c0f3ae36d4035fcc38178a3a283b4cf [file] [log] [blame]
Sithara Punnassery589fac22016-10-03 11:51:53 -07001/*
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 */
16package org.onosproject.incubator.elasticcfg;
17
18import org.onosproject.event.ListenerService;
19
20import java.util.concurrent.CompletableFuture;
21
22/**
23 * Service for storing and distributing elastic configuration data.
24 */
25public 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.
136 *
137 */
138 CompletableFuture<ConfigNode> getNode(ConfigStoreType store,
139 ConfigNodePath path, TraversalMode mode,
140 ConfigFilter filter);
141
142 /**
143 * Returns the number of children under the given path, excluding
144 * the node at the path.
145 *
146 * @param store type of store which the application wants to access.
147 * @param path data structure with absolute path to the parent and
148 * relative path to the node
149 * @param filter how the value nodes should be filtered
150 * @return future that will be completed with {@code Integer}, the
151 * count of the children
152 * after applying the filtering conditions as well.
153 * Future will be completed with a {@code FailedException} if path
154 * does not point to a valid node
155 */
156 CompletableFuture<Integer> getNumberOfChildren(ConfigStoreType store,
157 ConfigNodePath path, ConfigFilter filter);
158
159 //TODO
160 /**
161 * Filter
162 * What should be the filtering conditions?
163 * a list of keys? node attribute/s? level1 children?
164 * Merge Trees
165 * add sub tree
166 * delete subtree
167 * update sub tree
168 * get sub tree
169 * How to handle big subtrees?
170 * how many levels? how many results to limit?
171 */
172
173 /**
174 * Registers a listener to be notified when the subtree rooted at
175 * the specified path
176 * is modified.
177 *
178 * @param store type of store which the application wants to access.
179 * @param path data structure with absolute path to the parent and
180 * relative path to the node
181 * @param listener listener to be notified
182 * @return a future that is completed when the operation completes
183 */
184 CompletableFuture<Void> addConfigListener(ConfigStoreType store,
185 ConfigNodePath path,
186 ElasticConfigListener listener);
187
188 /**
189 * Unregisters a previously added listener.
190 *
191 * @param listener listener to unregister
192 * @return a future that is completed when the operation completes
193 */
194 CompletableFuture<Void> removeConfigListener(ElasticConfigListener listener);
195}