Thomas Vachuska

ONOS-3599 Fixed exceptions during link provider activation.

Change-Id: I423b24dc27c1d53975d7ced933d803dda052a421
...@@ -45,6 +45,7 @@ import org.apache.felix.scr.annotations.Property; ...@@ -45,6 +45,7 @@ import org.apache.felix.scr.annotations.Property;
45 import org.apache.felix.scr.annotations.Reference; 45 import org.apache.felix.scr.annotations.Reference;
46 import org.apache.felix.scr.annotations.ReferenceCardinality; 46 import org.apache.felix.scr.annotations.ReferenceCardinality;
47 import org.onlab.packet.Ethernet; 47 import org.onlab.packet.Ethernet;
48 +import org.onlab.util.Tools;
48 import org.onosproject.cfg.ComponentConfigService; 49 import org.onosproject.cfg.ComponentConfigService;
49 import org.onosproject.cluster.ClusterService; 50 import org.onosproject.cluster.ClusterService;
50 import org.onosproject.core.ApplicationId; 51 import org.onosproject.core.ApplicationId;
...@@ -77,6 +78,7 @@ import org.onosproject.net.packet.PacketProcessor; ...@@ -77,6 +78,7 @@ import org.onosproject.net.packet.PacketProcessor;
77 import org.onosproject.net.packet.PacketService; 78 import org.onosproject.net.packet.PacketService;
78 import org.onosproject.net.provider.AbstractProvider; 79 import org.onosproject.net.provider.AbstractProvider;
79 import org.onosproject.net.provider.ProviderId; 80 import org.onosproject.net.provider.ProviderId;
81 +import org.onosproject.store.service.ConsistentMapException;
80 import org.osgi.service.component.ComponentContext; 82 import org.osgi.service.component.ComponentContext;
81 import org.slf4j.Logger; 83 import org.slf4j.Logger;
82 84
...@@ -99,6 +101,9 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -99,6 +101,9 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
99 // When a Device/Port has this annotation, do not send out LLDP/BDDP 101 // When a Device/Port has this annotation, do not send out LLDP/BDDP
100 public static final String NO_LLDP = "no-lldp"; 102 public static final String NO_LLDP = "no-lldp";
101 103
104 + private static final int MAX_RETRIES = 5;
105 + private static final int RETRY_DELAY = 1_000; // millis
106 +
102 private final Logger log = getLogger(getClass()); 107 private final Logger log = getLogger(getClass());
103 108
104 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 109 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -227,10 +232,9 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -227,10 +232,9 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
227 SuppressionConfig cfg = cfgRegistry.getConfig(appId, SuppressionConfig.class); 232 SuppressionConfig cfg = cfgRegistry.getConfig(appId, SuppressionConfig.class);
228 if (cfg == null) { 233 if (cfg == null) {
229 // If no configuration is found, register default. 234 // If no configuration is found, register default.
230 - cfg = cfgRegistry.addConfig(appId, SuppressionConfig.class); 235 + cfg = Tools.retryable(this::setDefaultSuppressionConfig,
231 - cfg.deviceTypes(DEFAULT_RULES.getSuppressedDeviceType()) 236 + ConsistentMapException.class,
232 - .annotation(DEFAULT_RULES.getSuppressedAnnotation()) 237 + MAX_RETRIES, RETRY_DELAY).get();
233 - .apply();
234 } 238 }
235 cfgListener.reconfigureSuppressionRules(cfg); 239 cfgListener.reconfigureSuppressionRules(cfg);
236 240
...@@ -238,6 +242,14 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -238,6 +242,14 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
238 log.info("Started"); 242 log.info("Started");
239 } 243 }
240 244
245 + private SuppressionConfig setDefaultSuppressionConfig() {
246 + SuppressionConfig cfg = cfgRegistry.addConfig(appId, SuppressionConfig.class);
247 + cfg.deviceTypes(DEFAULT_RULES.getSuppressedDeviceType())
248 + .annotation(DEFAULT_RULES.getSuppressedAnnotation())
249 + .apply();
250 + return cfg;
251 + }
252 +
241 @Deactivate 253 @Deactivate
242 public void deactivate() { 254 public void deactivate() {
243 cfgRegistry.removeListener(cfgListener); 255 cfgRegistry.removeListener(cfgListener);
......