Improve network config validation errors to show which fields are invalid.

Previously, uploading invalid config results in a generic error message
which makes it difficult to figure out what is wrong with the config

Change-Id: I307d2fc0669679b067389c722556eef3aae098b9
diff --git a/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java b/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java
index 2d4fc4d..87148a8 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java
@@ -39,6 +39,7 @@
 import org.onosproject.net.config.Config;
 import org.onosproject.net.config.ConfigApplyDelegate;
 import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.InvalidConfigException;
 import org.onosproject.net.config.NetworkConfigEvent;
 import org.onosproject.net.config.NetworkConfigStore;
 import org.onosproject.net.config.NetworkConfigStoreDelegate;
@@ -248,7 +249,17 @@
     public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) {
         // Create the configuration and validate it.
         C config = createConfig(subject, configClass, json);
-        checkArgument(config.isValid(), INVALID_CONFIG_JSON);
+
+        try {
+            checkArgument(config.isValid(), INVALID_CONFIG_JSON);
+        } catch (RuntimeException e) {
+            ConfigFactory<S, C> configFactory = getConfigFactory(configClass);
+            String subjectKey = configFactory.subjectFactory().subjectClassKey();
+            String subjectString = configFactory.subjectFactory().subjectKey(config.subject());
+            String configKey = config.key();
+
+            throw new InvalidConfigException(subjectKey, subjectString, configKey, e);
+        }
 
         // Insert the validated configuration and get it back.
         Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json);