X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fdistribution%2Fsanitytest%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsanitytest%2Finternal%2FActivator.java;h=d92277269a01f2f8fc3eac7df8af6d78f212bf22;hp=262884fa3545ba5e8ac9ee91eb720b86e609c8f7;hb=98a87e05e8658955e697525434f028c34bdfa877;hpb=d684dd484ca6d7a31bd4fc66fd6d4778938586ba diff --git a/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java b/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java index 262884fa35..d92277269a 100644 --- a/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java +++ b/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java @@ -1,13 +1,17 @@ package org.opendaylight.controller.sanitytest.internal; -import org.osgi.framework.*; - import java.util.Timer; import java.util.TimerTask; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.wiring.BundleRevision; + public class Activator implements BundleActivator { - //30 Second - private static final int DELAY = 30000; + //10 Second initial, 1 second subsequent + private static final int INITIAL_DELAY = 10000; + private static final int SUBSEQUENT_DELAY = 1000; private String stateToString(int state) { @@ -20,32 +24,73 @@ public class Activator implements BundleActivator { return "RESOLVED"; case Bundle.UNINSTALLED: return "UNINSTALLED"; + case Bundle.STARTING: + return "STARTING"; default: - return "Not CONVERTED"; + return "Not CONVERTED: state value is " + state; } } public void start(final BundleContext bundleContext) throws Exception { Timer monitorTimer = new Timer("monitor timer", true); - monitorTimer.schedule(new TimerTask() { @Override public void run() { + int countup = 0; boolean failed = false; - for(Bundle bundle : bundleContext.getBundles()){ - if(bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.RESOLVED) { - System.out.println("Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState())); - failed = true; + boolean resolved = false; + while (!resolved) { + resolved = true; + failed = false; + for(Bundle bundle : bundleContext.getBundles()){ + /* + * A bundle should be ACTIVE, unless it a fragment, in which case it should be RESOLVED + */ + int state = bundle.getState(); + if ((bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) { + //fragment + if (state != Bundle.RESOLVED) { + System.out.println("------ Failed to activate/resolve fragment = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState())); + failed = true; + if (state == Bundle.STARTING) + resolved = false; + } + } else { + if(state != Bundle.ACTIVE) { + System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState())); + failed = true; + if (state == Bundle.STARTING) + resolved = false; + } + } + } + if (!resolved) { + countup++; + if (countup < 60) { + System.out.println("all bundles haven't finished starting, will repeat"); + try { + Thread.sleep(SUBSEQUENT_DELAY); + } catch (Exception e) { + ; + } + } else + resolved = true; } } if(failed){ - System.exit(-1); + System.out.flush(); + System.out.println("exiting with 1 as failed"); + System.out.close(); + Runtime.getRuntime().exit(1); } else { - System.exit(0); + System.out.flush(); + System.out.println("exiting with 0 as succeeded"); + System.out.close(); + Runtime.getRuntime().exit(0); } } - }, DELAY); + }, INITIAL_DELAY); } public void stop(BundleContext bundleContext) throws Exception {