Updated MountPoint implementation 72/2572/3
authorTony Tkacik <ttkacik@cisco.com>
Sat, 9 Nov 2013 19:00:28 +0000 (20:00 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 9 Nov 2013 19:09:29 +0000 (19:09 +0000)
  - Fixed bug in AbstractDataReadRouter

Change-Id: Ie00387f57328ed5c0e8130e4456be8c1e9f0456d
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/routing/AbstractDataReadRouter.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/mount/MountProvisionInstance.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/mount/MountService.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerActivator.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointImpl.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.xtend
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataReaderRouter.xtend
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/MountProviderServiceProxy.java [new file with mode: 0644]
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.xtend

index f83c61f..531ce22 100644 (file)
@@ -75,7 +75,7 @@ public abstract class AbstractDataReadRouter<P extends Path<?>, D> implements Da
         return new Function<DataReader<P, D>, D>() {
             @Override
             public D apply(DataReader<P, D> input) {
-                return input.readConfigurationData(path);
+                return input.readOperationalData(path);
             }
         };
     }
index 8f6a5d0..92542bc 100644 (file)
@@ -1,8 +1,13 @@
 package org.opendaylight.controller.sal.core.api.mount;
 
 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
+import org.opendaylight.controller.sal.core.api.data.DataProviderService;
 import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService;
 
