From cd0eea4a97a6279b801074061dd64f6663e8b837 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Sun, 17 May 2015 10:49:00 -0400 Subject: [PATCH] Bug 2970: Fix GlobalBundleScanningSchemaServiceImpl to get RESOLVED bundles correctly The GlobalBundleScanningSchemaServiceImpl uses a BundleTracker to get all RESOLVED bundles. When BundleTracker#open() is called on start(), the BundleTracker will notify addingBundles of all current bundles that pass the state mask. The OSGi container must resolve all bundles before activating on startup. So after open() is called we should have all the current bundles that have yang models and a complete SchemaContext on startup based on the installed bundles from he last run. However I was seeing some bundles notified during open() but others notified later. This why CDS and other components may not see a complete SchemaContext on startup. The problem is that GlobalBundleScanningSchemaServiceImpl is passing the wrong state mask constants. It's referencing constants defined in BundleEvent but the BundleTracker checks bundle.getState() which corresponds to constants defined in Bundle. The 2 have slightly different constants and the values differ. When I change it to use Bundle constants, it works as expected, ie all current bundles are notified during open() and we have a complete SchemaContext after start(). I really don't see how this worked before at all using the wrong constants. I also noticed that start() is being called twice, once in GlobalBundleScanningSchemaServiceImpl#createInstance and then also in the Activator after it calls createInstance. So 2 instances of BundleTracker were being created resulting in double the notifications. I removed the call to start() in the Activator. Change-Id: I8c8330f75dd1a779af186688aae4cfaee89bd43b Signed-off-by: Tom Pantelis --- .../GlobalBundleScanningSchemaServiceImpl.java | 17 ++++++++++++++--- .../dom/broker/osgi/SchemaServiceActivator.java | 2 -- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/GlobalBundleScanningSchemaServiceImpl.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/GlobalBundleScanningSchemaServiceImpl.java index 68edea7d75..f7a5ea1e95 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/GlobalBundleScanningSchemaServiceImpl.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/GlobalBundleScanningSchemaServiceImpl.java @@ -81,13 +81,20 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi public void start() { checkState(context != null); + LOG.debug("start() starting"); listenerTracker = new ServiceTracker<>(context, SchemaContextListener.class, GlobalBundleScanningSchemaServiceImpl.this); - bundleTracker = new BundleTracker<>(context, BundleEvent.RESOLVED | BundleEvent.UNRESOLVED, scanner); + bundleTracker = new BundleTracker<>(context, Bundle.RESOLVED | Bundle.STARTING | + Bundle.STOPPING | Bundle.ACTIVE, scanner); bundleTracker.open(); + + LOG.debug("BundleTracker.open() complete"); + listenerTracker.open(); starting = false; tryToUpdateSchemaContext(); + + LOG.debug("start() complete"); } @Override @@ -184,7 +191,8 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi } if (!urls.isEmpty()) { - LOG.debug("Loaded {} new URLs, rebuilding schema context", urls.size()); + LOG.debug("Loaded {} new URLs from bundle {}, attempting to rebuild schema context", + urls.size(), bundle.getSymbolicName()); tryToUpdateSchemaContext(); } @@ -193,7 +201,6 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi @Override public void modifiedBundle(final Bundle bundle, final BundleEvent event, final Iterable object) { - LOG.debug("Modified bundle {} {} {}", bundle, event, object); } /** @@ -232,6 +239,10 @@ public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvi } Optional schema = contextResolver.getSchemaContext(); if(schema.isPresent()) { + if(LOG.isDebugEnabled()) { + LOG.debug("Got new SchemaContext: # of modules {}", schema.get().getAllModuleIdentifiers().size()); + } + updateContext(schema.get()); } } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/SchemaServiceActivator.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/SchemaServiceActivator.java index 113a9c08db..37093c7d13 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/SchemaServiceActivator.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/SchemaServiceActivator.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.sal.dom.broker.osgi; import java.util.Hashtable; - import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.controller.sal.dom.broker.GlobalBundleScanningSchemaServiceImpl; import org.osgi.framework.BundleActivator; @@ -24,7 +23,6 @@ public class SchemaServiceActivator implements BundleActivator { @Override public void start(final BundleContext context) { schemaService = GlobalBundleScanningSchemaServiceImpl.createInstance(context); - schemaService.start(); schemaServiceReg = context.registerService(SchemaService.class, schemaService, new Hashtable()); } -- 2.36.6