diff options
author | Ashlee Young <ashlee@wildernessvoice.com> | 2015-11-22 10:02:05 -0800 |
---|---|---|
committer | Ashlee Young <ashlee@wildernessvoice.com> | 2015-11-22 10:02:05 -0800 |
commit | 77ce3be7567bd01c66d8ee88a93b485666723501 (patch) | |
tree | 283e7f39a501750bbd705fbb91645b20198900f1 /framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java | |
parent | 00e6500d0813dcbccaaa741ef38cc1eae6d11e07 (diff) |
Removed patch path since changes have been merged upstream to a different path. Updated README with directions.
Change-Id: Ie419abd2d3d3ef7315de9f607dcd757a78190995
Signed-off-by: Ashlee Young <ashlee@wildernessvoice.com>
Diffstat (limited to 'framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java')
-rw-r--r-- | framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java index 3e73d8f4..ca8eea37 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java @@ -60,6 +60,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; import static org.onosproject.net.config.NetworkConfigEvent.Type.*; /** @@ -71,10 +72,12 @@ public class DistributedNetworkConfigStore extends AbstractStore<NetworkConfigEvent, NetworkConfigStoreDelegate> implements NetworkConfigStore { - private static final int MAX_BACKOFF = 10; - private final Logger log = LoggerFactory.getLogger(getClass()); + private static final int MAX_BACKOFF = 10; + private static final String INVALID_CONFIG_JSON = + "JSON node does not contain valid configuration"; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected StorageService storageService; @@ -187,8 +190,17 @@ public class DistributedNetworkConfigStore @Override public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) { - return createConfig(subject, configClass, - configs.putAndGet(key(subject, configClass), json).value()); + // Create the configuration and validate it. + C config = createConfig(subject, configClass, json); + checkArgument(config.isValid(), INVALID_CONFIG_JSON); + + // Insert the validated configuration and get it back. + Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json); + + // Re-create the config if for some reason what we attempted to put + // was supplanted by someone else already. + return versioned.value() == json ? config : + createConfig(subject, configClass, versioned.value()); } @Override |