BUG-8987: Print Exception when Css registration fails 33/62633/2
authorClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Mon, 4 Sep 2017 11:02:48 +0000 (13:02 +0200)
committerClaudio D. Gasparini <claudio.gasparini@pantheon.tech>
Mon, 11 Sep 2017 07:44:41 +0000 (07:44 +0000)
Change-Id: I34236ac8546358fe3c00985fbbf40f69aa0bef19
Signed-off-by: Claudio D. Gasparini <claudio.gasparini@pantheon.tech>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RIBImpl.java
bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/util/ClusterSingletonServiceRegistrationHelper.java
bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/util/ClusterSingletonServiceRegistrationHelperTest.java
bgp/topology-provider/src/main/java/org/opendaylight/bgpcep/bgp/topology/provider/config/BgpTopologyDeployerImpl.java

index d792e0458927baf7afa58c9812c3522209a5dacf..631e2799464d2a414164b6616be12a9bdf5ad803 100755 (executable)
@@ -90,8 +90,6 @@ public final class RIBImpl extends BGPRIBStateImpl implements ClusterSingletonSe
     private static final Logger LOG = LoggerFactory.getLogger(RIBImpl.class);
     private static final QName RIB_ID_QNAME = QName.create(Rib.QNAME, "id").intern();
     private static final ContainerNode EMPTY_TABLE_ATTRIBUTES = ImmutableNodes.containerNode(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes.QNAME);
-    private static final int MAX_REGISTRATION_ATTEMPTS = 10;
-    private static final int SLEEP_TIME = MAX_REGISTRATION_ATTEMPTS;
 
     private final BGPDispatcher dispatcher;
     private final AsNumber localAs;
@@ -380,9 +378,10 @@ public final class RIBImpl extends BGPRIBStateImpl implements ClusterSingletonSe
     }
 
     @Override
