Bump versions by x.y.(z+1)
[netconf.git] / netconf / mdsal-netconf-connector / src / main / java / org / opendaylight / netconf / mdsal / connector / MdsalNetconfOperationServiceFactory.java
index 273709db1c61a33ec9cd1d4ebda65b7c9033aad8..829f66bb4257697a1da73fd1b3d28fae6a03bef9 100644 (file)
@@ -5,31 +5,32 @@
  * 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.netconf.mdsal.connector;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.io.CharStreams;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.Optional;
 import java.util.Set;
-import org.opendaylight.controller.config.util.capability.Capability;
-import org.opendaylight.controller.config.util.capability.YangModuleCapability;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import java.util.concurrent.ExecutionException;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
+import org.opendaylight.netconf.api.capability.BasicCapability;
+import org.opendaylight.netconf.api.capability.Capability;
+import org.opendaylight.netconf.api.capability.YangModuleCapability;
 import org.opendaylight.netconf.api.monitoring.CapabilityListener;
 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.api.Module;
 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.SchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
@@ -39,6 +40,8 @@ import org.slf4j.LoggerFactory;
 public class MdsalNetconfOperationServiceFactory implements NetconfOperationServiceFactory, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(MdsalNetconfOperationServiceFactory.class);
+    private static final BasicCapability VALIDATE_CAPABILITY =
+        new BasicCapability("urn:ietf:params:netconf:capability:validate:1.0");
 
     private final DOMDataBroker dataBroker;
     private final DOMRpcService rpcService;
@@ -48,8 +51,7 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ
     private final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener;
 
     public MdsalNetconfOperationServiceFactory(
-            final SchemaService schemaService,
-            final SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProviderDependency,
+            final DOMSchemaService schemaService,
             final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener,
             final DOMDataBroker dataBroker,
             final DOMRpcService rpcService) {
@@ -57,7 +59,8 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ
         this.dataBroker = dataBroker;
         this.rpcService = rpcService;
 
-        this.rootSchemaSourceProviderDependency = rootSchemaSourceProviderDependency;
+        this.rootSchemaSourceProviderDependency = schemaService.getExtensions()
+                .getInstance(DOMYangTextSourceProvider.class);
         this.currentSchemaContext = new CurrentSchemaContext(Preconditions.checkNotNull(schemaService),
                 rootSchemaSourceProviderDependency);
         this.netconfOperationServiceFactoryListener = netconfOperationServiceFactoryListener;
@@ -118,16 +121,14 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ
             final Module module, final SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProviderDependency) {
 
         final SourceIdentifier moduleSourceIdentifier = RevisionSourceIdentifier.create(module.getName(),
-                SimpleDateFormatUtil.DEFAULT_DATE_REV == module.getRevision() ? Optional.absent() :
-                        Optional.of(module.getQNameModule().getFormattedRevision()));
+                module.getRevision());
 
         InputStream sourceStream = null;
         String source;
         try {
-            sourceStream = rootSchemaSourceProviderDependency.getSource(moduleSourceIdentifier).checkedGet()
-                    .openStream();
+            sourceStream = rootSchemaSourceProviderDependency.getSource(moduleSourceIdentifier).get().openStream();
             source = CharStreams.toString(new InputStreamReader(sourceStream, StandardCharsets.UTF_8));
-        } catch (IOException | SchemaSourceException e) {
+        } catch (ExecutionException | InterruptedException | IOException e) {
             LOG.warn("Ignoring source for module {}. Unable to read content", moduleSourceIdentifier, e);
             source = null;
         }
@@ -146,11 +147,16 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ
 
         LOG.warn("Missing source for module {}. This module will not be available from netconf server",
             moduleSourceIdentifier);
-        return Optional.absent();
+        return Optional.empty();
     }
 
     @Override
     public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
+        // Advertise validate capability only if DOMDataBroker provides DOMDataTransactionValidator
+        if (dataBroker.getExtensions().get(DOMDataTransactionValidator.class) != null) {
+            listener.onCapabilitiesChanged(Collections.singleton(VALIDATE_CAPABILITY), Collections.emptySet());
+        }
+        // Advertise namespaces of supported YANG models as NETCONF capabilities
         return currentSchemaContext.registerCapabilityListener(listener);
     }
 }