use of org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO in project netconf by opendaylight.
the class DefaultSchemaResourceManager method createResources.
@NonNull
private SchemaResourcesDTO createResources(final String subdir) {
// Setup the baseline empty registry
final SharedSchemaRepository repository = new SharedSchemaRepository(subdir, parserFactory);
// Teach the registry how to transform YANG text to IRSchemaSource internally
repository.registerSchemaSourceListener(TextToIRTransformer.create(repository, repository));
// Attach a soft cache of IRSchemaSource instances. This is important during convergence when we are fishing
// for a consistent set of modules, as it skips the need to re-parse the text sources multiple times. It also
// helps establishing different sets of contexts, as they can share this pre-made cache.
repository.registerSchemaSourceListener(// FIXME: add knobs to control cache lifetime explicitly
GuavaSchemaSourceCache.createSoftCache(repository, IRSchemaSource.class));
// Attach the filesystem cache, providing persistence capability, so that restarts do not require us to
// re-populate the cache. This also acts as a side-load capability, as anything pre-populated into that
// directory will not be fetched from the device.
repository.registerSchemaSourceListener(new FilesystemSchemaSourceCache<>(repository, YangTextSchemaSource.class, new File(rootDirectory + File.separator + subdir)));
return new SchemaResourcesDTO(repository, repository, repository.createEffectiveModelContextFactory(SchemaContextFactoryConfiguration.getDefault()), new NetconfStateSchemasResolverImpl());
}
use of org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO in project netconf by opendaylight.
the class NetconfNodeActorTest method registerSlaveMountPoint.
private ActorRef registerSlaveMountPoint() {
SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
doReturn(mockRegistry).when(schemaResourceDTO2).getSchemaRegistry();
doReturn(mockSchemaRepository).when(schemaResourceDTO2).getSchemaRepository();
final ActorRef slaveRef = system.actorOf(NetconfNodeActor.props(NetconfTopologySetupBuilder.create().setSchemaResourceDTO(schemaResourceDTO2).setActorSystem(system).setBaseSchemas(BASE_SCHEMAS).build(), remoteDeviceId, TIMEOUT, mockMountPointService));
doReturn(Futures.immediateFuture(mockSchemaContext)).when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
verify(mockMountPointBuilder, timeout(5000)).register();
verify(mockMountPointBuilder).addService(eq(DOMSchemaService.class), any());
verify(mockMountPointBuilder).addService(eq(DOMDataBroker.class), any());
verify(mockMountPointBuilder).addService(eq(NetconfDataTreeService.class), any());
verify(mockMountPointBuilder).addService(eq(DOMRpcService.class), any());
verify(mockMountPointBuilder).addService(eq(DOMNotificationService.class), any());
testKit.expectMsgClass(Success.class);
return slaveRef;
}
use of org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO in project netconf by opendaylight.
the class NetconfNodeActorTest method testRegisterMountPointWithSchemaFailures.
@SuppressWarnings("unchecked")
@Test
public void testRegisterMountPointWithSchemaFailures() throws Exception {
SchemaResourcesDTO schemaResourceDTO2 = mock(SchemaResourcesDTO.class);
doReturn(mockRegistry).when(schemaResourceDTO2).getSchemaRegistry();
doReturn(mockSchemaRepository).when(schemaResourceDTO2).getSchemaRepository();
final NetconfTopologySetup setup = NetconfTopologySetupBuilder.create().setSchemaResourceDTO(schemaResourceDTO2).setBaseSchemas(BASE_SCHEMAS).setActorSystem(system).build();
final ActorRef slaveRef = system.actorOf(NetconfNodeActor.props(setup, remoteDeviceId, TIMEOUT, mockMountPointService));
// Test unrecoverable failure.
doReturn(Futures.immediateFailedFuture(new SchemaResolutionException("mock"))).when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
testKit.expectMsgClass(Success.class);
verify(mockRegistry, timeout(5000)).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER1));
verify(mockRegistry, timeout(5000)).registerSchemaSource(any(), withSourceId(SOURCE_IDENTIFIER2));
verify(mockMountPointBuilder, after(1000).never()).register();
verify(mockSchemaSourceReg1, timeout(1000)).close();
verify(mockSchemaSourceReg2, timeout(1000)).close();
// Test recoverable AskTimeoutException - schema context resolution should be retried.
reset(mockSchemaSourceReg1, mockSchemaSourceReg2);
doReturn(Futures.immediateFailedFuture(new SchemaResolutionException("mock", new AskTimeoutException("timeout")))).doReturn(Futures.immediateFuture(mockSchemaContext)).when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
testKit.expectMsgClass(Success.class);
verify(mockMountPointBuilder, timeout(5000)).register();
verifyNoMoreInteractions(mockSchemaSourceReg1, mockSchemaSourceReg2);
// Test AskTimeoutException with an interleaved successful registration. The first schema context resolution
// attempt should not be retried.
reset(mockSchemaSourceReg1, mockSchemaSourceReg2, mockSchemaRepository, mockSchemaContextFactory);
resetMountPointMocks();
final EffectiveModelContextFactory mockSchemaContextFactorySuccess = mock(EffectiveModelContextFactory.class);
doReturn(Futures.immediateFuture(mockSchemaContext)).when(mockSchemaContextFactorySuccess).createEffectiveModelContext(anyCollection());
doAnswer(unused -> {
SettableFuture<SchemaContext> future = SettableFuture.create();
new Thread(() -> {
doReturn(mockSchemaContextFactorySuccess).when(mockSchemaRepository).createEffectiveModelContextFactory();
slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
future.setException(new SchemaResolutionException("mock", new AskTimeoutException("timeout")));
}).start();
return future;
}).when(mockSchemaContextFactory).createEffectiveModelContext(anyCollection());
doReturn(mockSchemaContextFactory).when(mockSchemaRepository).createEffectiveModelContextFactory();
slaveRef.tell(new RegisterMountPoint(ImmutableList.of(SOURCE_IDENTIFIER1, SOURCE_IDENTIFIER2), masterRef), testKit.getRef());
verify(mockMountPointBuilder, timeout(5000)).register();
verify(mockSchemaRepository, times(2)).createEffectiveModelContextFactory();
}
use of org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO 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());
}
use of org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO in project netconf by opendaylight.
the class MountPointEndToEndTest method setupMaster.
private void setupMaster() throws Exception {
AbstractConcurrentDataBrokerTest dataBrokerTest = newDataBrokerTest();
masterDataBroker = dataBrokerTest.getDataBroker();
deviceDOMDataBroker = dataBrokerTest.getDomBroker();
bindingToNormalized = dataBrokerTest.getDataBrokerTestCustomizer().getAdapterContext().currentSerializer();
masterSystem = ActorSystem.create(ACTOR_SYSTEM_NAME, ConfigFactory.load().getConfig("Master"));
masterClusterSingletonServiceProvider = new DOMClusterSingletonServiceProviderImpl();
masterClusterSingletonServiceProvider.initializeProvider();
doReturn(masterSystem).when(mockMasterActorSystemProvider).getActorSystem();
doReturn(MoreExecutors.newDirectExecutorService()).when(mockThreadPool).getExecutor();
final SchemaResourcesDTO resources = resourceManager.getSchemaResources(new NetconfNodeBuilder().setSchemaCacheDirectory(TEST_DEFAULT_SUBDIR).build(), "test");
resources.getSchemaRegistry().registerSchemaSource(id -> Futures.immediateFuture(YangTextSchemaSource.delegateForByteSource(id, topModuleInfo.getYangTextByteSource())), PotentialSchemaSource.create(RevisionSourceIdentifier.create(TOP_MODULE_NAME, topModuleInfo.getName().getRevision()), YangTextSchemaSource.class, 1));
masterNetconfTopologyManager = new NetconfTopologyManager(BASE_SCHEMAS, masterDataBroker, mockRpcProviderRegistry, mockActionProviderRegistry, masterClusterSingletonServiceProvider, mockKeepaliveExecutor, mockThreadPool, mockMasterActorSystemProvider, eventExecutor, mockClientDispatcher, TOPOLOGY_ID, config, masterMountPointService, mockEncryptionService, mockRpcProviderService, deviceActionFactory, resourceManager) {
@Override
protected NetconfTopologyContext newNetconfTopologyContext(final NetconfTopologySetup setup, final ServiceGroupIdentifier serviceGroupIdent, final Timeout actorResponseWaitTime, final DeviceActionFactory deviceActionFact) {
NetconfTopologyContext context = super.newNetconfTopologyContext(setup, serviceGroupIdent, actorResponseWaitTime, deviceActionFact);
NetconfTopologyContext spiedContext = spy(context);
doAnswer(invocation -> {
final MasterSalFacade spiedFacade = (MasterSalFacade) spy(invocation.callRealMethod());
doReturn(deviceDOMDataBroker).when(spiedFacade).newDeviceDataBroker();
masterSalFacadeFuture.set(spiedFacade);
return spiedFacade;
}).when(spiedContext).newMasterSalFacade();
return spiedContext;
}
};
masterNetconfTopologyManager.init();
verifyTopologyNodesCreated(masterDataBroker);
}
Aggregations