From b475c0760ae397d2d485a37931f508820d88cce0 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Mon, 23 May 2016 15:22:24 +0200 Subject: HONEYCOMB-61: Detect VPP disconnect using keepalives Change-Id: Ic664dbf452504d0fff97e8c766d735d9c5d95c72 Signed-off-by: Maros Marsalek --- .../v3po/translate/v3po/vppstate/VersionCustomizer.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'v3po/v3po2vpp/src/main/java/io/fd/honeycomb') diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizer.java index ad181a701..8122fd245 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizer.java @@ -21,6 +21,7 @@ import io.fd.honeycomb.v3po.translate.read.ReadFailedException; import io.fd.honeycomb.v3po.translate.spi.read.ChildReaderCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils; +import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version; @@ -36,6 +37,11 @@ public final class VersionCustomizer extends FutureJVppCustomizer implements ChildReaderCustomizer { + /** + * Default timeout for executing version read + */ + private static final int DEFAULT_TIMEOUT_IN_SECONDS = 30; + public VersionCustomizer(@Nonnull final FutureJVpp futureJVpp) { super(futureJVpp); } @@ -54,13 +60,11 @@ public final class VersionCustomizer @Override public void readCurrentAttributes(@Nonnull InstanceIdentifier id, @Nonnull final VersionBuilder builder, @Nonnull final ReadContext context) throws ReadFailedException { + // Execute with timeout + final CompletionStage showVersionFuture = getFutureJVpp().showVersion(new ShowVersion()); + final ShowVersionReply reply = TranslateUtils.getReply(showVersionFuture.toCompletableFuture(), id, + DEFAULT_TIMEOUT_IN_SECONDS); - ShowVersionReply reply; - try { - reply = getFutureJVpp().showVersion(new ShowVersion()).toCompletableFuture().get(); - } catch (Exception e) { - throw new ReadFailedException(id, e); - } builder.setBranch(TranslateUtils.toString(reply.version)); builder.setName(TranslateUtils.toString(reply.program)); builder.setBuildDate(TranslateUtils.toString(reply.buildDate)); -- cgit 1.2.3-korg