Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Thomas Vachuska | 4998caa | 2015-08-26 13:28:38 -0700 | [diff] [blame] | 16 | package org.onosproject.store.config.impl; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | 0a400ea | 2015-09-04 11:25:03 -0700 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.JsonNode; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 21 | import com.fasterxml.jackson.databind.node.BooleanNode; |
| 22 | import com.fasterxml.jackson.databind.node.DoubleNode; |
Ayaka Koshibe | 1a00251 | 2015-09-03 13:09:23 -0700 | [diff] [blame] | 23 | import com.fasterxml.jackson.databind.node.IntNode; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 24 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 25 | import com.fasterxml.jackson.databind.node.LongNode; |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 26 | import com.fasterxml.jackson.databind.node.NullNode; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 27 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 28 | import com.fasterxml.jackson.databind.node.ShortNode; |
| 29 | import com.fasterxml.jackson.databind.node.TextNode; |
| 30 | import com.google.common.collect.ImmutableSet; |
| 31 | import com.google.common.collect.Maps; |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 32 | import com.google.common.collect.Sets; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 33 | import org.apache.felix.scr.annotations.Activate; |
| 34 | import org.apache.felix.scr.annotations.Component; |
| 35 | import org.apache.felix.scr.annotations.Deactivate; |
| 36 | import org.apache.felix.scr.annotations.Reference; |
| 37 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 38 | import org.apache.felix.scr.annotations.Service; |
| 39 | import org.onlab.util.KryoNamespace; |
Thomas Vachuska | 5f2cbe6 | 2015-07-30 15:10:34 -0700 | [diff] [blame] | 40 | import org.onlab.util.Tools; |
Ray Milkey | a412236 | 2015-08-18 15:19:08 -0700 | [diff] [blame] | 41 | import org.onosproject.net.config.Config; |
| 42 | import org.onosproject.net.config.ConfigApplyDelegate; |
| 43 | import org.onosproject.net.config.ConfigFactory; |
| 44 | import org.onosproject.net.config.NetworkConfigEvent; |
| 45 | import org.onosproject.net.config.NetworkConfigStore; |
| 46 | import org.onosproject.net.config.NetworkConfigStoreDelegate; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 47 | import org.onosproject.store.AbstractStore; |
| 48 | import org.onosproject.store.serializers.KryoNamespaces; |
| 49 | import org.onosproject.store.service.ConsistentMap; |
Thomas Vachuska | 5f2cbe6 | 2015-07-30 15:10:34 -0700 | [diff] [blame] | 50 | import org.onosproject.store.service.ConsistentMapException; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 51 | import org.onosproject.store.service.MapEvent; |
| 52 | import org.onosproject.store.service.MapEventListener; |
| 53 | import org.onosproject.store.service.Serializer; |
| 54 | import org.onosproject.store.service.StorageService; |
| 55 | import org.onosproject.store.service.Versioned; |
| 56 | import org.slf4j.Logger; |
| 57 | import org.slf4j.LoggerFactory; |
| 58 | |
| 59 | import java.util.LinkedHashMap; |
| 60 | import java.util.Map; |
| 61 | import java.util.Objects; |
| 62 | import java.util.Set; |
| 63 | |
Thomas Vachuska | ce0bbb3 | 2015-11-18 16:56:10 -0800 | [diff] [blame] | 64 | import static com.google.common.base.Preconditions.checkArgument; |
Ray Milkey | a412236 | 2015-08-18 15:19:08 -0700 | [diff] [blame] | 65 | import static org.onosproject.net.config.NetworkConfigEvent.Type.*; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Implementation of a distributed network configuration store. |
| 69 | */ |
| 70 | @Component(immediate = true) |
| 71 | @Service |
| 72 | public class DistributedNetworkConfigStore |
| 73 | extends AbstractStore<NetworkConfigEvent, NetworkConfigStoreDelegate> |
| 74 | implements NetworkConfigStore { |
| 75 | |
| 76 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 77 | |
Thomas Vachuska | ce0bbb3 | 2015-11-18 16:56:10 -0800 | [diff] [blame] | 78 | private static final int MAX_BACKOFF = 10; |
| 79 | private static final String INVALID_CONFIG_JSON = |
| 80 | "JSON node does not contain valid configuration"; |
| 81 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 83 | protected StorageService storageService; |
| 84 | |
Thomas Vachuska | 0a400ea | 2015-09-04 11:25:03 -0700 | [diff] [blame] | 85 | private ConsistentMap<ConfigKey, JsonNode> configs; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 86 | |
| 87 | private final Map<String, ConfigFactory> factoriesByConfig = Maps.newConcurrentMap(); |
| 88 | private final ObjectMapper mapper = new ObjectMapper(); |
| 89 | private final ConfigApplyDelegate applyDelegate = new InternalApplyDelegate(); |
Thomas Vachuska | 0a400ea | 2015-09-04 11:25:03 -0700 | [diff] [blame] | 90 | private final MapEventListener<ConfigKey, JsonNode> listener = new InternalMapListener(); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 91 | |
| 92 | @Activate |
| 93 | public void activate() { |
| 94 | KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder() |
| 95 | .register(KryoNamespaces.API) |
Jonathan Hart | 111b42b | 2015-07-14 13:28:05 -0700 | [diff] [blame] | 96 | .register(ConfigKey.class, ObjectNode.class, ArrayNode.class, |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 97 | JsonNodeFactory.class, LinkedHashMap.class, |
| 98 | TextNode.class, BooleanNode.class, |
HIGUCHI Yuta | d9fe3a3 | 2015-11-24 18:52:25 -0800 | [diff] [blame] | 99 | LongNode.class, DoubleNode.class, ShortNode.class, IntNode.class, |
| 100 | NullNode.class); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 101 | |
Thomas Vachuska | 0a400ea | 2015-09-04 11:25:03 -0700 | [diff] [blame] | 102 | configs = storageService.<ConfigKey, JsonNode>consistentMapBuilder() |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 103 | .withSerializer(Serializer.using(kryoBuilder.build())) |
| 104 | .withName("onos-network-configs") |
Madan Jampani | 3d6a2f6 | 2015-08-12 07:19:07 -0700 | [diff] [blame] | 105 | .withRelaxedReadConsistency() |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 106 | .build(); |
| 107 | configs.addListener(listener); |
| 108 | log.info("Started"); |
| 109 | } |
| 110 | |
| 111 | @Deactivate |
| 112 | public void deactivate() { |
| 113 | configs.removeListener(listener); |
| 114 | log.info("Stopped"); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void addConfigFactory(ConfigFactory configFactory) { |
| 119 | factoriesByConfig.put(configFactory.configClass().getName(), configFactory); |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 120 | processPendingConfigs(configFactory); |
Thomas Vachuska | e636022 | 2015-07-21 10:10:36 -0700 | [diff] [blame] | 121 | notifyDelegate(new NetworkConfigEvent(CONFIG_REGISTERED, configFactory.configKey(), |
| 122 | configFactory.configClass())); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 125 | // Sweep through any pending configurations, validate them and then prune them. |
| 126 | private void processPendingConfigs(ConfigFactory configFactory) { |
| 127 | Set<ConfigKey> toBePruned = Sets.newHashSet(); |
| 128 | configs.keySet().forEach(k -> { |
| 129 | if (Objects.equals(k.configKey, configFactory.configKey())) { |
| 130 | validateConfig(k, configFactory, configs.get(k).value()); |
| 131 | toBePruned.add(k); // Prune whether valid or not |
| 132 | } |
| 133 | }); |
| 134 | toBePruned.forEach(configs::remove); |
| 135 | } |
| 136 | |
| 137 | @SuppressWarnings("unchecked") |
| 138 | private void validateConfig(ConfigKey key, ConfigFactory configFactory, JsonNode json) { |
| 139 | Config config = createConfig(key.subject, configFactory.configClass(), json); |
| 140 | try { |
| 141 | checkArgument(config.isValid(), INVALID_CONFIG_JSON); |
| 142 | configs.putAndGet(key(key.subject, configFactory.configClass()), json); |
| 143 | } catch (Exception e) { |
| 144 | log.warn("Failed to validate pending {} configuration for {}: {}", |
| 145 | key.configKey, configFactory.subjectFactory().subjectKey(key.subject), json); |
| 146 | } |
| 147 | } |
| 148 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 149 | @Override |
| 150 | public void removeConfigFactory(ConfigFactory configFactory) { |
| 151 | factoriesByConfig.remove(configFactory.configClass().getName()); |
Thomas Vachuska | e636022 | 2015-07-21 10:10:36 -0700 | [diff] [blame] | 152 | notifyDelegate(new NetworkConfigEvent(CONFIG_UNREGISTERED, configFactory.configKey(), |
| 153 | configFactory.configClass())); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | @Override |
| 157 | @SuppressWarnings("unchecked") |
| 158 | public <S, C extends Config<S>> ConfigFactory<S, C> getConfigFactory(Class<C> configClass) { |
| 159 | return (ConfigFactory<S, C>) factoriesByConfig.get(configClass.getName()); |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | @SuppressWarnings("unchecked") |
| 164 | public <S> Set<S> getSubjects(Class<S> subjectClass) { |
| 165 | ImmutableSet.Builder<S> builder = ImmutableSet.builder(); |
| 166 | configs.keySet().forEach(k -> { |
| 167 | if (subjectClass.isInstance(k.subject)) { |
| 168 | builder.add((S) k.subject); |
| 169 | } |
| 170 | }); |
| 171 | return builder.build(); |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | @SuppressWarnings("unchecked") |
| 176 | public <S, C extends Config<S>> Set<S> getSubjects(Class<S> subjectClass, Class<C> configClass) { |
| 177 | ImmutableSet.Builder<S> builder = ImmutableSet.builder(); |
| 178 | String cName = configClass.getName(); |
| 179 | configs.keySet().forEach(k -> { |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 180 | if (subjectClass.isInstance(k.subject) && Objects.equals(cName, k.configClass)) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 181 | builder.add((S) k.subject); |
| 182 | } |
| 183 | }); |
| 184 | return builder.build(); |
| 185 | } |
| 186 | |
| 187 | @Override |
| 188 | @SuppressWarnings("unchecked") |
| 189 | public <S> Set<Class<? extends Config<S>>> getConfigClasses(S subject) { |
| 190 | ImmutableSet.Builder<Class<? extends Config<S>>> builder = ImmutableSet.builder(); |
| 191 | configs.keySet().forEach(k -> { |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 192 | if (Objects.equals(subject, k.subject) && k.configClass != null && delegate != null) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 193 | builder.add(factoriesByConfig.get(k.configClass).configClass()); |
| 194 | } |
| 195 | }); |
| 196 | return builder.build(); |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public <S, T extends Config<S>> T getConfig(S subject, Class<T> configClass) { |
Madan Jampani | a29c677 | 2015-08-17 13:17:07 -0700 | [diff] [blame] | 201 | // TODO: need to identify and address the root cause for timeouts. |
Thomas Vachuska | 0a400ea | 2015-09-04 11:25:03 -0700 | [diff] [blame] | 202 | Versioned<JsonNode> json = Tools.retryable(configs::get, ConsistentMapException.class, 1, MAX_BACKOFF) |
| 203 | .apply(key(subject, configClass)); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 204 | return json != null ? createConfig(subject, configClass, json.value()) : null; |
| 205 | } |
| 206 | |
| 207 | |
| 208 | @Override |
| 209 | public <S, C extends Config<S>> C createConfig(S subject, Class<C> configClass) { |
Thomas Vachuska | 0a400ea | 2015-09-04 11:25:03 -0700 | [diff] [blame] | 210 | ConfigFactory<S, C> factory = getConfigFactory(configClass); |
| 211 | Versioned<JsonNode> json = configs.computeIfAbsent(key(subject, configClass), |
| 212 | k -> factory.isList() ? |
| 213 | mapper.createArrayNode() : |
| 214 | mapper.createObjectNode()); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 215 | return createConfig(subject, configClass, json.value()); |
| 216 | } |
| 217 | |
| 218 | @Override |
Thomas Vachuska | 0a400ea | 2015-09-04 11:25:03 -0700 | [diff] [blame] | 219 | public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) { |
Thomas Vachuska | ce0bbb3 | 2015-11-18 16:56:10 -0800 | [diff] [blame] | 220 | // Create the configuration and validate it. |
| 221 | C config = createConfig(subject, configClass, json); |
| 222 | checkArgument(config.isValid(), INVALID_CONFIG_JSON); |
| 223 | |
| 224 | // Insert the validated configuration and get it back. |
| 225 | Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json); |
| 226 | |
| 227 | // Re-create the config if for some reason what we attempted to put |
| 228 | // was supplanted by someone else already. |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 229 | return versioned.value() == json ? config : createConfig(subject, configClass, versioned.value()); |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public <S> void queueConfig(S subject, String configKey, JsonNode json) { |
| 234 | configs.put(key(subject, configKey), json); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public <S, C extends Config<S>> void clearConfig(S subject, Class<C> configClass) { |
| 239 | configs.remove(key(subject, configClass)); |
| 240 | } |
| 241 | |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 242 | @Override |
| 243 | public <S> void clearQueuedConfig(S subject, String configKey) { |
| 244 | configs.remove(key(subject, configKey)); |
| 245 | } |
| 246 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 247 | /** |
| 248 | * Produces a config from the specified subject, config class and raw JSON. |
| 249 | * |
| 250 | * @param subject config subject |
| 251 | * @param configClass config class |
| 252 | * @param json raw JSON data |
| 253 | * @return config object or null of no factory found or if the specified |
| 254 | * JSON is null |
| 255 | */ |
| 256 | @SuppressWarnings("unchecked") |
| 257 | private <S, C extends Config<S>> C createConfig(S subject, Class<C> configClass, |
Thomas Vachuska | 0a400ea | 2015-09-04 11:25:03 -0700 | [diff] [blame] | 258 | JsonNode json) { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 259 | if (json != null) { |
| 260 | ConfigFactory<S, C> factory = factoriesByConfig.get(configClass.getName()); |
| 261 | if (factory != null) { |
| 262 | C config = factory.createConfig(); |
| 263 | config.init(subject, factory.configKey(), json, mapper, applyDelegate); |
| 264 | return config; |
| 265 | } |
| 266 | } |
| 267 | return null; |
| 268 | } |
| 269 | |
| 270 | |
| 271 | // Auxiliary delegate to receive notifications about changes applied to |
| 272 | // the network configuration - by the apps. |
| 273 | private class InternalApplyDelegate implements ConfigApplyDelegate { |
| 274 | @Override |
| 275 | public void onApply(Config config) { |
| 276 | configs.put(key(config.subject(), config.getClass()), config.node()); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | // Produces a key for uniquely tracking a subject config. |
| 281 | private static ConfigKey key(Object subject, Class<?> configClass) { |
| 282 | return new ConfigKey(subject, configClass); |
| 283 | } |
| 284 | |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 285 | // Produces a key for uniquely tracking a subject config. |
| 286 | private static ConfigKey key(Object subject, String configKey) { |
| 287 | return new ConfigKey(subject, configKey); |
| 288 | } |
| 289 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 290 | // Auxiliary key to track subject configurations. |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 291 | // Keys with non-null configKey are pending configurations. |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 292 | private static final class ConfigKey { |
| 293 | final Object subject; |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 294 | final String configKey; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 295 | final String configClass; |
| 296 | |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 297 | // Create a key for pending configuration class |
| 298 | private ConfigKey(Object subject, String configKey) { |
| 299 | this.subject = subject; |
| 300 | this.configKey = configKey; |
| 301 | this.configClass = null; |
| 302 | } |
| 303 | |
| 304 | // Create a key for registered class configuration |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 305 | private ConfigKey(Object subject, Class<?> configClass) { |
| 306 | this.subject = subject; |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 307 | this.configKey = null; |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 308 | this.configClass = configClass.getName(); |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public int hashCode() { |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 313 | return Objects.hash(subject, configKey, configClass); |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | @Override |
| 317 | public boolean equals(Object obj) { |
| 318 | if (this == obj) { |
| 319 | return true; |
| 320 | } |
| 321 | if (obj instanceof ConfigKey) { |
| 322 | final ConfigKey other = (ConfigKey) obj; |
| 323 | return Objects.equals(this.subject, other.subject) |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 324 | && Objects.equals(this.configKey, other.configKey) |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 325 | && Objects.equals(this.configClass, other.configClass); |
| 326 | } |
| 327 | return false; |
| 328 | } |
| 329 | } |
| 330 | |
Thomas Vachuska | 0a400ea | 2015-09-04 11:25:03 -0700 | [diff] [blame] | 331 | private class InternalMapListener implements MapEventListener<ConfigKey, JsonNode> { |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 332 | @Override |
Thomas Vachuska | 0a400ea | 2015-09-04 11:25:03 -0700 | [diff] [blame] | 333 | public void event(MapEvent<ConfigKey, JsonNode> event) { |
Thomas Vachuska | 6f350ed | 2016-01-08 09:53:03 -0800 | [diff] [blame] | 334 | // Do not delegate pending configs. |
| 335 | if (event.key().configClass == null) { |
| 336 | return; |
| 337 | } |
| 338 | |
Thomas Vachuska | 96d55b1 | 2015-05-11 08:52:03 -0700 | [diff] [blame] | 339 | NetworkConfigEvent.Type type; |
| 340 | switch (event.type()) { |
| 341 | case INSERT: |
| 342 | type = CONFIG_ADDED; |
| 343 | break; |
| 344 | case UPDATE: |
| 345 | type = CONFIG_UPDATED; |
| 346 | break; |
| 347 | case REMOVE: |
| 348 | default: |
| 349 | type = CONFIG_REMOVED; |
| 350 | break; |
| 351 | } |
| 352 | ConfigFactory factory = factoriesByConfig.get(event.key().configClass); |
| 353 | if (factory != null) { |
| 354 | notifyDelegate(new NetworkConfigEvent(type, event.key().subject, |
| 355 | factory.configClass())); |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | } |