Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [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 | 9306e6b | 2017-02-06 15:38:19 -0800 | [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 | * |
Sithara Punnassery | 61a8025 | 2017-08-07 11:16:08 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 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.impl; |
| 17 | |
Sithara Punnassery | 0620879 | 2017-02-10 16:25:29 -0800 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | import org.apache.felix.scr.annotations.Service; |
| 25 | import org.onlab.util.KryoNamespace; |
| 26 | import org.onosproject.config.DynamicConfigEvent; |
| 27 | import org.onosproject.config.DynamicConfigStore; |
| 28 | import org.onosproject.config.DynamicConfigStoreDelegate; |
| 29 | import org.onosproject.config.FailedException; |
| 30 | import org.onosproject.config.Filter; |
Henry Yu | 5c54e77 | 2017-04-19 14:13:56 -0400 | [diff] [blame] | 31 | import org.onosproject.config.ResourceIdParser; |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 32 | import org.onosproject.d.config.ResourceIds; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 33 | import org.onosproject.store.AbstractStore; |
| 34 | import org.onosproject.store.serializers.KryoNamespaces; |
| 35 | import org.onosproject.store.service.AsyncDocumentTree; |
| 36 | import org.onosproject.store.service.ConsistentMap; |
| 37 | import org.onosproject.store.service.DocumentPath; |
| 38 | import org.onosproject.store.service.DocumentTreeEvent; |
| 39 | import org.onosproject.store.service.DocumentTreeListener; |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 40 | import org.onosproject.store.service.IllegalDocumentModificationException; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 41 | import org.onosproject.store.service.MapEvent; |
| 42 | import org.onosproject.store.service.MapEventListener; |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 43 | import org.onosproject.store.service.NoSuchDocumentPathException; |
Sithara Punnassery | db3591b | 2017-08-10 19:44:53 -0700 | [diff] [blame] | 44 | import org.onosproject.store.service.Ordering; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 45 | import org.onosproject.store.service.Serializer; |
| 46 | import org.onosproject.store.service.StorageService; |
| 47 | import org.onosproject.store.service.Versioned; |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 48 | import org.onosproject.yang.model.DataNode; |
| 49 | import org.onosproject.yang.model.InnerNode; |
| 50 | import org.onosproject.yang.model.KeyLeaf; |
| 51 | import org.onosproject.yang.model.LeafListKey; |
| 52 | import org.onosproject.yang.model.LeafNode; |
| 53 | import org.onosproject.yang.model.ListKey; |
| 54 | import org.onosproject.yang.model.NodeKey; |
| 55 | import org.onosproject.yang.model.ResourceId; |
| 56 | import org.onosproject.yang.model.SchemaId; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 57 | import org.slf4j.Logger; |
| 58 | import org.slf4j.LoggerFactory; |
Henry Yu | 5c54e77 | 2017-04-19 14:13:56 -0400 | [diff] [blame] | 59 | |
| 60 | import java.math.BigInteger; |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 61 | import java.util.LinkedHashMap; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 62 | import java.util.Map; |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 63 | import java.util.Optional; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 64 | import java.util.concurrent.CompletableFuture; |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 65 | import java.util.concurrent.ExecutionException; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 66 | |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 67 | import static org.onosproject.config.DynamicConfigEvent.Type.NODE_ADDED; |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 68 | import static org.onosproject.config.DynamicConfigEvent.Type.NODE_DELETED; |
Henry Yu | 5c54e77 | 2017-04-19 14:13:56 -0400 | [diff] [blame] | 69 | import static org.onosproject.config.DynamicConfigEvent.Type.NODE_UPDATED; |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 70 | import static org.onosproject.config.DynamicConfigEvent.Type.UNKNOWN_OPRN; |
| 71 | |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 72 | /** |
| 73 | * Implementation of the dynamic config store. |
| 74 | */ |
Sithara Punnassery | 0620879 | 2017-02-10 16:25:29 -0800 | [diff] [blame] | 75 | @Beta |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 76 | @Component(immediate = true) |
| 77 | @Service |
| 78 | public class DistributedDynamicConfigStore |
| 79 | extends AbstractStore<DynamicConfigEvent, DynamicConfigStoreDelegate> |
| 80 | implements DynamicConfigStore { |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 81 | |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 82 | private final Logger log = LoggerFactory.getLogger(getClass()); |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 83 | |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 84 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 85 | protected StorageService storageService; |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 86 | |
| 87 | // FIXME transactionally mutate the 2 or consolidate into 1 AsyncDocTree |
| 88 | // effectively tree structure only |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 89 | private AsyncDocumentTree<DataNode.Type> keystore; |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 90 | // TODO Can we pass DocumentPath directly to ConsistentMap? |
| 91 | // Map<DocumentPath as String, leaf value> |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 92 | private ConsistentMap<String, LeafNode> objectStore; |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 93 | |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 94 | private final DocumentTreeListener<DataNode.Type> klistener = new InternalDocTreeListener(); |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 95 | private final MapEventListener<String, LeafNode> olistener = new InternalMapListener(); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 96 | |
| 97 | @Activate |
| 98 | public void activateStore() { |
| 99 | KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder() |
| 100 | .register(KryoNamespaces.BASIC) |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 101 | .register(Class.class) |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 102 | .register(DataNode.Type.class) |
| 103 | .register(LeafNode.class) |
| 104 | .register(InnerNode.class) |
| 105 | .register(ResourceId.class) |
| 106 | .register(NodeKey.class) |
| 107 | .register(SchemaId.class) |
Sithara Punnassery | 43833e1 | 2017-03-14 16:29:19 -0700 | [diff] [blame] | 108 | .register(LeafListKey.class) |
| 109 | .register(ListKey.class) |
| 110 | .register(KeyLeaf.class) |
Henry Yu | 5c54e77 | 2017-04-19 14:13:56 -0400 | [diff] [blame] | 111 | .register(BigInteger.class) |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 112 | .register(LinkedHashMap.class); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 113 | keystore = storageService.<DataNode.Type>documentTreeBuilder() |
| 114 | .withSerializer(Serializer.using(kryoBuilder.build())) |
| 115 | .withName("config-key-store") |
| 116 | .withRelaxedReadConsistency() |
Sithara Punnassery | db3591b | 2017-08-10 19:44:53 -0700 | [diff] [blame] | 117 | .withOrdering(Ordering.INSERTION) |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 118 | .buildDocumentTree(); |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 119 | objectStore = storageService.<String, LeafNode>consistentMapBuilder() |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 120 | .withSerializer(Serializer.using(kryoBuilder.build())) |
| 121 | .withName("config-object-store") |
| 122 | .withRelaxedReadConsistency() |
| 123 | .build(); |
| 124 | keystore.addListener(klistener); |
| 125 | objectStore.addListener(olistener); |
| 126 | log.info("DyanmicConfig Store Active"); |
| 127 | } |
| 128 | |
| 129 | @Deactivate |
| 130 | public void deactivateStore() { |
| 131 | keystore.removeListener(klistener); |
| 132 | objectStore.removeListener(olistener); |
| 133 | log.info("DyanmicConfig Store Stopped"); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public CompletableFuture<Boolean> |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 138 | addNode(ResourceId parent, DataNode node) { |
| 139 | String spath = ResourceIdParser.parseResId(parent); |
| 140 | log.trace(" addNode({}, {})", parent, node); |
| 141 | log.trace(" spath={}", spath); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 142 | if (spath == null) { |
| 143 | throw new FailedException("Invalid RsourceId, cannot create Node"); |
| 144 | } |
Yuta HIGUCHI | 153d358 | 2017-09-01 16:59:52 -0700 | [diff] [blame] | 145 | if (!spath.equals(ResourceIdParser.ROOT)) { |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 146 | if (completeVersioned(keystore.get(DocumentPath.from(spath))) == null) { |
Yuta HIGUCHI | ea1fe52 | 2017-09-01 14:24:02 -0700 | [diff] [blame] | 147 | throw new FailedException("Node or parent does not exist for " + spath); |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 148 | } |
Sithara Punnassery | bb64490 | 2017-03-16 22:08:29 -0700 | [diff] [blame] | 149 | } |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 150 | ResourceId abs = ResourceIds.resourceId(parent, node); |
| 151 | //spath = ResourceIdParser.appendNodeKey(spath, node.key()); |
| 152 | parseNode(ResourceIdParser.parseResId(abs), node); |
Yuta HIGUCHI | 153d358 | 2017-09-01 16:59:52 -0700 | [diff] [blame] | 153 | return CompletableFuture.completedFuture(true); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 156 | // FIXME this is more like addNode |
| 157 | /** |
| 158 | * @param path pointing to {@code node} |
| 159 | * @param node node |
| 160 | */ |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 161 | private void parseNode(String path, DataNode node) { |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 162 | log.trace("parseNode({}, {})", path, node); |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 163 | if (completeVersioned(keystore.get(DocumentPath.from(path))) != null) { |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 164 | throw new FailedException("Requested node already present in the" + |
Henry Yu | 5c54e77 | 2017-04-19 14:13:56 -0400 | [diff] [blame] | 165 | " store, please use an update method"); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 166 | } |
| 167 | if (node.type() == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) { |
| 168 | addLeaf(path, (LeafNode) node); |
| 169 | } else if (node.type() == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) { |
| 170 | path = ResourceIdParser.appendLeafList(path, (LeafListKey) node.key()); |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 171 | if (completeVersioned(keystore.get(DocumentPath.from(path))) != null) { |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 172 | throw new FailedException("Requested node already present in the" + |
Henry Yu | 5c54e77 | 2017-04-19 14:13:56 -0400 | [diff] [blame] | 173 | " store, please use an update method"); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 174 | } |
| 175 | addLeaf(path, (LeafNode) node); |
| 176 | } else if (node.type() == DataNode.Type.SINGLE_INSTANCE_NODE) { |
| 177 | traverseInner(path, (InnerNode) node); |
| 178 | } else if (node.type() == DataNode.Type.MULTI_INSTANCE_NODE) { |
| 179 | path = ResourceIdParser.appendKeyList(path, (ListKey) node.key()); |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 180 | if (completeVersioned(keystore.get(DocumentPath.from(path))) != null) { |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 181 | throw new FailedException("Requested node already present in the" + |
Henry Yu | 5c54e77 | 2017-04-19 14:13:56 -0400 | [diff] [blame] | 182 | " store, please use an update method"); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 183 | } |
| 184 | traverseInner(path, (InnerNode) node); |
| 185 | } else { |
| 186 | throw new FailedException("Invalid node type"); |
| 187 | } |
| 188 | } |
| 189 | |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 190 | // FIXME this is more like addInnteNode |
| 191 | /** |
| 192 | * @param path pointing to {@code node} |
| 193 | * @param node node |
| 194 | */ |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 195 | private void traverseInner(String path, InnerNode node) { |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 196 | log.trace("traverseInner({}, {})", path, node); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 197 | addKey(path, node.type()); |
| 198 | Map<NodeKey, DataNode> entries = node.childNodes(); |
| 199 | if (entries.size() == 0) { |
Henry Yu | 5c54e77 | 2017-04-19 14:13:56 -0400 | [diff] [blame] | 200 | return; |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 201 | } |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 202 | // FIXME ignoring results |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 203 | entries.forEach((k, v) -> { |
| 204 | String tempPath; |
| 205 | tempPath = ResourceIdParser.appendNodeKey(path, v.key()); |
| 206 | if (v.type() == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) { |
| 207 | addLeaf(tempPath, (LeafNode) v); |
| 208 | } else if (v.type() == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) { |
| 209 | tempPath = ResourceIdParser.appendLeafList(tempPath, (LeafListKey) v.key()); |
| 210 | addLeaf(tempPath, (LeafNode) v); |
| 211 | } else if (v.type() == DataNode.Type.SINGLE_INSTANCE_NODE) { |
| 212 | traverseInner(tempPath, (InnerNode) v); |
| 213 | } else if (v.type() == DataNode.Type.MULTI_INSTANCE_NODE) { |
| 214 | tempPath = ResourceIdParser.appendKeyList(tempPath, (ListKey) v.key()); |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 215 | traverseInner(tempPath, (InnerNode) v); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 216 | } else { |
| 217 | throw new FailedException("Invalid node type"); |
| 218 | } |
| 219 | }); |
| 220 | } |
| 221 | |
| 222 | private Boolean addLeaf(String path, LeafNode node) { |
| 223 | objectStore.put(path, node); |
| 224 | return addKey(path, node.type()); |
| 225 | } |
| 226 | |
| 227 | private Boolean addKey(String path, DataNode.Type type) { |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 228 | log.trace("addKey({}, {})", path, type); |
| 229 | DocumentPath dpath = DocumentPath.from(path); |
| 230 | log.trace("dpath={}", dpath); |
| 231 | // FIXME Not atomic, should probably use create or replace |
| 232 | if (completeVersioned(keystore.get(dpath)) != null) { |
| 233 | completeVersioned(keystore.set(dpath, type)); |
| 234 | log.trace("true"); |
Sithara Punnassery | c70b7e5 | 2017-08-10 14:28:08 -0700 | [diff] [blame] | 235 | return true; |
| 236 | } |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 237 | log.trace(" keystore.create({}, {})", dpath, type); |
| 238 | Boolean result = complete(keystore.create(dpath, type)); |
| 239 | log.trace("{}", result); |
| 240 | return result; |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | @Override |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 244 | public CompletableFuture<DataNode> readNode(ResourceId path, Filter filter) { |
| 245 | CompletableFuture<DataNode> eventFuture = CompletableFuture.completedFuture(null); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 246 | String spath = ResourceIdParser.parseResId(path); |
| 247 | DocumentPath dpath = DocumentPath.from(spath); |
| 248 | DataNode.Type type = null; |
| 249 | CompletableFuture<Versioned<DataNode.Type>> ret = keystore.get(dpath); |
| 250 | type = completeVersioned(ret); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 251 | if (type == null) { |
Yuta HIGUCHI | ea1fe52 | 2017-09-01 14:24:02 -0700 | [diff] [blame] | 252 | throw new FailedException("Requested node or some of the parents " + |
| 253 | "are not present in the requested path: " + |
| 254 | spath); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 255 | } |
| 256 | DataNode retVal = null; |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 257 | if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) { |
| 258 | retVal = readLeaf(spath); |
| 259 | } else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) { |
| 260 | retVal = readLeaf(spath); |
| 261 | } else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) { |
| 262 | NodeKey key = ResourceIdParser.getInstanceKey(path); |
| 263 | if (key == null) { |
| 264 | throw new FailedException("Key type did not match node type"); |
| 265 | } |
| 266 | DataNode.Builder superBldr = InnerNode |
| 267 | .builder(key.schemaId().name(), key.schemaId().namespace()) |
| 268 | .type(type); |
| 269 | readInner(superBldr, spath); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 270 | retVal = superBldr.build(); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 271 | } else if (type == DataNode.Type.MULTI_INSTANCE_NODE) { |
| 272 | NodeKey key = ResourceIdParser.getMultiInstanceKey(path); |
| 273 | if (key == null) { |
| 274 | throw new FailedException("Key type did not match node type"); |
| 275 | } |
| 276 | DataNode.Builder superBldr = InnerNode |
| 277 | .builder(key.schemaId().name(), key.schemaId().namespace()) |
| 278 | .type(type); |
| 279 | for (KeyLeaf keyLeaf : ((ListKey) key).keyLeafs()) { |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 280 | //String tempPath = ResourceIdParser.appendKeyLeaf(spath, keyLeaf); |
| 281 | //LeafNode lfnd = readLeaf(tempPath); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 282 | superBldr.addKeyLeaf(keyLeaf.leafSchema().name(), |
Henry Yu | 5c54e77 | 2017-04-19 14:13:56 -0400 | [diff] [blame] | 283 | keyLeaf.leafSchema().namespace(), String.valueOf(keyLeaf.leafValue())); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 284 | } |
| 285 | readInner(superBldr, spath); |
| 286 | retVal = superBldr.build(); |
| 287 | } else { |
| 288 | throw new FailedException("Invalid node type"); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 289 | } |
| 290 | if (retVal != null) { |
| 291 | eventFuture = CompletableFuture.completedFuture(retVal); |
| 292 | } else { |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 293 | log.info("STORE: Failed to READ node"); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 294 | } |
| 295 | return eventFuture; |
| 296 | } |
| 297 | |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 298 | private void readInner(DataNode.Builder superBldr, String spath) { |
| 299 | CompletableFuture<Map<String, Versioned<DataNode.Type>>> ret = keystore.getChildren( |
| 300 | DocumentPath.from(spath)); |
| 301 | Map<String, Versioned<DataNode.Type>> entries = null; |
| 302 | entries = complete(ret); |
Sithara Punnassery | 18ffcc7 | 2017-05-18 14:24:30 -0700 | [diff] [blame] | 303 | if ((entries != null) && (!entries.isEmpty())) { |
| 304 | entries.forEach((k, v) -> { |
| 305 | String[] names = k.split(ResourceIdParser.NM_CHK); |
| 306 | String name = names[0]; |
| 307 | String nmSpc = ResourceIdParser.getNamespace(names[1]); |
| 308 | String keyVal = ResourceIdParser.getKeyVal(names[1]); |
| 309 | DataNode.Type type = v.value(); |
| 310 | String tempPath = ResourceIdParser.appendNodeKey(spath, name, nmSpc); |
| 311 | if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) { |
| 312 | superBldr.createChildBuilder(name, nmSpc, readLeaf(tempPath).value()) |
| 313 | .type(type) |
| 314 | .exitNode(); |
| 315 | } else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) { |
| 316 | String mlpath = ResourceIdParser.appendLeafList(tempPath, keyVal); |
| 317 | LeafNode lfnode = readLeaf(mlpath); |
| 318 | superBldr.createChildBuilder(name, nmSpc, lfnode.value()) |
| 319 | .type(type) |
| 320 | .addLeafListValue(lfnode.value()) |
| 321 | .exitNode(); |
| 322 | //TODO this alone should be sufficient and take the nm, nmspc too |
| 323 | } else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) { |
| 324 | DataNode.Builder tempBldr = superBldr.createChildBuilder(name, nmSpc) |
| 325 | .type(type); |
| 326 | readInner(tempBldr, tempPath); |
| 327 | } else if (type == DataNode.Type.MULTI_INSTANCE_NODE) { |
| 328 | DataNode.Builder tempBldr = superBldr.createChildBuilder(name, nmSpc) |
| 329 | .type(type); |
| 330 | tempPath = ResourceIdParser.appendMultiInstKey(tempPath, k); |
| 331 | String[] keys = k.split(ResourceIdParser.KEY_CHK); |
| 332 | for (int i = 1; i < keys.length; i++) { |
| 333 | //String curKey = ResourceIdParser.appendKeyLeaf(tempPath, keys[i]); |
| 334 | //LeafNode lfnd = readLeaf(curKey); |
| 335 | String[] keydata = keys[i].split(ResourceIdParser.NM_CHK); |
| 336 | tempBldr.addKeyLeaf(keydata[0], keydata[1], keydata[2]); |
| 337 | } |
| 338 | readInner(tempBldr, tempPath); |
| 339 | } else { |
| 340 | throw new FailedException("Invalid node type"); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 341 | } |
Sithara Punnassery | 18ffcc7 | 2017-05-18 14:24:30 -0700 | [diff] [blame] | 342 | }); |
| 343 | } |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 344 | superBldr.exitNode(); |
| 345 | } |
| 346 | |
| 347 | private LeafNode readLeaf(String path) { |
| 348 | return objectStore.get(path).value(); |
| 349 | } |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 350 | |
Sithara Punnassery | 0da1a9c | 2017-05-17 16:16:22 -0700 | [diff] [blame] | 351 | private void parseForUpdate(String path, DataNode node) { |
| 352 | if (node.type() == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) { |
| 353 | addLeaf(path, (LeafNode) node); |
| 354 | } else if (node.type() == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) { |
| 355 | path = ResourceIdParser.appendLeafList(path, (LeafListKey) node.key()); |
| 356 | addLeaf(path, (LeafNode) node); |
| 357 | } else if (node.type() == DataNode.Type.SINGLE_INSTANCE_NODE) { |
| 358 | traverseInner(path, (InnerNode) node); |
| 359 | } else if (node.type() == DataNode.Type.MULTI_INSTANCE_NODE) { |
| 360 | path = ResourceIdParser.appendKeyList(path, (ListKey) node.key()); |
| 361 | traverseInner(path, (InnerNode) node); |
| 362 | } else { |
| 363 | throw new FailedException("Invalid node type"); |
| 364 | } |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 365 | } |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 366 | |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 367 | @Override |
Sithara Punnassery | 0da1a9c | 2017-05-17 16:16:22 -0700 | [diff] [blame] | 368 | public CompletableFuture<Boolean> updateNode(ResourceId complete, DataNode node) { |
| 369 | CompletableFuture<Boolean> eventFuture = CompletableFuture.completedFuture(true); |
Sithara Punnassery | 0da1a9c | 2017-05-17 16:16:22 -0700 | [diff] [blame] | 370 | String spath = ResourceIdParser.parseResId(complete); |
| 371 | if (spath == null) { |
| 372 | throw new FailedException("Invalid RsourceId, cannot update Node"); |
| 373 | } |
| 374 | if (spath.compareTo(ResourceIdParser.ROOT) != 0) { |
| 375 | if (completeVersioned(keystore.get(DocumentPath.from(spath))) == null) { |
| 376 | throw new FailedException("Node or parent doesnot exist, cannot update"); |
| 377 | } |
| 378 | } |
| 379 | spath = ResourceIdParser.appendNodeKey(spath, node.key()); |
| 380 | parseForUpdate(spath, node); |
| 381 | return eventFuture; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 382 | } |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 383 | |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 384 | @Override |
Sithara Punnassery | 18ffcc7 | 2017-05-18 14:24:30 -0700 | [diff] [blame] | 385 | public CompletableFuture<Boolean> nodeExist(ResourceId complete) { |
| 386 | Boolean stat = true; |
Sithara Punnassery | 18ffcc7 | 2017-05-18 14:24:30 -0700 | [diff] [blame] | 387 | String spath = ResourceIdParser.parseResId(complete); |
| 388 | if (spath == null) { |
| 389 | stat = false; |
| 390 | } else if (completeVersioned(keystore.get(DocumentPath.from(spath))) == null) { |
| 391 | stat = false; |
| 392 | } |
| 393 | return CompletableFuture.completedFuture(stat); |
| 394 | } |
| 395 | |
| 396 | @Override |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 397 | public CompletableFuture<Boolean> replaceNode(ResourceId path, DataNode node) { |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 398 | throw new FailedException("Not yet implemented"); |
| 399 | } |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 400 | |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 401 | @Override |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 402 | public CompletableFuture<Boolean> deleteNode(ResourceId path) { |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 403 | throw new FailedException("Not yet implemented"); |
| 404 | } |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 405 | |
Sithara Punnassery | e4ab4f2 | 2017-03-27 19:11:00 -0700 | [diff] [blame] | 406 | private void deleteInner(String spath) { |
| 407 | CompletableFuture<Map<String, Versioned<DataNode.Type>>> ret = keystore.getChildren( |
| 408 | DocumentPath.from(spath)); |
| 409 | Map<String, Versioned<DataNode.Type>> entries = null; |
| 410 | entries = complete(ret); |
Sithara Punnassery | 18ffcc7 | 2017-05-18 14:24:30 -0700 | [diff] [blame] | 411 | if ((entries != null) && (!entries.isEmpty())) { |
| 412 | entries.forEach((k, v) -> { |
| 413 | String[] names = k.split(ResourceIdParser.NM_CHK); |
| 414 | String name = names[0]; |
| 415 | String nmSpc = ResourceIdParser.getNamespace(names[1]); |
| 416 | String keyVal = ResourceIdParser.getKeyVal(names[1]); |
| 417 | DataNode.Type type = v.value(); |
| 418 | String tempPath = ResourceIdParser.appendNodeKey(spath, name, nmSpc); |
| 419 | if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) { |
| 420 | removeLeaf(tempPath); |
| 421 | } else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) { |
| 422 | String mlpath = ResourceIdParser.appendLeafList(tempPath, keyVal); |
| 423 | removeLeaf(mlpath); |
| 424 | } else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) { |
| 425 | deleteInner(tempPath); |
| 426 | } else if (type == DataNode.Type.MULTI_INSTANCE_NODE) { |
| 427 | tempPath = ResourceIdParser.appendMultiInstKey(tempPath, k); |
| 428 | deleteInner(tempPath); |
| 429 | } else { |
| 430 | throw new FailedException("Invalid node type"); |
| 431 | } |
| 432 | }); |
| 433 | } |
Sithara Punnassery | e4ab4f2 | 2017-03-27 19:11:00 -0700 | [diff] [blame] | 434 | keystore.removeNode(DocumentPath.from(spath)); |
| 435 | } |
| 436 | |
| 437 | private void removeLeaf(String path) { |
| 438 | keystore.removeNode(DocumentPath.from(path)); |
| 439 | objectStore.remove(path); |
| 440 | } |
| 441 | |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 442 | @Override |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 443 | public CompletableFuture<Boolean> deleteNodeRecursive(ResourceId path) { |
| 444 | String spath = ResourceIdParser.parseResId(path); |
Sithara Punnassery | e4ab4f2 | 2017-03-27 19:11:00 -0700 | [diff] [blame] | 445 | if (spath == null) { |
Sithara Punnassery | bc9edb1 | 2017-07-20 14:32:33 -0700 | [diff] [blame] | 446 | throw new FailedException("Invalid RsourceId, cannot delete Node"); |
Sithara Punnassery | e4ab4f2 | 2017-03-27 19:11:00 -0700 | [diff] [blame] | 447 | } |
| 448 | if (spath.compareTo(ResourceIdParser.ROOT) == 0) { |
| 449 | throw new FailedException("Cannot delete Root"); |
| 450 | } |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 451 | DocumentPath dpath = DocumentPath.from(spath); |
| 452 | DataNode.Type type = null; |
Sithara Punnassery | e4ab4f2 | 2017-03-27 19:11:00 -0700 | [diff] [blame] | 453 | CompletableFuture<Versioned<DataNode.Type>> ret = keystore.get(dpath); |
| 454 | type = completeVersioned(ret); |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 455 | if (type == null) { |
Sithara Punnassery | e4ab4f2 | 2017-03-27 19:11:00 -0700 | [diff] [blame] | 456 | throw new FailedException("Cannot delete, Requested node or some of the parents" + |
Henry Yu | 5c54e77 | 2017-04-19 14:13:56 -0400 | [diff] [blame] | 457 | "are not present in the requested path"); |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 458 | } |
Sithara Punnassery | e4ab4f2 | 2017-03-27 19:11:00 -0700 | [diff] [blame] | 459 | DataNode retVal = null; |
| 460 | if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) { |
| 461 | removeLeaf(spath); |
| 462 | } else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) { |
| 463 | removeLeaf(spath); |
| 464 | } else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) { |
| 465 | deleteInner(spath); |
| 466 | } else if (type == DataNode.Type.MULTI_INSTANCE_NODE) { |
| 467 | deleteInner(spath); |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 468 | } else { |
Sithara Punnassery | e4ab4f2 | 2017-03-27 19:11:00 -0700 | [diff] [blame] | 469 | throw new FailedException("Invalid node type"); |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 470 | } |
Sithara Punnassery | e4ab4f2 | 2017-03-27 19:11:00 -0700 | [diff] [blame] | 471 | return CompletableFuture.completedFuture(true); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 474 | public class InternalDocTreeListener implements DocumentTreeListener<DataNode.Type> { |
| 475 | @Override |
| 476 | public void event(DocumentTreeEvent<DataNode.Type> event) { |
| 477 | DynamicConfigEvent.Type type; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 478 | ResourceId path; |
| 479 | switch (event.type()) { |
| 480 | case CREATED: |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 481 | type = NODE_ADDED; |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 482 | //log.info("NODE added in store"); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 483 | break; |
| 484 | case UPDATED: |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 485 | //log.info("NODE updated in store"); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 486 | type = NODE_UPDATED; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 487 | break; |
| 488 | case DELETED: |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 489 | //log.info("NODE deleted in store"); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 490 | type = NODE_DELETED; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 491 | break; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 492 | default: |
Sithara Punnassery | 4cd2ced | 2017-03-17 17:36:43 -0700 | [diff] [blame] | 493 | //log.info("UNKNOWN operation in store"); |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 494 | type = UNKNOWN_OPRN; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 495 | } |
Sithara Punnassery | 44e2a70 | 2017-03-06 15:38:10 -0800 | [diff] [blame] | 496 | path = ResourceIdParser.getResId(event.path().pathElements()); |
| 497 | notifyDelegate(new DynamicConfigEvent(type, path)); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 501 | public class InternalMapListener implements MapEventListener<String, LeafNode> { |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 502 | @Override |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 503 | public void event(MapEvent<String, LeafNode> event) { |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 504 | switch (event.type()) { |
| 505 | case INSERT: |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 506 | //log.info("NODE created in store"); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 507 | break; |
| 508 | case UPDATE: |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 509 | //log.info("NODE updated in store"); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 510 | break; |
| 511 | case REMOVE: |
| 512 | default: |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 513 | //log.info("NODE removed in store"); |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 514 | break; |
| 515 | } |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 516 | } |
| 517 | } |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 518 | |
| 519 | private <T> T complete(CompletableFuture<T> future) { |
| 520 | try { |
| 521 | return future.get(); |
| 522 | } catch (InterruptedException e) { |
| 523 | Thread.currentThread().interrupt(); |
Yuta HIGUCHI | ea1fe52 | 2017-09-01 14:24:02 -0700 | [diff] [blame] | 524 | throw new FailedException(e.getCause().getMessage()); |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 525 | } catch (ExecutionException e) { |
Yuta HIGUCHI | ea1fe52 | 2017-09-01 14:24:02 -0700 | [diff] [blame] | 526 | if (e.getCause() instanceof IllegalDocumentModificationException) { |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 527 | throw new FailedException("Node or parent does not exist or is root or is not a Leaf Node", |
Yuta HIGUCHI | ea1fe52 | 2017-09-01 14:24:02 -0700 | [diff] [blame] | 528 | e.getCause()); |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 529 | } else if (e.getCause() instanceof NoSuchDocumentPathException) { |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 530 | throw new FailedException("ResourceId does not exist", e.getCause()); |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 531 | } else { |
Yuta HIGUCHI | ea1fe52 | 2017-09-01 14:24:02 -0700 | [diff] [blame] | 532 | throw new FailedException("Datastore operation failed", e.getCause()); |
Sithara Punnassery | 4b091dc | 2017-03-02 17:22:40 -0800 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | private <T> T completeVersioned(CompletableFuture<Versioned<T>> future) { |
Yuta HIGUCHI | 3b5d64e | 2017-09-12 22:44:22 -0700 | [diff] [blame^] | 538 | return Optional.ofNullable(complete(future)) |
| 539 | .map(Versioned::value) |
| 540 | .orElse(null); |
| 541 | } |
| 542 | } |