Search in sources :

Example 21 with ResourceId

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

the class OpenConfigTransceiverHandlerTest method testSetResourceId.

/**
 * UnitTest method for setResourceId.
 */
@Test
public void testSetResourceId() {
    // call setResourceId
    OpenConfigTransceiverHandler transceiver = new OpenConfigTransceiverHandler(parent);
    // get resourceId
    ResourceId resourceId = null;
    try {
        Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId");
        field.setAccessible(true);
        resourceId = (ResourceId) field.get(transceiver);
    } catch (NoSuchFieldException e) {
        Assert.fail("[NG]setResourceId:ResourceId does not exist.\n" + e);
    } catch (IllegalAccessException e) {
        Assert.fail("[NG]setResourceId:Access to ResourceId is illegal.\n" + e);
    }
    assertEquals("[NG]setResourceId:Set ResourceId is not an expected one.\n", rid, resourceId);
}
Also used : Field(java.lang.reflect.Field) ResourceId(org.onosproject.yang.model.ResourceId) Test(org.junit.Test)

Example 22 with ResourceId

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

the class DataResourceLocator method newInstance.

/**
 * Creates a DataResourceLocator object based on a given URI.
 *
 * @param uri given URI
 * @return instantiated DataResourceLocator object
 */
public static DataResourceLocator newInstance(URI uri) {
    URI uriForYangRuntime = uriForYangRuntime(uri);
    ResourceId yrtResourceId = ridForYangRuntime(uriForYangRuntime);
    /*
         * If the given URI starts with "devices/device" prefix, then form the
         * resource ID used by dyn-config by adding the prefix to the resource ID
         * used by YANG runtime. Otherwise the two resource IDs are the same.
         */
    ResourceId dcsResourceId = isDeviceResource(uri) ? addDevicePrefix(yrtResourceId, getDeviceId(uri)) : yrtResourceId;
    return new DataResourceLocator(yrtResourceId, dcsResourceId, uri, uriForYangRuntime);
}
Also used : DeviceResourceIds.toResourceId(org.onosproject.d.config.DeviceResourceIds.toResourceId) ResourceId(org.onosproject.yang.model.ResourceId) URI(java.net.URI)

Example 23 with ResourceId

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

the class RestconfManager method getDataForStore.

private ResourceData getDataForStore(ResourceData resourceData) {
    List<DataNode> nodes = resourceData.dataNodes();
    ResourceId rid = resourceData.resourceId();
    DataNode.Builder dbr = null;
    ResourceId parentId = null;
    try {
        NodeKey lastKey = rid.nodeKeys().get(rid.nodeKeys().size() - 1);
        SchemaId sid = lastKey.schemaId();
        if (lastKey instanceof ListKey) {
            dbr = InnerNode.builder(sid.name(), sid.namespace()).type(MULTI_INSTANCE_NODE);
            for (KeyLeaf keyLeaf : ((ListKey) lastKey).keyLeafs()) {
                Object val = keyLeaf.leafValue();
                dbr = dbr.addKeyLeaf(keyLeaf.leafSchema().name(), sid.namespace(), val);
                dbr = dbr.createChildBuilder(keyLeaf.leafSchema().name(), sid.namespace(), val).type(SINGLE_INSTANCE_LEAF_VALUE_NODE);
                // Exit for key leaf node
                dbr = dbr.exitNode();
            }
        } else {
            dbr = InnerNode.builder(sid.name(), sid.namespace()).type(SINGLE_INSTANCE_NODE);
        }
        if (nodes != null && !nodes.isEmpty()) {
            // adding the parent node for given list of nodes
            for (DataNode node : nodes) {
                dbr = ((InnerNode.Builder) dbr).addNode(node);
            }
        }
        parentId = rid.copyBuilder().removeLastKey().build();
    } catch (CloneNotSupportedException e) {
        log.error("getDataForStore()", e);
        return null;
    }
    ResourceData.Builder resData = DefaultResourceData.builder();
    resData.addDataNode(dbr.build());
    resData.resourceId(parentId);
    return resData.build();
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) KeyLeaf(org.onosproject.yang.model.KeyLeaf) InnerNode(org.onosproject.yang.model.InnerNode) ListKey(org.onosproject.yang.model.ListKey) ResourceId(org.onosproject.yang.model.ResourceId) DataNode(org.onosproject.yang.model.DataNode) RestconfUtils.convertJsonToDataNode(org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode) SchemaId(org.onosproject.yang.model.SchemaId) NodeKey(org.onosproject.yang.model.NodeKey)

