Merge "BUG-6890:Flow-Removed Notification configuration"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalRoleServiceImpl.java
index e5f7c944702373032d9664800e62f812d31819e6..9906515af633106c39dd1f239c6e653ff2d35722 100644 (file)
@@ -23,7 +23,6 @@ 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.openflowplugin.impl.role.RoleChangeException;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
@@ -46,8 +45,6 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
 
     private final DeviceContext deviceContext;
     private final RoleService roleService;
-    private final NodeId nodeId;
-    private final Short version;
 
     private final Semaphore currentRoleGuard = new Semaphore(1, true);
 
@@ -58,12 +55,10 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
         super(requestContextStack, deviceContext, SetRoleOutput.class);
         this.deviceContext = Preconditions.checkNotNull(deviceContext);
         this.roleService =  new RoleService(requestContextStack, deviceContext, RoleRequestOutput.class);
-        nodeId = deviceContext.getPrimaryConnectionContext().getNodeId();
-        version = deviceContext.getPrimaryConnectionContext().getFeatures().getVersion();
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final SetRoleInput input) {
+    protected OfHeader buildRequest(final Xid xid, final SetRoleInput input) throws ServiceException {
         return null;
     }
 
@@ -74,7 +69,7 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
             currentRoleGuard.acquire();
             LOG.trace("currentRole lock queue length: {} " + currentRoleGuard.getQueueLength());
         } catch (final InterruptedException e) {
-            LOG.error("Unexpected exception {} for acquire semaphor for input {}", e, input);
+            LOG.error("Unexpected exception {} for acquire semaphore for input {}", e, input);
             return RpcResultBuilder.<SetRoleOutput> failed().buildFuture();
         }
         // compare with last known role and set if different. If they are same, then return.
@@ -162,15 +157,15 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
     }
 
     private ListenableFuture<RpcResult<SetRoleOutput>> tryToChangeRole(final OfpRole role) {
-        LOG.info("RoleChangeTask called on device:{} OFPRole:{}", nodeId.getValue(), role);
+        LOG.info("RoleChangeTask called on device:{} OFPRole:{}", getDeviceInfo().getNodeId().getValue(), role);
 
-        final Future<BigInteger> generationFuture = roleService.getGenerationIdFromDevice(version);
+        final Future<BigInteger> generationFuture = roleService.getGenerationIdFromDevice(getVersion());
 
         return Futures.transform(JdkFutureAdapters.listenInPoolThread(generationFuture), (AsyncFunction<BigInteger, RpcResult<SetRoleOutput>>) generationId -> {
-            LOG.debug("RoleChangeTask, GenerationIdFromDevice from device {} is {}", nodeId.getValue(), generationId);
+            LOG.debug("RoleChangeTask, GenerationIdFromDevice from device {} is {}", getDeviceInfo().getNodeId().getValue(), generationId);
             final BigInteger nextGenerationId = getNextGenerationId(generationId);
-            LOG.debug("nextGenerationId received from device:{} is {}", nodeId.getValue(), nextGenerationId);
-            final Future<RpcResult<SetRoleOutput>> submitRoleFuture = roleService.submitRoleChange(role, version, nextGenerationId);
+            LOG.debug("nextGenerationId received from device:{} is {}", getDeviceInfo().getNodeId().getValue(), nextGenerationId);
+            final Future<RpcResult<SetRoleOutput>> submitRoleFuture = roleService.submitRoleChange(role, getVersion(), nextGenerationId);
             return JdkFutureAdapters.listenInPoolThread(submitRoleFuture);
         });
     }