Ray Milkey
Committed by Gerrit Code Review

Fix STC crashes due to devices not found

Change-Id: I23f17b125498fbc5a615498815f862b3544bea34
...@@ -15,19 +15,6 @@ ...@@ -15,19 +15,6 @@
15 */ 15 */
16 package org.onosproject.net.device.impl; 16 package org.onosproject.net.device.impl;
17 17
18 -import static com.google.common.base.Preconditions.checkNotNull;
19 -import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
20 -import static org.onlab.util.Tools.groupedThreads;
21 -import static org.onlab.util.Tools.nullIsNotFound;
22 -import static org.onosproject.net.MastershipRole.MASTER;
23 -import static org.onosproject.net.MastershipRole.NONE;
24 -import static org.onosproject.net.MastershipRole.STANDBY;
25 -import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
26 -import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
27 -import static org.onosproject.security.AppGuard.checkPermission;
28 -import static org.onosproject.security.AppPermission.Type.DEVICE_READ;
29 -import static org.slf4j.LoggerFactory.getLogger;
30 -
31 import java.util.Collection; 18 import java.util.Collection;
32 import java.util.HashSet; 19 import java.util.HashSet;
33 import java.util.List; 20 import java.util.List;
...@@ -90,6 +77,18 @@ import org.slf4j.Logger; ...@@ -90,6 +77,18 @@ import org.slf4j.Logger;
90 77
91 import com.google.common.util.concurrent.Futures; 78 import com.google.common.util.concurrent.Futures;
92 79
80 +import static com.google.common.base.Preconditions.checkNotNull;
81 +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
82 +import static org.onlab.util.Tools.groupedThreads;
83 +import static org.onosproject.net.MastershipRole.MASTER;
84 +import static org.onosproject.net.MastershipRole.NONE;
85 +import static org.onosproject.net.MastershipRole.STANDBY;
86 +import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
87 +import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
88 +import static org.onosproject.security.AppGuard.checkPermission;
89 +import static org.onosproject.security.AppPermission.Type.DEVICE_READ;
90 +import static org.slf4j.LoggerFactory.getLogger;
91 +
93 /** 92 /**
94 * Provides implementation of the device SB & NB APIs. 93 * Provides implementation of the device SB & NB APIs.
95 */ 94 */
...@@ -539,7 +538,10 @@ public class DeviceManager ...@@ -539,7 +538,10 @@ public class DeviceManager
539 portDescription); 538 portDescription);
540 return; 539 return;
541 } 540 }
542 - Device device = nullIsNotFound(getDevice(deviceId), "Device not found"); 541 + Device device = getDevice(deviceId);
542 + if (device == null) {
543 + log.trace("Device not found: {}", deviceId);
544 + }
543 if ((Device.Type.ROADM.equals(device.type())) || 545 if ((Device.Type.ROADM.equals(device.type())) ||
544 (Device.Type.OTN.equals(device.type()))) { 546 (Device.Type.OTN.equals(device.type()))) {
545 // FIXME This is ignoring all other info in portDescription given as input?? 547 // FIXME This is ignoring all other info in portDescription given as input??
......
...@@ -15,10 +15,24 @@ ...@@ -15,10 +15,24 @@
15 */ 15 */
16 package org.onosproject.store.device.impl; 16 package org.onosproject.store.device.impl;
17 17
18 -import com.google.common.collect.FluentIterable; 18 +import java.io.IOException;
19 -import com.google.common.collect.ImmutableList; 19 +import java.util.ArrayList;
20 -import com.google.common.collect.Maps; 20 +import java.util.Collection;
21 -import com.google.common.collect.Sets; 21 +import java.util.Collections;
22 +import java.util.HashMap;
23 +import java.util.HashSet;
24 +import java.util.Iterator;
25 +import java.util.List;
26 +import java.util.Map;
27 +import java.util.Map.Entry;
28 +import java.util.Objects;
29 +import java.util.Optional;
30 +import java.util.Set;
31 +import java.util.concurrent.ConcurrentMap;
32 +import java.util.concurrent.ExecutorService;
33 +import java.util.concurrent.ScheduledExecutorService;
34 +import java.util.concurrent.TimeUnit;
35 +import java.util.stream.Stream;
22 36
23 import org.apache.commons.lang3.RandomUtils; 37 import org.apache.commons.lang3.RandomUtils;
24 import org.apache.felix.scr.annotations.Activate; 38 import org.apache.felix.scr.annotations.Activate;
...@@ -82,24 +96,10 @@ import org.onosproject.store.service.StorageService; ...@@ -82,24 +96,10 @@ import org.onosproject.store.service.StorageService;
82 import org.onosproject.store.service.WallClockTimestamp; 96 import org.onosproject.store.service.WallClockTimestamp;
83 import org.slf4j.Logger; 97 import org.slf4j.Logger;
84 98
85 -import java.io.IOException; 99 +import com.google.common.collect.FluentIterable;
86 -import java.util.ArrayList; 100 +import com.google.common.collect.ImmutableList;
87 -import java.util.Collection; 101 +import com.google.common.collect.Maps;
88 -import java.util.Collections; 102 +import com.google.common.collect.Sets;
89 -import java.util.HashMap;
90 -import java.util.HashSet;
91 -import java.util.Iterator;
92 -import java.util.List;
93 -import java.util.Map;
94 -import java.util.Map.Entry;
95 -import java.util.Objects;
96 -import java.util.Optional;
97 -import java.util.Set;
98 -import java.util.concurrent.ConcurrentMap;
99 -import java.util.concurrent.ExecutorService;
100 -import java.util.concurrent.ScheduledExecutorService;
101 -import java.util.concurrent.TimeUnit;
102 -import java.util.stream.Stream;
103 103
104 import static com.google.common.base.Preconditions.checkArgument; 104 import static com.google.common.base.Preconditions.checkArgument;
105 import static com.google.common.base.Predicates.notNull; 105 import static com.google.common.base.Predicates.notNull;
...@@ -111,8 +111,15 @@ import static org.onlab.util.Tools.groupedThreads; ...@@ -111,8 +111,15 @@ import static org.onlab.util.Tools.groupedThreads;
111 import static org.onlab.util.Tools.minPriority; 111 import static org.onlab.util.Tools.minPriority;
112 import static org.onosproject.cluster.ControllerNodeToNodeId.toNodeId; 112 import static org.onosproject.cluster.ControllerNodeToNodeId.toNodeId;
113 import static org.onosproject.net.DefaultAnnotations.merge; 113 import static org.onosproject.net.DefaultAnnotations.merge;
114 -import static org.onosproject.net.device.DeviceEvent.Type.*; 114 +import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED;
115 -import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.*; 115 +import static org.onosproject.net.device.DeviceEvent.Type.PORT_ADDED;
116 +import static org.onosproject.net.device.DeviceEvent.Type.PORT_REMOVED;
117 +import static org.onosproject.net.device.DeviceEvent.Type.PORT_STATS_UPDATED;
118 +import static org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED;
119 +import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE;
120 +import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_INJECTED;
121 +import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_REMOVE_REQ;
122 +import static org.onosproject.store.device.impl.GossipDeviceStoreMessageSubjects.PORT_INJECTED;
116 import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; 123 import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT;
117 import static org.slf4j.LoggerFactory.getLogger; 124 import static org.slf4j.LoggerFactory.getLogger;
118 125
...@@ -669,7 +676,10 @@ public class GossipDeviceStore ...@@ -669,7 +676,10 @@ public class GossipDeviceStore
669 Timestamped<List<PortDescription>> portDescriptions) { 676 Timestamped<List<PortDescription>> portDescriptions) {
670 677
671 Device device = devices.get(deviceId); 678 Device device = devices.get(deviceId);
672 - checkArgument(device != null, DEVICE_NOT_FOUND, deviceId); 679 + if (device == null) {
680 + log.debug("Device is no longer valid: {}", deviceId);
681 + return Collections.emptyList();
682 + }
673 683
674 Map<ProviderId, DeviceDescriptions> descsMap = deviceDescs.get(deviceId); 684 Map<ProviderId, DeviceDescriptions> descsMap = deviceDescs.get(deviceId);
675 checkArgument(descsMap != null, DEVICE_NOT_FOUND, deviceId); 685 checkArgument(descsMap != null, DEVICE_NOT_FOUND, deviceId);
......