Merge "BUG-2673: Introduced new more low-level DOM Data Change APIs"
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / osgi / NetconfOperationServiceImpl.java
index 5055c935838e974125529d814334d1b616057b66..ef0a72c0f05f44bc2d040a1a03ea0fe2c1af1d0a 100644 (file)
@@ -8,55 +8,46 @@
 
 package org.opendaylight.controller.netconf.confignetconfconnector.osgi;
 
+import com.google.common.base.Optional;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Map;
+import java.util.HashSet;
 import java.util.Set;
-
 import org.opendaylight.controller.config.util.ConfigRegistryJMXClient;
-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.netconf.confignetconfconnector.transactions.TransactionProvider;
 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
 import org.opendaylight.controller.netconf.mapping.api.Capability;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
-import org.opendaylight.controller.netconf.mapping.api.NetconfOperationFilter;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.yangtools.yang.model.api.Module;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
-
 /**
- * Manages life cycle of {@link YangStoreSnapshot}.
+ * Manages life cycle of {@link YangStoreContext}.
  */
 public class NetconfOperationServiceImpl implements NetconfOperationService {
 
-    private final YangStoreSnapshot yangStoreSnapshot;
     private final NetconfOperationProvider operationProvider;
-    private final Set<Capability> capabilities;
     private final TransactionProvider transactionProvider;
+    private final YangStoreService yangStoreService;
 
-    public NetconfOperationServiceImpl(YangStoreService yangStoreService, ConfigRegistryJMXClient jmxClient,
-            String netconfSessionIdForReporting) throws YangStoreException {
+    public NetconfOperationServiceImpl(final YangStoreService yangStoreService, final ConfigRegistryJMXClient jmxClient,
+            final String netconfSessionIdForReporting) {
+
+        this.yangStoreService = yangStoreService;
 
-        yangStoreSnapshot = yangStoreService.getYangStoreSnapshot();
         transactionProvider = new TransactionProvider(jmxClient, netconfSessionIdForReporting);
-        operationProvider = new NetconfOperationProvider(yangStoreSnapshot, jmxClient, transactionProvider,
+        operationProvider = new NetconfOperationProvider(yangStoreService, jmxClient, transactionProvider,
                 netconfSessionIdForReporting);
-        capabilities = setupCapabilities(yangStoreSnapshot);
     }
 
     @Override
     public void close() {
-        yangStoreSnapshot.close();
         transactionProvider.close();
     }
 
     @Override
     public Set<Capability> getCapabilities() {
-        return capabilities;
+        return setupCapabilities(yangStoreService);
     }
 
     @Override
@@ -64,24 +55,18 @@ public class NetconfOperationServiceImpl implements NetconfOperationService {
         return operationProvider.getOperations();
     }
 
-    @Override
-    public Set<NetconfOperationFilter> getFilters() {
-        return Collections.emptySet();
-    }
-
-    private static Set<Capability> setupCapabilities(YangStoreSnapshot yangStoreSnapshot) {
-        Set<Capability> capabilities = Sets.newHashSet();
-
+    private static Set<Capability> setupCapabilities(final YangStoreContext yangStoreSnapshot) {
+        Set<Capability> capabilities = new HashSet<>();
         // [RFC6241] 8.3.  Candidate Configuration Capability
         capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0"));
+
+        // TODO rollback on error not supported EditConfigXmlParser:100
         // [RFC6241] 8.5.  Rollback-on-Error Capability
-        capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:rollback-on-error:1.0"));
-        // [RFC6022] get-schema RPC. TODO: implement rest of the RFC
-        capabilities.add(new BasicCapability("urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring?module=ietf-netconf-monitoring&revision=2010-10-04"));
+        // capabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:rollback-on-error:1.0"));
 
-        final Collection<Map.Entry<Module, String>> modulesAndContents = yangStoreSnapshot.getModuleMap().values();
-        for (Map.Entry<Module, String> moduleAndContent : modulesAndContents) {
-            capabilities.add(new YangStoreCapability(moduleAndContent));
+        Set<Module> modules = yangStoreSnapshot.getModules();
+        for (Module module : modules) {
+            capabilities.add(new YangStoreCapability(module, yangStoreSnapshot.getModuleSource(module)));
         }
 
         return capabilities;
@@ -91,7 +76,7 @@ public class NetconfOperationServiceImpl implements NetconfOperationService {
 
         private final String capability;
 
-        private BasicCapability(String capability) {
+        private BasicCapability(final String capability) {
             this.capability = capability;
         }
 
@@ -100,6 +85,11 @@ public class NetconfOperationServiceImpl implements NetconfOperationService {
             return capability;
         }
 
+        @Override
+        public Optional<String> getModuleNamespace() {
+            return Optional.absent();
+        }
+
         @Override
         public Optional<String> getModuleName() {
             return Optional.absent();
@@ -114,19 +104,30 @@ public class NetconfOperationServiceImpl implements NetconfOperationService {
         public Optional<String> getCapabilitySchema() {
             return Optional.absent();
         }
+
+        @Override
+        public Collection<String> getLocation() {
+            return Collections.emptyList();
+        }
+
+        @Override
+        public String toString() {
+            return capability;
+        }
     }
 
-    private static class YangStoreCapability extends BasicCapability {
+    private static final class YangStoreCapability extends BasicCapability {
 
         private final String content;
         private final String revision;
         private final String moduleName;
+        private final String moduleNamespace;
 
-        public YangStoreCapability(Map.Entry<Module, String> moduleAndContent) {
-            super(getAsString(moduleAndContent.getKey()));
-            this.content = moduleAndContent.getValue();
-            Module module = moduleAndContent.getKey();
+        public YangStoreCapability(final Module module, final String moduleContent) {
+            super(toCapabilityURI(module));
+            this.content = moduleContent;
             this.moduleName = module.getName();
+            this.moduleNamespace = module.getNamespace().toString();
             this.revision = Util.writeDate(module.getRevision());
         }
 
@@ -135,14 +136,9 @@ public class NetconfOperationServiceImpl implements NetconfOperationService {
             return Optional.of(content);
         }
 
-        private static String getAsString(Module module) {
-            final StringBuffer capabilityContent = new StringBuffer();
-            capabilityContent.append(module.getNamespace());
-            capabilityContent.append("?module=");
-            capabilityContent.append(module.getName());
-            capabilityContent.append("&revision=");
-            capabilityContent.append(Util.writeDate(module.getRevision()));
-            return capabilityContent.toString();
+        private static String toCapabilityURI(final Module module) {
+            return String.valueOf(module.getNamespace()) + "?module="
+                    + module.getName() + "&revision=" + Util.writeDate(module.getRevision());
         }
 
         @Override
@@ -150,6 +146,11 @@ public class NetconfOperationServiceImpl implements NetconfOperationService {
             return Optional.of(moduleName);
         }
 
+        @Override
+        public Optional<String> getModuleNamespace() {
+            return Optional.of(moduleNamespace);
+        }
+
         @Override
         public Optional<String> getRevision() {
             return Optional.of(revision);