BUG-8327: Introduce DOMYangTextSourceProvider and implement it 98/56298/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 28 Apr 2017 12:05:21 +0000 (14:05 +0200)
committerRobert Varga <nite@hq.sk>
Sun, 30 Apr 2017 11:58:27 +0000 (11:58 +0000)
Migration requires that DOMSchemaService provides the capability to
access underlying sources in YANG text. Rather than modifying the
base DOMSchemaService, make it an DOMExtensibleService and define
the appropriate extension, DOMYangTextSourceProvider.

Update OsgiBundleScanningSchemaService to implement the new
extension.

Change-Id: I4c75d8abdf850c42fe69a08201f976271a2cbc8f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 985c0859e1ad4a1c2dd734e75a4249ddd6b1e2a8)

dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMSchemaService.java
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMSchemaServiceExtension.java [new file with mode: 0644]
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMServiceExtension.java
dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMYangTextSourceProvider.java [new file with mode: 0644]
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/osgi/OsgiBundleScanningSchemaService.java
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/osgi/SchemaServiceActivator.java

index b6946c9552c86bcf7e45eff426a04e7d0fe62d81..caf7e33f3386291e01d4e84af2966679271b4722 100644 (file)
@@ -7,12 +7,13 @@
  */
 package org.opendaylight.mdsal.dom.api;
 
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 
-public interface DOMSchemaService extends DOMService {
-
+public interface DOMSchemaService extends DOMExtensibleService<DOMSchemaService, DOMSchemaServiceExtension> {
     /**
      * Returns session specific YANG schema context
      * @return
@@ -33,4 +34,9 @@ public interface DOMSchemaService extends DOMService {
      * @return Listener registration handle
      */
     ListenerRegistration<SchemaContextListener> registerSchemaContextListener(SchemaContextListener listener);
+
+    @Override
+    default Map<Class<? extends DOMSchemaServiceExtension>, DOMSchemaServiceExtension> getSupportedExtensions() {
+        return ImmutableMap.of();
+    }
 }
diff --git a/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMSchemaServiceExtension.java b/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMSchemaServiceExtension.java
new file mode 100644 (file)
index 0000000..609d8b6
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.dom.api;
+
+/**
+ * Type capture of a {@link DOMServiceExtension} applicable to {@link DOMSchemaService}
+ * implementations.
+ */
+public interface DOMSchemaServiceExtension extends DOMServiceExtension<DOMSchemaService, DOMSchemaServiceExtension> {
+
+}
index d790c3acc291af5d72b0623cac3a97d2019656f0..63687aa5493f42c243e10b75cf07432063ce7cb7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
diff --git a/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMYangTextSourceProvider.java b/dom/mdsal-dom-api/src/main/java/org/opendaylight/mdsal/dom/api/DOMYangTextSourceProvider.java
new file mode 100644 (file)
index 0000000..5544e1d
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.dom.api;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
+
+/**
+ * A DOMSchemaServiceExtension exposing access to {@link YangTextSchemaSource}. Instances of this method should be
+ * acquired from {@link DOMSchemaService}.
+ */
+@Beta
+public interface DOMYangTextSourceProvider extends DOMSchemaServiceExtension,
+        SchemaSourceProvider<YangTextSchemaSource> {
+
+}
index 98cd8544ccefc101dfab5bf94ec1178b2da59bd0..87e5c4d23e4e770fef87883f68188b1526b5df0d 100644 (file)
@@ -13,21 +13,30 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
+import com.google.common.util.concurrent.CheckedFuture;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicReference;
+import javax.annotation.Nonnull;
 import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaServiceExtension;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.util.ListenerRegistry;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.parser.repo.YangTextSchemaContextResolver;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -41,7 +50,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class OsgiBundleScanningSchemaService implements SchemaContextProvider, DOMSchemaService,
-        ServiceTrackerCustomizer<SchemaContextListener, SchemaContextListener>, AutoCloseable {
+        ServiceTrackerCustomizer<SchemaContextListener, SchemaContextListener>, DOMYangTextSourceProvider,
+        AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(OsgiBundleScanningSchemaService.class);
 
     private static final AtomicReference<OsgiBundleScanningSchemaService> GLOBAL_INSTANCE = new AtomicReference<>();
@@ -65,7 +75,7 @@ public class OsgiBundleScanningSchemaService implements SchemaContextProvider, D
         this.context = Preconditions.checkNotNull(context);
     }
 
-    public static OsgiBundleScanningSchemaService createInstance(final BundleContext ctx) {
+    public static @Nonnull OsgiBundleScanningSchemaService createInstance(final BundleContext ctx) {
         OsgiBundleScanningSchemaService instance = new OsgiBundleScanningSchemaService(ctx);
         Preconditions.checkState(GLOBAL_INSTANCE.compareAndSet(null, instance));
         instance.start();
@@ -296,4 +306,15 @@ public class OsgiBundleScanningSchemaService implements SchemaContextProvider, D
             final SchemaContextListener service) {
         context.ungetService(reference);
     }
+
+    @Override
+    public Map<Class<? extends DOMSchemaServiceExtension>, DOMSchemaServiceExtension> getSupportedExtensions() {
+        return ImmutableMap.of(DOMYangTextSourceProvider.class, this);
+    }
+
+    @Override
+    public CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> getSource(
+            final SourceIdentifier sourceIdentifier) {
+        return contextResolver.getSource(sourceIdentifier);
+    }
 }
index 52af5814faa6a9dc05e837e78c9194a5781e25b6..97370baf3895366ac9974baffd0ff2eb3cb899f1 100644 (file)
@@ -14,8 +14,6 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
 public class SchemaServiceActivator implements BundleActivator {
-
-
     private ServiceRegistration<DOMSchemaService> schemaServiceReg;
     private OsgiBundleScanningSchemaService schemaService;
 
@@ -23,11 +21,11 @@ public class SchemaServiceActivator implements BundleActivator {
     public void start(final BundleContext context) {
         schemaService = OsgiBundleScanningSchemaService.createInstance(context);
         schemaServiceReg = context.registerService(DOMSchemaService.class,
-                schemaService, new Hashtable<String,String>());
+                schemaService, new Hashtable<>());
     }
 
     @Override
-    public void stop(final BundleContext context) throws Exception {
+    public void stop(final BundleContext context) {
         schemaServiceReg.unregister();
         schemaService.close();
     }