BUG-4118: Li:backward compatibility - rpcs - initial proposal 73/26173/5
authorMichal Rehak <mirehak@cisco.com>
Tue, 8 Sep 2015 19:11:18 +0000 (21:11 +0200)
committerMichal Rehak <mirehak@cisco.com>
Fri, 27 Nov 2015 13:41:02 +0000 (14:41 +0100)
 - added config subsystem parameter for stats rpc control
 - API changes for delegating of new parameter, service lookup

Change-Id: I5a639b30a83fd9b025da5c7e1faffdc63eb1315b
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProvider.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/rpc/RpcContext.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/rpc/RpcManager.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/statistics/compatibility/BackwardCompatibleAtomicService.java [new file with mode: 0644]
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/statistics/compatibility/Delegator.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/config/openflow/plugin/impl/rev150327/OpenFlowProviderModule.java
openflowplugin-impl/src/main/yang/openflow-plugin-impl.yang

index db725f20e5cb3ee699b8b870a25f47c39a407256..82a69c5847a1a45a147a78ef86b93834f10ec928 100644 (file)
@@ -60,4 +60,11 @@ public interface OpenFlowPluginProvider extends AutoCloseable, BindingService {
 
     void setEntityOwnershipService(EntityOwnershipService entityOwnershipService);
 
 
     void setEntityOwnershipService(EntityOwnershipService entityOwnershipService);
 
-    }
+
+    /**
+     * Backward compatibility feature - exposing rpc for statistics polling (result is provided in form of async notification)
+     *
+     * @param isStatisticsRpcEnabled
+     */
+    void setIsStatisticsRpcEnabled(boolean isStatisticsRpcEnabled);
+}
index 30458e01e6009bd121f0eee7fbd4ec3667d369d4..3399a1b534e14547ffcd6941d9ec540f84e7ccaa 100644 (file)
@@ -20,4 +20,6 @@ import org.opendaylight.yangtools.yang.binding.RpcService;
  */
 public interface RpcContext extends RequestContextStack, AutoCloseable {
     <S extends RpcService> void registerRpcServiceImplementation(Class<S> serviceClass, S serviceInstance);
  */
 public interface RpcContext extends RequestContextStack, AutoCloseable {
     <S extends RpcService> void registerRpcServiceImplementation(Class<S> serviceClass, S serviceInstance);
+
+    <S extends RpcService> S lookupRpcService(Class<S> serviceClass);
 }
 }
index 928fd716d8b4b69955fa450c86ac61b45bcc3344..17b9466380068d1f66fb0496bef7e3df37d7115b 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.openflowplugin.api.openflow.rpc;
 
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextClosedHandler;
 package org.opendaylight.openflowplugin.api.openflow.rpc;
 
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextClosedHandler;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializator;
 
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializator;
 
@@ -21,4 +22,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitia
  */
 public interface RpcManager extends DeviceInitializator, DeviceInitializationPhaseHandler, AutoCloseable, DeviceContextClosedHandler {
 
  */
 public interface RpcManager extends DeviceInitializator, DeviceInitializationPhaseHandler, AutoCloseable, DeviceContextClosedHandler {
 
+    void setStatisticsRpcEnabled(boolean isStatisticsRpcEnabled);
+
+    void setNotificationPublishService(NotificationPublishService notificationPublishService);
 }
 }
diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/statistics/compatibility/BackwardCompatibleAtomicService.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/statistics/compatibility/BackwardCompatibleAtomicService.java
new file mode 100644 (file)
index 0000000..924a757
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2015 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.openflowplugin.api.openflow.statistics.compatibility;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+/**
+ * Prescribes handling and transforming of backward compatible services in order to provide simple to use service
+ * with notification support
+ *
+ * @param <O> rpc input
+ * @param <I> rpc input
+ * @deprecated for backward compatibility only (expected to extinct after Be-release)
+ */
+@Deprecated
+public interface BackwardCompatibleAtomicService<I, O> {
+
+    /**
+     * process rpc request and publish corresponding notification upon success
+     *
+     * @param input                      rpc input
+     * @param notificationPublishService publisher handle
+     */
+    ListenableFuture<RpcResult<O>> handleAndNotify(I input, NotificationPublishService notificationPublishService);
+}
diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/statistics/compatibility/Delegator.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/statistics/compatibility/Delegator.java
new file mode 100644 (file)
index 0000000..72bb7df
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2015 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.openflowplugin.api.openflow.statistics.compatibility;
+
+/**
+ * Simple delegator pattern support
+ */
+public interface Delegator<D> {
+
+    /**
+     * @param delegate backend task executor
+     */
+    void setDelegate(D delegate);
+}
index 0fb0a72e219ada124f3b6d9ede6cc567bd8e33e7..167753b993635986b56545758ff0375921613ab5 100644 (file)
@@ -79,6 +79,7 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     private Collection<SwitchConnectionProvider> switchConnectionProviders;
     private boolean switchFeaturesMandatory = false;
     private boolean isStatisticsPollingOff = false;
     private Collection<SwitchConnectionProvider> switchConnectionProviders;
     private boolean switchFeaturesMandatory = false;
     private boolean isStatisticsPollingOff = false;
+    private boolean isStatisticsRpcEnabled;
 
     public OpenFlowPluginProviderImpl(final long rpcRequestsQuota, final Long globalNotificationQuota) {
         Preconditions.checkArgument(rpcRequestsQuota > 0 && rpcRequestsQuota <= Integer.MAX_VALUE, "rpcRequestQuota has to be in range <1,%s>", Integer.MAX_VALUE);
 
     public OpenFlowPluginProviderImpl(final long rpcRequestsQuota, final Long globalNotificationQuota) {
         Preconditions.checkArgument(rpcRequestsQuota > 0 && rpcRequestsQuota <= Integer.MAX_VALUE, "rpcRequestQuota has to be in range <1,%s>", Integer.MAX_VALUE);
@@ -180,6 +181,8 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         roleManager.setDeviceInitializationPhaseHandler(statisticsManager);
         statisticsManager.setDeviceInitializationPhaseHandler(rpcManager);
         rpcManager.setDeviceInitializationPhaseHandler(deviceManager);
         roleManager.setDeviceInitializationPhaseHandler(statisticsManager);
         statisticsManager.setDeviceInitializationPhaseHandler(rpcManager);
         rpcManager.setDeviceInitializationPhaseHandler(deviceManager);
+        rpcManager.setStatisticsRpcEnabled(isStatisticsRpcEnabled);
+        rpcManager.setNotificationPublishService(notificationPublishService);
 
         deviceManager.setNotificationService(this.notificationProviderService);
         deviceManager.setNotificationPublishService(this.notificationPublishService);
 
         deviceManager.setNotificationService(this.notificationProviderService);
         deviceManager.setNotificationPublishService(this.notificationPublishService);
@@ -221,6 +224,11 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         return extensionConverterManager;
     }
 
         return extensionConverterManager;
     }
 
+    @Override
+    public void setIsStatisticsRpcEnabled(final boolean isStatisticsRpcEnabled) {
+        this.isStatisticsRpcEnabled = isStatisticsRpcEnabled;
+    }
+
     @Override
     public void close() throws Exception {
         //TODO: close all contexts, switchConnections (, managers)
     @Override
     public void close() throws Exception {
         //TODO: close all contexts, switchConnections (, managers)
index b373bf93db35c3b868cef95d7faf3a802e8fa82d..50d911a05185ad4b2d7d17a2ddd0e9ef33ea5662 100644 (file)
@@ -58,6 +58,18 @@ public class RpcContextImpl implements RpcContext {
         }
     }
 
         }
     }
 
