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