Search in sources :

Example 1 with SchemasBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder in project netconf by opendaylight.

the class MonitoringToMdsalWriterTest method testOnSchemasChanged.

@Test
public void testOnSchemasChanged() throws Exception {
    final InstanceIdentifier<Schemas> schemasId = InstanceIdentifier.create(NetconfState.class).child(Schemas.class);
    writer.start();
    final Schemas schemas = new SchemasBuilder().build();
    writer.onSchemasChanged(schemas);
    InOrder inOrder = inOrder(writeTransaction);
    inOrder.verify(writeTransaction).put(LogicalDatastoreType.OPERATIONAL, schemasId, schemas);
    inOrder.verify(writeTransaction).commit();
}
Also used : InOrder(org.mockito.InOrder) SchemasBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder) Schemas(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Schemas) NetconfState(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState) Test(org.junit.Test)

Example 2 with SchemasBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder in project lighty-netconf-simulator by PANTHEONtech.

the class NetconfDeviceImpl method prepareSchemasForNetconfMonitoring.

/**
 * Method creates schemas from device's schema context and
 * stores them in the netconf-state/schemas path in operational datastore.
 * netconfDeviceServices represents device services from which
 * the modules loaded in schema-context will be converted to schemas
 * stored in netconf-state/schemas.
 * @return transaction commit information in FluentFuture
 */
private FluentFuture<? extends CommitInfo> prepareSchemasForNetconfMonitoring() {
    HashMap<SchemaKey, Schema> mapSchemas = new HashMap<>();
    EffectiveModelContext modelContext = netconfDeviceServices.getAdapterContext().currentSerializer().getRuntimeContext().getEffectiveModelContext();
    Queue<Collection<? extends ModuleLike>> queueModulesCollections = new LinkedList<>();
    queueModulesCollections.add(modelContext.getModules());
    while (!queueModulesCollections.isEmpty()) {
        Collection<? extends ModuleLike> modules = queueModulesCollections.poll();
        for (ModuleLike module : modules) {
            Schema schema = createSchemaFromModule(module);
            if (!mapSchemas.containsKey(schema.key())) {
                mapSchemas.put(schema.key(), schema);
                if (!module.getSubmodules().isEmpty()) {
                    queueModulesCollections.add(module.getSubmodules());
                }
            }
        }
    }
    WriteTransaction writeTx = netconfDeviceServices.getDataBroker().newWriteOnlyTransaction();
    writeTx.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(NetconfState.class).child(Schemas.class).build(), new SchemasBuilder().setSchema(mapSchemas).build());
    return writeTx.commit();
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) HashMap(java.util.HashMap) Schema(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema) SchemaKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaKey) LinkedList(java.util.LinkedList) NetconfState(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState) ModuleLike(org.opendaylight.yangtools.yang.model.api.ModuleLike) Collection(java.util.Collection) SchemasBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 3 with SchemasBuilder

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder in project netconf by opendaylight.

the class NetconfCapabilityMonitoringService method transformSchemas.

private static Schemas transformSchemas(final Set<Capability> caps) {
    final Map<SchemaKey, Schema> schemas = Maps.newHashMapWithExpectedSize(caps.size());
    for (final Capability cap : caps) {
        if (isValidModuleCapability(cap)) {
            final SchemaKey key = new SchemaKey(Yang.class, cap.getModuleName().get(), cap.getRevision().orElse(""));
            schemas.put(key, new SchemaBuilder().withKey(key).setNamespace(new Uri(cap.getModuleNamespace().get())).setLocation(transformLocations(cap.getLocation())).build());
        }
    }
    return new SchemasBuilder().setSchema(schemas).build();
}
Also used : Capability(org.opendaylight.netconf.api.capability.Capability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) Schema(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema) SchemaBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaBuilder) SchemasBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder) SchemaKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaKey) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)

Aggregations

SchemasBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder)3 NetconfState (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState)2 Schema (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema)2 SchemaKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaKey)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)1 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)1 BasicCapability (org.opendaylight.netconf.api.capability.BasicCapability)1 Capability (org.opendaylight.netconf.api.capability.Capability)1 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)1 Schemas (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Schemas)1 SchemaBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaBuilder)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1 ModuleLike (org.opendaylight.yangtools.yang.model.api.ModuleLike)1