Example 24 with ResourceId

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

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

the class RestconfManager method executeRpc.

private RestconfRpcOutput executeRpc(URI uri, ObjectNode input, String clientIpAddress) {
    ResourceData rpcInputNode = convertJsonToDataNode(uri, input);
    ResourceId resourceId = rpcInputNode.resourceId();
    List<DataNode> inputDataNodeList = rpcInputNode.dataNodes();
    DataNode inputDataNode = inputDataNodeList.get(0);
    RpcInput rpcInput = new RpcInput(resourceId, inputDataNode);
    RestconfRpcOutput restconfOutput = null;
    try {
        CompletableFuture<RpcOutput> rpcFuture = dynamicConfigService.invokeRpc(rpcInput);
        RpcOutput rpcOutput = rpcFuture.get();
        restconfOutput = RestconfUtils.convertRpcOutput(resourceId, rpcOutput);
    } catch (InterruptedException e) {
        log.error("ERROR: computeResultQ.take() has been interrupted.");
        log.debug("executeRpc Exception:", e);
        RestconfError error = RestconfError.builder(RestconfError.ErrorType.RPC, RestconfError.ErrorTag.OPERATION_FAILED).errorMessage("RPC execution has been interrupted").errorPath(uri.getPath()).build();
        restconfOutput = new RestconfRpcOutput(INTERNAL_SERVER_ERROR, RestconfError.wrapErrorAsJson(Arrays.asList(error)));
        restconfOutput.reason("RPC execution has been interrupted");
    } catch (Exception e) {
        log.error("ERROR: executeRpc: {}", e.getMessage());
        log.debug("executeRpc Exception:", e);
        RestconfError error = RestconfError.builder(RestconfError.ErrorType.RPC, RestconfError.ErrorTag.OPERATION_FAILED).errorMessage(e.getMessage()).errorPath(uri.getPath()).build();
        restconfOutput = new RestconfRpcOutput(INTERNAL_SERVER_ERROR, RestconfError.wrapErrorAsJson(Arrays.asList(error)));
        restconfOutput.reason(e.getMessage());
    }
    return restconfOutput;
}
Also used : ResourceData(org.onosproject.yang.model.ResourceData) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) RestconfRpcOutput(org.onosproject.restconf.api.RestconfRpcOutput) ResourceId(org.onosproject.yang.model.ResourceId) DataNode(org.onosproject.yang.model.DataNode) RestconfUtils.convertJsonToDataNode(org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode) RpcInput(org.onosproject.yang.model.RpcInput) RestconfRpcOutput(org.onosproject.restconf.api.RestconfRpcOutput) RpcOutput(org.onosproject.yang.model.RpcOutput) RestconfError(org.onosproject.restconf.api.RestconfError) FailedException(org.onosproject.config.FailedException) RestconfException(org.onosproject.restconf.api.RestconfException)

Aggregations

ResourceId (org.onosproject.yang.model.ResourceId)30 Test (org.junit.Test)21 Field (java.lang.reflect.Field)12 DeviceResourceIds.toResourceId (org.onosproject.d.config.DeviceResourceIds.toResourceId)6 DataNode (org.onosproject.yang.model.DataNode)6 FailedException (org.onosproject.config.FailedException)4 RestconfUtils.convertJsonToDataNode (org.onosproject.restconf.utils.RestconfUtils.convertJsonToDataNode)4 DefaultResourceData (org.onosproject.yang.model.DefaultResourceData)4 ResourceData (org.onosproject.yang.model.ResourceData)4 RestconfException (org.onosproject.restconf.api.RestconfException)3 KeyLeaf (org.onosproject.yang.model.KeyLeaf)3 ListKey (org.onosproject.yang.model.ListKey)3 SchemaId (org.onosproject.yang.model.SchemaId)3 DeviceId (org.onosproject.net.DeviceId)2 URI (java.net.URI)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 DynamicConfigEvent (org.onosproject.config.DynamicConfigEvent)1 DynamicConfigListener (org.onosproject.config.DynamicConfigListener)1 DynamicConfigService (org.onosproject.config.DynamicConfigService)1 YangToolUtil.toCharSequence (org.onosproject.odtn.utils.YangToolUtil.toCharSequence)1