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
1 package org.opendaylight.controller.sanitytest.internal;
2
3 import org.osgi.framework.*;
4
5 import java.util.Timer;
6 import java.util.TimerTask;
7
8 public class Activator implements BundleActivator {
9     //30 Second
10     private static final int DELAY = 30000;
11
12
13     private String stateToString(int state) {
14         switch (state) {
15         case Bundle.ACTIVE:
16             return "ACTIVE";
17         case Bundle.INSTALLED:
18             return "INSTALLED";
19         case Bundle.RESOLVED:
20             return "RESOLVED";
21         case Bundle.UNINSTALLED:
22             return "UNINSTALLED";
23         default:
24             return "Not CONVERTED";
25         }
26     }
27
28     public void start(final BundleContext bundleContext) throws Exception {
29         Timer monitorTimer = new Timer("monitor timer", true);
30
31         monitorTimer.schedule(new TimerTask() {
32             @Override
33             public void run() {
34                 boolean failed = false;
35                 for(Bundle bundle : bundleContext.getBundles()){
36                     if(bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.RESOLVED) {
37                         System.out.println("Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
38                         failed = true;
39                     }
40                 }
41
42                 if(failed){
43                     System.exit(-1);
44                 } else {
45                     System.exit(0);
46                 }
47             }
48         }, DELAY);
49     }
50
51     public void stop(BundleContext bundleContext) throws Exception {
52
53     }
54 }