From 877ec2c51fe8ac336da682ca43adb21755ee54ef Mon Sep 17 00:00:00 2001 From: Sho SHIMIZU Date: Mon, 9 Feb 2015 12:50:36 -0800 Subject: [PATCH] Handle exception when compiling fails - Change arguments of the constructor of PathNotFoundException - Change the catched exception in Compiling.execute() Change-Id: I3b639ffd585900c2a6dd99aeeb313bf20c6104f4 --- .../net/intent/impl/Compiling.java | 9 ++----- .../impl/ConnectivityIntentCompiler.java | 2 +- ...MultiPointToSinglePointIntentCompiler.java | 2 +- .../OpticalConnectivityIntentCompiler.java | 3 +-- .../intent/impl/PathNotFoundException.java | 25 +++++++++++++------ .../impl/PathConstraintCalculationTest.java | 4 +-- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/Compiling.java b/core/net/src/main/java/org/onosproject/net/intent/impl/Compiling.java index 11f9a286d7..0673ee48b8 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/Compiling.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/Compiling.java @@ -47,14 +47,9 @@ class Compiling implements IntentUpdate { List installables = (current != null) ? current.installables() : null; pending.setInstallables(intentManager.compileIntent(pending.intent(), installables)); return Optional.of(new InstallCoordinating(intentManager, pending, current)); - } catch (PathNotFoundException e) { - log.debug("Path not found for intent {}", pending.intent()); - // TODO: revisit to implement failure handling - return Optional.of(new CompilingFailed(pending)); //FIXME failed state transition } catch (IntentException e) { - log.warn("Unable to compile intent {} due to:", pending.intent().id(), e); - // TODO: revisit to implement failure handling - return Optional.of(new CompilingFailed(pending)); //FIXME failed state transition + log.debug("Unable to compile intent {} due to: {}", pending.intent(), e); + return Optional.of(new CompilingFailed(pending)); } } } diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/ConnectivityIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/ConnectivityIntentCompiler.java index e029c78927..c6c36984e5 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/ConnectivityIntentCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/ConnectivityIntentCompiler.java @@ -105,7 +105,7 @@ public abstract class ConnectivityIntentCompiler } }).toList(); if (filtered.isEmpty()) { - throw new PathNotFoundException("No packet path from " + one + " to " + two); + throw new PathNotFoundException(one, two); } // TODO: let's be more intelligent about this eventually return filtered.iterator().next(); diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/MultiPointToSinglePointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/MultiPointToSinglePointIntentCompiler.java index 6fb94c9d62..cfb804b5c8 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/MultiPointToSinglePointIntentCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/MultiPointToSinglePointIntentCompiler.java @@ -101,7 +101,7 @@ public class MultiPointToSinglePointIntentCompiler private Path getPath(ConnectPoint one, ConnectPoint two) { Set paths = pathService.getPaths(one.deviceId(), two.deviceId()); if (paths.isEmpty()) { - throw new PathNotFoundException("No path from " + one + " to " + two); + throw new PathNotFoundException(one.elementId(), two.elementId()); } // TODO: let's be more intelligent about this eventually return paths.iterator().next(); diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/OpticalConnectivityIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/OpticalConnectivityIntentCompiler.java index 4eb78a0fdd..50ae43da3f 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/OpticalConnectivityIntentCompiler.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/OpticalConnectivityIntentCompiler.java @@ -89,8 +89,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler paths = topologyService.getPaths(topology, start.deviceId(), end.deviceId(), weight); if (paths.isEmpty()) { - throw new PathNotFoundException("No Optical path found from " + - start + " to " + end); + throw new PathNotFoundException(start.elementId(), end.elementId()); } // TODO: let's be more intelligent about this eventually diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/PathNotFoundException.java b/core/net/src/main/java/org/onosproject/net/intent/impl/PathNotFoundException.java index 32f1e355d3..41b1c8f110 100644 --- a/core/net/src/main/java/org/onosproject/net/intent/impl/PathNotFoundException.java +++ b/core/net/src/main/java/org/onosproject/net/intent/impl/PathNotFoundException.java @@ -15,23 +15,32 @@ */ package org.onosproject.net.intent.impl; +import com.google.common.base.MoreObjects; +import org.onosproject.net.ElementId; import org.onosproject.net.intent.IntentException; +import static com.google.common.base.Preconditions.checkNotNull; + /** * An exception thrown when a path is not found. */ public class PathNotFoundException extends IntentException { private static final long serialVersionUID = -2087045731049914733L; - public PathNotFoundException() { - super(); + private final ElementId source; + private final ElementId destination; + + public PathNotFoundException(ElementId source, ElementId destination) { + super(String.format("No path from %s to %s", source, destination)); + this.source = checkNotNull(source); + this.destination = checkNotNull(destination); } - public PathNotFoundException(String message) { - super(message); - } - - public PathNotFoundException(String message, Throwable cause) { - super(message, cause); + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("source", source) + .add("destination", destination) + .toString(); } } diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java index d54789a05e..9f69e65510 100644 --- a/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java +++ b/core/net/src/test/java/org/onosproject/net/intent/impl/PathConstraintCalculationTest.java @@ -138,7 +138,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { fail("Point to Point compilation with insufficient bandwidth does " + "not throw exception."); } catch (PathNotFoundException noPath) { - assertThat(noPath.getMessage(), containsString("No packet path")); + assertThat(noPath.getMessage(), containsString("No path")); } } @@ -173,7 +173,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { fail("Point to Point compilation with no available lambda does " + "not throw exception."); } catch (PathNotFoundException noPath) { - assertThat(noPath.getMessage(), containsString("No packet path")); + assertThat(noPath.getMessage(), containsString("No path")); } }