Search in sources :

Example 6 with DOMMountPoint

use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.

the class MountPointEndToEndTest method testMaster.

private MasterSalFacade testMaster() throws InterruptedException, ExecutionException, TimeoutException {
    LOG.info("****** Testing master");
    writeNetconfNode(TEST_DEFAULT_SUBDIR, masterDataBroker);
    final MasterSalFacade masterSalFacade = masterSalFacadeFuture.get(5, TimeUnit.SECONDS);
    final ArrayList<String> capabilities = Lists.newArrayList(NetconfMessageTransformUtil.NETCONF_CANDIDATE_URI.toString());
    masterSalFacade.onDeviceConnected(new EmptyMountPointContext(deviceSchemaContext), NetconfSessionPreferences.fromStrings(capabilities), deviceRpcService.getRpcService());
    DOMMountPoint masterMountPoint = awaitMountPoint(masterMountPointService);
    LOG.info("****** Testing master DOMDataBroker operations");
    testDOMDataBrokerOperations(getDOMDataBroker(masterMountPoint));
    LOG.info("****** Testing master DOMRpcService");
    testDOMRpcService(getDOMRpcService(masterMountPoint));
    return masterSalFacade;
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint)

Example 7 with DOMMountPoint

use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.

the class MountPointEndToEndTest method testSlave.

private void testSlave() throws InterruptedException, ExecutionException, TimeoutException {
    LOG.info("****** Testing slave");
    writeNetconfNode("slave", slaveDataBroker);
    verify(mockSlaveClusterSingletonServiceProvider, timeout(5000)).registerClusterSingletonService(any());
    // Since the master and slave use separate DataBrokers we need to copy the master's oper node to the slave.
    // This is essentially what happens in a clustered environment but we'll use a DTCL here.
    masterDataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, NODE_INSTANCE_ID), changes -> {
        final WriteTransaction slaveTx = slaveTxChain.newWriteOnlyTransaction();
        for (DataTreeModification<Node> dataTreeModification : changes) {
            DataObjectModification<Node> rootNode = dataTreeModification.getRootNode();
            InstanceIdentifier<Node> path = dataTreeModification.getRootPath().getRootIdentifier();
            switch(rootNode.getModificationType()) {
                case WRITE:
                case SUBTREE_MODIFIED:
                    slaveTx.merge(LogicalDatastoreType.OPERATIONAL, path, rootNode.getDataAfter());
                    break;
                case DELETE:
                    slaveTx.delete(LogicalDatastoreType.OPERATIONAL, path);
                    break;
                default:
                    break;
            }
        }
        slaveTx.commit();
    });
    DOMMountPoint slaveMountPoint = awaitMountPoint(slaveMountPointService);
    final NetconfTopologyContext slaveNetconfTopologyContext = slaveNetconfTopologyContextFuture.get(5, TimeUnit.SECONDS);
    verify(slaveNetconfTopologyContext, never()).newMasterSalFacade();
    LOG.info("****** Testing slave DOMDataBroker operations");
    testDOMDataBrokerOperations(getDOMDataBroker(slaveMountPoint));
    LOG.info("****** Testing slave DOMRpcService");
    testDOMRpcService(getDOMRpcService(slaveMountPoint));
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint)

Example 8 with DOMMountPoint

use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.

the class RestconfDataServiceImpl method patchData.

@Override
public PatchStatusContext patchData(final PatchContext context, final UriInfo uriInfo) {
    final DOMMountPoint mountPoint = RestconfDocumentedException.throwIfNull(context, ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE, "No patch documented provided").getInstanceIdentifierContext().getMountPoint();
    final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
    return PatchDataTransactionUtil.patchData(context, strategy, getSchemaContext(mountPoint));
}
Also used : DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) RestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)

Example 9 with DOMMountPoint

use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.

the class RestconfDataServiceImpl method deleteData.

