// 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);
+ }
+
yangStoreServiceServiceRegistration = context.registerService(YangStoreService.class, yangStoreService, new Hashtable<String, Object>());
configRegistryLookup = new ConfigRegistryLookupThread(yangStoreService);
configRegistryLookup.start();
RefreshingSCPModuleInfoRegistry moduleInfoRegistryWrapper = new RefreshingSCPModuleInfoRegistry(
moduleInfoBackedContext, moduleInfoBackedContext, moduleInfoBackedContext, moduleInfoBackedContext, bindingContextProvider, context);
- ModuleInfoBundleTracker moduleInfoBundleTracker = new ModuleInfoBundleTracker(moduleInfoRegistryWrapper);
+ ModuleInfoBundleTracker moduleInfoBundleTracker = new ModuleInfoBundleTracker(context, moduleInfoRegistryWrapper);
// start config registry
BundleContextBackedModuleFactoriesResolver bundleContextBackedModuleFactoriesResolver = new BundleContextBackedModuleFactoriesResolver(
// track bundles containing factories
BlankTransactionServiceTracker blankTransactionServiceTracker = new BlankTransactionServiceTracker(
configRegistry);
- ModuleFactoryBundleTracker primaryModuleFactoryBundleTracker = new ModuleFactoryBundleTracker(
+ ModuleFactoryBundleTracker moduleFactoryTracker = new ModuleFactoryBundleTracker(
blankTransactionServiceTracker);
// start extensible tracker
- ExtensibleBundleTracker<?> bundleTracker = new ExtensibleBundleTracker<>(context,
- primaryModuleFactoryBundleTracker, moduleInfoBundleTracker);
- bundleTracker.open();
+ ExtensibleBundleTracker<?> moduleFactoryBundleTracker = new ExtensibleBundleTracker<>(context,
+ moduleFactoryTracker);
+ moduleFactoryBundleTracker.open();
+
+ moduleInfoBundleTracker.open();
// Wrap config registry with JMX notification publishing adapter
final JMXNotifierConfigRegistry notifyingConfigRegistry =
blankTransactionServiceTracker);
serviceTracker.open();
- List<AutoCloseable> list = Arrays.asList(bindingContextProvider, clsReg, configRegistry, wrap(bundleTracker),
+ List<AutoCloseable> list = Arrays.asList(bindingContextProvider, clsReg, configRegistry,
+ wrap(moduleFactoryBundleTracker), moduleInfoBundleTracker,
configRegReg, configRegistryJMXRegistrator, configRegistryJMXRegistratorWithNotifications, wrap(serviceTracker), moduleInfoRegistryWrapper, notifyingConfigRegistry);
autoCloseable = OsgiRegistrationUtil.aggregate(list);
} catch(Exception e) {
LOG.warn("Error starting config manager", e);
+ } catch(Error e) {
+ // Log JVM Error and re-throw. The OSGi container may silently fail the bundle and not always log
+ // the exception. This has been seen on initial feature install.
+ LOG.error("Error starting config manager", e);
+ throw e;
}
}
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
LOG.trace("AddingBundle for {} and event {} finished successfully",bundle,event);
return primaryTrackerRetVal;
} catch (Exception e) {
- LOG.error("Failed to add bundle ",e);
+ LOG.error("Failed to add bundle {}", bundle, e);
throw e;
}
}
}
});
LOG.trace("Removed bundle event for {} finished successfully.",bundle);
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("Addition of bundle failed, ", e);
+ } catch (Exception e) {
+ LOG.error("Failed to remove bundle {}", bundle, e);
}
}
import java.util.LinkedList;
import java.util.List;
import org.opendaylight.yangtools.concepts.ObjectRegistration;
-import org.opendaylight.yangtools.sal.binding.generator.api.ModuleInfoRegistry;
import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
+import org.osgi.util.tracker.BundleTracker;
import org.osgi.util.tracker.BundleTrackerCustomizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Tracks bundles and attempts to retrieve YangModuleInfo, which is then fed into ModuleInfoRegistry
*/
-public final class ModuleInfoBundleTracker implements BundleTrackerCustomizer<Collection<ObjectRegistration<YangModuleInfo>>> {
+public final class ModuleInfoBundleTracker implements AutoCloseable,
+ BundleTrackerCustomizer<Collection<ObjectRegistration<YangModuleInfo>>> {
private static final Logger LOG = LoggerFactory.getLogger(ModuleInfoBundleTracker.class);
public static final String MODULE_INFO_PROVIDER_PATH_PREFIX = "META-INF/services/";
- private final ModuleInfoRegistry moduleInfoRegistry;
+ private final RefreshingSCPModuleInfoRegistry moduleInfoRegistry;
+ private final BundleTracker<Collection<ObjectRegistration<YangModuleInfo>>> bundleTracker;
+ private boolean starting;
- public ModuleInfoBundleTracker(ModuleInfoRegistry moduleInfoRegistry) {
+ public ModuleInfoBundleTracker(BundleContext context, RefreshingSCPModuleInfoRegistry moduleInfoRegistry) {
this.moduleInfoRegistry = moduleInfoRegistry;
+ bundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING |
+ Bundle.STOPPING | Bundle.ACTIVE, this);
+ }
+
+ public void open() {
+ LOG.debug("ModuleInfoBundleTracker open starting");
+
+ starting = true;
+ bundleTracker.open();
+
+ starting = false;
+ moduleInfoRegistry.updateService();
+
+ LOG.debug("ModuleInfoBundleTracker open complete");
+ }
+
+ @Override
+ public void close() {
+ bundleTracker.close();
}
@Override
YangModuleInfo moduleInfo = retrieveModuleInfo(moduleInfoName, bundle);
registrations.add(moduleInfoRegistry.registerModuleInfo(moduleInfo));
}
+
+ if(!starting) {
+ moduleInfoRegistry.updateService();
+ }
} catch (IOException e) {
- LOG.error("Error while reading {}", resource, e);
- throw new RuntimeException(e);
+ LOG.error("Error while reading {} from bundle {}", resource, bundle, e);
+ } catch (RuntimeException e) {
+ LOG.error("Failed to process {} for bundle {}", resource, bundle, e);
}
LOG.trace("Got following registrations {}", registrations);
try {
reg.close();
} catch (Exception e) {
- throw new RuntimeException("Unable to unregister YangModuleInfo " + reg.getInstance(), e);
+ LOG.error("Unable to unregister YangModuleInfo {}", reg.getInstance(), e);
}
}
}
moduleInfoClass, bundle, e);
throw new IllegalStateException(errorMessage, e);
}
+
try{
return instance.getModuleInfo();
- } catch (NoClassDefFoundError e) {
-
-
- LOG.error("Error while executing getModuleInfo on {}", instance, e);
- throw e;
+ } catch (NoClassDefFoundError | ExceptionInInitializerError e) {
+ throw new IllegalStateException("Error while executing getModuleInfo on " + instance, e);
}
}
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Update SchemaContext service in Service Registry each time new YangModuleInfo is added or removed.
*/
public class RefreshingSCPModuleInfoRegistry implements ModuleInfoRegistry, AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(RefreshingSCPModuleInfoRegistry.class);
private final ModuleInfoRegistry moduleInfoRegistry;
private final SchemaContextProvider schemaContextProvider;
private final BindingContextProvider bindingContextProvider;
private final ClassLoadingStrategy classLoadingStrat;
- private final ServiceRegistration<SchemaContextProvider> osgiReg;
+ private volatile ServiceRegistration<SchemaContextProvider> osgiReg;
public RefreshingSCPModuleInfoRegistry(final ModuleInfoRegistry moduleInfoRegistry,
final SchemaContextProvider schemaContextProvider, final ClassLoadingStrategy classLoadingStrat,
.registerService(SchemaContextProvider.class, schemaContextProvider, new Hashtable<String, String>());
}
- private void updateService() {
- bindingContextProvider.update(classLoadingStrat, schemaContextProvider);
- osgiReg.setProperties(new Hashtable<String, Object>() {{
- put(BindingRuntimeContext.class.getName(), bindingContextProvider.getBindingContext());
- put(SchemaSourceProvider.class.getName(), sourceProvider);
+ public void updateService() {
+ if(osgiReg != null) {
+ try {
+ bindingContextProvider.update(classLoadingStrat, schemaContextProvider);
+ osgiReg.setProperties(new Hashtable<String, Object>() {{
+ put(BindingRuntimeContext.class.getName(), bindingContextProvider.getBindingContext());
+ put(SchemaSourceProvider.class.getName(), sourceProvider);
+ }}); // send modifiedService event
+ } catch (RuntimeException e) {
+ // The ModuleInfoBackedContext throws a RuntimeException if it can't create the schema context.
+ LOG.warn("Error updating the BindingContextProvider", e);
}
- }); // send modifiedService event
+ }
}
@Override
public ObjectRegistration<YangModuleInfo> registerModuleInfo(YangModuleInfo yangModuleInfo) {
ObjectRegistration<YangModuleInfo> yangModuleInfoObjectRegistration = moduleInfoRegistry.registerModuleInfo(yangModuleInfo);
ObjectRegistrationWrapper wrapper = new ObjectRegistrationWrapper(yangModuleInfoObjectRegistration);
- updateService();
return wrapper;
}
@Override
public void close() throws Exception {
- osgiReg.unregister();
+ if(osgiReg != null) {
+ osgiReg.unregister();
+ }
+
+ osgiReg = null;
}
private class ObjectRegistrationWrapper implements ObjectRegistration<YangModuleInfo> {
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-
import java.util.Dictionary;
import org.junit.Before;
import org.junit.Test;
doReturn(ymi).when(reg).registerModuleInfo(modInfo);
scpreg.registerModuleInfo(modInfo);
+ scpreg.updateService();
verify(codecRegistryProvider).update(classLoadingStrat, prov);