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;
}
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));
}
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));
}
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());
}
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();
}
}
Aggregations