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;
15 private static final int MAX_ATTEMPTS = 120;
18 private String stateToString(int state) {
22 case Bundle.INSTALLED:
26 case Bundle.UNINSTALLED:
31 return "Not CONVERTED: state value is " + state;
35 public void start(final BundleContext bundleContext) throws Exception {
36 Timer monitorTimer = new Timer("monitor timer", true);
37 monitorTimer.schedule(new TimerTask() {
41 boolean failed = false;
42 boolean resolved = false;
46 for(Bundle bundle : bundleContext.getBundles()){
48 * A bundle should be ACTIVE, unless it a fragment, in which case it should be RESOLVED
50 int state = bundle.getState();
51 if ((bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
53 if (state != Bundle.RESOLVED) {
54 System.out.println("------ Failed to activate/resolve fragment = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
56 if (state == Bundle.STARTING)
60 if(state != Bundle.ACTIVE) {
61 System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
63 if (state == Bundle.STARTING)
70 if (countup < MAX_ATTEMPTS) {
71 System.out.println("all bundles haven't finished starting, will repeat");
73 Thread.sleep(SUBSEQUENT_DELAY);
74 } catch (Exception e) {
75 System.out.println("Thread.sleep interuptted.");
85 System.out.println("exiting with 1 as failed");
87 Runtime.getRuntime().exit(1);
90 System.out.println("exiting with 0 as succeeded");
92 Runtime.getRuntime().exit(0);
98 public void stop(BundleContext bundleContext) throws Exception {