From fd9f74417ee286f94324ca8d2dff2f20bd0db4f3 Mon Sep 17 00:00:00 2001 From: Jianwei Mao Date: Thu, 24 May 2018 21:36:44 +0800 Subject: [PATCH] [ONOS-7685]Improve failure inspection template for P4 Runtime developer If P4InfoParser fail to parse p4info file, the parser will pass exact exception message to Apps by Cause of P4InfoParserException. So, developer must use P4InfoParserException.getCause().getMessage() to gain exact failure cause. This is hard to be reminded, especially when it is packed into IllegalStateException or other Exception class. Change-Id: Ica9cd24521a9eb8700cd1cbfce573631c30cbff2 --- .../p4tutorial/pipeconf/PipeconfFactory.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipeconfFactory.java b/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipeconfFactory.java index 47fad41054..f0078ec53a 100644 --- a/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipeconfFactory.java +++ b/apps/p4-tutorial/pipeconf/src/main/java/org/onosproject/p4tutorial/pipeconf/PipeconfFactory.java @@ -32,6 +32,8 @@ import org.onosproject.net.pi.model.PiPipelineModel; import org.onosproject.net.pi.service.PiPipeconfService; import org.onosproject.p4runtime.model.P4InfoParser; import org.onosproject.p4runtime.model.P4InfoParserException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.net.URL; @@ -44,6 +46,8 @@ import static org.onosproject.net.pi.model.PiPipeconf.ExtensionType.P4_INFO_TEXT @Component(immediate = true) public final class PipeconfFactory { + private final Logger log = LoggerFactory.getLogger(getClass()); + public static final PiPipeconfId PIPECONF_ID = new PiPipeconfId("p4-tutorial-pipeconf"); private static final URL P4INFO_URL = PipeconfFactory.class.getResource("/mytunnel.p4info"); private static final URL BMV2_JSON_URL = PipeconfFactory.class.getResource("/mytunnel.json"); @@ -54,21 +58,27 @@ public final class PipeconfFactory { @Activate public void activate() { // Registers the pipeconf at component activation. - piPipeconfService.register(buildPipeconf()); + try { + piPipeconfService.register(buildPipeconf()); + } catch (P4InfoParserException e) { + log.error("Fail to register {} - Exception: {} - Cause: {}", + PIPECONF_ID, e.getMessage(), e.getCause().getMessage()); + } } @Deactivate public void deactivate() { - piPipeconfService.remove(PIPECONF_ID); + // Unregisters the pipeconf at component deactivation. + try { + piPipeconfService.remove(PIPECONF_ID); + } catch (IllegalStateException e) { + log.warn("{} haven't been registered", PIPECONF_ID); + } } - private PiPipeconf buildPipeconf() { - final PiPipelineModel pipelineModel; - try { - pipelineModel = P4InfoParser.parse(P4INFO_URL); - } catch (P4InfoParserException e) { - throw new IllegalStateException(e); - } + private PiPipeconf buildPipeconf() throws P4InfoParserException { + + final PiPipelineModel pipelineModel = P4InfoParser.parse(P4INFO_URL); return DefaultPiPipeconf.builder() .withId(PIPECONF_ID)