Fix ONOS-4503 - allow ONOS to run in offline mode with no internet connection

Change-Id: I7122800e2c485743313c5d963bc75f8dd0292452
diff --git a/.buckconfig b/.buckconfig
index bb8acbf..7c17b3f 100644
--- a/.buckconfig
+++ b/.buckconfig
@@ -16,7 +16,7 @@
   in_build = true
 
 [maven_repositories]
-  central = https://repo.maven.apache.org/maven2
+  central = https://repo1.maven.org/maven2
 
 [project]
   ide = intellij
diff --git a/lib/BUCK b/lib/BUCK
index fd871a6..f0536e2 100644
--- a/lib/BUCK
+++ b/lib/BUCK
@@ -1,4 +1,4 @@
-# ***** This file was auto-generated at Thu Oct 27 21:27:03 PDT 2016. Do not edit this file manually. *****
+# ***** This file was auto-generated at Fri Nov 18 10:06:30 PST 2016. Do not edit this file manually. *****
 osgi_feature_group(
   name = 'COMPILE',
   visibility = ['PUBLIC'],
@@ -1006,9 +1006,9 @@
 
 remote_file (
   name = 'apache-karaf',
-  out = 'apache-karaf-3.0.5.tar.gz',
-  url = 'http://onlab.vicci.org/onos/third-party/apache-karaf-3.0.5.tar.gz',
-  sha1 = '85a20b135f22362b6983f7954b58f0d97308cf63',
+  out = 'apache-karaf-3.0.5-offline-20161115.tar.gz',
+  url = 'http://onlab.vicci.org/onos/third-party/apache-karaf-3.0.5-offline-20161115.tar.gz',
+  sha1 = 'b47ddf4bc2812e9bddf9dfb4f10cb2fd31ebf430',
   visibility = [ 'PUBLIC' ],
 )
 
diff --git a/lib/deps.json b/lib/deps.json
index 6799123..ad74228 100644
--- a/lib/deps.json
+++ b/lib/deps.json
@@ -183,7 +183,7 @@
     "typesafe-config": "mvn:com.typesafe:config:1.2.1",
     "validation-api": "mvn:javax.validation:validation-api:1.1.0.Final",
     "checkstyle": "mvn:com.puppycrawl.tools:checkstyle:6.11.2",
-    "apache-karaf": "http://onlab.vicci.org/onos/third-party/apache-karaf-3.0.5.tar.gz",
+    "apache-karaf": "http://onlab.vicci.org/onos/third-party/apache-karaf-3.0.5-offline-20161115.tar.gz",
     "bndlib": "mvn:biz.aQute.bnd:biz.aQute.bndlib:jar:3.1.0",
     "cord-config": "mvn:org.onosproject:cord-config:1.0-b1",
     "libthrift": "mvn:org.apache.thrift:libthrift:0.9.3",
diff --git a/tools/package/bin/build-offline-karaf b/tools/package/bin/build-offline-karaf
new file mode 100755
index 0000000..ea0f7ed
--- /dev/null
+++ b/tools/package/bin/build-offline-karaf
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+KARAF_VERSION="3.0.5"
+KARAF_TARFILE_NAME="apache-karaf-${KARAF_VERSION}.tar"
+BOOT_FEATURES="standard,ssh,scr,war,webconsole"
+
+# fetch the standard karaf bits
+rm -f /tmp/${KARAF_TARFILE_NAME}
+curl -o /tmp/${KARAF_TARFILE_NAME}.gz http://onlab.vicci.org/onos/third-party/${KARAF_TARFILE_NAME}.gz
+
+# get a small cell
+source ${ONOS_ROOT}/tools/dev/bash_profile
+cell borrow 60 1+0
+scp /tmp/${KARAF_TARFILE_NAME}.gz sdn@${OC1}:/tmp/${KARAF_TARFILE_NAME}.gz
+
+ssh sdn@${OC1} "
+
+    # unroll the base karaf
+    rm -rf karaf
+    mkdir karaf
+    cd karaf
+    tar xf /tmp/${KARAF_TARFILE_NAME}.gz
+
+    # set the ONOS default boot features
+    perl -pi.old -e 's|^(featuresBoot=).*|\1${BOOT_FEATURES}|' apache-karaf-${KARAF_VERSION}/etc/org.apache.karaf.features.cfg
+
+    # run karaf to fill the maven repo with required artifacts
+    apache-karaf-${KARAF_VERSION}/bin/karaf server 1>/tmp/onos.out 2>/tmp/onos.err &
+
+    sleep 15
+
+    # stop karaf and capture the artifacts that were downloaded into the maven repo
+    apache-karaf-${KARAF_VERSION}/bin/karaf stop 1>/tmp/onos.out 2>/tmp/onos.err &
+    cd ~/.m2/repository
+    tar cvf ~/repo.tar *
+
+    # start with a fresh karaf and overlay the downloaded artifacts
+    cd
+    rm -rf karaf-offline
+    mkdir karaf-offline
+    cd karaf-offline
+    tar xf /tmp/${KARAF_TARFILE_NAME}.gz
+
+    # load the downloaded artifacts into the karaf system directory
+    cd apache-karaf-${KARAF_VERSION}/system
+    tar xf ~/repo.tar
+
+    # create a zipped tar ball of the updated karaf tree
+    cd ~/karaf-offline
+    tar czf ~/karaf-offline.tar.gz apache-karaf-${KARAF_VERSION}
+"
+
+# fetch the new offline karaf tar ball
+BUILD_NUMBER="apache-karaf-${KARAF_VERSION}-offline-$(date +'%Y%m%d')"
+scp sdn@${OC1}:karaf-offline.tar.gz /tmp/${BUILD_NUMBER}.tar.gz
+
+cell return
+
+
+
+
+
+
diff --git a/tools/test/scenarios/wrapup.xml b/tools/test/scenarios/wrapup.xml
index 0a93b9a..99345e0 100644
--- a/tools/test/scenarios/wrapup.xml
+++ b/tools/test/scenarios/wrapup.xml
@@ -20,5 +20,7 @@
             <step name="Fetch-Logs-${#}" exec="onos-fetch-logs ${OC#}"
                   cwd="${WORKSPACE}/tmp/stc" requires="~^"/>
         </parallel>
+        <!-- FIXME Figure out how to handle a .m2 repo that exists before the test is run -->
+        <!-- <step name="Check-Maven-Repo" exec="ssh ${ONOS_USER}@${OC1} ls -l .m2 " env="!"/> -->
     </group>
 </scenario>