Fix RPC forwarding related bugs in Binding Independent Connector 50/4650/2
authorTony Tkacik <ttkacik@cisco.com>
Sun, 26 Jan 2014 17:24:25 +0000 (18:24 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Sun, 26 Jan 2014 17:24:25 +0000 (18:24 +0100)
  - Fix for set of small bugs which prevented invocation of RPC via Restconf

Change-Id: I090516187007c5b1411fd6a9aecf25724465228a
Signed-off-by: Robert Gallas <rgallas@cisco.com>
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingIndependentConnector.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerConfigActivator.xtend
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareRpcBroker.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.xtend
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/RpcProvisionRegistryProxy.java [new file with mode: 0644]

index d2295c49de06871ed01719c10e29d8b9433578c8..aaed12f740ea7224c540fdc936f544308ccb1a3e 100644 (file)
@@ -89,6 +89,8 @@ public class BindingIndependentConnector implements //
         Provider, //
         AutoCloseable {
 
+
+
     private final Logger LOG = LoggerFactory.getLogger(BindingIndependentConnector.class);
 
     @SuppressWarnings( "deprecation")
@@ -589,7 +591,7 @@ public class BindingIndependentConnector implements //
                 }
 
             } catch (Exception e) {
-                LOG.error("Could not forward Rpcs of type {}", service.getName());
+                LOG.error("Could not forward Rpcs of type {}", service.getName(),e);
             }
             registrations = ImmutableSet.of();
         }
@@ -721,8 +723,10 @@ public class BindingIndependentConnector implements //
                         } else {
                             strategy = new NoInputNoOutputInvocationStrategy(rpc,targetMethod);
                         }
+                    } else if(inputClass.isPresent()){
+                        strategy = new NoOutputInvocationStrategy(rpc,targetMethod, inputClass.get());
                     } else {
-                        strategy = null;
+                        strategy = new NoInputNoOutputInvocationStrategy(rpc,targetMethod);
                     }
                     return strategy;
                 }
@@ -814,6 +818,46 @@ public class BindingIndependentConnector implements //
             return Futures.immediateFuture(null);
         }
     }
+    
+    private class NoOutputInvocationStrategy extends RpcInvocationStrategy {
+
+        
+        @SuppressWarnings("rawtypes")
+        private WeakReference<Class> inputClass;
+
+        @SuppressWarnings({ "rawtypes", "unchecked" })
+        public NoOutputInvocationStrategy(QName rpc, Method targetMethod, 
+                Class<? extends DataContainer> inputClass) {
+            super(rpc,targetMethod);
+            this.inputClass = new WeakReference(inputClass);
+        }
+        
+        
+        @Override
+        public RpcResult<CompositeNode> uncheckedInvoke(RpcService rpcService, CompositeNode domInput) throws Exception {
+            DataContainer bindingInput = mappingService.dataObjectFromDataDom(inputClass.get(), domInput);
+            Future<RpcResult<?>> result = (Future<RpcResult<?>>) targetMethod.invoke(rpcService, bindingInput);
+            if (result == null) {
+                return Rpcs.getRpcResult(false);
+            }
+            RpcResult<?> bindingResult = result.get();
+            return Rpcs.getRpcResult(true);
+        }
+
+        @Override
+        public Future<RpcResult<?>> forwardToDomBroker(DataObject input) {
+            if(biRouter != null) {
+                CompositeNode xml = mappingService.toDataDom(input);
+                CompositeNode wrappedXml = ImmutableCompositeNode.create(rpc,ImmutableList.<Node<?>>of(xml));
+                RpcResult<CompositeNode> result = biRouter.invokeRpc(rpc, wrappedXml);
+                Object baResultValue = null;
+                RpcResult<?> baResult = Rpcs.<Void>getRpcResult(result.isSuccessful(), null, result.getErrors());
+                return Futures.<RpcResult<?>>immediateFuture(baResult);
+            }
+            return Futures.<RpcResult<?>>immediateFuture(Rpcs.getRpcResult(false));
+        }
+
+    }
 
     public boolean isRpcForwarding() {
         return rpcForwarding;
@@ -824,7 +868,6 @@ public class BindingIndependentConnector implements //
     }
 
     public boolean isNotificationForwarding() {
-        // TODO Auto-generated method stub
         return notificationForwarding;
     }
 
index 53fa4d087d5a02d2013b28ef6a616ab83cba69a9..1159d5650e6599a72db0af912909244d17cf612b 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
 import org.osgi.framework.BundleContext
 import org.osgi.framework.ServiceRegistration
 import org.opendaylight.controller.sal.dom.broker.impl.SchemaContextProviders