@Override
public Response deleteData(final String identifier) {
    final InstanceIdentifierContext<?> instanceIdentifier = ParserIdentifier.toInstanceIdentifier(identifier, schemaContextHandler.get(), Optional.of(mountPointService));
    final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
    final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
    return DeleteDataTransactionUtil.deleteData(strategy, instanceIdentifier.getInstanceIdentifier());
}
Also used : DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) RestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)

Example 10 with DOMMountPoint

use of org.opendaylight.mdsal.dom.api.DOMMountPoint in project netconf by opendaylight.

the class RestconfDataServiceImpl method readData.

@Override
public Response readData(final String identifier, final UriInfo uriInfo) {
    final ReadDataParams readParams = QueryParams.newReadDataParams(uriInfo);
    final EffectiveModelContext schemaContextRef = schemaContextHandler.get();
    final InstanceIdentifierContext<?> instanceIdentifier = ParserIdentifier.toInstanceIdentifier(identifier, schemaContextRef, Optional.of(mountPointService));
    final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
    // FIXME: this looks quite crazy, why do we even have it?
    if (mountPoint == null && identifier != null && identifier.contains(STREAMS_PATH) && !identifier.contains(STREAM_PATH_PART)) {
        createAllYangNotificationStreams(schemaContextRef, uriInfo);
    }
    final QueryParameters queryParams = QueryParams.newQueryParameters(readParams, instanceIdentifier);
    final List<YangInstanceIdentifier> fieldPaths = queryParams.fieldPaths();
    final RestconfStrategy strategy = getRestconfStrategy(mountPoint);
    final NormalizedNode node;
    if (fieldPaths != null && !fieldPaths.isEmpty()) {
        node = ReadDataTransactionUtil.readData(readParams.content(), instanceIdentifier.getInstanceIdentifier(), strategy, readParams.withDefaults(), schemaContextRef, fieldPaths);
    } else {
        node = ReadDataTransactionUtil.readData(readParams.content(), instanceIdentifier.getInstanceIdentifier(), strategy, readParams.withDefaults(), schemaContextRef);
    }
    // FIXME: this is utter craziness, refactor it properly!
    if (identifier != null && identifier.contains(STREAM_PATH) && identifier.contains(STREAM_ACCESS_PATH_PART) && identifier.contains(STREAM_LOCATION_PATH_PART)) {
        final String value = (String) node.body();
        final String streamName = value.substring(value.indexOf(NOTIFICATION_STREAM + '/'));
        delegRestconfSubscrService.subscribeToStream(streamName, uriInfo);
    }
    if (node == null) {
        throw new RestconfDocumentedException("Request could not be completed because the relevant data model content does not exist", ErrorType.PROTOCOL, ErrorTag.DATA_MISSING);
    }
    switch(readParams.content()) {
        case ALL:
        case CONFIG:
            final QName type = node.getIdentifier().getNodeType();
            return Response.status(Status.OK).entity(NormalizedNodePayload.ofReadData(instanceIdentifier, node, queryParams)).header("ETag", '"' + type.getModule().getRevision().map(Revision::toString).orElse(null) + "-" + type.getLocalName() + '"').header("Last-Modified", FORMATTER.format(LocalDateTime.now(Clock.systemUTC()))).build();
        default:
            return Response.status(Status.OK).entity(NormalizedNodePayload.ofReadData(instanceIdentifier, node, queryParams)).build();
    }
}
Also used : ReadDataParams(org.opendaylight.restconf.nb.rfc8040.ReadDataParams) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) QName(org.opendaylight.yangtools.yang.common.QName) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) RestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy) MdsalRestconfStrategy(org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy) QueryParameters(org.opendaylight.restconf.nb.rfc8040.legacy.QueryParameters) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Revision(org.opendaylight.yangtools.yang.common.Revision) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Aggregations

DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)38 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)16 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)15 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)13 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)9 NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)8 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)8 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)7 RestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy)7 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)6 Test (org.junit.Test)5 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)5 QName (org.opendaylight.yangtools.yang.common.QName)5 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ExecutionException (java.util.concurrent.ExecutionException)4 DOMDataTreeReadWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction)4 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)4 SchemaNode (org.opendaylight.yangtools.yang.model.api.SchemaNode)4