Search in sources :

Example 1 with Configuration

use of org.opendaylight.restconf.nb.rfc8040.streams.Configuration in project netconf by opendaylight.

the class CreateStreamUtilTest method createStreamTest.

@Test
public void createStreamTest() {
    payload = prepareDomPayload("create-data-change-event-subscription", RpcDefinition::getInput, "toaster", "path");
    final DOMRpcResult result = CreateStreamUtil.createDataChangeNotifiStream(payload, refSchemaCtx);
    assertEquals(result.getErrors(), Collections.emptyList());
    final NormalizedNode testedNn = result.getResult();
    assertNotNull(testedNn);
    final NormalizedNodePayload contextRef = prepareDomPayload("create-data-change-event-subscription", RpcDefinition::getOutput, "data-change-event-subscription/toaster:toaster/datastore=CONFIGURATION/scope=BASE", "stream-name");
    assertEquals(contextRef.getData(), testedNn);
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 2 with Configuration

use of org.opendaylight.restconf.nb.rfc8040.streams.Configuration in project netconf by opendaylight.

the class RestconfDataServiceImplTest method testReadDataMountPoint.

/**
 * Test read data from mount point when both {@link LogicalDatastoreType#CONFIGURATION} and
 * {@link LogicalDatastoreType#OPERATIONAL} contains the same data and some additional data to be merged.
 */
@Test
public void testReadDataMountPoint() {
    doReturn(new MultivaluedHashMap<String, String>()).when(uriInfo).getQueryParameters();
    doReturn(immediateFluentFuture(Optional.of(buildBaseContConfig))).when(read).read(LogicalDatastoreType.CONFIGURATION, iidBase);
    doReturn(immediateFluentFuture(Optional.of(buildBaseContOperational))).when(read).read(LogicalDatastoreType.OPERATIONAL, iidBase);
    final Response response = dataService.readData("example-jukebox:jukebox/yang-ext:mount/example-jukebox:jukebox", uriInfo);
    assertNotNull(response);
    assertEquals(200, response.getStatus());
    // response must contain all child nodes from config and operational containers merged in one container
    final NormalizedNode data = ((NormalizedNodePayload) response.getEntity()).getData();
    assertTrue(data instanceof ContainerNode);
    assertEquals(3, ((ContainerNode) data).size());
    assertTrue(((ContainerNode) data).findChildByArg(buildPlayerCont.getIdentifier()).isPresent());
    assertTrue(((ContainerNode) data).findChildByArg(buildLibraryCont.getIdentifier()).isPresent());
    assertTrue(((ContainerNode) data).findChildByArg(buildPlaylistList.getIdentifier()).isPresent());
}
Also used : Response(javax.ws.rs.core.Response) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNodePayload(org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 3 with Configuration

use of org.opendaylight.restconf.nb.rfc8040.streams.Configuration in project netconf by opendaylight.

the class RestconfDataServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    doReturn(Set.of()).when(queryParamenters).entrySet();
    doReturn(queryParamenters).when(uriInfo).getQueryParameters();
    baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
    containerPlayerQname = QName.create(baseQName, "player");
    leafQname = QName.create(baseQName, "gap");
    final QName containerLibraryQName = QName.create(baseQName, "library");
    final QName listPlaylistQName = QName.create(baseQName, "playlist");
    final LeafNode<?> buildLeaf = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(leafQname)).withValue(0.2).build();
    buildPlayerCont = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(containerPlayerQname)).withChild(buildLeaf).build();
    buildLibraryCont = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(containerLibraryQName)).build();
    buildPlaylistList = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(listPlaylistQName)).build();
    buildBaseCont = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(baseQName)).withChild(buildPlayerCont).build();
    // config contains one child the same as in operational and one additional
    buildBaseContConfig = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(baseQName)).withChild(buildPlayerCont).withChild(buildLibraryCont).build();
    // operational contains one child the same as in config and one additional
    buildBaseContOperational = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(baseQName)).withChild(buildPlayerCont).withChild(buildPlaylistList).build();
    iidBase = YangInstanceIdentifier.builder().node(baseQName).build();
    contextRef = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
    schemaNode = DataSchemaContextTree.from(contextRef).findChild(iidBase).orElseThrow().getDataSchemaNode();
    doReturn(CommitInfo.emptyFluentFuture()).when(write).commit();
    doReturn(CommitInfo.emptyFluentFuture()).when(readWrite).commit();
    DOMDataBroker mockDataBroker = mock(DOMDataBroker.class);
    doReturn(read).when(mockDataBroker).newReadOnlyTransaction();
    doReturn(readWrite).when(mockDataBroker).newReadWriteTransaction();
    doReturn(write).when(mockDataBroker).newWriteOnlyTransaction();
    final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(mockDataBroker, mock(DOMSchemaService.class));
    schemaContextHandler.onModelContextUpdated(contextRef);
    dataService = new RestconfDataServiceImpl(schemaContextHandler, mockDataBroker, mountPointService, delegRestconfSubscrService, actionService, configuration);
    doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any(YangInstanceIdentifier.class));
    doReturn(Optional.of(FixedDOMSchemaService.of(contextRef))).when(mountPoint).getService(DOMSchemaService.class);
    doReturn(Optional.of(mountDataBroker)).when(mountPoint).getService(DOMDataBroker.class);
    doReturn(Optional.empty()).when(mountPoint).getService(NetconfDataTreeService.class);
    doReturn(read).when(mountDataBroker).newReadOnlyTransaction();
    doReturn(readWrite).when(mountDataBroker).newReadWriteTransaction();
}
Also used : SchemaContextHandler(org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler) QName(org.opendaylight.yangtools.yang.common.QName) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) FixedDOMSchemaService(org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) Before(org.junit.Before)

