diff options
Diffstat (limited to 'framework/src/onos/tools/dev/bin')
-rwxr-xr-x | framework/src/onos/tools/dev/bin/clean-branches.py | 51 | ||||
-rwxr-xr-x | framework/src/onos/tools/dev/bin/onos-app | 72 | ||||
-rwxr-xr-x | framework/src/onos/tools/dev/bin/onos-build-selective | 44 | ||||
-rwxr-xr-x | framework/src/onos/tools/dev/bin/onos-build-selective-hook | 10 | ||||
-rw-r--r-- | framework/src/onos/tools/dev/bin/onos-build-selective.exclude | 9 | ||||
-rwxr-xr-x | framework/src/onos/tools/dev/bin/onos-create-app | 42 | ||||
-rwxr-xr-x | framework/src/onos/tools/dev/bin/onos-karaf | 7 | ||||
-rwxr-xr-x | framework/src/onos/tools/dev/bin/onos-local-log | 10 | ||||
-rwxr-xr-x | framework/src/onos/tools/dev/bin/onos-setup-karaf | 123 | ||||
-rwxr-xr-x | framework/src/onos/tools/dev/bin/onos-setup-ubuntu-devenv | 21 | ||||
-rwxr-xr-x | framework/src/onos/tools/dev/bin/onos-update-bundle | 16 |
11 files changed, 405 insertions, 0 deletions
diff --git a/framework/src/onos/tools/dev/bin/clean-branches.py b/framework/src/onos/tools/dev/bin/clean-branches.py new file mode 100755 index 00000000..3de7cb70 --- /dev/null +++ b/framework/src/onos/tools/dev/bin/clean-branches.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +from subprocess import check_output +import sys + +def get_merged_branches_by_change_id(): + '''a list of merged branches, by change id excluding support branches and master''' + raw_changeIds = check_output('git log origin/master | grep -i change-id | awk {\' print $2 \'}', shell=True) + changeIds = [b.strip() for b in raw_changeIds.split('\n') if b.strip()] + raw_branches = check_output('git branch -a', shell=True) + branches = [b.strip() for b in raw_branches.split('\n') + if b.strip() and not b.startswith('*') and \ + not b.strip().startswith('onos') and not b.strip().startswith('remotes') and b.strip() != 'master'] + to_delete = [] + for branch in branches: + raw_local_change_ids = check_output('git show %s | grep -i change-id | awk {\' print $2 \'}' % branch, shell=True) + local_change_ids = [ b.strip() for b in raw_local_change_ids.split('\n') if b.strip() ] + for local_change_id in local_change_ids: + if local_change_id in changeIds and branch not in to_delete: + to_delete.append(branch) + + return to_delete + + +def delete_branch(branch): + return check_output('git branch -D %s' % branch, shell=True).strip() + + +if __name__ == '__main__': + dry_run = '--confirm' not in sys.argv + one_by_one = '--one-by-one' in sys.argv + to_delete = get_merged_branches_by_change_id() + if len(to_delete) == 0: + print "Nothing to clean" + sys.exit(0) + for branch in to_delete: + if dry_run: + print branch + else: + if one_by_one: + print 'Do you want to delete branch %s [y/N]' % branch + ans = raw_input() + if ans == 'y' or ans == 'Y': + print delete_branch(branch) + else: + print delete_branch(branch) + + if dry_run: + print '*****************************************************************' + print 'Did not actually delete anything yet, pass in --confirm to delete' + print diff --git a/framework/src/onos/tools/dev/bin/onos-app b/framework/src/onos/tools/dev/bin/onos-app new file mode 100755 index 00000000..d6fe562b --- /dev/null +++ b/framework/src/onos/tools/dev/bin/onos-app @@ -0,0 +1,72 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Tool to manage ONOS applications using REST API. +# ----------------------------------------------------------------------------- + +node=${1:-$OCI} +cmd=${2:-list} +app=${3} + +export URL=http://$node:8181/onos/v1/applications +export HDR="-HContent-Type:application/octet-stream" +export curl="curl -sS --user $ONOS_WEB_USER:$ONOS_WEB_PASS" + +# Prints usage help +function usage { + echo "usage: onos-app <node-ip> list" >&2 + echo " onos-app <node-ip> {install|install!} <app-file>" >&2 + echo " onos-app <node-ip> {reinstall|reinstall!} [<app-name>] <app-file>" >&2 + echo " onos-app <node-ip> {activate|deactivate|uninstall} <app-name>" >&2 + exit 1 +} + +# Extract app name from the specified *.oar file +function appName { + aux=/tmp/aux$$.jar + cp $1 $aux + pushd /tmp >/dev/null + jar xf $aux app.xml && grep name= app.xml | cut -d\" -f2 + rm -f $aux /tmp/app.xml + popd >/dev/null +} + +[ -z $node -o "$node" = "-h" -o "$node" = "--help" -o "$node" = "-?" ] && usage + +case $cmd in + list) $curl -X GET $URL;; + install!|install) + [ $cmd = "install!" ] && activate="?activate=true" + [ $# -lt 3 -o ! -f $app ] && usage + $curl -X POST $HDR $URL$activate --data-binary @$app + ;; + + reinstall!|reinstall) + [ $cmd = "reinstall!" ] && activate="?activate=true" + [ $# -lt 4 -a ! -f "$3" ] && usage + [ $# -eq 4 -a ! -f "$4" ] && usage + oar=$4 + [ $# -lt 4 ] && oar=$3 && app=$(appName $oar) + $curl -X DELETE $URL/$app + $curl -X POST $HDR $URL$activate --data-binary @$oar + ;; + + uninstall) + [ $# -lt 3 ] && usage + $curl -X DELETE $URL/$app + ;; + activate) + [ $# -lt 3 ] && usage + $curl -X POST $URL/$app/active + ;; + deactivate) + [ $# -lt 3 ] && usage + $curl -X DELETE $URL/$app/active + ;; + + *) usage;; +esac + + +status=$? +echo # new line for prompt +exit $status diff --git a/framework/src/onos/tools/dev/bin/onos-build-selective b/framework/src/onos/tools/dev/bin/onos-build-selective new file mode 100755 index 00000000..ac2dec8e --- /dev/null +++ b/framework/src/onos/tools/dev/bin/onos-build-selective @@ -0,0 +1,44 @@ +#!/bin/bash +# ---------------------------------------------------------------------------- +# Selectively builds only those projects that contained modified Java files. +# ---------------------------------------------------------------------------- + +cd $ONOS_ROOT + +projects=$(find $ONOS_ROOT -type f -path '*/src/*' \ + -exec $ONOS_ROOT/tools/dev/bin/onos-build-selective-hook {} \; | \ + grep -v -f $ONOS_ROOT/tools/dev/bin/onos-build-selective.exclude | \ + sort -u | sed "s:$ONOS_ROOT::g" | tr '\n' ',' | \ + sed 's:/,:,:g;s:,/:,:g;s:^/::g;s:,$::g') + +if [ -n "$projects" ]; then + # Ascertain artifact IDs of the projects to be rebuilt + modulesERE="" + for pd in ${projects//,/ }; do + artifactId=$(grep -E "^ <artifactId>.*</artifactId>$" ${pd}/pom.xml | \ + sed 's/.[^>]*>//;s/<.*//') + modulesERE="$modulesERE|$artifactId" + done + modulesERE=${modulesERE#|*} + + # Search through staged app.xml files for any apps that require one or + # more of the modified artifacts. + appProjects=$(find $ONOS_ROOT -type f -path '*/target/oar/app.xml' | \ + xargs grep '<artifact>' | grep -E "/($modulesERE)/" | \ + cut -d: -f1 | sed 's:/target/oar/.*::g' | \ + sort -u | sed "s:$ONOS_ROOT::g" | tr '\n' ',' | \ + sed 's:/,:,:g;s:,/:,:g;s:^/::g;s:,$::g') + + # If we found any, append those app projects to the list of projects to + # be built. + [ -n "$appProjects" ] && projects=$projects,$appProjects + + echo Building projects $projects + cd $ONOS_ROOT && mvn --projects $projects ${@:-clean install} + status=$? + + [ -n "$appProjects" ] && echo "App staging required for projects $appProjects" + exit $status +else + exit 0 +fi diff --git a/framework/src/onos/tools/dev/bin/onos-build-selective-hook b/framework/src/onos/tools/dev/bin/onos-build-selective-hook new file mode 100755 index 00000000..fbe77522 --- /dev/null +++ b/framework/src/onos/tools/dev/bin/onos-build-selective-hook @@ -0,0 +1,10 @@ +#!/bin/bash +# ---------------------------------------------------------------------------- +# Echoes project-level directory if a source file within is newer than the +# target directory. +# ---------------------------------------------------------------------------- + +[ ${1/*\//} = "package-info.java" ] && exit 0 + +project=${1/src*/} +[ ${project}target -nt $1 ] || echo ${project} diff --git a/framework/src/onos/tools/dev/bin/onos-build-selective.exclude b/framework/src/onos/tools/dev/bin/onos-build-selective.exclude new file mode 100644 index 00000000..1265494e --- /dev/null +++ b/framework/src/onos/tools/dev/bin/onos-build-selective.exclude @@ -0,0 +1,9 @@ +.*/archetypes/.* +.*/maven-plugin/.* +.*/build/conf/.* +.*/docs/.* +.*/openflow/drivers/.* +.*/cord-gui/.* +.*/jdvue/.* +.*/ovsdb/api/.* +.*/netconf/flow/.*
\ No newline at end of file diff --git a/framework/src/onos/tools/dev/bin/onos-create-app b/framework/src/onos/tools/dev/bin/onos-create-app new file mode 100755 index 00000000..65b00b65 --- /dev/null +++ b/framework/src/onos/tools/dev/bin/onos-create-app @@ -0,0 +1,42 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Tool to create an application from scratch using ONOS Maven archetypes. +# ----------------------------------------------------------------------------- + +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 +. $ONOS_ROOT/tools/build/envDefaults + +type=${1:-bundle} + +[ $type = app ] && archetype=bundle || archetype=$type + +if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then + echo "usage: $(basename $0) {app|bundle|ui|cli|api} groupId artifactId version package mvn-options" + echo " All arguments are optional" + exit 1 +fi + +otherOptions="" +[ -n "$1" ] && shift +[ -n "$1" ] && otherOptions="$otherOptions -DgroupId=$1" && shift +[ -n "$1" ] && otherOptions="$otherOptions -DartifactId=$1" && dir=$1 && shift +[ -n "$1" ] && otherOptions="$otherOptions -Dversion=$1" && shift +[ -n "$1" ] && otherOptions="$otherOptions -Dpackage=$1" && shift + +mvn archetype:generate -DarchetypeGroupId=org.onosproject \ + -DarchetypeArtifactId=onos-$archetype-archetype \ + -DarchetypeVersion=$ONOS_POM_VERSION $otherOptions "$@" + +# Patch the pom.xml file to make this an app. +if [ $type = app ]; then + # We need to add a few lines to the pom.xml to make this an app + if [ -n "$dir" ] && [ -d $dir ]; then + egrep -v " (<!--|-->)" $dir/pom.xml > $dir/pom.app.xml + mv $dir/pom.app.xml $dir/pom.xml + else + echo + echo "IMPORTANT:" + echo "To build the application, you need to uncomment the 'onos.app.name' and 'onos.app.origin' properties in the pom.xml" + echo + fi +fi diff --git a/framework/src/onos/tools/dev/bin/onos-karaf b/framework/src/onos/tools/dev/bin/onos-karaf new file mode 100755 index 00000000..9c575fb4 --- /dev/null +++ b/framework/src/onos/tools/dev/bin/onos-karaf @@ -0,0 +1,7 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Makes sure local ONOS karaf instance is primed & staged and then launches +# karaf using the supplied arguments. +# ----------------------------------------------------------------------------- + +onos-setup-karaf && karaf "$@"
\ No newline at end of file diff --git a/framework/src/onos/tools/dev/bin/onos-local-log b/framework/src/onos/tools/dev/bin/onos-local-log new file mode 100755 index 00000000..a17d3b9c --- /dev/null +++ b/framework/src/onos/tools/dev/bin/onos-local-log @@ -0,0 +1,10 @@ +#!/bin/bash +# ---------------------------------------------------------------------------- +# Continuously watches the Apache Karaf log; survives 'karaf clean' +# ---------------------------------------------------------------------------- +KARAF_LOG=${KARAF_LOG:-~/apache-karaf-$KARAF_VERSION/data/log/karaf.log} + +while true; do + [ ! -f $KARAF_LOG ] && sleep 2 && continue + tail -n 512 -f -F $KARAF_LOG +done diff --git a/framework/src/onos/tools/dev/bin/onos-setup-karaf b/framework/src/onos/tools/dev/bin/onos-setup-karaf new file mode 100755 index 00000000..3323d9d1 --- /dev/null +++ b/framework/src/onos/tools/dev/bin/onos-setup-karaf @@ -0,0 +1,123 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Downloads and sets-up Apache Karaf as a basis for running ONOS locally +# as a single-instance. +# +# Note that this in no way impacts the method for running ONOS remotely. +# For that, one should use onos-package and onos-install tools. +# ----------------------------------------------------------------------------- + +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 +. $ONOS_ROOT/tools/build/envDefaults + +# TODO: consider putting this under ~/Applications/onos/apache-karaf-... +export KARAF_ROOT=${KARAF_ROOT:-~/Applications/apache-karaf-$KARAF_VERSION} +export STAGE=$(dirname $KARAF_ROOT) + +# Validates the specified IP regular expression against existing adapters. +# Excludes local-loopback. +function validateIp { + ifconfig | awk '{ print $2}' | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | grep $1 +} + +# Clean the previous Karaf directory if requested and if it exists. +if [ "$1" = "clean" ]; then + shift + CLEAN="true" + [ -d $KARAF_ROOT ] && rm -fr $KARAF_ROOT $STAGE/apps $STAGE/config +fi + +ONOS_IP=${ONOS_IP:-127.0.0.1} +IP="${1:-$ONOS_IP}" + +# If IP was not given, nor configured attempt to use ONOS_NIC env. variable +if [ -z "$IP" -a -n "$ONOS_NIC" ]; then + IP=$(validateIp $ONOS_NIC) + [ -z "$IP" ] && echo "No adapter with IP matching $ONOS_NIC found!" +else + # Otherwise, verify that the IP address given exists among the adapters. + saveIp=$IP + IP=$(validateIp $IP) + [ -z "$IP" ] && echo "No adapter with IP $saveIp found!" +fi + +# If IP is still not surmised or if usage was requested, show usage and IPs. +if [ -z "$IP" -o "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then + echo "usage: $(basename $0) [clean] <ip-address>" + echo "Available IP addresses are:" + validateIp . + exit 1 +fi + +SUBNET="$(echo $IP | cut -d. -f1-3)" + +# Bail on any errors +set -e + +# Check if Apache Karaf is already installed. +if [ ! -d $KARAF_ROOT ]; then + # Check if Apache Karaf bits are available and if not, fetch them. + if [ ! -f $KARAF_TAR ]; then + echo "Downloading $KARAF_TAR..." + curl -sL http://downloads.onosproject.org/third-party/apache-karaf-$KARAF_VERSION.tar.gz > $KARAF_TAR + fi + [ ! -f $KARAF_ZIP -a ! -f $KARAF_TAR ] && \ + echo "Apache Karaf bits $KARAF_ZIP or $KARAF_TAR not found" && exit 1 + + echo "Unpacking $KARAF_TAR to $STAGE..." + mkdir -p $STAGE + cd $STAGE + tar zxf $KARAF_TAR + rm -rf $KARAF_ROOT/demos +fi + +if ! grep -q "/onos-features/" $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then + # Patch the Apache Karaf distribution file to add ONOS features repository + echo "Adding ONOS feature repository..." + perl -pi.old -e "s|^(featuresRepositories=.*)|\1,mvn:org.onosproject/onos-features/$ONOS_POM_VERSION/xml/features|" \ + $KARAF_ROOT/etc/org.apache.karaf.features.cfg +fi + +if ! grep -q ",onos-api," $KARAF_ROOT/etc/org.apache.karaf.features.cfg; then + # Patch the Apache Karaf distribution file to load default ONOS boot features + export BOOT_FEATURES="webconsole,onos-api,onos-core,onos-incubator,onos-cli,onos-rest,onos-gui" + echo "Adding ONOS boot features $BOOT_FEATURES..." + perl -pi.old -e "s|^(featuresBoot=.*)|\1,$BOOT_FEATURES|" \ + $KARAF_ROOT/etc/org.apache.karaf.features.cfg +fi + +if [ ! -f $KARAF_ROOT/lib/onos-branding-$ONOS_POM_VERSION.jar ]; then + # Patch the Apache Karaf distribution with ONOS branding bundle + echo "Branding as ONOS..." + rm -f $KARAF_ROOT/lib/onos-branding-*.jar + cp $M2_REPO/org/onosproject/onos-branding/$ONOS_POM_VERSION/onos-branding-$ONOS_POM_VERSION.jar \ + $KARAF_ROOT/lib +fi + +echo "Creating local cluster configs for IP $IP..." +[ -d $STAGE/config ] || mkdir -p $STAGE/config +cat > $STAGE/config/cluster.json <<EOF + { "ipPrefix": "$SUBNET.*", + "nodes":[ { "id": "$IP", "ip": "$IP", "tcpPort": 9876 }]} +EOF + +cat > $STAGE/config/tablets.json <<EOF + { "nodes": [ { "ip": "$IP", "id": "$IP", "tcpPort": 9876 }], + "partitions": { "p1": [ { "ip": "$IP", "id": "$IP", "tcpPort": 9876 }]}} +EOF + +if [ "$CLEAN" = "true" ]; then + echo "Copying package configs..." + cp -r $ONOS_ROOT/tools/package/etc/* $KARAF_ROOT/etc/ + cp -r $ONOS_ROOT/tools/package/config/* $STAGE/config/ +fi + +echo "Staging builtin apps..." +rm -fr $STAGE/apps +onos-stage-apps $STAGE/apps $KARAF_ROOT/system + +ACTIVE_APPS=${ONOS_APPS:-drivers,openflow} +echo "Customizing apps to be auto-activated: $ACTIVE_APPS..." +for app in ${ACTIVE_APPS//,/ }; do + touch $STAGE/apps/org.onosproject.$app/active +done diff --git a/framework/src/onos/tools/dev/bin/onos-setup-ubuntu-devenv b/framework/src/onos/tools/dev/bin/onos-setup-ubuntu-devenv new file mode 100755 index 00000000..d528c6b2 --- /dev/null +++ b/framework/src/onos/tools/dev/bin/onos-setup-ubuntu-devenv @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Script to install ONOS dependencies on Ubuntu 14.04 +# + +echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections + +echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections + +sudo apt-get install software-properties-common -y +sudo add-apt-repository ppa:webupd8team/java -y +sudo apt-get update && sudo apt-get install oracle-java8-installer oracle-java8-set-default git wget -y +export JAVA_HOME=/usr/lib/jvm/java-8-oracle + +cd; mkdir Downloads Applications +cd Downloads +wget http://download.nextag.com/apache/karaf/3.0.3/apache-karaf-3.0.3.tar.gz +wget http://archive.apache.org/dist/maven/maven-3/3.3.1/binaries/apache-maven-3.3.1-bin.tar.gz +tar -zxvf apache-karaf-3.0.3.tar.gz -C ../Applications/ +tar -zxvf apache-maven-3.3.1-bin.tar.gz -C ../Applications/ + diff --git a/framework/src/onos/tools/dev/bin/onos-update-bundle b/framework/src/onos/tools/dev/bin/onos-update-bundle new file mode 100755 index 00000000..9e9e08bb --- /dev/null +++ b/framework/src/onos/tools/dev/bin/onos-update-bundle @@ -0,0 +1,16 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Update bundle on locally running karaf. +# ----------------------------------------------------------------------------- + +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 +. $ONOS_ROOT/tools/build/envDefaults + +cd ~/.m2/repository +jar=$(find org/onosproject -type f -name '*.jar' | grep -e $1 | grep -v -e -tests | head -n 1) + +[ -z "$jar" ] && echo "No bundle $1 found for" && exit 1 + +bundle=$(echo $(basename $jar .jar) | sed 's/-[0-9].*//g') + +client "bundle:update -f $bundle" 2>/dev/null |