Committed by
Gerrit Code Review
Fix for ONOS-5152:Encoder for Disjoint Rest API with NPE:onos-1.7
Change-Id: I172e247353f7d70f6d7761e8a6be27f21b3c2684
Showing
5 changed files
with
79 additions
and
3 deletions
... | @@ -45,6 +45,16 @@ public class DefaultDisjointPath extends DefaultPath implements DisjointPath { | ... | @@ -45,6 +45,16 @@ public class DefaultDisjointPath extends DefaultPath implements DisjointPath { |
45 | this.path2 = path2; | 45 | this.path2 = path2; |
46 | } | 46 | } |
47 | 47 | ||
48 | + /** | ||
49 | + * Creates a disjoint path pair from single default paths. | ||
50 | + * | ||
51 | + * @param providerId provider identity | ||
52 | + * @param path1 primary path | ||
53 | + */ | ||
54 | + public DefaultDisjointPath(ProviderId providerId, DefaultPath path1) { | ||
55 | + this(providerId, path1, null); | ||
56 | + } | ||
57 | + | ||
48 | @Override | 58 | @Override |
49 | public List<Link> links() { | 59 | public List<Link> links() { |
50 | if (usingPath1) { | 60 | if (usingPath1) { | ... | ... |
... | @@ -239,6 +239,9 @@ public abstract class AbstractPathService | ... | @@ -239,6 +239,9 @@ public abstract class AbstractPathService |
239 | primary = path.primary(); | 239 | primary = path.primary(); |
240 | backup = path.backup(); | 240 | backup = path.backup(); |
241 | } | 241 | } |
242 | + if (backup == null) { | ||
243 | + return new DefaultDisjointPath(PID, (DefaultPath) edgeToEdgePath(srcLink, dstLink, primary)); | ||
244 | + } | ||
242 | return new DefaultDisjointPath(PID, (DefaultPath) edgeToEdgePath(srcLink, dstLink, primary), | 245 | return new DefaultDisjointPath(PID, (DefaultPath) edgeToEdgePath(srcLink, dstLink, primary), |
243 | (DefaultPath) edgeToEdgePath(srcLink, dstLink, backup)); | 246 | (DefaultPath) edgeToEdgePath(srcLink, dstLink, backup)); |
244 | } | 247 | } | ... | ... |
... | @@ -43,6 +43,7 @@ import org.onosproject.net.HostLocation; | ... | @@ -43,6 +43,7 @@ import org.onosproject.net.HostLocation; |
43 | import org.onosproject.net.Link; | 43 | import org.onosproject.net.Link; |
44 | import org.onosproject.net.MastershipRole; | 44 | import org.onosproject.net.MastershipRole; |
45 | import org.onosproject.net.Path; | 45 | import org.onosproject.net.Path; |
46 | +import org.onosproject.net.DisjointPath; | ||
46 | import org.onosproject.net.Port; | 47 | import org.onosproject.net.Port; |
47 | import org.onosproject.net.device.PortStatistics; | 48 | import org.onosproject.net.device.PortStatistics; |
48 | import org.onosproject.net.driver.Driver; | 49 | import org.onosproject.net.driver.Driver; |
... | @@ -123,6 +124,7 @@ public class CodecManager implements CodecService { | ... | @@ -123,6 +124,7 @@ public class CodecManager implements CodecService { |
123 | registerCodec(Topology.class, new TopologyCodec()); | 124 | registerCodec(Topology.class, new TopologyCodec()); |
124 | registerCodec(TopologyCluster.class, new TopologyClusterCodec()); | 125 | registerCodec(TopologyCluster.class, new TopologyClusterCodec()); |
125 | registerCodec(Path.class, new PathCodec()); | 126 | registerCodec(Path.class, new PathCodec()); |
127 | + registerCodec(DisjointPath.class, new DisjointPathCodec()); | ||
126 | registerCodec(Group.class, new GroupCodec()); | 128 | registerCodec(Group.class, new GroupCodec()); |
127 | registerCodec(Driver.class, new DriverCodec()); | 129 | registerCodec(Driver.class, new DriverCodec()); |
128 | registerCodec(GroupBucket.class, new GroupBucketCodec()); | 130 | registerCodec(GroupBucket.class, new GroupBucketCodec()); | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.codec.impl; | ||
17 | + | ||
18 | +import org.onosproject.codec.CodecContext; | ||
19 | +import org.onosproject.codec.JsonCodec; | ||
20 | +import org.onosproject.net.Link; | ||
21 | +import org.onosproject.net.DisjointPath; | ||
22 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
23 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
24 | + | ||
25 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
26 | + | ||
27 | +/** | ||
28 | + * DisjointPath JSON codec. | ||
29 | + */ | ||
30 | +public final class DisjointPathCodec extends AnnotatedCodec<DisjointPath> { | ||
31 | + @Override | ||
32 | + public ObjectNode encode(DisjointPath disjointPath, CodecContext context) { | ||
33 | + checkNotNull(disjointPath, "Path cannot be null"); | ||
34 | + JsonCodec<Link> codec = context.codec(Link.class); | ||
35 | + ObjectNode result = context.mapper() | ||
36 | + .createObjectNode(); | ||
37 | + | ||
38 | + ObjectNode primary = context.mapper() | ||
39 | + .createObjectNode() | ||
40 | + .put("cost", disjointPath.primary().cost()); | ||
41 | + | ||
42 | + result.set("primary", primary); | ||
43 | + ArrayNode jsonLinks = primary.putArray("links"); | ||
44 | + for (Link link : disjointPath.primary().links()) { | ||
45 | + jsonLinks.add(codec.encode(link, context)); | ||
46 | + } | ||
47 | + if (disjointPath.backup() != null) { | ||
48 | + ObjectNode backup = context.mapper() | ||
49 | + .createObjectNode() | ||
50 | + .put("cost", disjointPath.backup().cost()); | ||
51 | + result.set("backup", backup); | ||
52 | + ArrayNode jsonLinks1 = backup.putArray("links"); | ||
53 | + for (Link link1 : disjointPath.backup().links()) { | ||
54 | + jsonLinks1.add(codec.encode(link1, context)); | ||
55 | + } | ||
56 | + } | ||
57 | + return annotate(result, disjointPath, context); | ||
58 | + } | ||
59 | + | ||
60 | +} | ||
61 | + |
... | @@ -77,12 +77,12 @@ public class PathsWebResource extends AbstractWebResource { | ... | @@ -77,12 +77,12 @@ public class PathsWebResource extends AbstractWebResource { |
77 | } | 77 | } |
78 | 78 | ||
79 | /** | 79 | /** |
80 | - * Gets all shortest disjoint paths between any two hosts or devices. | 80 | + * Gets all shortest disjoint path pairs between any two hosts or devices. |
81 | - * Returns array of all shortest disjoint paths between any two elements. | 81 | + * Returns array of all shortest disjoint path pairs between any two elements. |
82 | * @onos.rsModel Paths | 82 | * @onos.rsModel Paths |
83 | * @param src source identifier | 83 | * @param src source identifier |
84 | * @param dst destination identifier | 84 | * @param dst destination identifier |
85 | - * @return 200 OK with array of all shortest disjoint paths between any two elements | 85 | + * @return 200 OK with array of all shortest disjoint path pairs between any two elements |
86 | */ | 86 | */ |
87 | @GET | 87 | @GET |
88 | @Produces(MediaType.APPLICATION_JSON) | 88 | @Produces(MediaType.APPLICATION_JSON) | ... | ... |
-
Please register or login to post a comment