+    @Override
+    public <S extends RpcService> S lookupRpcService(Class<S> serviceClass) {
+        S service = null;
+        for (RoutedRpcRegistration<?> rpcRegistration : rpcRegistrations) {
+            final RpcService rpcService = rpcRegistration.getInstance();
+            if (serviceClass.isInstance(rpcService)) {
+                service = (S) rpcService;
+                break;
+            }
+        }
+        return service;
+    }
     /**
      * Unregisters all services.
      *
     /**
      * Unregisters all services.
      *
index 3031214d09f4b18503a50ae1030df7f418cab870..7bb6e37f727f6265678d839e8dd4b169bc189fb0 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.openflowplugin.impl.rpc;
 
  */
 package org.opendaylight.openflowplugin.impl.rpc;
 
+import java.util.concurrent.atomic.AtomicLong;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
@@ -28,6 +30,8 @@ public class RpcManagerImpl implements RpcManager {
     private DeviceInitializationPhaseHandler deviceInitPhaseHandler;
     private final int maxRequestsQuota;
     private final ConcurrentHashMap<DeviceContext, RpcContext> contexts = new ConcurrentHashMap<>();
     private DeviceInitializationPhaseHandler deviceInitPhaseHandler;
     private final int maxRequestsQuota;
     private final ConcurrentHashMap<DeviceContext, RpcContext> contexts = new ConcurrentHashMap<>();
+    private boolean isStatisticsRpcEnabled;
+    private NotificationPublishService notificationPublishService;
 
     public RpcManagerImpl(final RpcProviderRegistry rpcProviderRegistry,
                           final int quotaValue) {
 
     public RpcManagerImpl(final RpcProviderRegistry rpcProviderRegistry,
                           final int quotaValue) {
@@ -92,6 +96,13 @@ public class RpcManagerImpl implements RpcManager {
                         deviceContext.getDeviceState().getNodeId(), e);
             }
         }
                         deviceContext.getDeviceState().getNodeId(), e);
             }
         }
+    }
+    public void setStatisticsRpcEnabled(boolean isStatisticsRpcEnabled) {
+        this.isStatisticsRpcEnabled = isStatisticsRpcEnabled;
+    }
 
 
+    @Override
+    public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
+        this.notificationPublishService = notificationPublishService;
     }
 }
     }
 }
index bb09b939a39b81ba13316e4e903028951f9eff98..cc7d179466349a2f704a077555ae9808166d61e1 100644 (file)
@@ -37,6 +37,8 @@ public class OpenFlowProviderModule extends org.opendaylight.yang.gen.v1.urn.ope
         openflowPluginProvider.setSwitchFeaturesMandatory(getSwitchFeaturesMandatory());
         openflowPluginProvider.setIsStatisticsPollingOff(getIsStatisticsPollingOff());
         openflowPluginProvider.setEntityOwnershipService(getEntityOwnershipServiceDependency());
         openflowPluginProvider.setSwitchFeaturesMandatory(getSwitchFeaturesMandatory());
         openflowPluginProvider.setIsStatisticsPollingOff(getIsStatisticsPollingOff());
         openflowPluginProvider.setEntityOwnershipService(getEntityOwnershipServiceDependency());
+        openflowPluginProvider.setIsStatisticsRpcEnabled(getIsStatisticsRpcEnabled());
+
         openflowPluginProvider.initialize();
 
         return openflowPluginProvider;
         openflowPluginProvider.initialize();
 
         return openflowPluginProvider;
index 1da6cd74de95a8e99da97d7aa7ae7dad7f9d7973..aee2d6ccd1d1c776f6a84cf3737094bc152f511e 100644 (file)
@@ -95,6 +95,12 @@ module openflow-plugin-provider-impl {
                 type boolean;
                 default "false";
             }
                 type boolean;
                 default "false";
             }
+            leaf is-statistics-rpc-enabled {
+                status deprecated;
+                description "Exposing backward compatible statistics rpcs providing result in form of async notification";
+                type boolean;
+                default "false";
+            }
         }
 
     }
         }
 
     }