Simple Sanity Test to validate that all the bundles in a distribution are active...
[controller.git] / opendaylight / distribution / sanitytest / src / main / java / org / opendaylight / controller / sanitytest / internal / Activator.java
diff --git a/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java b/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java
new file mode 100644 (file)
index 0000000..262884f
--- /dev/null
@@ -0,0 +1,54 @@
+package org.opendaylight.controller.sanitytest.internal;
+
+import org.osgi.framework.*;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+public class Activator implements BundleActivator {
+    //30 Second
+    private static final int DELAY = 30000;
+
+
+    private String stateToString(int state) {
+        switch (state) {
+        case Bundle.ACTIVE:
+            return "ACTIVE";
+        case Bundle.INSTALLED:
+            return "INSTALLED";
+        case Bundle.RESOLVED:
+            return "RESOLVED";
+        case Bundle.UNINSTALLED:
+            return "UNINSTALLED";
+        default:
+            return "Not CONVERTED";
+        }
+    }
+
+    public void start(final BundleContext bundleContext) throws Exception {
+        Timer monitorTimer = new Timer("monitor timer", true);
+
+        monitorTimer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                boolean failed = false;
+                for(Bundle bundle : bundleContext.getBundles()){
+                    if(bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.RESOLVED) {
+                        System.out.println("Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
+                        failed = true;
+                    }
+                }
+
+                if(failed){
+                    System.exit(-1);
+                } else {
+                    System.exit(0);
+                }
+            }
+        }, DELAY);
+    }
+
+    public void stop(BundleContext bundleContext) throws Exception {
+
+    }
+}