Remove ScanningSchemaServiceProvider 01/98801/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Dec 2021 10:02:09 +0000 (11:02 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Dec 2021 10:08:00 +0000 (11:08 +0100)
This class is not used anywhere, remove it. Also clean up dependencies
a bit.

Change-Id: Ic940691658250a0e86a2a5d3c2c8f22f3bf3f904
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-broker/pom.xml
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/schema/ScanningSchemaServiceProvider.java [deleted file]
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/schema/ScanningSchemaServiceProviderTest.java [deleted file]

index fc5514efb2bcf8567b16e6a17661f2f842b0d432..85892243612ffbd3fdb3a4021a5ac8103b16c630 100644 (file)
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>org.opendaylight.mdsal</groupId>
+            <artifactId>mdsal-common-api</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.mdsal</groupId>
             <artifactId>mdsal-dom-api</artifactId>
             <groupId>org.opendaylight.mdsal</groupId>
             <artifactId>mdsal-dom-spi</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>concepts</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>util</artifactId>
         </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-data-impl</artifactId>
+            <artifactId>yang-common</artifactId>
         </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-parser-impl</artifactId>
+            <artifactId>yang-data-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-data-impl</artifactId>
         </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>yang-model-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-parser-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-repo-api</artifactId>
+        </dependency>
         <dependency>
             <groupId>com.guicedee.services</groupId>
             <artifactId>javax.inject</artifactId>
diff --git a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/schema/ScanningSchemaServiceProvider.java b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/schema/ScanningSchemaServiceProvider.java
deleted file mode 100644 (file)
index 3a833ca..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.broker.schema;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.util.concurrent.ListenableFuture;
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import org.checkerframework.checker.lock.qual.GuardedBy;
-import org.opendaylight.mdsal.dom.spi.AbstractDOMSchemaService;
-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.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
-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.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.parser.repo.YangTextSchemaContextResolver;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Deprecated
-public class ScanningSchemaServiceProvider extends AbstractDOMSchemaService.WithYangTextSources
-        implements AutoCloseable {
-    private static final Logger LOG = LoggerFactory.getLogger(ScanningSchemaServiceProvider.class);
-
-    private final YangTextSchemaContextResolver contextResolver = YangTextSchemaContextResolver.create("global-bundle");
-    @GuardedBy("lock")
-    private final ListenerRegistry<EffectiveModelContextListener> listeners = ListenerRegistry.create();
-    private final Object lock = new Object();
-
-    public void tryToUpdateSchemaContext() {
-        synchronized (lock) {
-            final Optional<? extends EffectiveModelContext> optSchema = contextResolver.getEffectiveModelContext();
-            optSchema.ifPresent(schema -> {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Got new SchemaContext: # of modules {}", schema.getModules().size());
-                }
-                notifyListeners(schema);
-            });
-        }
-    }
-
-    @VisibleForTesting
-    @SuppressWarnings("checkstyle:IllegalCatch")
-    public void notifyListeners(final EffectiveModelContext schemaContext) {
-        synchronized (lock) {
-            listeners.streamListeners().forEach(listener -> {
-                try {
-                    listener.onModelContextUpdated(schemaContext);
-                } catch (final Exception e) {
-                    LOG.error("Exception occured during invoking listener {}", listener, e);
-                }
-            });
-        }
-    }
-
-    public List<Registration> registerAvailableYangs(final List<URL> yangs) {
-        final List<Registration> sourceRegistrator = new ArrayList<>();
-        for (final URL url : yangs) {
-            try {
-                sourceRegistrator.add(contextResolver.registerSource(url));
-            } catch (SchemaSourceException | IOException | YangSyntaxErrorException e) {
-                LOG.warn("Failed to register {}, ignoring it", url, e);
-            }
-        }
-        return sourceRegistrator;
-    }
-
-    public boolean hasListeners() {
-        synchronized (lock) {
-            return !listeners.isEmpty();
-        }
-    }
-
-    @Override
-    public EffectiveModelContext getGlobalContext() {
-        return contextResolver.getEffectiveModelContext().orElse(null);
-    }
-
-    @Override
-    public ListenerRegistration<EffectiveModelContextListener> registerSchemaContextListener(
-            final EffectiveModelContextListener listener) {
-        synchronized (lock) {
-            contextResolver.getEffectiveModelContext().ifPresent(listener::onModelContextUpdated);
-            return listeners.register(listener);
-        }
-    }
-
-    @Override
-    public ListenableFuture<? extends YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
-        return contextResolver.getSource(sourceIdentifier);
-    }
-
-    @Override
-    public void close() {
-        synchronized (lock) {
-            listeners.clear();
-        }
-    }
-}
diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/schema/ScanningSchemaServiceProviderTest.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/schema/ScanningSchemaServiceProviderTest.java
deleted file mode 100644 (file)
index 84c503b..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * 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.broker.schema;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.internal.util.io.IOUtil;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.concepts.Registration;
-import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-
-public class ScanningSchemaServiceProviderTest {
-
-    private ArrayList<URL> yangs;
-    private ScanningSchemaServiceProvider schemaService;
-
-    @Before
-    public void setup() {
-        yangs = new ArrayList<>();
-        addYang("/odl-datastore-test.yang");
-
-        schemaService = new ScanningSchemaServiceProvider();
-        assertNotNull(schemaService);
-        addYangs(schemaService);
-    }
-
-    @After
-    public void close() {
-        schemaService.close();
-    }
-
-    private void addYang(final String yang) {
-        yangs.add(ScanningSchemaServiceProvider.class.getResource(yang));
-    }
-
-    @Test
-    public void initJarScanningSchemaServiceTest() throws Exception {
-        assertNotNull(schemaService.getGlobalContext());
-        assertNotNull(schemaService.getEffectiveModelContext());
-        assertEquals(schemaService.getGlobalContext(), schemaService.getEffectiveModelContext());
-    }
-
-    @Test
-    public void listenersTests() {
-        assertFalse(schemaService.hasListeners());
-
-        final SchemaContextHolder actualSchemaCtx = new SchemaContextHolder();
-        final EffectiveModelContextListener listener = actualSchemaCtx::setSchemaContext;
-        final ListenerRegistration<EffectiveModelContextListener> registerSchemaContextListener =
-                schemaService.registerSchemaContextListener(listener);
-        assertEquals(registerSchemaContextListener.getInstance(), listener);
-        assertEquals(schemaService.getEffectiveModelContext(), actualSchemaCtx.getSchemaContext());
-    }
-
-    @Test
-    public void notifyListenersTest() {
-        final EffectiveModelContext baseSchemaCtx = schemaService.getGlobalContext();
-        assertNotNull(baseSchemaCtx);
-        assertTrue(baseSchemaCtx.getModules().size() == 1);
-
-        final SchemaContextHolder actualSchemaCtx = new SchemaContextHolder();
-
-        final EffectiveModelContextListener schemaCtxListener = actualSchemaCtx::setSchemaContext;
-        final ListenerRegistration<EffectiveModelContextListener> registerSchemaContextListener =
-                schemaService.registerSchemaContextListener(schemaCtxListener);
-        assertEquals(registerSchemaContextListener.getInstance(), schemaCtxListener);
-        assertNotNull(actualSchemaCtx.getSchemaContext());
-        assertEquals(baseSchemaCtx, actualSchemaCtx.getSchemaContext());
-
-        addYang("/empty-test1.yang");
-        addYangs(schemaService);
-
-        final EffectiveModelContext nextSchemaCtx = schemaService.getGlobalContext();
-        assertNotNull(nextSchemaCtx);
-        assertTrue(nextSchemaCtx.getModules().size() == 2);
-
-        assertNotEquals(baseSchemaCtx, nextSchemaCtx);
-
-        schemaService.notifyListeners(nextSchemaCtx);
-        assertEquals(nextSchemaCtx, actualSchemaCtx.getSchemaContext());
-
-        addYang("/empty-test2.yang");
-        addYangs(schemaService);
-
-        final EffectiveModelContext unregistredListenerSchemaCtx = schemaService.getGlobalContext();
-        assertNotNull(unregistredListenerSchemaCtx);
-        assertTrue(unregistredListenerSchemaCtx.getModules().size() == 3);
-
-        assertNotEquals(baseSchemaCtx, unregistredListenerSchemaCtx);
-        assertNotEquals(nextSchemaCtx, unregistredListenerSchemaCtx);
-
-        registerSchemaContextListener.close();
-        schemaService.notifyListeners(unregistredListenerSchemaCtx);
-
-        assertNotEquals(unregistredListenerSchemaCtx, actualSchemaCtx.getSchemaContext());
-        assertEquals(nextSchemaCtx, actualSchemaCtx.getSchemaContext());
-
-        schemaService.registerSchemaContextListener(schemaCtxListener);
-        assertEquals(unregistredListenerSchemaCtx, actualSchemaCtx.getSchemaContext());
-    }
-
-    @Test
-    public void tryToUpdateSchemaCtxTest() {
-        final SchemaContext baseSchemaContext = schemaService.getEffectiveModelContext();
-        assertNotNull(baseSchemaContext);
-        assertTrue(baseSchemaContext.getModules().size() == 1);
-
-        final SchemaContextHolder actualSchemaCtx = new SchemaContextHolder();
-        schemaService.registerSchemaContextListener(actualSchemaCtx::setSchemaContext);
-
-        assertEquals(baseSchemaContext, actualSchemaCtx.getSchemaContext());
-
-        addYang("/empty-test1.yang");
-        addYangs(schemaService);
-
-        final SchemaContext nextSchemaContext = schemaService.getEffectiveModelContext();
-        assertNotNull(baseSchemaContext);
-        assertTrue(baseSchemaContext.getModules().size() == 1);
-
-        assertNotEquals(baseSchemaContext, nextSchemaContext);
-
-        schemaService.tryToUpdateSchemaContext();
-        assertEquals(nextSchemaContext, actualSchemaCtx.getSchemaContext());
-    }
-
-    @Test
-    public void getSourceTest() throws Exception {
-        final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("odl-datastore-test",
-            Revision.of("2014-03-13"));
-        final YangTextSchemaSource yangTextSchemaSource = schemaService.getSource(sourceIdentifier).get();
-        final Collection<String> lines = IOUtil.readLines(yangTextSchemaSource.openStream());
-        assertEquals("module odl-datastore-test {", lines.iterator().next());
-    }
-
-    @Test
-    public void getSupportedExtensionsTest() {
-        assertEquals(schemaService.getExtensions().values().iterator().next(), schemaService);
-    }
-
-    private void addYangs(final ScanningSchemaServiceProvider service) {
-        final List<Registration> registerAvailableYangs = service.registerAvailableYangs(yangs);
-        assertTrue(!registerAvailableYangs.isEmpty());
-    }
-
-    private class SchemaContextHolder {
-
-        private EffectiveModelContext schemaCtx;
-
-        public void setSchemaContext(final EffectiveModelContext ctx) {
-            schemaCtx = ctx;
-        }
-
-        public EffectiveModelContext getSchemaContext() {
-            return schemaCtx;
-        }
-    }
-}