+import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry
 
 class BrokerConfigActivator implements AutoCloseable {
 
@@ -29,12 +30,12 @@ class BrokerConfigActivator implements AutoCloseable {
     @Property
     private var DataBrokerImpl dataService;
 
-    private var ServiceRegistration<SchemaService> schemaReg;
     private var ServiceRegistration<DataBrokerService> dataReg;
     private var ServiceRegistration<DataProviderService> dataProviderReg;
     private var ServiceRegistration<MountService> mountReg;
     private var ServiceRegistration<MountProvisionService> mountProviderReg;
     private var SchemaService schemaService;
+    private var ServiceRegistration<RpcProvisionRegistry> rpcProvisionRegistryReg;
     private var MountPointManagerImpl mountService;
 
     SchemaAwareDataStoreAdapter wrappedStore
@@ -45,7 +46,6 @@ class BrokerConfigActivator implements AutoCloseable {
 
         val serviceRef = context.getServiceReference(SchemaService);
         schemaService = context.getService(serviceRef);
-        schemaReg = context.registerService(SchemaService, schemaService, emptyProperties);
 
         broker.setRouter(new SchemaAwareRpcBroker("/", SchemaContextProviders.fromSchemaService(schemaService)));
 
@@ -70,14 +70,16 @@ class BrokerConfigActivator implements AutoCloseable {
 
         mountReg = context.registerService(MountService, mountService, emptyProperties);
         mountProviderReg = context.registerService(MountProvisionService, mountService, emptyProperties);
+
+        rpcProvisionRegistryReg = context.registerService(RpcProvisionRegistry, broker.getRouter(), emptyProperties);
     }
 
     override def close() {
-        schemaReg?.unregister();
         dataReg?.unregister();
         dataProviderReg?.unregister();
         mountReg?.unregister();
         mountProviderReg?.unregister();
+        rpcProvisionRegistryReg?.unregister();
     }
 
 }
index de6cfa627656186d31bf21d91a6229af6768aec2..f0f5ac3e33926376d59d67669672fa7a15870189 100644 (file)
@@ -119,6 +119,7 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable<String> {
         RpcDefinition definition = findRpcDefinition(rpcType);
         checkArgument(!isRoutedRpc(definition), "RPC Type must not be routed.");
         GlobalRpcRegistration reg = new GlobalRpcRegistration(rpcType, implementation, this);
+        implementations.putIfAbsent(rpcType, implementation);
         return reg;
     }
 
index 938808facd58911411a60377b39061947ade2e23..3f77133c2e3a2937fac78254b7f858b0ddadf42f 100644 (file)
@@ -8,6 +8,7 @@ import org.opendaylight.controller.sal.core.api.notify.NotificationPublishServic
 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
+import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry
 
 class ProxyFactory {
 
@@ -40,6 +41,10 @@ class ProxyFactory {
         new SchemaServiceProxy(ref as ServiceReference<SchemaService>, service);
     }
 
+    private static def dispatch createProxyImpl(ServiceReference<?> ref, RpcProvisionRegistry service) {
+        new RpcProvisionRegistryProxy(ref as ServiceReference<RpcProvisionRegistry>, service);
+    }
+
     private static def dispatch createProxyImpl(ServiceReference<?> reference, BrokerService service) {
         throw new IllegalArgumentException("Not supported class");
     }
diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/RpcProvisionRegistryProxy.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/RpcProvisionRegistryProxy.java
new file mode 100644 (file)
index 0000000..e375e14
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2013 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.controller.sal.dom.broker.osgi;
+
+import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
+import org.opendaylight.controller.sal.core.api.Broker;
+import org.opendaylight.controller.sal.core.api.RpcImplementation;
+import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
+import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
+import org.opendaylight.controller.sal.core.api.RpcRoutingContext;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.osgi.framework.ServiceReference;
+
+public class RpcProvisionRegistryProxy extends AbstractBrokerServiceProxy<RpcProvisionRegistry>
+                                       implements RpcProvisionRegistry {
+
+    public RpcProvisionRegistryProxy(ServiceReference<RpcProvisionRegistry> ref, RpcProvisionRegistry delegate) {
+        super(ref, delegate);
+    }
+
+    @Override
+    public Broker.RpcRegistration addRpcImplementation(QName rpcType, RpcImplementation implementation) throws IllegalArgumentException {
+        return getDelegate().addRpcImplementation(rpcType, implementation);
+    }
+
+    @Override
+    public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener) {
+        return getDelegate().addRpcRegistrationListener(listener);
+    }
+
+    @Override
+    public Broker.RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
+        return getDelegate().addRoutedRpcImplementation(rpcType, implementation);
+    }
+
+    @Override
+    public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(L listener) {
+        return getDelegate().registerRouteChangeListener(listener);
+    }
+}