Making number of components configurable using the central component configuration subsystem.

Change-Id: Ia32c51480913689339a766d9849e792d62f7d133
diff --git a/core/api/src/main/java/org/onosproject/net/intent/Intent.java b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
index 7621c7d..7959929 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/Intent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
@@ -62,21 +62,22 @@
     /**
      * Creates a new intent.
      *
-     * @param appId         application identifier
-     * @param resources     required network resources (optional)
+     * @param appId     application identifier
+     * @param resources required network resources (optional)
      */
     protected Intent(ApplicationId appId,
                      Collection<NetworkResource> resources) {
         this(appId, null, resources, DEFAULT_INTENT_PRIORITY);
     }
 
-        /**
-         * Creates a new intent.
-         *
-         * @param appId         application identifier
-         * @param key           optional key
-         * @param resources     required network resources (optional)
-         */
+    /**
+     * Creates a new intent.
+     *
+     * @param appId     application identifier
+     * @param key       optional key
+     * @param resources required network resources (optional)
+     * @param priority  flow rule priority
+     */
     protected Intent(ApplicationId appId,
                      Key key,
                      Collection<NetworkResource> resources,
@@ -156,6 +157,7 @@
      * Binds an id generator for unique intent id generation.
      *
      * Note: A generator cannot be bound if there is already a generator bound.
+     *
      * @param newIdGenerator id generator
      */
     public static void bindIdGenerator(IdGenerator newIdGenerator) {
@@ -167,6 +169,7 @@
      * Unbinds an id generator.
      *
      * Note: The caller must provide the old id generator to succeed.
+     *
      * @param oldIdGenerator the current id generator
      */
     public static void unbindIdGenerator(IdGenerator oldIdGenerator) {
diff --git a/core/net/src/main/java/org/onosproject/cfg/impl/ComponentConfigManager.java b/core/net/src/main/java/org/onosproject/cfg/impl/ComponentConfigManager.java
index 25af7ff..1e0ca6b 100644
--- a/core/net/src/main/java/org/onosproject/cfg/impl/ComponentConfigManager.java
+++ b/core/net/src/main/java/org/onosproject/cfg/impl/ComponentConfigManager.java
@@ -203,9 +203,8 @@
 
     // Loads existing property values that may have been set.
     private void loadExistingValues(String componentName) {
-        // FIXME: implement this by talking to the config admin.
         try {
-            Configuration cfg = cfgAdmin.getConfiguration(componentName);
+            Configuration cfg = cfgAdmin.getConfiguration(componentName, null);
             Map<String, ConfigProperty> map = properties.get(componentName);
             Dictionary<String, Object> props = cfg.getProperties();
             if (props != null) {
@@ -229,7 +228,7 @@
     // after each other.
     private void triggerUpdate(String componentName) {
         try {
-            Configuration cfg = cfgAdmin.getConfiguration(componentName);
+            Configuration cfg = cfgAdmin.getConfiguration(componentName, null);
             Map<String, ConfigProperty> map = properties.get(componentName);
             Dictionary<String, Object> props = new Hashtable<>();
             map.values().forEach(p -> props.put(p.name(), p.value()));
diff --git a/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java b/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java
index 03a7169..956102c 100644
--- a/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java
+++ b/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java
@@ -17,6 +17,7 @@
 
 import static com.google.common.base.Strings.isNullOrEmpty;
 import static java.util.concurrent.Executors.newFixedThreadPool;
+import static org.onlab.util.Tools.get;
 import static org.onlab.util.Tools.groupedThreads;
 import static org.onosproject.core.CoreService.CORE_PROVIDER_ID;
 import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED;
@@ -162,16 +163,16 @@
             return;
         }
 
-        Dictionary properties = context.getProperties();
+        Dictionary<?, ?> properties = context.getProperties();
         int newMaxEvents, newMaxBatchMs, newMaxIdleMs;
         try {
-            String s = (String) properties.get("maxEvents");
+            String s = get(properties, "maxEvents");
             newMaxEvents = isNullOrEmpty(s) ? maxEvents : Integer.parseInt(s.trim());
 
-            s = (String) properties.get("maxBatchMs");
+            s = get(properties, "maxBatchMs");
             newMaxBatchMs = isNullOrEmpty(s) ? maxBatchMs : Integer.parseInt(s.trim());
 
-            s = (String) properties.get("maxIdleMs");
+            s = get(properties, "maxIdleMs");
             newMaxIdleMs = isNullOrEmpty(s) ? maxIdleMs : Integer.parseInt(s.trim());
 
         } catch (NumberFormatException | ClassCastException e) {
diff --git a/core/net/src/main/resources/org/onosproject/net/topology/impl/DefaultTopologyProvider.cfgdef b/core/net/src/main/resources/org/onosproject/net/topology/impl/DefaultTopologyProvider.cfgdef
index f7819dd..c380f70 100644
--- a/core/net/src/main/resources/org/onosproject/net/topology/impl/DefaultTopologyProvider.cfgdef
+++ b/core/net/src/main/resources/org/onosproject/net/topology/impl/DefaultTopologyProvider.cfgdef
@@ -1,20 +1,4 @@
-#
-# Copyright 2015 Open Networking Laboratory                                
-#                                                                          
-# Licensed under the Apache License, Version 2.0 (the "License");          
-# you may not use this file except in compliance with the License.         
-# You may obtain a copy of the License at                                  
-#                                                                          
-#     http://www.apache.org/licenses/LICENSE-2.0                           
-#                                                                          
-# Unless required by applicable law or agreed to in writing, software      
-# distributed under the License is distributed on an "AS IS" BASIS,        
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
-# See the License for the specific language governing permissions and      
-# limitations under the License.
-#
-
-# This is for temporary provision for testing purposes and will be auto-generated.
+# Temporary: to be auto-generated in near future
 maxEvents|INTEGER|1000|Maximum number of events to accumulate
 maxIdleMs|INTEGER|10|Maximum number of millis between events
 maxBatchMs|INTEGER|50|Maximum number of millis for whole batch
diff --git a/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java b/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java
index 2906775..bcb34ea 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/flow/impl/DistributedFlowRuleStore.java
@@ -95,6 +95,7 @@
 
 import static com.google.common.base.Strings.isNullOrEmpty;
 import static org.apache.felix.scr.annotations.ReferenceCardinality.MANDATORY_UNARY;
+import static org.onlab.util.Tools.get;
 import static org.onlab.util.Tools.groupedThreads;
 import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
 import static org.onosproject.store.flow.impl.FlowStoreMessageSubjects.*;
@@ -267,10 +268,10 @@
         int newPoolSize;
         boolean newBackupEnabled;
         try {
-            String s = (String) properties.get("msgHandlerPoolSize");
+            String s = get(properties, "msgHandlerPoolSize");
             newPoolSize = isNullOrEmpty(s) ? msgHandlerPoolSize : Integer.parseInt(s.trim());
 
-            s = (String) properties.get("backupEnabled");
+            s = get(properties, "backupEnabled");
             newBackupEnabled = isNullOrEmpty(s) ? backupEnabled : Boolean.parseBoolean(s.trim());
 
         } catch (NumberFormatException | ClassCastException e) {
diff --git a/core/store/dist/src/main/resource/org/onosproject/store/flow/impl/DistributedFlowRuleStore.cfgdef b/core/store/dist/src/main/resource/org/onosproject/store/flow/impl/DistributedFlowRuleStore.cfgdef
new file mode 100644
index 0000000..a579a92
--- /dev/null
+++ b/core/store/dist/src/main/resource/org/onosproject/store/flow/impl/DistributedFlowRuleStore.cfgdef
@@ -0,0 +1,3 @@
+# Temporary: to be auto-generated in near future
+msgHandlerPoolSize|INTEGER|8|Number of threads in the message handler pool
+backupEnabled|BOOLEAN|false|Indicates whether backups are enabled or not
diff --git a/core/store/src/main/resources/org/onosproject/store/flow/impl/DistributedFlowRuleStore.cfgdef b/core/store/src/main/resources/org/onosproject/store/flow/impl/DistributedFlowRuleStore.cfgdef
new file mode 100644
index 0000000..7d0d6d9
--- /dev/null
+++ b/core/store/src/main/resources/org/onosproject/store/flow/impl/DistributedFlowRuleStore.cfgdef
@@ -0,0 +1,3 @@
+# Temporary: to be auto-generated in near future
+msgHandlerPoolSize|INTEGER|8|Number of threads in the message handler pool
+backupEnabled|BOOLEAN|DEFAULT_BACKUP_ENABLED|Indicates whether backups are enabled or not