Bug 7799: Set inactive on any flapping service error
[controller.git] / opendaylight / md-sal / samples / clustering-test-app / provider / src / main / java / org / opendaylight / controller / clustering / it / provider / impl / FlappingSingletonService.java
index 21e6acf1c7124ac26da757185f5f4f6fa0c32311..5ca33ad51d63e268ce905a6cb87c44b9fb84dc81 100644 (file)
@@ -56,6 +56,7 @@ public class FlappingSingletonService implements ClusterSingletonService {
                 registration = null;
             } catch (final Exception e) {
                 LOG.warn("There was a problem closing flapping singleton service.", e);
+                setInactive();
                 flapCount = -flapCount;
             }
         });
@@ -71,9 +72,15 @@ public class FlappingSingletonService implements ClusterSingletonService {
             // remove  whole executor shenanigans after it's fixed.
             // Needs to be delayed slightly otherwise it's triggered as well.
             EXECUTOR.schedule(() -> {
-                LOG.debug("Running registration");
-                registration =
-                        singletonServiceProvider.registerClusterSingletonService(this);
+                LOG.debug("Running re-registration");
+                try {
+                    registration =
+                            singletonServiceProvider.registerClusterSingletonService(this);
+                } catch (final Exception e) {
+                    LOG.warn("There was a problem re-registering flapping singleton service.", e);
+                    setInactive();
+                    flapCount = -flapCount - 1;
+                }
 
             }, 200, TimeUnit.MILLISECONDS);
         }