Search in sources :

Example 1 with ModuleLike

use of org.opendaylight.yangtools.yang.model.api.ModuleLike 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)

Aggregations

Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)1 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)1 NetconfState (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState)1 SchemasBuilder (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder)1 Schema (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema)1 SchemaKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaKey)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1 ModuleLike (org.opendaylight.yangtools.yang.model.api.ModuleLike)1