/* * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.odlparent.bundlestest.lib; import static java.util.Objects.requireNonNull; import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; import org.awaitility.Awaitility; import org.awaitility.core.ConditionTimeoutException; import org.opendaylight.odlparent.bundles.diag.DiagProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Utility to verify bundle diagnostic state. * * @author Michael Vorburger.ch, based on guidance from Christian Schneider */ public class TestBundleDiag { private static final Logger LOG = LoggerFactory.getLogger(TestBundleDiag.class); private final DiagProvider diagProvider; public TestBundleDiag(final DiagProvider diagProvider) { this.diagProvider = requireNonNull(diagProvider); } /** * Does something similar to Karaf's "diag" CLI command, and throws a {@link SystemStateFailureException} if * anything including bundle wiring is not OK. * *
The implementation is based on Karaf's BundleService, and not the BundleStateService, because each Karaf
* supported DI system (such as Blueprint and Declarative Services, see String constants in BundleStateService),
* will have a separate BundleStateService. The BundleService however will contain the combined status of all
* BundleStateServices.
*
* @param timeout maximum time to wait for bundles to settle
* @param timeoutUnit time unit of timeout
* @throws SystemStateFailureException if all bundles do not settle within the timeout period
*/
public void checkBundleDiagInfos(final long timeout, final TimeUnit timeoutUnit)
throws SystemStateFailureException {
checkBundleDiagInfos(timeout, timeoutUnit, (timeInfo, bundleDiagInfos) ->
LOG.info("checkBundleDiagInfos: Elapsed time {}s, remaining time {}s, {}",
timeInfo.elapsedTimeInMS() / 1000, timeInfo.remainingTimeInMS() / 1000,
bundleDiagInfos.getFullDiagnosticText()));
}
public void checkBundleDiagInfos(final long timeout, final TimeUnit timeoutUnit,
final BiConsumer