Handle exception when compiling fails
- Change arguments of the constructor of PathNotFoundException
- Change the catched exception in Compiling.execute()
Change-Id: I3b639ffd585900c2a6dd99aeeb313bf20c6104f4
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 11f9a28..0673ee4 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 @@
List<Intent> 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 e029c78..c6c3698 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 @@
}
}).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 6fb94c9..cfb804b 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 @@
private Path getPath(ConnectPoint one, ConnectPoint two) {
Set<Path> 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 4eb78a0..50ae43d 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 @@
Set<Path> 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 32f1e35..41b1c8f 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 d54789a..9f69e65 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 @@
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 @@
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"));
}
}