Search in sources :

Example 1 with SystemReadyListener

use of org.opendaylight.infrautils.ready.SystemReadyListener in project infrautils by opendaylight.

the class DiagStatusTestModule method configureBindings.

@Override
protected void configureBindings() throws UnknownHostException {
    bind(DiagStatusService.class).to(DiagStatusServiceImpl.class);
    bind(new TypeLiteral<List<ServiceStatusProvider>>() {
    }).toInstance(Collections.emptyList());
    bind(SystemReadyMonitor.class).annotatedWith(OsgiService.class).toInstance(new SystemReadyMonitor() {

        @Override
        public void registerListener(SystemReadyListener listener) {
        // NOOP
        }

        @Override
        public SystemState getSystemState() {
            return SystemState.ACTIVE;
        }
    });
    bind(DiagStatusServiceMBean.class).to(DiagStatusServiceMBeanImpl.class);
}
Also used : ServiceStatusProvider(org.opendaylight.infrautils.diagstatus.ServiceStatusProvider) SystemState(org.opendaylight.infrautils.ready.SystemState) TypeLiteral(com.google.inject.TypeLiteral) SystemReadyListener(org.opendaylight.infrautils.ready.SystemReadyListener) DiagStatusServiceMBean(org.opendaylight.infrautils.diagstatus.DiagStatusServiceMBean) DiagStatusService(org.opendaylight.infrautils.diagstatus.DiagStatusService) SystemReadyMonitor(org.opendaylight.infrautils.ready.SystemReadyMonitor) OsgiService(org.ops4j.pax.cdi.api.OsgiService)

Example 2 with SystemReadyListener

use of org.opendaylight.infrautils.ready.SystemReadyListener in project infrautils by opendaylight.

the class SystemReadyImpl method run.

@Override
// below
@SuppressWarnings("checkstyle:IllegalCatch")
public void run() {
    try {
        // 5 minutes really ought to be enough for the whole circus to completely boot up?!
        testBundleDiag.checkBundleDiagInfos(5, TimeUnit.MINUTES, (timeInfo, bundleDiagInfos) -> LOG.info("checkBundleDiagInfos: Elapsed time {}s, remaining time {}s, {}", timeInfo.getElapsedTimeInMS() / 1000, timeInfo.getRemainingTimeInMS() / 1000, // INFRAUTILS-17: getSummaryText() instead getFullDiagnosticText() because ppl found log confusing
        bundleDiagInfos.getSummaryText()));
        currentSystemState.set(ACTIVE);
        LOG.info("System ready; AKA: Aye captain, all warp coils are now operating at peak efficiency! [M.]");
        if (!listeners.isEmpty()) {
            LOG.info("Now notifying all its registered SystemReadyListeners...");
        }
        @Var SystemReadyListener listener;
        while ((listener = listeners.poll()) != null) {
            listener.onSystemBootReady();
        }
    } catch (SystemStateFailureException e) {
        LOG.error("Failed, some bundles did not start (SystemReadyListeners are not called)", e);
        currentSystemState.set(FAILURE);
    // We do not re-throw this
    } catch (RuntimeException throwable) {
        // It's exceptionally OK to catch RuntimeException here,
        // because we do want to set the currentFullSystemStatus
        LOG.error("Failed unexpectedly (SystemReadyListeners are not called)", throwable);
        currentSystemState.set(FAILURE);
        // and now we do re-throw it!
        throw throwable;
    }
}
Also used : Var(com.google.errorprone.annotations.Var) SystemReadyListener(org.opendaylight.infrautils.ready.SystemReadyListener) SystemStateFailureException(org.opendaylight.odlparent.bundlestest.lib.SystemStateFailureException)

Aggregations

SystemReadyListener (org.opendaylight.infrautils.ready.SystemReadyListener)2 Var (com.google.errorprone.annotations.Var)1 TypeLiteral (com.google.inject.TypeLiteral)1 DiagStatusService (org.opendaylight.infrautils.diagstatus.DiagStatusService)1 DiagStatusServiceMBean (org.opendaylight.infrautils.diagstatus.DiagStatusServiceMBean)1 ServiceStatusProvider (org.opendaylight.infrautils.diagstatus.ServiceStatusProvider)1 SystemReadyMonitor (org.opendaylight.infrautils.ready.SystemReadyMonitor)1 SystemState (org.opendaylight.infrautils.ready.SystemState)1 SystemStateFailureException (org.opendaylight.odlparent.bundlestest.lib.SystemStateFailureException)1 OsgiService (org.ops4j.pax.cdi.api.OsgiService)1