Jayasree Ghosh
Committed by Gerrit Code Review

Fix for ONOS-5152:Encoder for Disjoint Rest API with NPE:onos-1.7

Change-Id: I172e247353f7d70f6d7761e8a6be27f21b3c2684
......@@ -45,6 +45,16 @@ public class DefaultDisjointPath extends DefaultPath implements DisjointPath {
this.path2 = path2;
}
/**
* Creates a disjoint path pair from single default paths.
*
* @param providerId provider identity
* @param path1 primary path
*/
public DefaultDisjointPath(ProviderId providerId, DefaultPath path1) {
this(providerId, path1, null);
}
@Override
public List<Link> links() {
if (usingPath1) {
......
......@@ -239,6 +239,9 @@ public abstract class AbstractPathService
primary = path.primary();
backup = path.backup();
}
if (backup == null) {
return new DefaultDisjointPath(PID, (DefaultPath) edgeToEdgePath(srcLink, dstLink, primary));
}
return new DefaultDisjointPath(PID, (DefaultPath) edgeToEdgePath(srcLink, dstLink, primary),
(DefaultPath) edgeToEdgePath(srcLink, dstLink, backup));
}
......
......@@ -43,6 +43,7 @@ import org.onosproject.net.HostLocation;
import org.onosproject.net.Link;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.Path;
import org.onosproject.net.DisjointPath;
import org.onosproject.net.Port;
import org.onosproject.net.device.PortStatistics;
import org.onosproject.net.driver.Driver;
......@@ -123,6 +124,7 @@ public class CodecManager implements CodecService {
registerCodec(Topology.class, new TopologyCodec());
registerCodec(TopologyCluster.class, new TopologyClusterCodec());
registerCodec(Path.class, new PathCodec());
registerCodec(DisjointPath.class, new DisjointPathCodec());
registerCodec(Group.class, new GroupCodec());
registerCodec(Driver.class, new DriverCodec());
registerCodec(GroupBucket.class, new GroupBucketCodec());
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.codec.impl;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.net.Link;
import org.onosproject.net.DisjointPath;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* DisjointPath JSON codec.
*/
public final class DisjointPathCodec extends AnnotatedCodec<DisjointPath> {
@Override
public ObjectNode encode(DisjointPath disjointPath, CodecContext context) {
checkNotNull(disjointPath, "Path cannot be null");
JsonCodec<Link> codec = context.codec(Link.class);
ObjectNode result = context.mapper()
.createObjectNode();
ObjectNode primary = context.mapper()
.createObjectNode()
.put("cost", disjointPath.primary().cost());
result.set("primary", primary);
ArrayNode jsonLinks = primary.putArray("links");
for (Link link : disjointPath.primary().links()) {
jsonLinks.add(codec.encode(link, context));
}
if (disjointPath.backup() != null) {
ObjectNode backup = context.mapper()
.createObjectNode()
.put("cost", disjointPath.backup().cost());
result.set("backup", backup);
ArrayNode jsonLinks1 = backup.putArray("links");
for (Link link1 : disjointPath.backup().links()) {
jsonLinks1.add(codec.encode(link1, context));
}
}
return annotate(result, disjointPath, context);
}
}
......@@ -77,12 +77,12 @@ public class PathsWebResource extends AbstractWebResource {
}
/**
* Gets all shortest disjoint paths between any two hosts or devices.
* Returns array of all shortest disjoint paths between any two elements.
* Gets all shortest disjoint path pairs between any two hosts or devices.
* Returns array of all shortest disjoint path pairs between any two elements.
* @onos.rsModel Paths
* @param src source identifier
* @param dst destination identifier
* @return 200 OK with array of all shortest disjoint paths between any two elements
* @return 200 OK with array of all shortest disjoint path pairs between any two elements
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
......