blob: 9f31621e1e9ea5107358c4300125348b5c5aebc8 [file] [log] [blame]
Sithara Punnassery9306e6b2017-02-06 15:38:19 -08001/*
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.config.impl;
17
Sithara Punnassery06208792017-02-10 16:25:29 -080018import com.google.common.annotations.Beta;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
24import org.apache.felix.scr.annotations.Service;
25import org.onlab.util.KryoNamespace;
26import org.onosproject.config.DynamicConfigEvent;
27import org.onosproject.config.DynamicConfigStore;
28import org.onosproject.config.DynamicConfigStoreDelegate;
Sithara Punnassery44e2a702017-03-06 15:38:10 -080029import org.onosproject.config.ResourceIdParser;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080030import org.onosproject.config.FailedException;
31import org.onosproject.config.Filter;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080032import org.onosproject.store.AbstractStore;
33import org.onosproject.store.serializers.KryoNamespaces;
34import org.onosproject.store.service.AsyncDocumentTree;
35import org.onosproject.store.service.ConsistentMap;
36import org.onosproject.store.service.DocumentPath;
37import org.onosproject.store.service.DocumentTreeEvent;
38import org.onosproject.store.service.DocumentTreeListener;
Sithara Punnassery44e2a702017-03-06 15:38:10 -080039import org.onosproject.store.service.IllegalDocumentModificationException;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080040import org.onosproject.store.service.MapEvent;
41import org.onosproject.store.service.MapEventListener;
Sithara Punnassery44e2a702017-03-06 15:38:10 -080042import org.onosproject.store.service.NoSuchDocumentPathException;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080043import org.onosproject.store.service.Serializer;
44import org.onosproject.store.service.StorageService;
45import org.onosproject.store.service.Versioned;
Sithara Punnassery44e2a702017-03-06 15:38:10 -080046import org.onosproject.yang.model.DataNode;
47import org.onosproject.yang.model.InnerNode;
48import org.onosproject.yang.model.KeyLeaf;
49import org.onosproject.yang.model.LeafListKey;
50import org.onosproject.yang.model.LeafNode;
51import org.onosproject.yang.model.ListKey;
52import org.onosproject.yang.model.NodeKey;
53import org.onosproject.yang.model.ResourceId;
54import org.onosproject.yang.model.SchemaId;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080055import org.slf4j.Logger;
56import org.slf4j.LoggerFactory;
Sithara Punnassery43833e12017-03-14 16:29:19 -070057import java.util.List;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080058import java.util.Map;
59import java.util.concurrent.CompletableFuture;
Sithara Punnassery4b091dc2017-03-02 17:22:40 -080060import java.util.concurrent.ExecutionException;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080061
Sithara Punnassery44e2a702017-03-06 15:38:10 -080062import static org.onosproject.config.DynamicConfigEvent.Type.NODE_ADDED;
63import static org.onosproject.config.DynamicConfigEvent.Type.NODE_UPDATED;
64import static org.onosproject.config.DynamicConfigEvent.Type.NODE_DELETED;
65import static org.onosproject.config.DynamicConfigEvent.Type.UNKNOWN_OPRN;
66
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080067/**
68 * Implementation of the dynamic config store.
69 */
Sithara Punnassery06208792017-02-10 16:25:29 -080070@Beta
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080071@Component(immediate = true)
72@Service
73public class DistributedDynamicConfigStore
74 extends AbstractStore<DynamicConfigEvent, DynamicConfigStoreDelegate>
75 implements DynamicConfigStore {
76 private final Logger log = LoggerFactory.getLogger(getClass());
77 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
78 protected StorageService storageService;
79 private AsyncDocumentTree<DataNode.Type> keystore;
Sithara Punnassery4b091dc2017-03-02 17:22:40 -080080 private ConsistentMap<String, LeafNode> objectStore;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080081 private final DocumentTreeListener<DataNode.Type> klistener = new InternalDocTreeListener();
Sithara Punnassery4b091dc2017-03-02 17:22:40 -080082 private final MapEventListener<String, LeafNode> olistener = new InternalMapListener();
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080083
84 @Activate
85 public void activateStore() {
86 KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder()
87 .register(KryoNamespaces.BASIC)
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080088 .register(java.lang.Class.class)
89 .register(DataNode.Type.class)
90 .register(LeafNode.class)
91 .register(InnerNode.class)
92 .register(ResourceId.class)
93 .register(NodeKey.class)
94 .register(SchemaId.class)
Sithara Punnassery43833e12017-03-14 16:29:19 -070095 .register(LeafListKey.class)
96 .register(ListKey.class)
97 .register(KeyLeaf.class)
Sithara Punnassery9306e6b2017-02-06 15:38:19 -080098 .register(java.util.LinkedHashMap.class);
99 keystore = storageService.<DataNode.Type>documentTreeBuilder()
100 .withSerializer(Serializer.using(kryoBuilder.build()))
101 .withName("config-key-store")
102 .withRelaxedReadConsistency()
103 .buildDocumentTree();
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800104 objectStore = storageService.<String, LeafNode>consistentMapBuilder()
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800105 .withSerializer(Serializer.using(kryoBuilder.build()))
106 .withName("config-object-store")
107 .withRelaxedReadConsistency()
108 .build();
109 keystore.addListener(klistener);
110 objectStore.addListener(olistener);
111 log.info("DyanmicConfig Store Active");
112 }
113
114 @Deactivate
115 public void deactivateStore() {
116 keystore.removeListener(klistener);
117 objectStore.removeListener(olistener);
118 log.info("DyanmicConfig Store Stopped");
119 }
120
121 @Override
122 public CompletableFuture<Boolean>
123 addNode(ResourceId path, DataNode node) {
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800124 throw new FailedException("Not yet implemented");
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800125 }
126
127 @Override
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800128 public CompletableFuture<Boolean>
129 addRecursive(ResourceId complete, DataNode node) {
130 CompletableFuture<Boolean> eventFuture = CompletableFuture.completedFuture(true);
Sithara Punnassery43833e12017-03-14 16:29:19 -0700131 List<NodeKey> nodeKeyList = complete.nodeKeys();
132 NodeKey f = nodeKeyList.get(0);
133 if (f.schemaId().name().compareTo("/") == 0) {
134 nodeKeyList.remove(0);
135 }
Sithara Punnasserybb644902017-03-16 22:08:29 -0700136 String spath = ResourceIdParser.parseResId(complete);
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800137 if (spath == null) {
138 throw new FailedException("Invalid RsourceId, cannot create Node");
139 }
Sithara Punnasserybb644902017-03-16 22:08:29 -0700140 if (keystore.get(DocumentPath.from(spath)).join() == null) {
141 ////TODO recursively creating missing parents
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800142 throw new FailedException("Some of the parents in the path " +
143 "are not present, creation not supported currently");
Sithara Punnasserybb644902017-03-16 22:08:29 -0700144 }
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800145 spath = ResourceIdParser.appendNodeKey(spath, node.key());
146 parseNode(spath, node);
147 return eventFuture;
148 }
149
150 private void parseNode(String path, DataNode node) {
151 if (keystore.get(DocumentPath.from(path)).join() != null) {
152 throw new FailedException("Requested node already present in the" +
153 " store, please use an update method");
154 }
155 if (node.type() == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
156 addLeaf(path, (LeafNode) node);
157 } else if (node.type() == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
158 path = ResourceIdParser.appendLeafList(path, (LeafListKey) node.key());
159 if (keystore.get(DocumentPath.from(path)).join() != null) {
160 throw new FailedException("Requested node already present in the" +
161 " store, please use an update method");
162 }
163 addLeaf(path, (LeafNode) node);
164 } else if (node.type() == DataNode.Type.SINGLE_INSTANCE_NODE) {
165 traverseInner(path, (InnerNode) node);
166 } else if (node.type() == DataNode.Type.MULTI_INSTANCE_NODE) {
167 path = ResourceIdParser.appendKeyList(path, (ListKey) node.key());
168 if (keystore.get(DocumentPath.from(path)).join() != null) {
169 throw new FailedException("Requested node already present in the" +
170 " store, please use an update method");
171 }
172 traverseInner(path, (InnerNode) node);
173 } else {
174 throw new FailedException("Invalid node type");
175 }
176 }
177
178 private void traverseInner(String path, InnerNode node) {
179 addKey(path, node.type());
180 Map<NodeKey, DataNode> entries = node.childNodes();
181 if (entries.size() == 0) {
182 throw new FailedException("Inner node cannot have empty children map");
183 }
184 entries.forEach((k, v) -> {
185 String tempPath;
186 tempPath = ResourceIdParser.appendNodeKey(path, v.key());
187 if (v.type() == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
188 addLeaf(tempPath, (LeafNode) v);
189 } else if (v.type() == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
190 tempPath = ResourceIdParser.appendLeafList(tempPath, (LeafListKey) v.key());
191 addLeaf(tempPath, (LeafNode) v);
192 } else if (v.type() == DataNode.Type.SINGLE_INSTANCE_NODE) {
193 traverseInner(tempPath, (InnerNode) v);
194 } else if (v.type() == DataNode.Type.MULTI_INSTANCE_NODE) {
195 tempPath = ResourceIdParser.appendKeyList(tempPath, (ListKey) v.key());
196 traverseInner(path, (InnerNode) v);
197 } else {
198 throw new FailedException("Invalid node type");
199 }
200 });
201 }
202
203 private Boolean addLeaf(String path, LeafNode node) {
204 objectStore.put(path, node);
205 return addKey(path, node.type());
206 }
207
208 private Boolean addKey(String path, DataNode.Type type) {
209 Boolean stat = false;
210 CompletableFuture<Boolean> ret = keystore.create(DocumentPath.from(path), type);
211 return complete(ret);
212 }
213
214 @Override
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800215 public CompletableFuture<DataNode> readNode(ResourceId path, Filter filter) {
216 CompletableFuture<DataNode> eventFuture = CompletableFuture.completedFuture(null);
Sithara Punnassery43833e12017-03-14 16:29:19 -0700217 List<NodeKey> nodeKeyList = path.nodeKeys();
218 NodeKey f = nodeKeyList.get(0);
219 if (f.schemaId().name().compareTo("/") == 0) {
220 nodeKeyList.remove(0);
221 }
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800222 String spath = ResourceIdParser.parseResId(path);
223 DocumentPath dpath = DocumentPath.from(spath);
224 DataNode.Type type = null;
225 CompletableFuture<Versioned<DataNode.Type>> ret = keystore.get(dpath);
226 type = completeVersioned(ret);
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800227 if (type == null) {
228 throw new FailedException("Requested node or some of the parents" +
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800229 "are not present in the requested path");
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800230 }
231 DataNode retVal = null;
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800232 if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
233 retVal = readLeaf(spath);
234 } else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
235 retVal = readLeaf(spath);
236 } else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) {
237 NodeKey key = ResourceIdParser.getInstanceKey(path);
238 if (key == null) {
239 throw new FailedException("Key type did not match node type");
240 }
241 DataNode.Builder superBldr = InnerNode
242 .builder(key.schemaId().name(), key.schemaId().namespace())
243 .type(type);
244 readInner(superBldr, spath);
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800245 retVal = superBldr.build();
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800246 } else if (type == DataNode.Type.MULTI_INSTANCE_NODE) {
247 NodeKey key = ResourceIdParser.getMultiInstanceKey(path);
248 if (key == null) {
249 throw new FailedException("Key type did not match node type");
250 }
251 DataNode.Builder superBldr = InnerNode
252 .builder(key.schemaId().name(), key.schemaId().namespace())
253 .type(type);
254 for (KeyLeaf keyLeaf : ((ListKey) key).keyLeafs()) {
255 String tempPath = ResourceIdParser.appendKeyLeaf(spath, keyLeaf);
256 LeafNode lfnd = readLeaf(tempPath);
257 superBldr.addKeyLeaf(keyLeaf.leafSchema().name(),
258 keyLeaf.leafSchema().namespace(), lfnd.value());
259 }
260 readInner(superBldr, spath);
261 retVal = superBldr.build();
262 } else {
263 throw new FailedException("Invalid node type");
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800264 }
265 if (retVal != null) {
266 eventFuture = CompletableFuture.completedFuture(retVal);
267 } else {
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800268 log.info("STORE: FAILED to READ node");
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800269 }
270 return eventFuture;
271 }
272
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800273 private void readInner(DataNode.Builder superBldr, String spath) {
274 CompletableFuture<Map<String, Versioned<DataNode.Type>>> ret = keystore.getChildren(
275 DocumentPath.from(spath));
276 Map<String, Versioned<DataNode.Type>> entries = null;
277 entries = complete(ret);
278 if ((entries == null) || (entries.size() == 0)) {
279 throw new FailedException("Inner node cannot have empty children map");
280 }
281 entries.forEach((k, v) -> {
282 String[] names = k.split(ResourceIdParser.NM_SEP);
283 String name = names[0];
284 String nmSpc = names[1];
285 DataNode.Type type = v.value();
286 String tempPath = ResourceIdParser.appendNodeKey(spath, name, nmSpc);
287 if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
288 superBldr.createChildBuilder(name, nmSpc, readLeaf(tempPath).value())
289 .type(type)
290 .exitNode();
291 } else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
292 String mlpath = ResourceIdParser.appendLeafList(tempPath, names[2]);
293 LeafNode lfnode = readLeaf(mlpath);
294 superBldr.createChildBuilder(name, nmSpc, lfnode.value())
295 .type(type)
296 .addLeafListValue(lfnode.value())
297 .exitNode();
298 //TODO this alone should be sufficient and take the nm, nmspc too
299 } else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) {
300 DataNode.Builder tempBldr = superBldr.createChildBuilder(name, nmSpc)
301 .type(type);
302 readInner(tempBldr, tempPath);
303 } else if (type == DataNode.Type.MULTI_INSTANCE_NODE) {
304 DataNode.Builder tempBldr = superBldr.createChildBuilder(name, nmSpc)
305 .type(type);
306 tempPath = ResourceIdParser.appendMultiInstKey(tempPath, k);
307 String[] keys = k.split(ResourceIdParser.KEY_SEP);
308 for (int i = 1; i < keys.length; i++) {
309 String curKey = ResourceIdParser.appendKeyLeaf(tempPath, keys[i]);
310 LeafNode lfnd = readLeaf(curKey);
311 String[] keydata = keys[i].split(ResourceIdParser.NM_SEP);
312 superBldr.addKeyLeaf(keydata[0], keydata[1], lfnd.value());
313 }
314 readInner(tempBldr, tempPath);
315 } else {
316 throw new FailedException("Node type should either be LEAF or INNERNODE");
317 }
318 });
319 superBldr.exitNode();
320 }
321
322 private LeafNode readLeaf(String path) {
323 return objectStore.get(path).value();
324 }
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800325 @Override
326 public CompletableFuture<Boolean> updateNode(ResourceId path, DataNode node) {
327 throw new FailedException("Not yet implemented");
328 }
329 @Override
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800330 public CompletableFuture<Boolean> updateNodeRecursive(ResourceId path, DataNode node) {
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800331 throw new FailedException("Not yet implemented");
332 }
333 @Override
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800334 public CompletableFuture<Boolean> replaceNode(ResourceId path, DataNode node) {
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800335 throw new FailedException("Not yet implemented");
336 }
337 @Override
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800338 public CompletableFuture<Boolean> deleteNode(ResourceId path) {
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800339 throw new FailedException("Not yet implemented");
340 }
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800341
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800342 @Override
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800343 public CompletableFuture<Boolean> deleteNodeRecursive(ResourceId path) {
Sithara Punnassery43833e12017-03-14 16:29:19 -0700344 List<NodeKey> nodeKeyList = path.nodeKeys();
345 NodeKey f = nodeKeyList.get(0);
346 if (f.schemaId().name().compareTo("/") == 0) {
347 nodeKeyList.remove(0);
348 }
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800349 String spath = ResourceIdParser.parseResId(path);
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800350 DocumentPath dpath = DocumentPath.from(spath);
351 DataNode.Type type = null;
352 CompletableFuture<Versioned<DataNode.Type>> vtype = keystore.removeNode(dpath);
353 type = completeVersioned(vtype);
354 if (type == null) {
355 throw new FailedException("node delete failed");
356 }
357 Versioned<LeafNode> res = objectStore.remove(spath);
358 if (res == null) {
359 return CompletableFuture.completedFuture(false);
360 } else {
361 return CompletableFuture.completedFuture(true);
362 }
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800363 }
364
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800365 public class InternalDocTreeListener implements DocumentTreeListener<DataNode.Type> {
366 @Override
367 public void event(DocumentTreeEvent<DataNode.Type> event) {
368 DynamicConfigEvent.Type type;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800369 ResourceId path;
370 switch (event.type()) {
371 case CREATED:
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800372 log.info("NODE created in store");
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800373 type = NODE_ADDED;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800374 break;
375 case UPDATED:
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800376 log.info("NODE updated in store");
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800377 type = NODE_UPDATED;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800378 break;
379 case DELETED:
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800380 log.info("NODE deleted in store");
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800381 type = NODE_DELETED;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800382 break;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800383 default:
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800384 log.info("UNKNOWN operation in store");
385 type = UNKNOWN_OPRN;
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800386 }
Sithara Punnassery44e2a702017-03-06 15:38:10 -0800387 path = ResourceIdParser.getResId(event.path().pathElements());
388 notifyDelegate(new DynamicConfigEvent(type, path));
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800389 }
390 }
391
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800392 public class InternalMapListener implements MapEventListener<String, LeafNode> {
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800393 @Override
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800394 public void event(MapEvent<String, LeafNode> event) {
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800395 switch (event.type()) {
396 case INSERT:
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800397 //log.info("NODE created in store");
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800398 break;
399 case UPDATE:
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800400 //log.info("NODE updated in store");
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800401 break;
402 case REMOVE:
403 default:
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800404 //log.info("NODE removed in store");
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800405 break;
406 }
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800407 }
408 }
Sithara Punnassery4b091dc2017-03-02 17:22:40 -0800409
410 private <T> T complete(CompletableFuture<T> future) {
411 try {
412 return future.get();
413 } catch (InterruptedException e) {
414 Thread.currentThread().interrupt();
415 throw new FailedException(e.getCause().getMessage());
416 } catch (ExecutionException e) {
417 if (e.getCause() instanceof IllegalDocumentModificationException) {
418 throw new FailedException("Node or parent doesnot exist or is root or is not a Leaf Node");
419 } else if (e.getCause() instanceof NoSuchDocumentPathException) {
420 throw new FailedException("Resource id does not exist");
421 } else {
422 throw new FailedException("Datastore operation failed");
423 }
424 }
425 }
426
427 private <T> T completeVersioned(CompletableFuture<Versioned<T>> future) {
428 try {
429 return future.get().value();
430 } catch (InterruptedException e) {
431 Thread.currentThread().interrupt();
432 throw new FailedException(e.getCause().getMessage());
433 } catch (ExecutionException e) {
434 if (e.getCause() instanceof IllegalDocumentModificationException) {
435 throw new FailedException("Node or parent does not exist or is root or is not a Leaf Node");
436 } else if (e.getCause() instanceof NoSuchDocumentPathException) {
437 throw new FailedException("Resource id does not exist");
438 } else {
439 throw new FailedException("Datastore operation failed");
440 }
441 }
442 }
Sithara Punnassery9306e6b2017-02-06 15:38:19 -0800443}