Search in sources :

Example 1 with FailedException

use of org.onosproject.config.FailedException in project onos by opennetworkinglab.

the class DistributedDynamicConfigStore method deleteInner.

private void deleteInner(String spath) {
    CompletableFuture<Map<String, Versioned<DataNode.Type>>> ret = keystore.getChildren(DocumentPath.from(spath));
    Map<String, Versioned<DataNode.Type>> entries = null;
    entries = complete(ret);
    if ((entries != null) && (!entries.isEmpty())) {
        entries.forEach((k, v) -> {
            String[] names = k.split(ResourceIdParser.NM_CHK);
            String name = names[0];
            String nmSpc = ResourceIdParser.getNamespace(names[1]);
            String keyVal = ResourceIdParser.getKeyVal(names[1]);
            DataNode.Type type = v.value();
            String tempPath = ResourceIdParser.appendNodeKey(spath, name, nmSpc);
            if (type == DataNode.Type.SINGLE_INSTANCE_LEAF_VALUE_NODE) {
                removeLeaf(tempPath);
            } else if (type == DataNode.Type.MULTI_INSTANCE_LEAF_VALUE_NODE) {
                String mlpath = ResourceIdParser.appendLeafList(tempPath, keyVal);
                removeLeaf(mlpath);
            } else if (type == DataNode.Type.SINGLE_INSTANCE_NODE) {
                deleteInner(tempPath);
            } else if (type == DataNode.Type.MULTI_INSTANCE_NODE) {
                tempPath = ResourceIdParser.appendMultiInstKey(tempPath, k);
                deleteInner(tempPath);
            } else {
                throw new FailedException("Invalid node type");
            }
        });
    }
    log.trace(" keystore.removeNode({})", spath);
    keystore.removeNode(DocumentPath.from(spath));
}
Also used : LeafType(org.onosproject.yang.model.LeafType) Versioned(org.onosproject.store.service.Versioned) DataNode(org.onosproject.yang.model.DataNode) FailedException(org.onosproject.config.FailedException) ConsistentMap(org.onosproject.store.service.ConsistentMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with FailedException

use of org.onosproject.config.FailedException in project onos by opennetworkinglab.

the class RestconfManager method runGetOperationOnDataResource.

@Override
public ObjectNode runGetOperationOnDataResource(URI uri) throws RestconfException {
    DataResourceLocator rl = DataResourceLocator.newInstance(uri);
    // TODO: define Filter (if there is any requirement).
    Filter filter = Filter.builder().build();
    DataNode dataNode;
    try {
        if (!dynamicConfigService.nodeExist(rl.ridForDynConfig())) {
            return null;
        }
        dataNode = dynamicConfigService.readNode(rl.ridForDynConfig(), filter);
    } catch (FailedException e) {
        log.error("ERROR: DynamicConfigService: ", e);
        throw new RestconfException("ERROR: DynamicConfigService", e, RestconfError.ErrorTag.OPERATION_FAILED, INTERNAL_SERVER_ERROR, Optional.of(uri.getPath()));
    }
    ObjectNode rootNode = convertDataNodeToJson(rl.ridForYangRuntime(), dataNode);
    return rootNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Filter(org.onosproject.config.Filter) DataNode(org.onosproject.yang.model.DataNode) RestconfUtils.convertJsonToDataNode(org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode) FailedException(org.onosproject.config.FailedException) RestconfException(org.onosproject.restconf.api.RestconfException)

Example 3 with FailedException

use of org.onosproject.config.FailedException in project onos by opennetworkinglab.

the class RestconfManager method runPutOperationOnDataResource.

@Override
public void runPutOperationOnDataResource(URI uri, ObjectNode rootNode) throws RestconfException {
    DataResourceLocator rl = DataResourceLocator.newInstance(uri);
    ResourceData receivedData = convertJsonToDataNode(rmLastPathSegment(rl.uriForYangRuntime()), rootNode);
    List<DataNode> dataNodeList = receivedData.dataNodes();
    if (dataNodeList == null || dataNodeList.isEmpty()) {
        log.warn("There is no one Data Node can be proceed.");
        return;
    }
    if (dataNodeList.size() > 1) {
        log.warn("There are more than one Data Node can be proceed: {}", dataNodeList.size());
    }
    DataNode dataNode = dataNodeList.get(0);
    try {
        /*
             * If the data node already exists, then replace it.
             * Otherwise, create it.
             */
        if (dynamicConfigService.nodeExist(rl.ridForDynConfig())) {
            dynamicConfigService.replaceNode(parentOf(rl.ridForDynConfig()), dataNode);
        } else {
            dynamicConfigService.createNode(parentOf(rl.ridForDynConfig()), dataNode);
        }
    } catch (FailedException e) {
        log.error("ERROR: DynamicConfigService: ", e);
        throw new RestconfException("ERROR: DynamicConfigService", e, RestconfError.ErrorTag.OPERATION_FAILED, INTERNAL_SERVER_ERROR, Optional.of(uri.getPath()));
    }
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) DataNode(org.onosproject.yang.model.DataNode) RestconfUtils.convertJsonToDataNode(org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode) FailedException(org.onosproject.config.FailedException) RestconfException(org.onosproject.restconf.api.RestconfException)

Example 4 with FailedException

use of org.onosproject.config.FailedException in project onos by opennetworkinglab.

the class RestconfManager method runPatchOperationOnDataResource.

@Override
public void runPatchOperationOnDataResource(URI uri, ObjectNode rootNode) throws RestconfException {
    DataResourceLocator rl = DataResourceLocator.newInstance(uri);
    ResourceData receivedData = convertJsonToDataNode(rmLastPathSegment(rl.uriForYangRuntime()), rootNode);
    ResourceId rid = receivedData.resourceId();
    List<DataNode> dataNodeList = receivedData.dataNodes();
    if (dataNodeList == null || dataNodeList.isEmpty()) {
        log.warn("There is no one Data Node can be proceed.");
        return;
    }
    if (dataNodeList.size() > 1) {
        log.warn("There are more than one Data Node can be proceed: {}", dataNodeList.size());
    }
    DataNode dataNode = dataNodeList.get(0);
    if (rid == null) {
        rid = ResourceId.builder().addBranchPointSchema("/", null).build();
        dataNode = removeTopNode(dataNode);
    }
    try {
        dynamicConfigService.updateNode(parentOf(rl.ridForDynConfig()), dataNode);
    } catch (FailedException e) {
        log.error("ERROR: DynamicConfigService: ", e);
        throw new RestconfException("ERROR: DynamicConfigService", e, RestconfError.ErrorTag.OPERATION_FAILED, INTERNAL_SERVER_ERROR, Optional.of(uri.getPath()));
    }
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) ResourceId(org.onosproject.yang.model.ResourceId) DataNode(org.onosproject.yang.model.DataNode) RestconfUtils.convertJsonToDataNode(org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode) FailedException(org.onosproject.config.FailedException) RestconfException(org.onosproject.restconf.api.RestconfException)

Example 5 with FailedException

use of org.onosproject.config.FailedException in project onos by opennetworkinglab.

the class DistributedDynamicConfigStore method addNode.

@Override
public CompletableFuture<Boolean> addNode(ResourceId parent, DataNode node) {
    String spath = ResourceIdParser.parseResId(parent);
    log.trace(" addNode({}, {})", parent, node);
    log.trace(" spath={}", spath);
    if (spath == null) {
        throw new FailedException("Invalid ResourceId, cannot create Node");
    }
    if (spath.equals(ResourceIdParser.ROOT)) {
        // If not present, adding static ROOT node after immutable documentTree root.
        if (complete(keystore.get(DocumentPath.from(spath))) == null) {
            addLeaf(spath, LeafNode.builder(DeviceResourceIds.ROOT_NAME, DCS_NAMESPACE).type(DataNode.Type.SINGLE_INSTANCE_NODE).build());
        }
        ResourceId abs = ResourceIds.resourceId(parent, node);
        parseNode(ResourceIdParser.parseResId(abs), node);
        return CompletableFuture.completedFuture(true);
    } else if (complete(keystore.get(DocumentPath.from(spath))) == null) {
        throw new FailedException("Node or parent does not exist for " + spath);
    }
    ResourceId abs = ResourceIds.resourceId(parent, node);
    // spath = ResourceIdParser.appendNodeKey(spath, node.key());
    parseNode(ResourceIdParser.parseResId(abs), node);
    return CompletableFuture.completedFuture(true);
}
Also used : ResourceId(org.onosproject.yang.model.ResourceId) FailedException(org.onosproject.config.FailedException)

Aggregations

FailedException (org.onosproject.config.FailedException)10 DataNode (org.onosproject.yang.model.DataNode)8 Versioned (org.onosproject.store.service.Versioned)4 RestconfException (org.onosproject.restconf.api.RestconfException)3 RestconfUtils.convertJsonToDataNode (org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ConsistentMap (org.onosproject.store.service.ConsistentMap)2 DocumentPath (org.onosproject.store.service.DocumentPath)2 DefaultResourceData (org.onosproject.yang.model.DefaultResourceData)2 LeafNode (org.onosproject.yang.model.LeafNode)2 LeafType (org.onosproject.yang.model.LeafType)2 NodeKey (org.onosproject.yang.model.NodeKey)2 ResourceData (org.onosproject.yang.model.ResourceData)2 ResourceId (org.onosproject.yang.model.ResourceId)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Filter (org.onosproject.config.Filter)1 RpcExecutor (org.onosproject.config.RpcExecutor)1 InnerNode (org.onosproject.yang.model.InnerNode)1 KeyLeaf (org.onosproject.yang.model.KeyLeaf)1