Jayasree Ghosh

Fix for ONOS-5020:Encoder for Disjoint Rest API with NPE Issue Fix

Change-Id: I1036e806943c53bc00cb7cde73b66c115c1eeffe
......@@ -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) {
......
......@@ -42,6 +42,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;
......@@ -120,6 +121,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);
}
}
......@@ -485,8 +485,7 @@ public class DefaultTopology extends AbstractModel implements Topology {
if (!path.hasBackup()) {
// There was no secondary path available.
return new DefaultDisjointPath(CORE_PROVIDER_ID,
(DefaultPath) networkPath(path.primary()),
null);
(DefaultPath) networkPath(path.primary()));
}
return new DefaultDisjointPath(CORE_PROVIDER_ID,
(DefaultPath) networkPath(path.primary()),
......
......@@ -292,6 +292,9 @@ public class PathManager implements PathService {
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));
}
......
......@@ -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)
......