X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fyang-store-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fstore%2Fimpl%2FExtenderYangTracker.java;h=74a36c553fe7237e1a7df4bc7dff24c18bc6b28b;hp=90b94ef120c8d2e05473e76db4db7e7dd325c46a;hb=af3eaa839bf6f6c86495b24d2174eeb6624501c0;hpb=585bee2f6dd169168e3fba2d357534d4fd3bfdd5 diff --git a/opendaylight/config/yang-store-impl/src/main/java/org/opendaylight/controller/config/yang/store/impl/ExtenderYangTracker.java b/opendaylight/config/yang-store-impl/src/main/java/org/opendaylight/controller/config/yang/store/impl/ExtenderYangTracker.java index 90b94ef120..74a36c553f 100644 --- a/opendaylight/config/yang-store-impl/src/main/java/org/opendaylight/controller/config/yang/store/impl/ExtenderYangTracker.java +++ b/opendaylight/config/yang-store-impl/src/main/java/org/opendaylight/controller/config/yang/store/impl/ExtenderYangTracker.java @@ -14,12 +14,9 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; import org.opendaylight.controller.config.yang.store.api.YangStoreException; import org.opendaylight.controller.config.yang.store.api.YangStoreService; import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot; -import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry; -import org.opendaylight.yangtools.yang.model.api.Module; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; @@ -36,8 +33,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Enumeration; import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -78,7 +73,7 @@ public class ExtenderYangTracker extends BundleTracker implements YangSt } @Override - public Object addingBundle(Bundle bundle, BundleEvent event) { + public synchronized Object addingBundle(Bundle bundle, BundleEvent event) { // Ignore system bundle: // system bundle might have config-api on classpath && @@ -121,17 +116,18 @@ public class ExtenderYangTracker extends BundleTracker implements YangSt return bundle; } - private void onSnapshotFailure(Bundle bundle, List addedURLs, Exception failureReason) { + private synchronized void onSnapshotFailure(Bundle bundle, List addedURLs, Exception failureReason) { // inconsistent state inconsistentBundlesToYangURLs.putAll(bundle, addedURLs); - logger.debug("Yang store is falling back on last consistent state containing {}, inconsistent yang files {}, reason {}", + logger.debug("Yang store is falling back on last consistent state containing {}, inconsistent yang files {}", consistentBundlesToYangURLs, inconsistentBundlesToYangURLs, failureReason); logger.warn("Yang store is falling back on last consistent state containing {} files, inconsistent yang files size is {}, reason {}", consistentBundlesToYangURLs.size(), inconsistentBundlesToYangURLs.size(), failureReason.toString()); + cache.setInconsistentURLsForReporting(inconsistentBundlesToYangURLs.values()); } - private void onSnapshotSuccess(Multimap proposedNewState, YangStoreSnapshotImpl snapshot) { + private synchronized void onSnapshotSuccess(Multimap proposedNewState, YangStoreSnapshotImpl snapshot) { // consistent state // merge into consistentBundlesToYangURLs.clear(); @@ -139,12 +135,12 @@ public class ExtenderYangTracker extends BundleTracker implements YangSt inconsistentBundlesToYangURLs.clear(); updateCache(snapshot); - - logger.info("Yang store updated to new consistent state containing {} yang files", consistentBundlesToYangURLs.size()); + cache.setInconsistentURLsForReporting(Collections. emptySet()); + logger.trace("Yang store updated to new consistent state containing {} yang files", consistentBundlesToYangURLs.size()); logger.debug("Yang store updated to new consistent state containing {}", consistentBundlesToYangURLs); } - private void updateCache(YangStoreSnapshotImpl snapshot) { + private synchronized void updateCache(YangStoreSnapshotImpl snapshot) { cache.cacheYangStore(consistentBundlesToYangURLs, snapshot); } @@ -185,7 +181,15 @@ public class ExtenderYangTracker extends BundleTracker implements YangSt yangStoreSnapshot.countModuleMXBeanEntries(), multimap.values().size()); return yangStoreSnapshot; } catch (RuntimeException e) { - throw new YangStoreException("Unable to parse yang files from following URLs: " + multimap, e); + StringBuffer causeStr = new StringBuffer(); + Throwable cause = e; + while (cause != null) { + causeStr.append(e.getMessage()); + causeStr.append("\n"); + cause = e.getCause(); + } + throw new YangStoreException("Unable to parse yang files. \n" + causeStr.toString() + + "URLs: " + multimap, e); } } @@ -211,68 +215,3 @@ public class ExtenderYangTracker extends BundleTracker implements YangSt cache.invalidate(); } } - -class YangStoreCache { - - @GuardedBy("this") - private Set cachedUrls = null; - @GuardedBy("this") - private Optional cachedYangStoreSnapshot = getInitialSnapshot(); - - synchronized Optional getSnapshotIfPossible(Multimap bundlesToYangURLs) { - Set urls = setFromMultimapValues(bundlesToYangURLs); - - if (cachedUrls==null || cachedUrls.equals(urls)) { - Preconditions.checkState(cachedYangStoreSnapshot.isPresent()); - YangStoreSnapshot freshSnapshot = new YangStoreSnapshotImpl(cachedYangStoreSnapshot.get()); - return Optional.of(freshSnapshot); - } - - return Optional.absent(); - } - - private static Set setFromMultimapValues( - Multimap bundlesToYangURLs) { - Set urls = Sets.newHashSet(bundlesToYangURLs.values()); - Preconditions.checkState(bundlesToYangURLs.size() == urls.size()); - return urls; - } - - synchronized void cacheYangStore(Multimap urls, - YangStoreSnapshot yangStoreSnapshot) { - this.cachedUrls = setFromMultimapValues(urls); - this.cachedYangStoreSnapshot = Optional.of(yangStoreSnapshot); - } - - synchronized void invalidate() { - cachedUrls.clear(); - if (cachedYangStoreSnapshot.isPresent()){ - cachedYangStoreSnapshot.get().close(); - cachedYangStoreSnapshot = Optional.absent(); - } - } - - private Optional getInitialSnapshot() { - YangStoreSnapshot initialSnapshot = new YangStoreSnapshot() { - @Override - public Map> getModuleMXBeanEntryMap() { - return Collections.emptyMap(); - } - - @Override - public Map> getModuleMap() { - return Collections.emptyMap(); - } - - @Override - public int countModuleMXBeanEntries() { - return 0; - } - - @Override - public void close() { - } - }; - return Optional.of(initialSnapshot); - } -}