Merge "SONAR TD - StatisticsContextImpl, StatisticsManagerImpl"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / SalRoleServiceImpl.java
index a8b4eb8107553851ad4264fe29b2d0c893de064a..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;
@@ -59,7 +58,7 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
     }
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final SetRoleInput input) {
+    protected OfHeader buildRequest(final Xid xid, final SetRoleInput input) throws ServiceException {
         return null;
     }
 
@@ -68,9 +67,9 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
         LOG.info("SetRole called with input:{}", input);
         try {
             currentRoleGuard.acquire();
-            LOG.trace("currentRole lock queue: " + currentRoleGuard.getQueueLength());
+            LOG.trace("currentRole lock queue length: {} " + currentRoleGuard.getQueueLength());
         } catch (final InterruptedException e) {
-            LOG.warn("Unexpected exception for acquire semaphor for input {}", 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.
@@ -95,7 +94,7 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
 
             @Override
             public void onFailure(final Throwable t) {
-                LOG.warn("SetRoleService set Role {} for Node: {} fail.", input.getControllerRole(),
+                LOG.error("SetRoleService set Role {} for Node: {} fail . Reason {}", input.getControllerRole(),
                         input.getNode().getValue(), t);
                 currentRoleGuard.release();
             }
@@ -125,6 +124,7 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
             return;
         case WORKING:
             // We can proceed
+            LOG.trace("Device {} has been working", input.getNode());
             break;
         default:
             LOG.warn("Device {} is in state {}, role change is not allowed", input.getNode(), state);
@@ -143,28 +143,28 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
                     currentRole = input.getControllerRole();
                     future.set(RpcResultBuilder.<SetRoleOutput> success().withResult(result.getResult()).build());
                 } else {
-                    LOG.info("setRole() failed with errors, will retry: {} times.", MAX_RETRIES - retryCounter);
+                    LOG.error("setRole() failed with errors, will retry: {} times.", MAX_RETRIES - retryCounter);
                     repeaterForChangeRole(future, input, (retryCounter + 1));
                 }
             }
 
             @Override
             public void onFailure(final Throwable t) {
-                LOG.info("Exception in setRole(), will retry: {} times.", MAX_RETRIES - retryCounter, t);
+                LOG.error("Exception in setRole(), will retry: {} times.", t, MAX_RETRIES - retryCounter);
                 repeaterForChangeRole(future, input, (retryCounter + 1));
             }
         });
     }
 
     private ListenableFuture<RpcResult<SetRoleOutput>> tryToChangeRole(final OfpRole role) {
-        LOG.info("RoleChangeTask called on device:{} OFPRole:{}", getNodeId().getValue(), role);
+        LOG.info("RoleChangeTask called on device:{} OFPRole:{}", getDeviceInfo().getNodeId().getValue(), role);
 
         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 {}", getNodeId().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 {}", getNodeId().getValue(), 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);
         });