Yuta HIGUCHI

Fix NPE in AbstractPathService.

Was triggering NPE when used in plain PathManager

- implement PathService to inherit interface javadoc

Change-Id: I345ec84ed3e61a383574fd58679fb00291b4bba0
......@@ -18,9 +18,6 @@ package org.onosproject.net.topology;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultDisjointPath;
import org.onosproject.net.DefaultEdgeLink;
......@@ -46,9 +43,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* Helper class for path service.
* <p>
* Class inheriting this must manually initialize {@code topologyService}
* and {@code hostService} fields.
*/
@Component(componentAbstract = true)
public abstract class AbstractPathService {
public abstract class AbstractPathService
implements PathService {
private static final String ELEMENT_ID_NULL = "Element ID cannot be null";
private static final EdgeLink NOT_HOST = new NotHost();
......@@ -56,12 +56,11 @@ public abstract class AbstractPathService {
private static final ProviderId PID = new ProviderId("core", "org.onosproject.core");
private static final PortNumber P0 = PortNumber.portNumber(0);
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TopologyService topologyService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
@Override
public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
checkNotNull(src, ELEMENT_ID_NULL);
checkNotNull(dst, ELEMENT_ID_NULL);
......@@ -94,6 +93,7 @@ public abstract class AbstractPathService {
return edgeToEdgePaths(srcEdge, dstEdge, paths);
}
@Override
public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeight weight) {
checkNotNull(src, ELEMENT_ID_NULL);
checkNotNull(dst, ELEMENT_ID_NULL);
......@@ -126,6 +126,7 @@ public abstract class AbstractPathService {
return edgeToEdgePathsDisjoint(srcEdge, dstEdge, paths);
}
@Override
public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeight weight,
Map<Link, Object> riskProfile) {
checkNotNull(src, ELEMENT_ID_NULL);
......
......@@ -18,13 +18,17 @@ package org.onosproject.net.topology.impl;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.net.DisjointPath;
import org.onosproject.net.ElementId;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.host.HostService;
import org.onosproject.net.topology.LinkWeight;
import org.onosproject.net.topology.PathService;
import org.onosproject.net.topology.TopologyService;
import org.onosproject.net.topology.AbstractPathService;
import org.slf4j.Logger;
......@@ -45,11 +49,19 @@ import static org.onosproject.security.AppPermission.Type.*;
@Service
public class PathManager extends AbstractPathService implements PathService {
private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TopologyService topologyService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
@Activate
public void activate() {
// initialize AbstractPathService
super.topologyService = this.topologyService;
super.hostService = this.hostService;
log.info("Started");
}
......