-public interface MountProvisionInstance extends MountInstance, NotificationPublishService, RpcProvisionRegistry {
+public interface MountProvisionInstance extends //
+        MountInstance,//
+        NotificationPublishService, //
+        RpcProvisionRegistry,//
+        DataProviderService {
 
 }
index 530b02b..3180271 100644 (file)
@@ -7,10 +7,11 @@
  */
 package org.opendaylight.controller.sal.core.api.mount;
 
+import org.opendaylight.controller.sal.core.api.BrokerService;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 
 
-public interface MountService {
+public interface MountService extends BrokerService {
 
     MountInstance getMountPoint(InstanceIdentifier path);
 }
index 2bab4db..e49cb4b 100644 (file)
@@ -6,6 +6,8 @@ import org.opendaylight.controller.sal.core.api.Broker;
 import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
 import org.opendaylight.controller.sal.core.api.data.DataProviderService;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
+import org.opendaylight.controller.sal.core.api.mount.MountService;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -20,6 +22,9 @@ public class BrokerActivator implements BundleActivator {
     private ServiceRegistration<DataProviderService> dataProviderReg;
     private SchemaServiceImpl schemaService;
     private DataBrokerImpl dataService;
+    private MountPointManagerImpl mountService;
+    private ServiceRegistration<MountService> mountReg;
+    private ServiceRegistration<MountProvisionService> mountProviderReg;
 
     @Override
     public void start(BundleContext context) throws Exception {
@@ -38,7 +43,11 @@ public class BrokerActivator implements BundleActivator {
         dataReg = context.registerService(DataBrokerService.class, dataService, emptyProperties);
         dataProviderReg = context.registerService(DataProviderService.class, dataService, emptyProperties);
         
+        mountService = new MountPointManagerImpl();
+        mountService.setDataBroker(dataService);
         
+        mountReg = context.registerService(MountService.class, mountService, emptyProperties);
+        mountProviderReg =  context.registerService(MountProvisionService.class, mountService, emptyProperties);
     }
 
     @Override
index 7037b46..eafc402 100644 (file)
@@ -1,15 +1,19 @@
 package org.opendaylight.controller.sal.dom.broker;
 
+import java.util.List;
 import java.util.Set;
 import java.util.concurrent.Future;
 
+import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
+import org.opendaylight.controller.sal.common.DataStoreIdentifier;
 import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.core.api.RpcImplementation;
 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration;
 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
 import org.opendaylight.controller.sal.core.api.data.DataChangeListener;
 import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.core.api.data.DataValidator;
 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
 import org.opendaylight.controller.sal.core.api.notify.NotificationListener;
 import org.opendaylight.controller.sal.dom.broker.impl.DataReaderRouter;
@@ -23,17 +27,33 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.InstanceIdentifierBuilder;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
 
 public class MountPointImpl implements MountProvisionInstance {
 
-    final RpcRouter rpcs;
-    final DataReaderRouter dataReader;
-    final NotificationRouter notificationRouter;
+    private final RpcRouter rpcs;
+    private final DataReaderRouter dataReader;
+    private final NotificationRouter notificationRouter;
+    private final DataReader<InstanceIdentifier,CompositeNode> readWrapper;
+    
+    
+    private final InstanceIdentifier mountPath;
 
     public MountPointImpl(InstanceIdentifier path) {
+        this.mountPath = path;
         rpcs = new RpcRouterImpl("");
         dataReader = new DataReaderRouter();
         notificationRouter = new NotificationRouterImpl();
+        readWrapper = new ReadWrapper();
+    }
+
+    public InstanceIdentifier getMountPath() {
+        return mountPath;
+    }
+
+    public DataReader<InstanceIdentifier, CompositeNode> getReadWrapper() {
+        return readWrapper;
     }
 
     @Override
@@ -113,6 +133,62 @@ public class MountPointImpl implements MountProvisionInstance {
     @Override
     public void sendNotification(CompositeNode notification) {
         publish(notification);
+    }
+    
+    @Override
+    public Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registerCommitHandler(
+            InstanceIdentifier path, DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+    
+    @Override
+    public void removeRefresher(DataStoreIdentifier store, DataRefresher refresher) {
+     // NOOP
+    }
+    
+    @Override
+    public void addRefresher(DataStoreIdentifier store, DataRefresher refresher) {
+     // NOOP
+    }
+    
+    @Override
+    public void addValidator(DataStoreIdentifier store, DataValidator validator) {
+     // NOOP
+    }
+    @Override
+    public void removeValidator(DataStoreIdentifier store, DataValidator validator) {
+        // NOOP
+    }
+    
+    class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
+        
+        
+        private InstanceIdentifier shortenPath(InstanceIdentifier path) {
+            InstanceIdentifier ret = null;
+            if(mountPath.contains(path)) {
+                List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
+                ret = new InstanceIdentifier(newArgs);
+            }
+            return ret;
+        }
+        
+        @Override
+        public CompositeNode readConfigurationData(InstanceIdentifier path) {
+            InstanceIdentifier newPath = shortenPath(path);
+            if(newPath == null) {
+                return null;
+            }
+            return MountPointImpl.this.readConfigurationData(newPath);
+        }
         
+        @Override
+        public CompositeNode readOperationalData(InstanceIdentifier path) {
+            InstanceIdentifier newPath = shortenPath(path);
+            if(newPath == null) {
+                return null;
+            }
+            return MountPointImpl.this.readOperationalData(newPath);
+        }
     }
 }
index c64d1e5..19634d7 100644 (file)
@@ -6,15 +6,27 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
 import java.util.concurrent.ConcurrentMap
 import java.util.concurrent.ConcurrentHashMap
 import static com.google.common.base.Preconditions.*;
+import org.opendaylight.controller.sal.core.api.data.DataProviderService
 
 class MountPointManagerImpl implements MountProvisionService {
     
+    @Property
+    DataProviderService dataBroker;
+    
     ConcurrentMap<InstanceIdentifier,MountPointImpl> mounts = new ConcurrentHashMap();
     
     override createMountPoint(InstanceIdentifier path) {
         checkState(!mounts.containsKey(path),"Mount already created");
         val mount = new MountPointImpl(path);
+        registerMountPoint(mount);
         mounts.put(path,mount);
+        return mount;
+    }
+    
+    def registerMountPoint(MountPointImpl impl) {
+        dataBroker?.registerConfigurationReader(impl.mountPath,impl.readWrapper);
+        dataBroker?.registerOperationalReader(impl.mountPath,impl.readWrapper);
+        
     }
     
     
@@ -30,6 +42,4 @@ class MountPointManagerImpl implements MountProvisionService {
     override getMountPoint(InstanceIdentifier path) {
         mounts.get(path);
     }
-    
-    
 }
index 1e0f338..b0c61c9 100644 (file)
@@ -3,6 +3,7 @@ package org.opendaylight.controller.sal.dom.broker.impl
 import org.opendaylight.controller.md.sal.common.impl.routing.AbstractDataReadRouter
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
 import org.opendaylight.yangtools.yang.data.api.CompositeNode
+import org.opendaylight.controller.md.sal.common.api.data.DataReader
 
 class DataReaderRouter extends AbstractDataReadRouter<InstanceIdentifier, CompositeNode> {
 
diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/MountProviderServiceProxy.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/MountProviderServiceProxy.java
new file mode 100644 (file)
index 0000000..0d18cb3
--- /dev/null
@@ -0,0 +1,27 @@
+package org.opendaylight.controller.sal.dom.broker.osgi;
+
+import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
+import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
+import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.osgi.framework.ServiceReference;
+
+public class MountProviderServiceProxy extends AbstractBrokerServiceProxy<MountProvisionService> implements MountProvisionService{
+
+    
+    public MountProviderServiceProxy(ServiceReference<MountProvisionService> ref, MountProvisionService delegate) {
+        super(ref, delegate);
+    }
+
+    public MountProvisionInstance getMountPoint(InstanceIdentifier path) {
+        return getDelegate().getMountPoint(path);
+    }
+
+    public MountProvisionInstance createMountPoint(InstanceIdentifier path) {
+        return getDelegate().createMountPoint(path);
+    }
+
+    public MountProvisionInstance createOrGetMountPoint(InstanceIdentifier path) {
+        return getDelegate().createOrGetMountPoint(path);
+    }
+}
index eb73867..938808f 100644 (file)
@@ -7,6 +7,7 @@ import org.opendaylight.controller.sal.core.api.data.DataProviderService
 import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService
 import org.opendaylight.controller.sal.core.api.notify.NotificationService
 import org.opendaylight.controller.sal.core.api.model.SchemaService
+import org.opendaylight.controller.sal.core.api.mount.MountProvisionService
 
 class ProxyFactory {
 
@@ -30,6 +31,11 @@ class ProxyFactory {
         new NotificationServiceProxy(ref as ServiceReference<NotificationService>, service);
     }
 
+    private static def dispatch createProxyImpl(ServiceReference<?> ref, MountProvisionService service) {
+        new MountProviderServiceProxy(ref as ServiceReference<MountProvisionService>, service);
+    }
+
+
     private static def dispatch createProxyImpl(ServiceReference<?> ref, SchemaService service) {
         new SchemaServiceProxy(ref as ServiceReference<SchemaService>, service);
     }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.