mirror of
https://github.com/opennetworkinglab/onos.git
synced 2026-05-05 04:06:49 +02:00
[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
This commit is contained in:
parent
4eae29804f
commit
fd9f74417e
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user