Search in sources :

Example 76 with EffectiveModelContext

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);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 77 with EffectiveModelContext

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;
}
Also used : EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 78 with EffectiveModelContext

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));
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 79 with EffectiveModelContext

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);
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) QName(org.opendaylight.yangtools.yang.common.QName) IOException(java.io.IOException) Document(org.w3c.dom.Document) XMLStreamException(javax.xml.stream.XMLStreamException) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 80 with EffectiveModelContext

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);
}
Also used : SchemaContextHandler(org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Before(org.junit.Before)

Aggregations

EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)182 Test (org.junit.Test)99 Module (org.opendaylight.yangtools.yang.model.api.Module)37 QName (org.opendaylight.yangtools.yang.common.QName)29 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)28 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)26 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)24 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)24 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)21 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)18 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)16 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)16 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)16 IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)14 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)13 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)13 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)13 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)11 IOException (java.io.IOException)9 Collection (java.util.Collection)9