Added ability to form a cluster via REST API.

Change-Id: Ib71f6b4caed1b1c4b9db78596ee35bf5cab05184
diff --git a/core/net/pom.xml b/core/net/pom.xml
index c47f91d..d8aecf9 100644
--- a/core/net/pom.xml
+++ b/core/net/pom.xml
@@ -82,6 +82,11 @@
             <groupId>org.apache.karaf.features</groupId>
             <artifactId>org.apache.karaf.features.core</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.karaf.system</groupId>
+            <artifactId>org.apache.karaf.system.core</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/core/net/src/main/java/org/onosproject/cluster/impl/ClusterManager.java b/core/net/src/main/java/org/onosproject/cluster/impl/ClusterManager.java
index d9da6c6..3f7e460 100644
--- a/core/net/src/main/java/org/onosproject/cluster/impl/ClusterManager.java
+++ b/core/net/src/main/java/org/onosproject/cluster/impl/ClusterManager.java
@@ -15,18 +15,13 @@
  */
 package org.onosproject.cluster.impl;
 
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.slf4j.LoggerFactory.getLogger;
-
-import java.util.Set;
-
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.karaf.system.SystemService;
 import org.joda.time.DateTime;
 import org.onlab.packet.IpAddress;
 import org.onosproject.cluster.ClusterAdminService;
@@ -41,6 +36,12 @@
 import org.onosproject.event.EventDeliveryService;
 import org.slf4j.Logger;
 
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.slf4j.LoggerFactory.getLogger;
+
 /**
  * Implementation of the cluster service.
  */
@@ -62,6 +63,9 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected EventDeliveryService eventDispatcher;
 
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected SystemService systemService;
+
     @Activate
     public void activate() {
         store.setDelegate(delegate);
@@ -105,6 +109,20 @@
     }
 
     @Override
+    public void formCluster(Set<ControllerNode> nodes, String ipPrefix) {
+        checkNotNull(nodes, "Nodes cannot be null");
+        checkArgument(!nodes.isEmpty(), "Nodes cannot be empty");
+        checkNotNull(ipPrefix, "IP prefix cannot be null");
+        store.formCluster(nodes, ipPrefix);
+        try {
+            log.warn("Shutting down container for cluster reconfiguration!");
+            systemService.reboot("now", SystemService.Swipe.NONE);
+        } catch (Exception e) {
+            log.error("Unable to reboot container", e);
+        }
+    }
+
+    @Override
     public ControllerNode addNode(NodeId nodeId, IpAddress ip, int tcpPort) {
         checkNotNull(nodeId, INSTANCE_ID_NULL);
         checkNotNull(ip, "IP address cannot be null");