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
Showing
6 changed files
with
23 additions
and
20 deletions
... | @@ -47,14 +47,9 @@ class Compiling implements IntentUpdate { | ... | @@ -47,14 +47,9 @@ class Compiling implements IntentUpdate { |
47 | List<Intent> installables = (current != null) ? current.installables() : null; | 47 | List<Intent> installables = (current != null) ? current.installables() : null; |
48 | pending.setInstallables(intentManager.compileIntent(pending.intent(), installables)); | 48 | pending.setInstallables(intentManager.compileIntent(pending.intent(), installables)); |
49 | return Optional.of(new InstallCoordinating(intentManager, pending, current)); | 49 | return Optional.of(new InstallCoordinating(intentManager, pending, current)); |
50 | - } catch (PathNotFoundException e) { | ||
51 | - log.debug("Path not found for intent {}", pending.intent()); | ||
52 | - // TODO: revisit to implement failure handling | ||
53 | - return Optional.of(new CompilingFailed(pending)); //FIXME failed state transition | ||
54 | } catch (IntentException e) { | 50 | } catch (IntentException e) { |
55 | - log.warn("Unable to compile intent {} due to:", pending.intent().id(), e); | 51 | + log.debug("Unable to compile intent {} due to: {}", pending.intent(), e); |
56 | - // TODO: revisit to implement failure handling | 52 | + return Optional.of(new CompilingFailed(pending)); |
57 | - return Optional.of(new CompilingFailed(pending)); //FIXME failed state transition | ||
58 | } | 53 | } |
59 | } | 54 | } |
60 | } | 55 | } | ... | ... |
... | @@ -105,7 +105,7 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> | ... | @@ -105,7 +105,7 @@ public abstract class ConnectivityIntentCompiler<T extends ConnectivityIntent> |
105 | } | 105 | } |
106 | }).toList(); | 106 | }).toList(); |
107 | if (filtered.isEmpty()) { | 107 | if (filtered.isEmpty()) { |
108 | - throw new PathNotFoundException("No packet path from " + one + " to " + two); | 108 | + throw new PathNotFoundException(one, two); |
109 | } | 109 | } |
110 | // TODO: let's be more intelligent about this eventually | 110 | // TODO: let's be more intelligent about this eventually |
111 | return filtered.iterator().next(); | 111 | return filtered.iterator().next(); | ... | ... |
... | @@ -101,7 +101,7 @@ public class MultiPointToSinglePointIntentCompiler | ... | @@ -101,7 +101,7 @@ public class MultiPointToSinglePointIntentCompiler |
101 | private Path getPath(ConnectPoint one, ConnectPoint two) { | 101 | private Path getPath(ConnectPoint one, ConnectPoint two) { |
102 | Set<Path> paths = pathService.getPaths(one.deviceId(), two.deviceId()); | 102 | Set<Path> paths = pathService.getPaths(one.deviceId(), two.deviceId()); |
103 | if (paths.isEmpty()) { | 103 | if (paths.isEmpty()) { |
104 | - throw new PathNotFoundException("No path from " + one + " to " + two); | 104 | + throw new PathNotFoundException(one.elementId(), two.elementId()); |
105 | } | 105 | } |
106 | // TODO: let's be more intelligent about this eventually | 106 | // TODO: let's be more intelligent about this eventually |
107 | return paths.iterator().next(); | 107 | return paths.iterator().next(); | ... | ... |
... | @@ -89,8 +89,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -89,8 +89,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
89 | Set<Path> paths = topologyService.getPaths(topology, start.deviceId(), | 89 | Set<Path> paths = topologyService.getPaths(topology, start.deviceId(), |
90 | end.deviceId(), weight); | 90 | end.deviceId(), weight); |
91 | if (paths.isEmpty()) { | 91 | if (paths.isEmpty()) { |
92 | - throw new PathNotFoundException("No Optical path found from " + | 92 | + throw new PathNotFoundException(start.elementId(), end.elementId()); |
93 | - start + " to " + end); | ||
94 | } | 93 | } |
95 | 94 | ||
96 | // TODO: let's be more intelligent about this eventually | 95 | // TODO: let's be more intelligent about this eventually | ... | ... |
... | @@ -15,23 +15,32 @@ | ... | @@ -15,23 +15,32 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent.impl; | 16 | package org.onosproject.net.intent.impl; |
17 | 17 | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | +import org.onosproject.net.ElementId; | ||
18 | import org.onosproject.net.intent.IntentException; | 20 | import org.onosproject.net.intent.IntentException; |
19 | 21 | ||
22 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
23 | + | ||
20 | /** | 24 | /** |
21 | * An exception thrown when a path is not found. | 25 | * An exception thrown when a path is not found. |
22 | */ | 26 | */ |
23 | public class PathNotFoundException extends IntentException { | 27 | public class PathNotFoundException extends IntentException { |
24 | private static final long serialVersionUID = -2087045731049914733L; | 28 | private static final long serialVersionUID = -2087045731049914733L; |
25 | 29 | ||
26 | - public PathNotFoundException() { | 30 | + private final ElementId source; |
27 | - super(); | 31 | + private final ElementId destination; |
28 | - } | ||
29 | 32 | ||
30 | - public PathNotFoundException(String message) { | 33 | + public PathNotFoundException(ElementId source, ElementId destination) { |
31 | - super(message); | 34 | + super(String.format("No path from %s to %s", source, destination)); |
35 | + this.source = checkNotNull(source); | ||
36 | + this.destination = checkNotNull(destination); | ||
32 | } | 37 | } |
33 | 38 | ||
34 | - public PathNotFoundException(String message, Throwable cause) { | 39 | + @Override |
35 | - super(message, cause); | 40 | + public String toString() { |
41 | + return MoreObjects.toStringHelper(this) | ||
42 | + .add("source", source) | ||
43 | + .add("destination", destination) | ||
44 | + .toString(); | ||
36 | } | 45 | } |
37 | } | 46 | } | ... | ... |
... | @@ -138,7 +138,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { | ... | @@ -138,7 +138,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { |
138 | fail("Point to Point compilation with insufficient bandwidth does " | 138 | fail("Point to Point compilation with insufficient bandwidth does " |
139 | + "not throw exception."); | 139 | + "not throw exception."); |
140 | } catch (PathNotFoundException noPath) { | 140 | } catch (PathNotFoundException noPath) { |
141 | - assertThat(noPath.getMessage(), containsString("No packet path")); | 141 | + assertThat(noPath.getMessage(), containsString("No path")); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
... | @@ -173,7 +173,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { | ... | @@ -173,7 +173,7 @@ public class PathConstraintCalculationTest extends AbstractIntentTest { |
173 | fail("Point to Point compilation with no available lambda does " | 173 | fail("Point to Point compilation with no available lambda does " |
174 | + "not throw exception."); | 174 | + "not throw exception."); |
175 | } catch (PathNotFoundException noPath) { | 175 | } catch (PathNotFoundException noPath) { |
176 | - assertThat(noPath.getMessage(), containsString("No packet path")); | 176 | + assertThat(noPath.getMessage(), containsString("No path")); |
177 | } | 177 | } |
178 | } | 178 | } |
179 | 179 | ... | ... |
-
Please register or login to post a comment