1 package org.opendaylight.controller.sanitytest.internal;
3 import java.util.Timer;
4 import java.util.TimerTask;
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;
11 public class Activator implements BundleActivator {
12 //10 Second initial, 1 second subsequent
13 private static final int INITIAL_DELAY = 10000;
14 private static final int SUBSEQUENT_DELAY = 1000;
17 private String stateToString(int state) {
21 case Bundle.INSTALLED:
25 case Bundle.UNINSTALLED:
30 return "Not CONVERTED: state value is " + state;
34 public void start(final BundleContext bundleContext) throws Exception {
35 Timer monitorTimer = new Timer("monitor timer", true);
36 monitorTimer.schedule(new TimerTask() {
40 boolean failed = false;
41 boolean resolved = false;
45 for(Bundle bundle : bundleContext.getBundles()){
47 * A bundle should be ACTIVE, unless it a fragment, in which case it should be RESOLVED
49 int state = bundle.getState();
50 if ((bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
52 if (state != Bundle.RESOLVED) {
53 System.out.println("------ Failed to activate/resolve fragment = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
55 if (state == Bundle.STARTING)
59 if(state != Bundle.ACTIVE) {
60 System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
62 if (state == Bundle.STARTING)
70 System.out.println("all bundles haven't finished starting, will repeat");
72 Thread.sleep(SUBSEQUENT_DELAY);
73 } catch (Exception e) {
74 System.out.println("Thread.sleep interuptted.");
84 System.out.println("exiting with 1 as failed");
86 Runtime.getRuntime().exit(1);
89 System.out.println("exiting with 0 as succeeded");
91 Runtime.getRuntime().exit(0);
97 public void stop(BundleContext bundleContext) throws Exception {