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; ...@@ -18,9 +18,6 @@ package org.onosproject.net.topology;
18 import com.google.common.collect.ImmutableSet; 18 import com.google.common.collect.ImmutableSet;
19 import com.google.common.collect.Lists; 19 import com.google.common.collect.Lists;
20 import com.google.common.collect.Sets; 20 import com.google.common.collect.Sets;
21 -import org.apache.felix.scr.annotations.Component;
22 -import org.apache.felix.scr.annotations.Reference;
23 -import org.apache.felix.scr.annotations.ReferenceCardinality;
24 import org.onosproject.net.ConnectPoint; 21 import org.onosproject.net.ConnectPoint;
25 import org.onosproject.net.DefaultDisjointPath; 22 import org.onosproject.net.DefaultDisjointPath;
26 import org.onosproject.net.DefaultEdgeLink; 23 import org.onosproject.net.DefaultEdgeLink;
...@@ -46,9 +43,12 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -46,9 +43,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
46 43
47 /** 44 /**
48 * Helper class for path service. 45 * Helper class for path service.
46 + * <p>
47 + * Class inheriting this must manually initialize {@code topologyService}
48 + * and {@code hostService} fields.
49 */ 49 */
50 -@Component(componentAbstract = true) 50 +public abstract class AbstractPathService
51 -public abstract class AbstractPathService { 51 + implements PathService {
52 52
53 private static final String ELEMENT_ID_NULL = "Element ID cannot be null"; 53 private static final String ELEMENT_ID_NULL = "Element ID cannot be null";
54 private static final EdgeLink NOT_HOST = new NotHost(); 54 private static final EdgeLink NOT_HOST = new NotHost();
...@@ -56,12 +56,11 @@ public abstract class AbstractPathService { ...@@ -56,12 +56,11 @@ public abstract class AbstractPathService {
56 private static final ProviderId PID = new ProviderId("core", "org.onosproject.core"); 56 private static final ProviderId PID = new ProviderId("core", "org.onosproject.core");
57 private static final PortNumber P0 = PortNumber.portNumber(0); 57 private static final PortNumber P0 = PortNumber.portNumber(0);
58 58
59 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 protected TopologyService topologyService; 59 protected TopologyService topologyService;
61 60
62 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 protected HostService hostService; 61 protected HostService hostService;
64 62
63 + @Override
65 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) { 64 public Set<Path> getPaths(ElementId src, ElementId dst, LinkWeight weight) {
66 checkNotNull(src, ELEMENT_ID_NULL); 65 checkNotNull(src, ELEMENT_ID_NULL);
67 checkNotNull(dst, ELEMENT_ID_NULL); 66 checkNotNull(dst, ELEMENT_ID_NULL);
...@@ -94,6 +93,7 @@ public abstract class AbstractPathService { ...@@ -94,6 +93,7 @@ public abstract class AbstractPathService {
94 return edgeToEdgePaths(srcEdge, dstEdge, paths); 93 return edgeToEdgePaths(srcEdge, dstEdge, paths);
95 } 94 }
96 95
96 + @Override
97 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeight weight) { 97 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeight weight) {
98 checkNotNull(src, ELEMENT_ID_NULL); 98 checkNotNull(src, ELEMENT_ID_NULL);
99 checkNotNull(dst, ELEMENT_ID_NULL); 99 checkNotNull(dst, ELEMENT_ID_NULL);
...@@ -126,6 +126,7 @@ public abstract class AbstractPathService { ...@@ -126,6 +126,7 @@ public abstract class AbstractPathService {
126 return edgeToEdgePathsDisjoint(srcEdge, dstEdge, paths); 126 return edgeToEdgePathsDisjoint(srcEdge, dstEdge, paths);
127 } 127 }
128 128
129 + @Override
129 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeight weight, 130 public Set<DisjointPath> getDisjointPaths(ElementId src, ElementId dst, LinkWeight weight,
130 Map<Link, Object> riskProfile) { 131 Map<Link, Object> riskProfile) {
131 checkNotNull(src, ELEMENT_ID_NULL); 132 checkNotNull(src, ELEMENT_ID_NULL);
......
...@@ -18,13 +18,17 @@ package org.onosproject.net.topology.impl; ...@@ -18,13 +18,17 @@ package org.onosproject.net.topology.impl;
18 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
21 +import org.apache.felix.scr.annotations.Reference;
22 +import org.apache.felix.scr.annotations.ReferenceCardinality;
21 import org.apache.felix.scr.annotations.Service; 23 import org.apache.felix.scr.annotations.Service;
22 import org.onosproject.net.DisjointPath; 24 import org.onosproject.net.DisjointPath;
23 import org.onosproject.net.ElementId; 25 import org.onosproject.net.ElementId;
24 import org.onosproject.net.Link; 26 import org.onosproject.net.Link;
25 import org.onosproject.net.Path; 27 import org.onosproject.net.Path;
28 +import org.onosproject.net.host.HostService;
26 import org.onosproject.net.topology.LinkWeight; 29 import org.onosproject.net.topology.LinkWeight;
27 import org.onosproject.net.topology.PathService; 30 import org.onosproject.net.topology.PathService;
31 +import org.onosproject.net.topology.TopologyService;
28 import org.onosproject.net.topology.AbstractPathService; 32 import org.onosproject.net.topology.AbstractPathService;
29 import org.slf4j.Logger; 33 import org.slf4j.Logger;
30 34
...@@ -45,11 +49,19 @@ import static org.onosproject.security.AppPermission.Type.*; ...@@ -45,11 +49,19 @@ import static org.onosproject.security.AppPermission.Type.*;
45 @Service 49 @Service
46 public class PathManager extends AbstractPathService implements PathService { 50 public class PathManager extends AbstractPathService implements PathService {
47 51
48 -
49 private final Logger log = getLogger(getClass()); 52 private final Logger log = getLogger(getClass());
50 53
54 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
55 + protected TopologyService topologyService;
56 +
57 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 + protected HostService hostService;
59 +
51 @Activate 60 @Activate
52 public void activate() { 61 public void activate() {
62 + // initialize AbstractPathService
63 + super.topologyService = this.topologyService;
64 + super.hostService = this.hostService;
53 log.info("Started"); 65 log.info("Started");
54 } 66 }
55 67
......