-    public ClusterSingletonServiceRegistration registerClusterSingletonService(final ClusterSingletonService clusterSingletonService) {
-        return ClusterSingletonServiceRegistrationHelper.registerSingletonService(this.provider, clusterSingletonService, MAX_REGISTRATION_ATTEMPTS,
-                SLEEP_TIME);
+    public ClusterSingletonServiceRegistration registerClusterSingletonService(
+        final ClusterSingletonService clusterSingletonService) {
+        return ClusterSingletonServiceRegistrationHelper
+            .registerSingletonService(this.provider, clusterSingletonService);
     }
 
     @Override
index 3602d616487b2406360dc8431c8030c2d525f958..8df6f68b230569a71df08cabea7fa17956eb9e81 100644 (file)
@@ -18,41 +18,64 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Utility class which provides helper functionality for ClusterSingletonService.
- *
  */
 public final class ClusterSingletonServiceRegistrationHelper {
 
     private static final Logger LOG = LoggerFactory.getLogger(ClusterSingletonServiceRegistrationHelper.class);
+    private static final int MAX_REGISTRATION_ATTEMPTS = 10;
+    private static final int SLEEP_TIME_MILLIS = MAX_REGISTRATION_ATTEMPTS;
 
     private ClusterSingletonServiceRegistrationHelper() {
         throw new UnsupportedOperationException();
     }
 
     /**
-     * This helper function wraps {@link ClusterSingletonServiceProvider#registerClusterSingletonService(ClusterSingletonService)} in order to
-     * execute repeated registration attempts while catching RuntimeException. If registration is not successful, RuntimeException is re-thrown.
+     * This helper function wraps
+     * {@link ClusterSingletonServiceProvider#registerClusterSingletonService(ClusterSingletonService)} in order to
+     * execute repeated registration attempts while catching RuntimeException. If registration is not successful,
+     * RuntimeException is re-thrown.
+     *
      * @param singletonProvider
      * @param clusterSingletonService
-     * @param maxAttempts Upper bound for registration retries count.
-     * @param sleepTime Sleep time between registration retries in milliseconds.
+     * @param maxAttempts             Upper bound for registration retries count.
+     * @param sleepTime               Sleep time between registration retries in milliseconds.
      * @return Registration
      */
-    public static ClusterSingletonServiceRegistration registerSingletonService(final ClusterSingletonServiceProvider singletonProvider,
-            final ClusterSingletonService clusterSingletonService, final int maxAttempts, final int sleepTime) {
+    public static ClusterSingletonServiceRegistration registerSingletonService(
+        final ClusterSingletonServiceProvider singletonProvider,
+        final ClusterSingletonService clusterSingletonService, final int maxAttempts, final int sleepTime) {
         int attempts = maxAttempts;
         while (true) {
             try {
-              return singletonProvider.registerClusterSingletonService(clusterSingletonService);
+                return singletonProvider.registerClusterSingletonService(clusterSingletonService);
             } catch (final RuntimeException e) {
                 if (attempts == 0) {
-                    LOG.error("Giving up after {} registration attempts for service {}.", maxAttempts, clusterSingletonService, e);
+                    LOG.error("Giving up after {} registration attempts for service {}.", maxAttempts,
+                        clusterSingletonService, e);
                     throw e;
                 }
                 attempts--;
-                LOG.warn("Failed to register {} service to ClusterSingletonServiceProvider. Try again in {} ms.", clusterSingletonService, sleepTime);
+                LOG.warn("Failed to register {} service to ClusterSingletonServiceProvider. Try again in {} ms. {}",
+                    clusterSingletonService, sleepTime, e);
                 Uninterruptibles.sleepUninterruptibly(sleepTime, TimeUnit.MILLISECONDS);
             }
         }
     }
 
+    /**
+     * This helper function wraps
+     * {@link ClusterSingletonServiceProvider#registerClusterSingletonService(ClusterSingletonService)} in order to
+     * execute repeated registration attempts while catching RuntimeException. If registration is not successful,
+     * RuntimeException is re-thrown. 10 registration attempts will be tried with 10 ms pause between each
+     * other.
+     *
+     * @param singletonProvider
+     * @param clusterSingletonService
+     * @return Registration
+     */
+    public static ClusterSingletonServiceRegistration registerSingletonService(final ClusterSingletonServiceProvider
+        singletonProvider, final ClusterSingletonService clusterSingletonService) {
+        return ClusterSingletonServiceRegistrationHelper.registerSingletonService(singletonProvider,
+            clusterSingletonService, MAX_REGISTRATION_ATTEMPTS, SLEEP_TIME_MILLIS);
+    }
 }
index 0dcafc81933f321518bedd399bd01b095a5c8fa3..6ac4382a9bdd7c6b163ec8ccb9d367d1b5ece1c3 100644 (file)
@@ -58,7 +58,8 @@ public class ClusterSingletonServiceRegistrationHelperTest {
 
     @Test
     public void testRegisterSingletonServiceSuccessfulRetry() {
-        final ClusterSingletonServiceRegistration registerSingletonService = registerSingletonService(this.singletonProvider, this.clusterSingletonService, 1, 1);
+        final ClusterSingletonServiceRegistration registerSingletonService =
+            registerSingletonService(this.singletonProvider, this.clusterSingletonService, 1, 1);
         Assert.assertEquals(this.serviceRegistration, registerSingletonService);
         //first reg. attempt failed, second succeeded
         Mockito.verify(this.singletonProvider, Mockito.times(2)).registerClusterSingletonService(Mockito.any());
index 3b89b16b4e4e01cb8a730bfceff34c5abeea4c30..1c53211e35855b170b95ab3919098a1ca73af550 100644 (file)
@@ -48,8 +48,6 @@ public final class BgpTopologyDeployerImpl implements AutoCloseable, ClusteredDa
 
     private static final Logger LOG = LoggerFactory.getLogger(BgpTopologyDeployerImpl.class);
     private static final InstanceIdentifier<Topology> TOPOLOGY_IID = InstanceIdentifier.create(NetworkTopology.class).child(Topology.class);
-    private static final int MAX_REGISTRATION_ATTEMPTS = 10;
-    private static final int SLEEP_TIME = MAX_REGISTRATION_ATTEMPTS;
 
     @GuardedBy("this")
     private final Set<BgpTopologyProvider> topologyProviders = new HashSet<>();
@@ -170,8 +168,10 @@ public final class BgpTopologyDeployerImpl implements AutoCloseable, ClusteredDa
         return Iterables.filter(this.topologyProviders, input -> input.topologyTypeFilter(topology));
     }
 
-    private ClusterSingletonServiceRegistration registerSingletonService(final ClusterSingletonService clusterSingletonService) {
-        return ClusterSingletonServiceRegistrationHelper.registerSingletonService(this.singletonProvider, clusterSingletonService, MAX_REGISTRATION_ATTEMPTS, SLEEP_TIME);
+    private ClusterSingletonServiceRegistration registerSingletonService(
+        final ClusterSingletonService clusterSingletonService) {
+        return ClusterSingletonServiceRegistrationHelper
+            .registerSingletonService(this.singletonProvider, clusterSingletonService);
     }
 
 }