Search in sources :

Example 1 with DataNode

use of org.onosproject.yang.model.DataNode in project onos by opennetworkinglab.

the class DynamicDeviceConfigServiceViewTest method testReadNode.

@Test
public void testReadNode() {
    Filter filter = null;
    DataNode returned = view.readNode(relIntf, filter);
    assertTrue(ResourceIds.isPrefix(rid, realPath));
// FIXME test realFilter
// TODO do we expect something to happen on returned?
}
Also used : Filter(org.onosproject.config.Filter) DataNode(org.onosproject.yang.model.DataNode) Test(org.junit.Test)

Example 2 with DataNode

use of org.onosproject.yang.model.DataNode in project onos by opennetworkinglab.

the class OdtnTapiHandlersTestCommand method doExecute.

@Override
public void doExecute() {
    dcs = get(DynamicConfigService.class);
    modelConverter = get(ModelConverter.class);
    setupTapiContext();
    DataNode data = contextHandler.getDataNode();
    ResourceId empty = ResourceId.builder().build();
    CharSequence strNode = toCharSequence(toXmlCompositeStream(toCompositeData(toResourceData(empty, data))));
    StringBuilder exp = loadXml("/test-tapi-context.xml");
    if (XmlString.prettifyXml(strNode).toString().contentEquals(exp)) {
        printlog("result: ok");
    } else {
        printlog("result: failed");
    }
}
Also used : DynamicConfigService(org.onosproject.config.DynamicConfigService) ResourceId(org.onosproject.yang.model.ResourceId) DataNode(org.onosproject.yang.model.DataNode) ModelConverter(org.onosproject.yang.model.ModelConverter)

Example 3 with DataNode

use of org.onosproject.yang.model.DataNode in project onos by opennetworkinglab.

the class DcsBasedTapiDataProducer method readContextModelObject.

/**
 * Get Tapi context modelObject from Dcs.
 *
 * @return Tapi context modelObject in Dcs store
 */
// FIXME update this method using TapiContextHandler
private DefaultContext readContextModelObject() {
    // read DataNode from DCS
    ModelObjectId mid = ModelObjectId.builder().addChild(DefaultContext.class).build();
    DataNode node = dcs.readNode(getResourceId(mid), Filter.builder().build());
    // convert to ModelObject
    ResourceData data = DefaultResourceData.builder().addDataNode(node).resourceId(ResourceId.builder().build()).build();
    ModelObjectData modelData = modelConverter.createModel(data);
    DefaultContext context = (DefaultContext) modelData.modelObjects().get(0);
    return context;
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) DataNode(org.onosproject.yang.model.DataNode) DefaultModelObjectData(org.onosproject.yang.model.DefaultModelObjectData) ModelObjectData(org.onosproject.yang.model.ModelObjectData) DefaultContext(org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.DefaultContext) ModelObjectId(org.onosproject.yang.model.ModelObjectId)

Example 4 with DataNode

use of org.onosproject.yang.model.DataNode 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 5 with DataNode

use of org.onosproject.yang.model.DataNode in project onos by opennetworkinglab.

the class RestconfManager method runPostOperationOnDataResource.

@Override
public void runPostOperationOnDataResource(URI uri, ObjectNode rootNode) throws RestconfException {
    DataResourceLocator rl = DataResourceLocator.newInstance(uri);
    ResourceData receivedData = convertJsonToDataNode(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.createNode(rl.ridForDynConfig(), dataNode);
    } catch (Exception e) {
        if (e.getMessage().startsWith("Requested node already present")) {
            throw new RestconfException("Already exists", e, RestconfError.ErrorTag.DATA_EXISTS, CONFLICT, Optional.of(uri.getPath()));
        } else {
            log.error("ERROR: DynamicConfigService: creating {} with {}", ResourceIds.toInstanceIdentifier(rl.ridForDynConfig()), dataNode, 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) RestconfException(org.onosproject.restconf.api.RestconfException) FailedException(org.onosproject.config.FailedException) RestconfException(org.onosproject.restconf.api.RestconfException)

Aggregations

DataNode (org.onosproject.yang.model.DataNode)14 FailedException (org.onosproject.config.FailedException)8 DefaultResourceData (org.onosproject.yang.model.DefaultResourceData)7 ResourceData (org.onosproject.yang.model.ResourceData)7 RestconfUtils.convertJsonToDataNode (org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode)6 ResourceId (org.onosproject.yang.model.ResourceId)6 RestconfException (org.onosproject.restconf.api.RestconfException)5 NodeKey (org.onosproject.yang.model.NodeKey)3 Filter (org.onosproject.config.Filter)2 DocumentPath (org.onosproject.store.service.DocumentPath)2 Versioned (org.onosproject.store.service.Versioned)2 InnerNode (org.onosproject.yang.model.InnerNode)2 KeyLeaf (org.onosproject.yang.model.KeyLeaf)2 ModelObjectId (org.onosproject.yang.model.ModelObjectId)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Test (org.junit.Test)1 DynamicConfigService (org.onosproject.config.DynamicConfigService)1 YangToolUtil.toCharSequence (org.onosproject.odtn.utils.YangToolUtil.toCharSequence)1 RestconfError (org.onosproject.restconf.api.RestconfError)1 RestconfRpcOutput (org.onosproject.restconf.api.RestconfRpcOutput)1