2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sanitytest.internal;
10 import java.util.Timer;
11 import java.util.TimerTask;
13 import org.osgi.framework.Bundle;
14 import org.osgi.framework.BundleActivator;
15 import org.osgi.framework.BundleContext;
16 import org.osgi.framework.wiring.BundleRevision;
18 public class Activator implements BundleActivator {
19 //10 Second initial, 1 second subsequent
20 private static final int INITIAL_DELAY = 10000;
21 private static final int SUBSEQUENT_DELAY = 1000;
22 private static final int MAX_ATTEMPTS = 120;
25 private String stateToString(int state) {
29 case Bundle.INSTALLED:
33 case Bundle.UNINSTALLED:
38 return "Not CONVERTED: state value is " + state;
42 public void start(final BundleContext bundleContext) throws Exception {
43 Timer monitorTimer = new Timer("monitor timer", true);
44 monitorTimer.schedule(new TimerTask() {
48 boolean failed = false;
49 boolean resolved = false;
53 for(Bundle bundle : bundleContext.getBundles()){
55 * A bundle should be ACTIVE, unless it a fragment, in which case it should be RESOLVED
57 int state = bundle.getState();
58 if ((bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
60 if (state != Bundle.RESOLVED) {
61 System.out.println("------ Failed to activate/resolve fragment = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
63 if (state == Bundle.STARTING)
67 if(state != Bundle.ACTIVE) {
68 System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
70 if (state == Bundle.STARTING)
77 if (countup < MAX_ATTEMPTS) {
78 System.out.println("all bundles haven't finished starting, will repeat");
80 Thread.sleep(SUBSEQUENT_DELAY);
81 } catch (Exception e) {
82 System.out.println("Thread.sleep interuptted.");
92 System.out.println("exiting with 1 as failed");
94 Runtime.getRuntime().exit(1);
97 System.out.println("exiting with 0 as succeeded");
99 Runtime.getRuntime().exit(0);
105 public void stop(BundleContext bundleContext) throws Exception {