Sho SHIMIZU
Committed by Brian O'Connor

Handle exception when compiling fails

- Change arguments of the constructor of PathNotFoundException
- Change the catched exception in Compiling.execute()

Change-Id: I3b639ffd585900c2a6dd99aeeb313bf20c6104f4
......@@ -47,14 +47,9 @@ class Compiling implements IntentUpdate {
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));
}
}
}
......
......@@ -105,7 +105,7 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent>
}
}).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();
......
......@@ -101,7 +101,7 @@ public class MultiPointToSinglePointIntentCompiler
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();
......
......@@ -89,8 +89,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
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
......
......@@ -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(String message) {
super(message);
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, Throwable cause) {
super(message, cause);
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("source", source)
.add("destination", destination)
.toString();
}
}
......
......@@ -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"));
}
}
......