Integrate the Distribution Sanity Test with the build
[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         monitorTimer.schedule(new TimerTask() {
31             @Override
32             public void run() {
33                 boolean failed = false;
34                 for(Bundle bundle : bundleContext.getBundles()){
35                     if(bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.RESOLVED) {
36                         System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
37                         failed = true;
38                     }
39                 }
40
41                 if(failed){
42                     System.exit(-1);
43                 } else {
44                     System.exit(0);
45                 }
46             }
47         }, DELAY);
48     }
49
50     public void stop(BundleContext bundleContext) throws Exception {
51
52     }
53 }