Search in sources :

Example 11 with ResourceId

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

the class OpenConfigConfigOfComponentHandlerTest method testSetResourceId.

/**
 * UnitTest method for setResourceId.
 */
@Test
public void testSetResourceId() {
    // call setResourceId
    OpenConfigConfigOfComponentHandler config = new OpenConfigConfigOfComponentHandler(parent);
    // get resourceId
    ResourceId resourceId = null;
    try {
        Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId");
        field.setAccessible(true);
        resourceId = (ResourceId) field.get(config);
    } 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 12 with ResourceId

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

the class OpenConfigLogicalChannelAssignmentsHandlerTest method testSetResourceId.

/**
 * UnitTest method for setResourceId.
 */
@Test
public void testSetResourceId() {
    // call setResourceId
    OpenConfigLogicalChannelAssignmentsHandler logicalChannelAssignments = new OpenConfigLogicalChannelAssignmentsHandler(parent);
    // get resourceId
    ResourceId resourceId = null;
    try {
        Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId");
        field.setAccessible(true);
        resourceId = (ResourceId) field.get(logicalChannelAssignments);
    } 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 13 with ResourceId

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

Example 14 with ResourceId

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

the class OdtnDcsModelCheckCommand method dumpDcsStore.

private <T extends InnerModelObject> void dumpDcsStore(Class<T> cls) {
    ModelObjectId mid = ModelObjectId.builder().addChild(cls).build();
    DataNode all = dcs.readNode(getResourceId(mid), Filter.builder().build());
    ResourceId empty = ResourceId.builder().build();
    CharSequence strNode = toCharSequence(toXmlCompositeStream(toCompositeData(toResourceData(empty, all))));
    printlog("XML:\n{}", XmlString.prettifyXml(strNode));
}
Also used : ResourceId(org.onosproject.yang.model.ResourceId) DataNode(org.onosproject.yang.model.DataNode) YangToolUtil.toCharSequence(org.onosproject.odtn.utils.YangToolUtil.toCharSequence) ModelObjectId(org.onosproject.yang.model.ModelObjectId)

Example 15 with ResourceId

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

the class OpenConfigAssignmentHandlerTest method testSetResourceId.

/**
 * UnitTest method for setResourceId.
 */
@Test
public void testSetResourceId() {
    // call setResourceId
    OpenConfigAssignmentHandler assignment = new OpenConfigAssignmentHandler(2, parent);
    // get resourceId
    ResourceId resourceId = null;
    try {
        Field field = OpenConfigObjectHandler.class.getDeclaredField("resourceId");
        field.setAccessible(true);
        resourceId = (ResourceId) field.get(assignment);
    } 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)

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