use of org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource in project controller by opendaylight.
the class YangStoreActivator method start.
@Override
@SuppressWarnings("checkstyle:hiddenField")
public void start(final BundleContext context) throws Exception {
LOG.debug("ConfigPersister starting");
this.context = context;
final ServiceTrackerCustomizer<SchemaContextProvider, YangStoreService> schemaServiceTrackerCustomizer = new ServiceTrackerCustomizer<SchemaContextProvider, YangStoreService>() {
private final AtomicBoolean alreadyStarted = new AtomicBoolean(false);
@Override
public YangStoreService addingService(final ServiceReference<SchemaContextProvider> reference) {
LOG.debug("Got addingService(SchemaContextProvider) event");
if (reference.getProperty(SchemaSourceProvider.class.getName()) == null && reference.getProperty(BindingRuntimeContext.class.getName()) == null) {
LOG.debug("SchemaContextProvider not from config-manager. Ignoring");
return null;
}
// Yang store service should not be registered multiple times
if (!this.alreadyStarted.compareAndSet(false, true)) {
LOG.warn("Starting yang store service multiple times. Received new service {}", reference);
throw new RuntimeException("Starting yang store service multiple times");
}
final SchemaContextProvider schemaContextProvider = reference.getBundle().getBundleContext().getService(reference);
final Object sourceProvider = Preconditions.checkNotNull(reference.getProperty(SchemaSourceProvider.class.getName()), "Source provider not found");
Preconditions.checkArgument(sourceProvider instanceof SchemaSourceProvider);
// TODO avoid cast
final YangStoreService yangStoreService = new YangStoreService(schemaContextProvider, (SchemaSourceProvider<YangTextSchemaSource>) sourceProvider);
final BindingRuntimeContext runtimeContext = (BindingRuntimeContext) reference.getProperty(BindingRuntimeContext.class.getName());
LOG.debug("BindingRuntimeContext retrieved as {}", runtimeContext);
if (runtimeContext != null) {
yangStoreService.refresh(runtimeContext);
}
YangStoreActivator.this.yangStoreServiceServiceRegistration = context.registerService(YangStoreService.class, yangStoreService, new Hashtable<>());
YangStoreActivator.this.configRegistryLookup = new ConfigRegistryLookupThread(yangStoreService);
YangStoreActivator.this.configRegistryLookup.start();
return yangStoreService;
}
@Override
public void modifiedService(final ServiceReference<SchemaContextProvider> reference, final YangStoreService service) {
if (service == null) {
return;
}
LOG.debug("Got modifiedService(SchemaContextProvider) event");
final BindingRuntimeContext runtimeContext = (BindingRuntimeContext) reference.getProperty(BindingRuntimeContext.class.getName());
LOG.debug("BindingRuntimeContext retrieved as {}", runtimeContext);
service.refresh(runtimeContext);
}
@Override
public void removedService(final ServiceReference<SchemaContextProvider> reference, final YangStoreService service) {
if (service == null) {
return;
}
LOG.debug("Got removedService(SchemaContextProvider) event");
this.alreadyStarted.set(false);
YangStoreActivator.this.configRegistryLookup.interrupt();
YangStoreActivator.this.yangStoreServiceServiceRegistration.unregister();
YangStoreActivator.this.yangStoreServiceServiceRegistration = null;
}
};
final ServiceTracker<SchemaContextProvider, YangStoreService> schemaContextProviderServiceTracker = new ServiceTracker<>(context, SchemaContextProvider.class, schemaServiceTrackerCustomizer);
schemaContextProviderServiceTracker.open();
}
use of org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource in project controller by opendaylight.
the class RemoteSchemaProviderTest method getExistingYangTextSchemaSource.
@Test
public void getExistingYangTextSchemaSource() throws IOException, SchemaSourceException {
String source = "Test";
YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource(ID, ByteSource.wrap(source.getBytes()));
YangTextSchemaSourceSerializationProxy sourceProxy = new YangTextSchemaSourceSerializationProxy(schemaSource);
Mockito.when(mockedRemoteSchemaRepository.getYangTextSchemaSource(ID)).thenReturn(Futures.successful(sourceProxy));
YangTextSchemaSource providedSource = remoteSchemaProvider.getSource(ID).checkedGet();
assertEquals(providedSource.getIdentifier(), ID);
assertArrayEquals(providedSource.read(), schemaSource.read());
}
use of org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource in project controller by opendaylight.
the class RemoteYangTextSourceProviderImplTest method testGetExistingYangTextSchemaSource.
@Test
public void testGetExistingYangTextSchemaSource() throws Exception {
String source = "Test source.";
YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource(ID, ByteSource.wrap(source.getBytes()));
Mockito.when(mockedLocalRepository.getSchemaSource(ID, YangTextSchemaSource.class)).thenReturn(Futures.immediateCheckedFuture(schemaSource));
Future<YangTextSchemaSourceSerializationProxy> retrievedSourceFuture = remoteRepository.getYangTextSchemaSource(ID);
assertTrue(retrievedSourceFuture.isCompleted());
YangTextSchemaSource resultSchemaSource = Await.result(retrievedSourceFuture, Duration.Zero()).getRepresentation();
assertEquals(resultSchemaSource.getIdentifier(), schemaSource.getIdentifier());
assertArrayEquals(resultSchemaSource.read(), schemaSource.read());
}
Aggregations