Example 4 with Configuration

use of org.opendaylight.restconf.nb.rfc8040.streams.Configuration in project netconf by opendaylight.

the class RestconfStreamsSubscriptionServiceImplTest method setUp.

@Before
public void setUp() throws FileNotFoundException, URISyntaxException {
    final DOMDataTreeWriteTransaction wTx = mock(DOMDataTreeWriteTransaction.class);
    doReturn(wTx).when(dataBroker).newWriteOnlyTransaction();
    doReturn(CommitInfo.emptyFluentFuture()).when(wTx).commit();
    schemaHandler = new SchemaContextHandler(dataBroker, mock(DOMSchemaService.class));
    DOMDataTreeChangeService dataTreeChangeService = mock(DOMDataTreeChangeService.class);
    doReturn(mock(ListenerRegistration.class)).when(dataTreeChangeService).registerDataTreeChangeListener(any(), any());
    doReturn(ImmutableClassToInstanceMap.of(DOMDataTreeChangeService.class, dataTreeChangeService)).when(dataBroker).getExtensions();
    doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters();
    doReturn(new LocalUriInfo().getBaseUriBuilder()).when(uriInfo).getBaseUriBuilder();
    doReturn(new URI("http://127.0.0.1/" + URI)).when(uriInfo).getAbsolutePath();
    schemaHandler.onModelContextUpdated(YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/notifications")));
    configurationWs = new Configuration(0, 100, 10, false);
    configurationSse = new Configuration(0, 100, 10, true);
}
Also used : DOMDataTreeChangeService(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService) SchemaContextHandler(org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler) Configuration(org.opendaylight.restconf.nb.rfc8040.streams.Configuration) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) URI(java.net.URI) Before(org.junit.Before)

Example 5 with Configuration

use of org.opendaylight.restconf.nb.rfc8040.streams.Configuration in project netconf by opendaylight.

the class PlainPatchDataTransactionUtil method patchData.

/**
 * Prepare variables for put data to DS. Close {@link DOMTransactionChain} if any inside of object
 * {@link RestconfStrategy} provided as a parameter if any.
 *
 * @param payload       data to put
 * @param schemaContext reference to {@link EffectiveModelContext}
 * @param strategy      object that perform the actual DS operations
 * @return {@link Response}
 */
public static Response patchData(final NormalizedNodePayload payload, final RestconfStrategy strategy, final EffectiveModelContext schemaContext) {
    final RestconfTransaction transaction = strategy.prepareWriteExecution();
    YangInstanceIdentifier path = payload.getInstanceIdentifierContext().getInstanceIdentifier();
    NormalizedNode data = payload.getData();
    try {
        LOG.trace("Merge CONFIGURATION within Restconf Patch: {} with payload {}", path, data);
        TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction);
        transaction.merge(path, data);
    } catch (final RestconfDocumentedException e) {
        transaction.cancel();
        throw new IllegalArgumentException(e);
    }
    final FluentFuture<? extends CommitInfo> future = transaction.commit();
    final ResponseFactory response = new ResponseFactory(Status.OK);
    // closes transactionChain if any, may throw
    FutureCallbackTx.addCallback(future, PatchDataTransactionUtil.PATCH_TX_TYPE, response, path);
    return response.build();
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) RestconfTransaction(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Aggregations

NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 Before (org.junit.Before)2 Test (org.junit.Test)2 SchemaContextHandler (org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler)2 NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 URI (java.net.URI)1 Response (javax.ws.rs.core.Response)1 DOMDataBroker (org.opendaylight.mdsal.dom.api.DOMDataBroker)1 DOMDataTreeChangeService (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService)1 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)1 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)1 DOMSchemaService (org.opendaylight.mdsal.dom.api.DOMSchemaService)1 FixedDOMSchemaService (org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService)1 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)1 RestconfTransaction (org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction)1 Configuration (org.opendaylight.restconf.nb.rfc8040.streams.Configuration)1 ListenerRegistration (org.opendaylight.yangtools.concepts.ListenerRegistration)1 QName (org.opendaylight.yangtools.yang.common.QName)1 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)1