diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..de52cc5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +############################################################################## +# Copyright 2017 IBM Corporation +# +# 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. +############################################################################## +language: bash +sudo: true + +script: + - ./travis-test.sh \ No newline at end of file diff --git a/README.md b/README.md index 17af65f..afb53f9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/IBM/openwhisk-data-processing-message-hub.svg?branch=master)](https://travis-ci.org/IBM/openwhisk-data-processing-message-hub) + # Getting Started with OpenWhisk and Message Hub This project provides sample code for creating your Message Hub (Kafka) data processing app with Apache OpenWhisk on IBM Bluemix. It should take no more than 10 minutes to get up and running. diff --git a/actions/mhpost/package.json b/actions/mhpost/package.json index 602997f..46f6e21 100644 --- a/actions/mhpost/package.json +++ b/actions/mhpost/package.json @@ -1,14 +1,11 @@ { "name": "mypost", - "version": "0.1", + "version": "0.1.0", "description": "Action posting messages to a Message Hub topic", "author": "IBM", "license": "Apache-2.0", "dependencies": { - "message-hub-rest": "file:./node_modules/message-hub-rest" - }, - "engines": { - "node": "6.9" + "message-hub-rest": "1.2.0" }, "main": "index.js" } diff --git a/deploy.sh b/deploy.sh index ed1b0a5..45e0907 100755 --- a/deploy.sh +++ b/deploy.sh @@ -18,6 +18,10 @@ # Load configuration variables source local.env +function usage() { + echo -e "Usage: $0 [--install,--uninstall,--env]" +} + function install() { echo -e "Installing OpenWhisk actions, triggers, and rules for openwhisk-data-processing-message-hub..." diff --git a/kafka_consume.sh b/kafka_consume.sh index 14701ef..f5b21c8 100755 --- a/kafka_consume.sh +++ b/kafka_consume.sh @@ -31,7 +31,7 @@ decode_response() { local ARG=$1 local ENCODED=${1##*,\"value\":\"} local ENCODED=${ENCODED%%\",\"partition\":*} - DECODED=`echo $ENCODED | base64 -D` + DECODED=`echo $ENCODED | base64 --decode` fi } diff --git a/travis-test.sh b/travis-test.sh new file mode 100755 index 0000000..3c72f77 --- /dev/null +++ b/travis-test.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +############################################################################## +# Copyright 2017 IBM Corporation +# +# 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. +############################################################################## +set -e + +OPEN_WHISK_BIN=/home/ubuntu/bin +LINK=https://openwhisk.ng.bluemix.net/cli/go/download/linux/amd64/wsk + +echo "Downloading OpenWhisk CLI from '$LINK'...\n" +curl -O $LINK +chmod u+x wsk +export PATH=$PATH:`pwd` + +echo "Configuring CLI from apihost and API key\n" +wsk property set --apihost openwhisk.ng.bluemix.net --auth $OPEN_WHISK_KEY #OPEN_WHISK_KEY defined in travis-ci console + +echo "Configure local.env" +touch local.env #Configurations defined in travis-ci console + +echo "installing jq for bash json parsing" +sudo apt-get install jq + +echo "Deploying wsk actions, etc." +./deploy.sh --install + +echo "Waiting for triggers/actions to finish installing (sleep 5)" +sleep 5 + +echo "Publishing a kafka message" +./kafka_publish.sh + +echo "Waiting for triggers/actions to finish executing(sleep 5)" +sleep 5 + +echo "Consuming kafka out-topic queue" +KAFKA_MESSAGE=`./kafka_consume.sh | tail -3 | head -1` +echo "consumed message: $KAFKA_MESSAGE" + +MSG_AGENT=`echo $KAFKA_MESSAGE | jq -r '.agent'` +if [[ $MSG_AGENT == "OpenWhisk action" ]] +then + echo "Found the message we were expecting" +else + echo "Something went wrong" + echo "Uninstalling wsk actions, etc." + ./deploy.sh --uninstall + exit -1 +fi + +echo "Uninstalling wsk actions, etc." +./deploy.sh --uninstall \ No newline at end of file