Search in sources :

Example 86 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.

the class BaseYangSwaggerGenerator method getApiDeclaration.

public CommonApiObject getApiDeclaration(final String module, final String revision, final UriInfo uriInfo, final URIType uriType, final OAversion oaversion) {
    final EffectiveModelContext schemaContext = schemaService.getGlobalContext();
    Preconditions.checkState(schemaContext != null);
    final SwaggerObject doc = getApiDeclaration(module, revision, uriInfo, schemaContext, "", uriType, oaversion);
    return getAppropriateDoc(doc, oaversion);
}
Also used : SwaggerObject(org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 87 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project controller by opendaylight.

the class ShardManagerTest method testOnCreateShard.

@Test
public void testOnCreateShard() {
    LOG.info("testOnCreateShard starting");
    final TestKit kit = new TestKit(getSystem());
    datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
    ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
    EffectiveModelContext schemaContext = TEST_SCHEMA_CONTEXT;
    shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
    DatastoreContext datastoreContext = DatastoreContext.newBuilder().shardElectionTimeoutFactor(100).persistent(false).build();
    Shard.Builder shardBuilder = Shard.builder();
    ModuleShardConfiguration config = new ModuleShardConfiguration(XMLNamespace.of("foo-ns"), "foo-module", "foo", null, members("member-1", "member-5", "member-6"));
    shardManager.tell(new CreateShard(config, shardBuilder, datastoreContext), kit.getRef());
    kit.expectMsgClass(Duration.ofSeconds(5), Success.class);
    shardManager.tell(new FindLocalShard("foo", true), kit.getRef());
    kit.expectMsgClass(Duration.ofSeconds(5), LocalShardFound.class);
    assertFalse("isRecoveryApplicable", shardBuilder.getDatastoreContext().isPersistent());
    assertTrue("Epxected ShardPeerAddressResolver", shardBuilder.getDatastoreContext().getShardRaftConfig().getPeerAddressResolver() instanceof ShardPeerAddressResolver);
    assertEquals("peerMembers", Sets.newHashSet(ShardIdentifier.create("foo", MemberName.forName("member-5"), shardMrgIDSuffix).toString(), ShardIdentifier.create("foo", MemberName.forName("member-6"), shardMrgIDSuffix).toString()), shardBuilder.getPeerAddresses().keySet());
    assertEquals("ShardIdentifier", ShardIdentifier.create("foo", MEMBER_1, shardMrgIDSuffix), shardBuilder.getId());
    assertSame("schemaContext", schemaContext, shardBuilder.getSchemaContext());
    // Send CreateShard with same name - should return Success with
    // a message.
    shardManager.tell(new CreateShard(config, shardBuilder, null), kit.getRef());
    Success success = kit.expectMsgClass(Duration.ofSeconds(5), Success.class);
    assertNotNull("Success status is null", success.status());
    LOG.info("testOnCreateShard ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) Success(akka.actor.Status.Success) EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Shard(org.opendaylight.controller.cluster.datastore.Shard) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) Test(org.junit.Test) AbstractClusterRefActorTest(org.opendaylight.controller.cluster.datastore.AbstractClusterRefActorTest)

Example 88 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project controller by opendaylight.

the class ShardManagerTest method testOnCreateShardWithNoInitialSchemaContext.

@Test
public void testOnCreateShardWithNoInitialSchemaContext() {
    LOG.info("testOnCreateShardWithNoInitialSchemaContext starting");
    final TestKit kit = new TestKit(getSystem());
    ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
    Shard.Builder shardBuilder = Shard.builder();
    ModuleShardConfiguration config = new ModuleShardConfiguration(XMLNamespace.of("foo-ns"), "foo-module", "foo", null, members("member-1"));
    shardManager.tell(new CreateShard(config, shardBuilder, null), kit.getRef());
    kit.expectMsgClass(Duration.ofSeconds(5), Success.class);
    EffectiveModelContext schemaContext = TEST_SCHEMA_CONTEXT;
    shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
    shardManager.tell(new FindLocalShard("foo", true), kit.getRef());
    kit.expectMsgClass(Duration.ofSeconds(5), LocalShardFound.class);
    assertSame("schemaContext", schemaContext, shardBuilder.getSchemaContext());
    assertNotNull("schemaContext is null", shardBuilder.getDatastoreContext());
    LOG.info("testOnCreateShardWithNoInitialSchemaContext ending");
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Shard(org.opendaylight.controller.cluster.datastore.Shard) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test) AbstractClusterRefActorTest(org.opendaylight.controller.cluster.datastore.AbstractClusterRefActorTest)

Example 89 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext 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 90 with EffectiveModelContext

use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project lighty-netconf-simulator by PANTHEONtech.

the class EditConfigRequestProcessor method ensureParentsByMerge.

private void ensureParentsByMerge(final YangInstanceIdentifier path, final DOMDataTreeWriteTransaction writeTx) {
    final EffectiveModelContext effectiveModelContext = getNetconfDeviceServices().getAdapterContext().currentSerializer().getRuntimeContext().getEffectiveModelContext();
    final List<PathArgument> normalizedPathWithoutChildArgs = new ArrayList<>();
    YangInstanceIdentifier rootNormalizedPath = null;
    final Iterator<PathArgument> it = path.getPathArguments().iterator();
    while (it.hasNext()) {
        final PathArgument pathArgument = it.next();
        if (rootNormalizedPath == null) {
            rootNormalizedPath = YangInstanceIdentifier.create(pathArgument);
        }
        if (it.hasNext()) {
            normalizedPathWithoutChildArgs.add(pathArgument);
        }
    }
    if (normalizedPathWithoutChildArgs.isEmpty()) {
        return;
    }
    Preconditions.checkArgument(rootNormalizedPath != null, "Empty path received");
    final NormalizedNode parentStructure = ImmutableNodes.fromInstanceId(effectiveModelContext, YangInstanceIdentifier.create(normalizedPathWithoutChildArgs));
    writeTx.merge(LogicalDatastoreType.CONFIGURATION, rootNormalizedPath, parentStructure);
}
Also used : ArrayList(java.util.ArrayList) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

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