sal role service and role injection 84/28184/3
authorKamal Rameshan <kramesha@cisco.com>
Fri, 21 Aug 2015 20:45:56 +0000 (13:45 -0700)
committermichal rehak <mirehak@cisco.com>
Thu, 15 Oct 2015 16:37:56 +0000 (16:37 +0000)
role cannot be assigned to the whole of openflowplugin.
Since we are scaling switches across a cluster, the role would be assigned per device.

Added a new sal-role yang, rpc and service.

This would be the first of subsequent commits.

Made changes to merge to master - header and testchanges

Change-Id: I0a681485c5ccb8bc839b3b18f3efb648b88bd86b
Signed-off-by: Kamal Rameshan <kramesha@cisco.com>
(cherry picked from commit f6d2398e08b0a9b2d7bb5c533e9ca17a5041a74f)

model/model-flow-service/src/main/yang/sal-role.yang [new file with mode: 0644]
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProvider.java
openflowplugin-api/src/main/yang/openflow-plugin-types.yang [deleted file]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalRoleServiceImpl.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistratorUtils.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
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistratorUtilsTest.java

diff --git a/model/model-flow-service/src/main/yang/sal-role.yang b/model/model-flow-service/src/main/yang/sal-role.yang
new file mode 100644 (file)
index 0000000..dceff0f
--- /dev/null
@@ -0,0 +1,44 @@
+module sal-role {
+    namespace "urn:opendaylight:role:service";
+    prefix role;
+
+    import flow-capable-transaction {prefix tr; revision-date "2015-03-04";}
+    import opendaylight-inventory {prefix inv;revision-date "2013-08-19";}
+
+    description "Openflow role management.";
+
+    revision "2015-07-27" {
+        description "Initial revision of role service";
+    }
+
+    typedef ofp-role {
+        description "role of OFPlugin instance";
+        type enumeration {
+            enum NOCHANGE {
+                description "no change to role";
+            }
+
+            enum BECOMEMASTER {
+                description "promote current role to MASTER";
+            }
+
+            enum BECOMESLAVE {
+                description "demote current role to SLAVE";
+            }
+        }
+    }
+
+    rpc set-role {
+        description "Setting role to openflow device.";
+        input {
+            uses tr:transaction-metadata;
+            uses "inv:node-context-ref";
+            leaf controller-role {
+                type ofp-role;
+            }
+        }
+        output {
+            uses tr:transaction-aware;
+        }
+    }
+}
\ No newline at end of file
index 8bd7877533a84fd3594154c011a3efbb84666da1..b22dbe3f760116ad019e8037e620fd0320eb0331 100644 (file)
@@ -15,7 +15,6 @@ import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService
 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.api.types.rev150327.OfpRole;
 
 /**
  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 27.3.2015.
@@ -40,11 +39,6 @@ public interface OpenFlowPluginProvider extends AutoCloseable, BindingService {
 
     void setNotificationPublishService(NotificationPublishService notificationPublishService);
 
-    /**
-     * Method sets role of this application in clustered environment.
-     */
-    void setRole(OfpRole role);
-
     /**
      * Method initializes all DeviceManager, RpcManager and related contexts.
      */
diff --git a/openflowplugin-api/src/main/yang/openflow-plugin-types.yang b/openflowplugin-api/src/main/yang/openflow-plugin-types.yang
deleted file mode 100644 (file)
index 88d512e..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-module openflow-plugin-types {
-       yang-version 1;
-    namespace "urn:opendaylight:params:xml:ns:yang:openflowplugin:api:types";
-    prefix "openflow-plugin-types";
-
-    description
-        "Openflow plugin specific types.";
-
-    revision "2015-03-27" {
-        description
-            "Initial revision";
-    }
-
-    typedef ofp-role {
-        description "role of OFPlugin instance";
-        type enumeration {
-            enum NOCHANGE {
-                description "no change to role";
-            }
-            enum BECOMEMASTER {
-                description "promote current role to MASTER";
-            }
-            enum BECOMESLAVE {
-                description "demote current role to SLAVE";
-            }
-        }
-    }
-
-}
\ No newline at end of file
index 91093587dab4d4b600566fbbfb500bef456cb51f..b8fb10f80c51072a9040dffb9f343bfd46e32668 100644 (file)
@@ -46,7 +46,6 @@ import org.opendaylight.openflowplugin.impl.util.TranslatorLibraryUtil;
 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManager;
 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManagerImpl;
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.api.types.rev150327.OfpRole;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -71,7 +70,6 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     private ExtensionConverterManager extensionConverterManager;
 
     private DataBroker dataBroker;
-    private OfpRole role;
     private Collection<SwitchConnectionProvider> switchConnectionProviders;
     private boolean switchFeaturesMandatory = false;
     private boolean isStatisticsPollingOff = false;
@@ -142,12 +140,6 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         this.rpcProviderRegistry = rpcProviderRegistry;
     }
 
