Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -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 | * |
| 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 | */ |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 16 | |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 17 | package org.onosproject.restconf.restconfmanager; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
| 21 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 26 | import org.apache.felix.scr.annotations.Service; |
| 27 | import org.glassfish.jersey.server.ChunkedOutput; |
Henry Yu | 14af778 | 2017-03-09 19:33:36 -0500 | [diff] [blame] | 28 | import org.onosproject.config.DynamicConfigService; |
| 29 | import org.onosproject.config.FailedException; |
| 30 | import org.onosproject.config.Filter; |
| 31 | import org.onosproject.restconf.api.RestconfException; |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 32 | import org.onosproject.restconf.api.RestconfRpcOutput; |
Henry Yu | 14af778 | 2017-03-09 19:33:36 -0500 | [diff] [blame] | 33 | import org.onosproject.restconf.api.RestconfService; |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 34 | import org.onosproject.restconf.utils.RestconfUtils; |
Henry Yu | 14af778 | 2017-03-09 19:33:36 -0500 | [diff] [blame] | 35 | import org.onosproject.yang.model.DataNode; |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 36 | import org.onosproject.yang.model.DefaultResourceData; |
sonugupta-huawei | f0af7aa | 2017-03-17 00:54:52 +0530 | [diff] [blame] | 37 | import org.onosproject.yang.model.InnerNode; |
| 38 | import org.onosproject.yang.model.KeyLeaf; |
| 39 | import org.onosproject.yang.model.ListKey; |
| 40 | import org.onosproject.yang.model.NodeKey; |
Henry Yu | 14af778 | 2017-03-09 19:33:36 -0500 | [diff] [blame] | 41 | import org.onosproject.yang.model.ResourceData; |
| 42 | import org.onosproject.yang.model.ResourceId; |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 43 | import org.onosproject.yang.model.RpcInput; |
| 44 | import org.onosproject.yang.model.RpcOutput; |
sonugupta-huawei | f0af7aa | 2017-03-17 00:54:52 +0530 | [diff] [blame] | 45 | import org.onosproject.yang.model.SchemaId; |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 46 | import org.slf4j.Logger; |
| 47 | import org.slf4j.LoggerFactory; |
| 48 | |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 49 | import java.net.URI; |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 50 | import java.util.List; |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 51 | import java.util.Map; |
| 52 | import java.util.concurrent.CompletableFuture; |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 53 | import java.util.concurrent.ExecutorService; |
| 54 | import java.util.concurrent.Executors; |
Henry Yu | 14af778 | 2017-03-09 19:33:36 -0500 | [diff] [blame] | 55 | |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 56 | import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 57 | import static org.onosproject.restconf.utils.RestconfUtils.convertDataNodeToJson; |
Henry Yu | 14af778 | 2017-03-09 19:33:36 -0500 | [diff] [blame] | 58 | import static org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode; |
| 59 | import static org.onosproject.restconf.utils.RestconfUtils.convertUriToRid; |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 60 | import static org.onosproject.restconf.utils.RestconfUtils.rmLastPathSegment; |
sonugupta-huawei | f0af7aa | 2017-03-17 00:54:52 +0530 | [diff] [blame] | 61 | import static org.onosproject.yang.model.DataNode.Type.MULTI_INSTANCE_NODE; |
| 62 | import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE; |
| 63 | import static org.onosproject.yang.model.DataNode.Type.SINGLE_INSTANCE_NODE; |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 64 | |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 65 | /* |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 66 | * ONOS RESTCONF application. The RESTCONF Manager |
| 67 | * implements the main logic of the RESTCONF application. |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 68 | * |
| 69 | * The design of the RESTCONF subsystem contains 2 major bundles: |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 70 | * This bundle module is the back-end of the server. |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 71 | * It provides the main logic of the RESTCONF server. It interacts with |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 72 | * the Dynamic Config Service and yang runtime service to run operations |
| 73 | * on the YANG data objects (i.e., resource id, yang data node). |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 74 | */ |
| 75 | |
jingan | 8a77332 | 2017-03-21 16:12:48 -0700 | [diff] [blame] | 76 | @Component(immediate = true) |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 77 | @Service |
| 78 | public class RestconfManager implements RestconfService { |
| 79 | |
| 80 | private static final String RESTCONF_ROOT = "/onos/restconf"; |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 81 | |
| 82 | private final int maxNumOfWorkerThreads = 5; |
| 83 | |
| 84 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 85 | |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Henry Yu | 14af778 | 2017-03-09 19:33:36 -0500 | [diff] [blame] | 87 | protected DynamicConfigService dynamicConfigService; |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 88 | |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 89 | private ExecutorService workerThreadPool; |
| 90 | |
| 91 | @Activate |
| 92 | protected void activate() { |
| 93 | workerThreadPool = Executors |
| 94 | .newFixedThreadPool(maxNumOfWorkerThreads, |
| 95 | new ThreadFactoryBuilder() |
| 96 | .setNameFormat("restconf-worker") |
| 97 | .build()); |
| 98 | log.info("Started"); |
| 99 | } |
| 100 | |
| 101 | @Deactivate |
| 102 | protected void deactivate() { |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 103 | workerThreadPool.shutdownNow(); |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 104 | log.info("Stopped"); |
| 105 | } |
| 106 | |
| 107 | @Override |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 108 | public ObjectNode runGetOperationOnDataResource(URI uri) |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 109 | throws RestconfException { |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 110 | ResourceId rid = convertUriToRid(uri); |
| 111 | // TODO: define Filter (if there is any requirement). |
Yuta HIGUCHI | ac85ee1 | 2017-08-03 20:07:35 -0700 | [diff] [blame] | 112 | Filter filter = Filter.builder().build(); |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 113 | DataNode dataNode; |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 114 | |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 115 | try { |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 116 | if (!dynamicConfigService.nodeExist(rid)) { |
| 117 | return null; |
| 118 | } |
Henry Yu | 14af778 | 2017-03-09 19:33:36 -0500 | [diff] [blame] | 119 | dataNode = dynamicConfigService.readNode(rid, filter); |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 120 | } catch (FailedException e) { |
| 121 | log.error("ERROR: DynamicConfigService: ", e); |
| 122 | throw new RestconfException("ERROR: DynamicConfigService", |
| 123 | INTERNAL_SERVER_ERROR); |
| 124 | } |
| 125 | ObjectNode rootNode = convertDataNodeToJson(rid, dataNode); |
| 126 | return rootNode; |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @Override |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 130 | public void runPostOperationOnDataResource(URI uri, ObjectNode rootNode) |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 131 | throws RestconfException { |
sonugupta-huawei | f0af7aa | 2017-03-17 00:54:52 +0530 | [diff] [blame] | 132 | ResourceData receivedData = convertJsonToDataNode(uri, rootNode); |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 133 | ResourceId rid = receivedData.resourceId(); |
| 134 | List<DataNode> dataNodeList = receivedData.dataNodes(); |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 135 | if (dataNodeList.size() > 1) { |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 136 | log.warn("There are more than one Data Node can be proceed: {}", dataNodeList.size()); |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 137 | } |
| 138 | DataNode dataNode = dataNodeList.get(0); |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 139 | |
| 140 | if (rid == null) { |
| 141 | rid = ResourceId.builder().addBranchPointSchema("/", null).build(); |
| 142 | dataNode = removeTopNode(dataNode); |
| 143 | } |
| 144 | |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 145 | try { |
Sithara Punnassery | 7b0c15e | 2017-07-07 15:08:19 -0700 | [diff] [blame] | 146 | dynamicConfigService.createNode(rid, dataNode); |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 147 | } catch (FailedException e) { |
| 148 | log.error("ERROR: DynamicConfigService: ", e); |
| 149 | throw new RestconfException("ERROR: DynamicConfigService", |
| 150 | INTERNAL_SERVER_ERROR); |
| 151 | } |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | @Override |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 155 | public void runPutOperationOnDataResource(URI uri, ObjectNode rootNode) |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 156 | throws RestconfException { |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 157 | ResourceId rid = convertUriToRid(uri); |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 158 | ResourceData receivedData = convertJsonToDataNode(rmLastPathSegment(uri), rootNode); |
| 159 | ResourceId parentRid = receivedData.resourceId(); |
| 160 | List<DataNode> dataNodeList = receivedData.dataNodes(); |
| 161 | if (dataNodeList.size() > 1) { |
| 162 | log.warn("There are more than one Data Node can be proceed: {}", dataNodeList.size()); |
| 163 | } |
| 164 | DataNode dataNode = dataNodeList.get(0); |
| 165 | |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 166 | try { |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 167 | /* |
| 168 | * If the data node already exists, then replace it. |
| 169 | * Otherwise, create it. |
| 170 | */ |
| 171 | if (dynamicConfigService.nodeExist(rid)) { |
| 172 | dynamicConfigService.replaceNode(parentRid, dataNode); |
| 173 | } else { |
| 174 | dynamicConfigService.createNode(parentRid, dataNode); |
| 175 | } |
| 176 | |
jingan | 7c5bf1f | 2017-02-09 02:58:09 -0800 | [diff] [blame] | 177 | } catch (FailedException e) { |
| 178 | log.error("ERROR: DynamicConfigService: ", e); |
| 179 | throw new RestconfException("ERROR: DynamicConfigService", |
| 180 | INTERNAL_SERVER_ERROR); |
| 181 | } |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | @Override |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 185 | public void runDeleteOperationOnDataResource(URI uri) |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 186 | throws RestconfException { |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 187 | ResourceId rid = convertUriToRid(uri); |
| 188 | try { |
| 189 | if (dynamicConfigService.nodeExist(rid)) { |
| 190 | dynamicConfigService.deleteNode(rid); |
| 191 | } |
| 192 | } catch (FailedException e) { |
| 193 | log.error("ERROR: DynamicConfigService: ", e); |
| 194 | throw new RestconfException("ERROR: DynamicConfigService", |
| 195 | INTERNAL_SERVER_ERROR); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public void runPatchOperationOnDataResource(URI uri, ObjectNode rootNode) |
| 201 | throws RestconfException { |
| 202 | ResourceData receivedData = convertJsonToDataNode(rmLastPathSegment(uri), rootNode); |
| 203 | ResourceId rid = receivedData.resourceId(); |
| 204 | List<DataNode> dataNodeList = receivedData.dataNodes(); |
| 205 | if (dataNodeList.size() > 1) { |
| 206 | log.warn("There are more than one Data Node can be proceed: {}", dataNodeList.size()); |
| 207 | } |
| 208 | DataNode dataNode = dataNodeList.get(0); |
| 209 | |
| 210 | if (rid == null) { |
| 211 | rid = ResourceId.builder().addBranchPointSchema("/", null).build(); |
| 212 | dataNode = removeTopNode(dataNode); |
| 213 | } |
| 214 | |
| 215 | try { |
| 216 | dynamicConfigService.updateNode(rid, dataNode); |
| 217 | } catch (FailedException e) { |
| 218 | log.error("ERROR: DynamicConfigService: ", e); |
| 219 | throw new RestconfException("ERROR: DynamicConfigService", |
| 220 | INTERNAL_SERVER_ERROR); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | private DataNode removeTopNode(DataNode dataNode) { |
| 225 | if (dataNode instanceof InnerNode && dataNode.key().schemaId().name().equals("/")) { |
| 226 | Map.Entry<NodeKey, DataNode> entry = ((InnerNode) dataNode).childNodes().entrySet().iterator().next(); |
| 227 | dataNode = entry.getValue(); |
| 228 | } |
| 229 | return dataNode; |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public String getRestconfRootPath() { |
| 234 | return RESTCONF_ROOT; |
| 235 | } |
| 236 | |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 237 | @Override |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 238 | public void subscribeEventStream(String streamId, String clientIpAddr, |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 239 | ChunkedOutput<String> output) |
| 240 | throws RestconfException { |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 241 | //TODO: to be completed |
| 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public CompletableFuture<RestconfRpcOutput> runRpc(URI uri, |
| 246 | ObjectNode input, |
| 247 | String clientIpAddress) { |
| 248 | CompletableFuture<RestconfRpcOutput> result = |
| 249 | CompletableFuture.supplyAsync(() -> executeRpc(uri, input, clientIpAddress)); |
| 250 | return result; |
| 251 | } |
| 252 | |
| 253 | private RestconfRpcOutput executeRpc(URI uri, ObjectNode input, String clientIpAddress) { |
| 254 | ResourceData rpcInputNode = convertJsonToDataNode(uri, input); |
| 255 | ResourceId resourceId = rpcInputNode.resourceId(); |
| 256 | List<DataNode> inputDataNodeList = rpcInputNode.dataNodes(); |
| 257 | DataNode inputDataNode = inputDataNodeList.get(0); |
| 258 | RpcInput rpcInput = new RpcInput(inputDataNode); |
| 259 | |
| 260 | RestconfRpcOutput restconfOutput = null; |
| 261 | try { |
| 262 | CompletableFuture<RpcOutput> rpcFuture = |
| 263 | dynamicConfigService.invokeRpc(resourceId, rpcInput); |
| 264 | RpcOutput rpcOutput = rpcFuture.get(); |
| 265 | restconfOutput = RestconfUtils.convertRpcOutput(resourceId, rpcOutput); |
| 266 | } catch (InterruptedException e) { |
| 267 | log.error("ERROR: computeResultQ.take() has been interrupted."); |
| 268 | log.debug("executeRpc Exception:", e); |
| 269 | restconfOutput = new RestconfRpcOutput(INTERNAL_SERVER_ERROR, null); |
| 270 | restconfOutput.reason("RPC execution has been interrupted"); |
| 271 | } catch (Exception e) { |
| 272 | log.error("ERROR: executeRpc: {}", e.getMessage()); |
| 273 | log.debug("executeRpc Exception:", e); |
| 274 | restconfOutput = new RestconfRpcOutput(INTERNAL_SERVER_ERROR, null); |
| 275 | restconfOutput.reason(e.getMessage()); |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Henry Yu | c10f7fc | 2017-07-26 13:42:08 -0400 | [diff] [blame] | 278 | return restconfOutput; |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 279 | } |
| 280 | |
sonugupta-huawei | f0af7aa | 2017-03-17 00:54:52 +0530 | [diff] [blame] | 281 | private ResourceData getDataForStore(ResourceData resourceData) { |
| 282 | List<DataNode> nodes = resourceData.dataNodes(); |
| 283 | ResourceId rid = resourceData.resourceId(); |
| 284 | DataNode.Builder dbr = null; |
| 285 | ResourceId parentId = null; |
| 286 | try { |
| 287 | NodeKey lastKey = rid.nodeKeys().get(rid.nodeKeys().size() - 1); |
| 288 | SchemaId sid = lastKey.schemaId(); |
| 289 | if (lastKey instanceof ListKey) { |
| 290 | dbr = InnerNode.builder( |
| 291 | sid.name(), sid.namespace()).type(MULTI_INSTANCE_NODE); |
| 292 | for (KeyLeaf keyLeaf : ((ListKey) lastKey).keyLeafs()) { |
| 293 | Object val = keyLeaf.leafValue(); |
| 294 | dbr = dbr.addKeyLeaf(keyLeaf.leafSchema().name(), |
| 295 | sid.namespace(), val); |
| 296 | dbr = dbr.createChildBuilder(keyLeaf.leafSchema().name(), |
| 297 | sid.namespace(), val) |
| 298 | .type(SINGLE_INSTANCE_LEAF_VALUE_NODE); |
sonugupta-huawei | 6119ac7 | 2017-03-21 16:25:40 +0530 | [diff] [blame] | 299 | //Exit for key leaf node |
| 300 | dbr = dbr.exitNode(); |
sonugupta-huawei | f0af7aa | 2017-03-17 00:54:52 +0530 | [diff] [blame] | 301 | } |
| 302 | } else { |
| 303 | dbr = InnerNode.builder( |
| 304 | sid.name(), sid.namespace()).type(SINGLE_INSTANCE_NODE); |
| 305 | } |
| 306 | if (nodes != null && !nodes.isEmpty()) { |
| 307 | // adding the parent node for given list of nodes |
| 308 | for (DataNode node : nodes) { |
| 309 | dbr = ((InnerNode.Builder) dbr).addNode(node); |
| 310 | } |
| 311 | } |
| 312 | parentId = rid.copyBuilder().removeLastKey().build(); |
| 313 | } catch (CloneNotSupportedException e) { |
| 314 | e.printStackTrace(); |
| 315 | } |
| 316 | ResourceData.Builder resData = DefaultResourceData.builder(); |
| 317 | resData.addDataNode(dbr.build()); |
| 318 | resData.resourceId(parentId); |
| 319 | return resData.build(); |
| 320 | } |
Jin Gan | 79f7537 | 2017-01-05 15:08:11 -0800 | [diff] [blame] | 321 | } |