diff --git a/gridworks b/gridworks index 8993171cc..ca8535999 100755 --- a/gridworks +++ b/gridworks @@ -19,6 +19,11 @@ error() { exit 1 } +warn() { + echo "$1" + exit 0 +} + usage() { cat < @@ -82,6 +87,37 @@ check_macosx() { fi } +check_downloaders() { + CURL="`which curl`" + WGET="`which wget`" + + if [ "$CURL" == "" ] && [ "$WGET" == "" ]; then + error "We need either 'curl' or 'wget' present in PATH to download external dependencies." + fi +} + +check_python() { + PYTHON="`which python`" + if [ "$PYTHON" == "" ] ; then + error "This action requires you to have 'python' installed. You can download it for free at http://www.python.org/" + fi + PYTHON_VERSION="`python --version 2>&1 | cut -f 2 -d ' ' | cut -f 1,2 -d .`" + if [ "$PYTHON_VERSION" != "2.5" ] && [ "$PYTHON_VERSION" != "2.6" ] ; then + error "This action requires python version 2.5.x or 2.6.x. You can download it for free at http://www.python.org/" + fi +} + +check_running() { + check_downloaders + URL="http://${GRIDWORKS_HOST}:${GRIDWORKS_PORT}/" + + if [ "$CURL" != "" ] ; then + NOT_RUNNING=`curl -s $URL > /dev/null || echo not_running` + elif [ "$WGET" != "" ] ; then + NOT_RUNNING=`wget -q -O - $URL > /dev/null || echo not_running` + fi +} + get_version() { VERSION=$1 @@ -103,25 +139,17 @@ get_revision() { REVISION=`echo $INFO | sed 's/.*Revision: /r/' | sed 's/ .*//'` } - -get_url_file() { - return `echo $1 | sed 's|.*/||'` -} download() { URL=$1 DEST=$2 - CURL="`which curl`" - WGET="`which wget`" - if [ "$CURL" == "" ] && [ "$WGET" == "" ]; then - error "We need either 'curl' or 'wget' present in PATH to download external dependencies." - fi + check_downloaders if [ "$CURL" != "" ] ; then - curl -L -o $DEST $URL || exit 1 + curl -L -o $DEST $URL || exit "Error while downloading $URL" elif [ "$WGET" != "" ] ; then - wget -O $DEST $URL || exit 1 + wget -O $DEST $URL || error "Error while downloading $URL" fi } @@ -135,28 +163,42 @@ tool_download() { download $URL $FILE fi if [ ! -d "$DIR" ] ; then - tar xzf $FILE || exit 1 + tar xzf $FILE || error "Error while expanding $FILE" fi cd .. } +load_data() { + FILE=$1 + NAME=$2 + URL="http://${GRIDWORKS_HOST}:${GRIDWORKS_PORT}/command/create-project-from-upload" + CURL="`which curl`" + + if [ "$CURL" == "" ] ; then + error "We need 'curl' present in PATH to upload data to gridworks." + else + curl -s -F "project-file=@$FILE" -F "project-name=$NAME" $URL > /dev/null || error "Error while uploading $FILE to Gridworks" + echo "Loaded $FILE as $NAME" + fi +} + # ---------------------------------------------------------------------------------------------- build_prepare() { if [ ! -d $GRIDWORKS_BUILD_DIR ] ; then - mkdir $GRIDWORKS_BUILD_DIR || exit 1 + mkdir $GRIDWORKS_BUILD_DIR || error "Error while making directory $GRIDWORKS_BUILD_DIR" fi } dist_prepare() { if [ ! -d $GRIDWORKS_DIST_DIR ] ; then - mkdir $GRIDWORKS_DIST_DIR || exit 1 + mkdir $GRIDWORKS_DIST_DIR || error "Error while making directory $GRIDWORKS_DIST_DIR" fi } tools_prepare() { if [ ! -d $GRIDWORKS_TOOLS_DIR ] ; then - mkdir $GRIDWORKS_TOOLS_DIR || exit 1 + mkdir $GRIDWORKS_TOOLS_DIR || error "Error while making directory $GRIDWORKS_TOOLS_DIR" fi } @@ -173,7 +215,7 @@ ant_prepare() { download $ANT_URL $ANT_FILE fi if [ ! -d $ANT_DIR ] ; then - tar xzf $ANT_FILE -C . || exit 1 + tar xzf $ANT_FILE -C . || error "Error while expanding $ANT_FILE" fi export ANT_HOME="`pwd`/$ANT_DIR" cd .. @@ -203,13 +245,29 @@ jarbundler_prepare() { } windmill_prepare() { - tools_prepare - - WINDMILL_URL="http://github.com/windmill/windmill/tarball/1.3beta2" - WINDMILL_FILE="windmill-1.3beta2.tar.gz" - WINDMILL_DIR="windmill-1.3beta2" - - tool_download $WINDMILL_URL $WINDMILL_FILE $WINDMILL_DIR + WINDMILL="`which windmill`" + if [ "$WINDMILL" == "" ] ; then + check_python + tools_prepare + + WINDMILL_URL="http://github.com/windmill/windmill/tarball/1.3beta2" + WINDMILL_FILE="windmill-1.3beta2.tar.gz" + WINDMILL_DIR="windmill-1.3beta2" + + tool_download $WINDMILL_URL $WINDMILL_FILE $WINDMILL_DIR + + WINDMILL="$GRIDWORKS_TOOLS_DIR/windmill" + if [ ! -f $WINDMILL ] ; then + cd $GRIDWORKS_TOOLS_DIR + WINDMILL_SRC=`find . -type d -depth 1 | grep windmill` + cd $WINDMILL_SRC + echo "About to install Windmill with 'sudo', you might be asked to input your admin password" + WINDMILL=`sudo python setup.py develop | grep 'Installing windmill script to' | sed 's|.* /|/|'`/windmill + cd .. + ln -s $WINDMILL windmill + cd .. + fi + fi } findbugs_prepare() { @@ -229,7 +287,7 @@ ant() { #export ANT_OPTS="-Xmx1024M" - $ANT -f build.xml $ANT_PARAMS -Dbuild.dir="$GRIDWORKS_BUILD_DIR" -Ddist.dir="$GRIDWORKS_DIST_DIR" -Dversion="$VERSION" -Dnum_version="$NUM_VERSION" -Drevision="$REVISION" $1 || exit 1 + $ANT -f build.xml $ANT_PARAMS -Dbuild.dir="$GRIDWORKS_BUILD_DIR" -Ddist.dir="$GRIDWORKS_DIST_DIR" -Dversion="$VERSION" -Dnum_version="$NUM_VERSION" -Drevision="$REVISION" $1 || error "Error while running ant task '$1'" } # ---------------------------------------------------------------------------------------------- @@ -282,7 +340,7 @@ mac_dist() { get_revision ANT_PARAMS="-Djarbundler.dir=${GRIDWORKS_TOOLS_DIR}/${JARBUNDLER_DIR}" - ant mac || exit 1 + ant mac mkdir -p "$GRIDWORKS_BUILD_DIR/mac/.background" cp src/graphics/dmg_background/dmg_background.png "$GRIDWORKS_BUILD_DIR/mac/.background/dmg_background.png" @@ -297,7 +355,7 @@ mac_dist() { echo "Building MacOSX DMG for $TITLE" hdiutil create -srcfolder "$GRIDWORKS_BUILD_DIR/mac" -volname "$TITLE" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${SIZE}m "$GRIDWORKS_BUILD_DIR/temp_gridworks.dmg" || error "can't create empty DMG" DEVICE=`hdiutil attach -readwrite -noverify -noautoopen "$GRIDWORKS_BUILD_DIR/temp_gridworks.dmg" | egrep '^/dev/' | sed 1q | awk '{print $1}'` - hdiutil attach "$GRIDWORKS_BUILD_DIR/temp_gridworks.dmg" + hdiutil attach "$GRIDWORKS_BUILD_DIR/temp_gridworks.dmg" || error "Can't attach temp DMG" echo ' tell application "Finder" @@ -321,11 +379,11 @@ mac_dist() { eject end tell end tell - ' | osascript || error "error running applescript" + ' | osascript || error "Error running applescript" sync sync - hdiutil detach $DEVICE + hdiutil detach $DEVICE || error "Error while detaching $DEVICE" if [ -f "$GRIDWORKS_DIST_DIR/gridworks-$VERSION-$REVISION.dmg" ] ; then rm "$GRIDWORKS_DIST_DIR/gridworks-$VERSION-$REVISION.dmg" @@ -338,12 +396,36 @@ mac_dist() { } test() { - ui_test $1 server_test $1 + ui_test $1 } ui_test() { windmill_prepare + + GRIDWORKS_DATA_DIR="${GRIDWORKS_TEST_DIR}/temp" + + add_option "-Dgridworks.headless=true" + + run fork + + echo "Waiting for Gridworks to load..." + sleep 5 + echo "... proceed with the tests." + echo "" + + load_data "$GRIDWORKS_TEST_DIR/data/food.csv" "Food" + sleep 3 + echo "" + + echo "Starting Windmill..." + $WINDMILL firefox http://${GRIDWORKS_HOST}:${GRIDWORKS_PORT}/ test=$GRIDWORKS_TEST_DIR/windmill exit > /dev/null + + echo "" + echo "Killing Gridworks" + kill -9 $GRIDWORKS_PID + echo "Cleaning up" + rm -rf $GRIDWORKS_DATA_DIR } server_test() { @@ -364,13 +446,15 @@ server_test() { RUN_CMD="$JAVA -cp $CLASSPATH $OPTS org.junit.runner.JUnitCore $TESTS" - echo "$RUN_CMD" - echo "" + #echo "$RUN_CMD" + #echo "" - exec $RUN_CMD + $RUN_CMD || error "Failed passing server tests" } run() { + FORK=$1 + if [ ! -d $GRIDWORKS_BUILD_DIR/classes ] ; then is_jar=`ls $GRIDWORKS_LIB_DIR | grep gridworks` if [ "$is_jar" == "" ] ; then @@ -379,6 +463,12 @@ run() { fi fi + check_running + + if [ "$NOT_RUNNING" == "" ] ; then + warn "Gridworks is already running." + fi + if [ -d $GRIDWORKS_BUILD_DIR/classes ] ; then add_option "-Dgridworks.autoreloading=true" fi @@ -394,13 +484,19 @@ run() { CLASSPATH="$GRIDWORKS_BUILD_DIR/classes:$GRIDWORKS_LIB_DIR/*" RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.metaweb.gridworks.Gridworks" + + #echo "$RUN_CMD" + #echo "" echo "Starting Gridworks at 'http://${GRIDWORKS_HOST}:${GRIDWORKS_PORT}/'" echo "" - #echo "$RUN_CMD" - #echo "" - exec $RUN_CMD + if [ "$FORK" == "" ] ; then + exec "$RUN_CMD" + else + sh -c "$RUN_CMD" & + GRIDWORKS_PID="$!" + fi } execute() { @@ -413,8 +509,8 @@ execute() { RUN_CMD="$JAVA -cp $CLASSPATH $OPTS $*" - echo "$RUN_CMD" - echo "" + #echo "$RUN_CMD" + #echo "" exec $RUN_CMD $* } diff --git a/src/server/java/com/metaweb/gridworks/Gridworks.java b/src/server/java/com/metaweb/gridworks/Gridworks.java index b77ea03ff..6f8b3062d 100644 --- a/src/server/java/com/metaweb/gridworks/Gridworks.java +++ b/src/server/java/com/metaweb/gridworks/Gridworks.java @@ -104,8 +104,11 @@ public class Gridworks { GridworksServer server = new GridworksServer(); server.init(host,port); - GridworksClient client = new GridworksClient(); - client.init(host,port); + boolean headless = Configurations.getBoolean("gridworks.headless",false); + if (!headless) { + GridworksClient client = new GridworksClient(); + client.init(host,port); + } // hook up the signal handlers new ShutdownSignalHandler("TERM", server); diff --git a/tests/windmill/test_basic_functions.py b/tests/windmill/test_basic_functions.py index 91902fa07..3baff19ad 100644 --- a/tests/windmill/test_basic_functions.py +++ b/tests/windmill/test_basic_functions.py @@ -3,42 +3,40 @@ from windmill.authoring import WindmillTestClient def test_gridworks(): client = WindmillTestClient(__name__) - #currently depends on their being a copy of food.csv - #TODO get working with upload somehow - client.click(link=u'WM Food 1') + # food.csv tests + client.click(link=u'Food') client.waits.forPageLoad(timeout=u'20000') - #create text facet from 1st word of Short Description + # create text facet from 1st word of Short Description filter_column(client, 'Shrt_Desc') client.click(jquery=u'(".menu-item:contains(\'Custom Text Facet\')")[0]') client.type(jquery=u'(".expression-preview-code")[0]', text=u"value.split(',')[0]") client.click(jquery=u'("button:contains(\'OK\')")[0]') - assert_expected_top_value(client, 'SPAGHETTIOS') client.click(jquery=u'("a:contains(\'re-sort by count\')")[0]') assert_expected_top_value(client, 'BEEF') - #Filter down to BEEF. Result == 457 rows + # Filter down to BEEF. Result == 457 rows client.click(jquery=u'("a.facet-choice-label:contains(\'BEEF\')")[0]') client.asserts.assertText(jquery=u'("span.viewPanel-summary-row-count")[0]', validator=u'457') - #create numeric filter from Water column - #assert that there's NOT a facet panel named 'Water' yet + # create numeric filter from Water column + # assert that there's NOT a facet panel named 'Water' yet assert client.execJS(js=u'$(".facet-panel span:contains(\'Water\')").length')['output'] == 0 filter_column(client, 'Water') client.click(jquery=u'(".menu-item:contains(\'Numeric Facet\')")[0]') - #assert that there's a facet panel named 'Water' + # assert that there's a facet panel named 'Water' assert client.execJS(js=u'$(".facet-panel span:contains(\'Water\')").length')['output'] > 0 - #drag to filter down set. Result == 10 rows + # drag to filter down set. Result == 10 rows client.dragDropElem(jquery=u'("a.ui-slider-handle")[0]', pixels=u'150, 0') client.asserts.assertText(jquery=u'("span.viewPanel-summary-row-count")[0]', validator=u'457') - #Next TODO - #lowercase the Shrt_Desc - #TitleCase the Shrt_Desc + # Next TODO + # lowercase the Shrt_Desc + # TitleCase the Shrt_Desc ''' - #history test -- in progress + # history test -- in progress client.mouseOver(classname=u'history-panel-body-collapsed') client.waits.forElement(link=u"Create new column Desc, split based on column Shrt_Desc by filling 0 rows with gel:split(value , ',')", timeout=u'8000') client.click(jquery=u'(".history-future .history-entry")[0]') @@ -56,9 +54,4 @@ def filter_column(client, column): def assert_expected_top_value(client, expected_value): actual_value = client.execJS(js=u'$("a.facet-choice-label")[0].text')['output'].strip() - assert actual_value == expected_value, "Expected actual_value to be '{0}'. Got '{1}'".format(expected_value, actual_value) - - - - - + assert actual_value == expected_value, "Expected actual_value to be '{0}'. Got '{1}'".format(expected_value, actual_value)