-    @Override
-    public void setRole(final OfpRole role) {
-        this.role = role;
-    }
-
-
     @Override
     public void initialize() {
 
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalRoleServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalRoleServiceImpl.java
new file mode 100644 (file)
index 0000000..c135576
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ * 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.impl.services;
+
+import java.util.concurrent.Future;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.Xid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+
+public class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInputBuilder, SetRoleOutput> implements SalRoleService  {
+
+    public SalRoleServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+        super(requestContextStack, deviceContext, SetRoleOutput.class);
+    }
+
+    @Override
+    protected OfHeader buildRequest(Xid xid, SetRoleInputBuilder input) {
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<SetRoleOutput>> setRole(SetRoleInput input) {
+        return null;
+    }
+}
index a437bd517d6e2e92896b3df470e1a2f6caf2f124..0797245504b61a38cbc223203cf9de92b430dc80 100644 (file)
@@ -16,6 +16,7 @@ import org.opendaylight.openflowplugin.impl.services.SalEchoServiceImpl;
 import org.opendaylight.openflowplugin.impl.services.SalFlowServiceImpl;
 import org.opendaylight.openflowplugin.impl.services.SalGroupServiceImpl;
 import org.opendaylight.openflowplugin.impl.services.SalMeterServiceImpl;
+import org.opendaylight.openflowplugin.impl.services.SalRoleServiceImpl;
 import org.opendaylight.openflowplugin.impl.services.SalTableServiceImpl;
 import org.opendaylight.openflowplugin.impl.statistics.services.OpendaylightFlowStatisticsServiceImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.echo.service.rev150305.SalEchoService;
@@ -26,6 +27,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.Sal
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
 
 public class MdSalRegistratorUtils {
@@ -45,5 +47,6 @@ public class MdSalRegistratorUtils {
         rpcContext.registerRpcServiceImplementation(PacketProcessingService.class, new PacketProcessingServiceImpl(rpcContext, deviceContext));
         rpcContext.registerRpcServiceImplementation(NodeConfigService.class, new NodeConfigServiceImpl(rpcContext, deviceContext));
         rpcContext.registerRpcServiceImplementation(OpendaylightFlowStatisticsService.class, new OpendaylightFlowStatisticsServiceImpl(rpcContext, deviceContext));
+        rpcContext.registerRpcServiceImplementation(SalRoleService.class, new SalRoleServiceImpl(rpcContext, deviceContext));
     }
 }
index 37ef120efb048f4add2d6db97dd579b2659ec8b0..2a967f49a765c065f60e25da5a18a0c85c3218f5 100644 (file)
@@ -30,7 +30,6 @@ public class OpenFlowProviderModule extends org.opendaylight.yang.gen.v1.urn.ope
         OpenFlowPluginProvider openflowPluginProvider = new OpenFlowPluginProviderImpl(getRpcRequestsQuota(), getGlobalNotificationQuota());
 
         openflowPluginProvider.setSwitchConnectionProviders(getOpenflowSwitchConnectionProviderDependency());
-        openflowPluginProvider.setRole(getRole());
         openflowPluginProvider.setDataBroker(getDataBrokerDependency());
         openflowPluginProvider.setRpcProviderRegistry(getRpcRegistryDependency());
         openflowPluginProvider.setNotificationProviderService(getNotificationAdapterDependency());
index aecb5c4eb8b0ce77f03396a97bbc5457c9c96b54..ef43dc3fcf3be68b1ccc494341cb5e12f533b72b 100644 (file)
@@ -9,7 +9,6 @@ module openflow-plugin-provider-impl {
     import openflow-switch-connection-provider {prefix openflow-switch-connection-provider;revision-date 2014-03-28;}
     import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;}
     import opendaylight-sal-binding-broker-impl { prefix sal-broker; revision-date 2013-10-28;}
-    import openflow-plugin-types { prefix ofp-types; revision-date 2015-03-27;}
     import openflowplugin-extension-registry {prefix ofp-ext-reg; revision-date 2015-04-25;}
 
     description
@@ -71,10 +70,6 @@ module openflow-plugin-provider-impl {
                     }
                 }
             }
-            leaf role {
-                type ofp-types:ofp-role;
-                default "NOCHANGE";
-            }
             leaf rpc-requests-quota {
                 type uint32;
                 default 500;
index 8923d4acf1356145495bfe224eec1177590165de..d9815accb83ddd45b0c15857dea52a606ebe9fc4 100644 (file)
@@ -37,7 +37,7 @@ import org.opendaylight.yangtools.yang.binding.RpcService;
 @RunWith(MockitoJUnitRunner.class)
 public class RpcManagerImplTest {
 
-    private static final int AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC = 9;
+    private static final int AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC = 10;
 
     private RpcManagerImpl rpcManager;
     @Mock
index 3aa9defc5712d26e9f2efcf266b5e515e76682ac..776a82fee3de417561596c819ebe6beb89283a04 100644 (file)
@@ -30,7 +30,7 @@ public class MdSalRegistratorUtilsTest {
      * Number of currently registrated services (can be changed) in {@link MdSalRegistratorUtils#registerServices
      * (RpcContext, DeviceContext)}
      */
-    private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 9;
+    private static final int NUMBER_OF_RPC_SERVICE_REGISTRATION = 10;
 
     @Test
     public void registerServiceTest() {