Search in sources :

Example 1 with YangTextSchemaSourceSerializationProxy

use of org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy in project netconf by opendaylight.

the class NetconfNodeActorTest method testYangTextSchemaSourceRequest.

@Test
public void testYangTextSchemaSourceRequest() throws Exception {
    final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("testID");
    final ProxyYangTextSourceProvider proxyYangProvider = new ProxyYangTextSourceProvider(masterRef, system.dispatcher(), TIMEOUT);
    final YangTextSchemaSource yangTextSchemaSource = YangTextSchemaSource.delegateForByteSource(sourceIdentifier, ByteSource.wrap("YANG".getBytes(UTF_8)));
    // Test success.
    final SchemaSourceRegistration<YangTextSchemaSource> schemaSourceReg = masterSchemaRepository.registerSchemaSource(id -> Futures.immediateFuture(yangTextSchemaSource), PotentialSchemaSource.create(sourceIdentifier, YangTextSchemaSource.class, 1));
    final Future<YangTextSchemaSourceSerializationProxy> resolvedSchemaFuture = proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
    final YangTextSchemaSourceSerializationProxy success = Await.result(resolvedSchemaFuture, TIMEOUT.duration());
    assertEquals(sourceIdentifier, success.getRepresentation().getIdentifier());
    assertEquals("YANG", convertStreamToString(success.getRepresentation().openStream()));
    // Test missing source failure.
    schemaSourceReg.close();
    final MissingSchemaSourceException ex = assertThrows(MissingSchemaSourceException.class, () -> {
        final Future<YangTextSchemaSourceSerializationProxy> failedSchemaFuture = proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
        Await.result(failedSchemaFuture, TIMEOUT.duration());
    });
    assertThat(ex.getMessage(), startsWith("No providers registered for source"));
    assertThat(ex.getMessage(), containsString(sourceIdentifier.toString()));
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) YangTextSchemaSourceSerializationProxy(org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy) MissingSchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException) Test(org.junit.Test)

Example 2 with YangTextSchemaSourceSerializationProxy

use of org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy in project netconf by opendaylight.

the class NetconfNodeActorTest method testMissingSchemaSourceOnMissingProvider.

@Test(expected = MissingSchemaSourceException.class)
public void testMissingSchemaSourceOnMissingProvider() throws Exception {
    final SharedSchemaRepository repository = new SharedSchemaRepository("test");
    SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
    doReturn(repository).when(schemaResourceDTO2).getSchemaRegistry();
    doReturn(repository).when(schemaResourceDTO2).getSchemaRepository();
    final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setActorSystem(system).setSchemaResourceDTO(schemaResourceDTO2).setIdleTimeout(Duration.apply(1, TimeUnit.SECONDS)).setBaseSchemas(BASE_SCHEMAS).build();
    final Props props = NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService);
    ActorRef actor = TestActorRef.create(system, props, "master_messages_2");
    final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("testID");
    final ProxyYangTextSourceProvider proxyYangProvider = new ProxyYangTextSourceProvider(actor, system.dispatcher(), TIMEOUT);
    final Future<YangTextSchemaSourceSerializationProxy> resolvedSchemaFuture = proxyYangProvider.getYangTextSchemaSource(sourceIdentifier);
    Await.result(resolvedSchemaFuture, TIMEOUT.duration());
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) YangTextSchemaSourceSerializationProxy(org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy) Props(akka.actor.Props) SharedSchemaRepository(org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository) SchemaResourcesDTO(org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO) NetconfTopologySetup(org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup) Test(org.junit.Test)

Example 3 with YangTextSchemaSourceSerializationProxy

use of org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy in project netconf by opendaylight.

the class ProxyYangTextSourceProvider method getYangTextSchemaSource.

@Override
public Future<YangTextSchemaSourceSerializationProxy> getYangTextSchemaSource(final SourceIdentifier sourceIdentifier) {
    final Future<Object> scalaFuture = Patterns.ask(masterRef, new YangTextSchemaSourceRequest(sourceIdentifier), actorResponseWaitTime);
    final Promise.DefaultPromise<YangTextSchemaSourceSerializationProxy> promise = new Promise.DefaultPromise<>();
    scalaFuture.onComplete(new OnComplete<Object>() {

        @Override
        public void onComplete(final Throwable failure, final Object success) {
            if (failure != null) {
                promise.failure(failure);
                return;
            }
            promise.success((YangTextSchemaSourceSerializationProxy) success);
        }
    }, executionContext);
    return promise.future();
}
Also used : Promise(scala.concurrent.impl.Promise) YangTextSchemaSourceRequest(org.opendaylight.netconf.topology.singleton.messages.YangTextSchemaSourceRequest) YangTextSchemaSourceSerializationProxy(org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy)

Example 4 with YangTextSchemaSourceSerializationProxy

use of org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy in project netconf by opendaylight.

the class NetconfNodeActor method sendYangTextSchemaSourceProxy.

private void sendYangTextSchemaSourceProxy(final SourceIdentifier sourceIdentifier, final ActorRef sender) {
    final ListenableFuture<YangTextSchemaSource> schemaSourceFuture = schemaRepository.getSchemaSource(sourceIdentifier, YangTextSchemaSource.class);
    Futures.addCallback(schemaSourceFuture, new FutureCallback<YangTextSchemaSource>() {

        @Override
        public void onSuccess(final YangTextSchemaSource yangTextSchemaSource) {
            try {
                LOG.debug("{}: getSchemaSource for {} succeeded", id, sourceIdentifier);
                sender.tell(new YangTextSchemaSourceSerializationProxy(yangTextSchemaSource), getSelf());
            } catch (IOException e) {
                sender.tell(new Failure(e), getSelf());
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.debug("{}: getSchemaSource for {} failed", id, sourceIdentifier, throwable);
            sender.tell(new Failure(throwable), getSelf());
        }
    }, MoreExecutors.directExecutor());
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) YangTextSchemaSourceSerializationProxy(org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy) IOException(java.io.IOException) Failure(akka.actor.Status.Failure)

Aggregations

YangTextSchemaSourceSerializationProxy (org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy)4 Test (org.junit.Test)2 RevisionSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier)2 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)2 YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)2 ActorRef (akka.actor.ActorRef)1 Props (akka.actor.Props)1 Failure (akka.actor.Status.Failure)1 TestActorRef (akka.testkit.TestActorRef)1 IOException (java.io.IOException)1 SchemaResourcesDTO (org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO)1 NetconfTopologySetup (org.opendaylight.netconf.topology.singleton.impl.utils.NetconfTopologySetup)1 YangTextSchemaSourceRequest (org.opendaylight.netconf.topology.singleton.messages.YangTextSchemaSourceRequest)1 MissingSchemaSourceException (org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException)1 SharedSchemaRepository (org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository)1 Promise (scala.concurrent.impl.Promise)1