use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class ListenerAdapter method prepareXml.
/**
* Tracks events of data change by customer.
*/
/**
* Prepare data in printable form and transform it to String.
*
* @return Data in printable form.
*/
private String prepareXml(final Collection<DataTreeCandidate> candidates) {
final EffectiveModelContext schemaContext = controllerContext.getGlobalSchema();
final Document doc = createDocument();
final Element notificationElement = basePartDoc(doc);
final Element dataChangedNotificationEventElement = doc.createElementNS("urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote", "data-changed-notification");
addValuesToDataChangedNotificationEventElement(doc, dataChangedNotificationEventElement, candidates, schemaContext);
notificationElement.appendChild(dataChangedNotificationEventElement);
return transformDoc(doc);
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class NetconfNestedNotificationTest method getNotificationSchemaContext.
private EffectiveModelContext getNotificationSchemaContext(final Collection<String> yangResources) {
final EffectiveModelContext context = YangParserTestUtils.parseYangResources(getClass(), yangResources);
final Collection<? extends Module> modules = context.getModules();
assertFalse(modules.isEmpty());
return context;
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class NetconfToNotificationTest method testMostRecentWrongYangModel.
@Test
public void testMostRecentWrongYangModel() throws Exception {
final EffectiveModelContext schemaContext = getNotificationSchemaContext(getClass(), true);
messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true, BASE_SCHEMAS.getBaseSchema());
assertThrows(IllegalArgumentException.class, () -> messageTransformer.toNotification(userNotification));
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class NetconfMessageTransformer method toRpcRequest.
@Override
public NetconfMessage toRpcRequest(final QName rpc, final NormalizedNode payload) {
// In case no input for rpc is defined, we can simply construct the payload here
// Determine whether a base netconf operation is being invoked
// and also check if the device exposed model for base netconf.
// If no, use pre built base netconf operations model
final boolean needToUseBaseCtx = mappedRpcs.get(rpc) == null && isBaseOrNotificationRpc(rpc);
final ImmutableMap<QName, ? extends RpcDefinition> currentMappedRpcs;
if (needToUseBaseCtx) {
currentMappedRpcs = baseSchema.getMappedRpcs();
} else {
currentMappedRpcs = mappedRpcs;
}
final RpcDefinition mappedRpc = Preconditions.checkNotNull(currentMappedRpcs.get(rpc), "Unknown rpc %s, available rpcs: %s", rpc, currentMappedRpcs.keySet());
if (mappedRpc.getInput().getChildNodes().isEmpty()) {
return new NetconfMessage(NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpc, counter).getNode().getOwnerDocument());
}
Preconditions.checkNotNull(payload, "Transforming an rpc with input: %s, payload cannot be null", rpc);
Preconditions.checkArgument(payload instanceof ContainerNode, "Transforming an rpc with input: %s, payload has to be a container, but was: %s", rpc, payload);
final DOMResult result = NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpc, counter);
try {
// If the schema context for netconf device does not contain model for base netconf operations,
// use default pre build context with just the base model
// This way operations like lock/unlock are supported even if the source for base model was not provided
final EffectiveModelContext ctx = needToUseBaseCtx ? baseSchema.getEffectiveModelContext() : mountContext.getEffectiveModelContext();
NetconfMessageTransformUtil.writeNormalizedOperationInput((ContainerNode) payload, result, Absolute.of(rpc), ctx);
} catch (final XMLStreamException | IOException | IllegalStateException e) {
throw new IllegalStateException("Unable to serialize input of " + rpc, e);
}
final Document node = result.getNode().getOwnerDocument();
return new NetconfMessage(node);
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class RestconfInvokeOperationsServiceImplTest method setup.
@Before
public void setup() throws Exception {
final EffectiveModelContext contextRef = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT));
final DOMDataBroker dataBroker = mock(DOMDataBroker.class);
final DOMDataTreeWriteTransaction wTx = mock(DOMDataTreeWriteTransaction.class);
doReturn(wTx).when(dataBroker).newWriteOnlyTransaction();
doReturn(CommitInfo.emptyFluentFuture()).when(wTx).commit();
final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(dataBroker, mock(DOMSchemaService.class));
schemaContextHandler.onModelContextUpdated(contextRef);
invokeOperationsService = new RestconfInvokeOperationsServiceImpl(rpcService, schemaContextHandler);
}
Aggregations