Skip to content

Commit

Permalink
Add /api/executions/running
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Feb 14, 2011
1 parent fa707b0 commit d221197
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 5 deletions.
10 changes: 5 additions & 5 deletions rundeckapp/grails-app/conf/UrlMappings.groovy
Expand Up @@ -16,13 +16,13 @@ class UrlMappings {
action = [GET:"apiJobExport", DELETE:"apiJobDelete"]
}

"/api/executions/running" (controller: 'menu', action: 'nowRunning')
"/api/executions/running" (controller: 'menu', action: 'apiExecutionsRunning')

"/api/execution/$id" (controller: 'execution', action: 'show')
"/api/execution/$id/abort" (controller: 'execution', action: 'kill')
// "/api/execution/$id" (controller: 'execution', action: 'show')
// "/api/execution/$id/abort" (controller: 'execution', action: 'kill')

"/api/run/command" (controller: 'scheduledExecution', action: 'runAndForget')
"/api/run/script" (controller: 'scheduledExecution', action: 'runAndForget')
// "/api/run/command" (controller: 'scheduledExecution', action: 'runAndForget')
// "/api/run/script" (controller: 'scheduledExecution', action: 'runAndForget')

"/api/projects" (controller: 'framework', action: 'listProjects')
"/api/project/$project?" (controller: 'framework', action: 'getProject')
Expand Down
42 changes: 42 additions & 0 deletions rundeckapp/grails-app/controllers/MenuController.groovy
Expand Up @@ -451,5 +451,47 @@ class MenuController {
}
}
}

/**
* API: /executions/running, version 1.2
*/
def apiExecutionsRunning = {

if(!params.project){
flash.error=g.message(code:'api.error.parameter.required',args:['project'])
return chain(controller:'api',action:'error')
}
//test valid project
Framework framework = frameworkService.getFrameworkFromUserSession(session,request)

def exists=frameworkService.existsFrameworkProject(params.project,framework)
if(!exists){
flash.error=g.message(code:'api.error.item.doesnotexist',args:['project',params.project])
return chain(controller:'api',action:'error')
}

QueueQuery query = new QueueQuery(runningFilter:'running',projFilter:params.project)
def results = nowrunning(query)
return new ApiController().success{ delegate->
delegate.'executions'(count:results.nowrunning.size()){
results.nowrunning.each{ Execution e->
execution(id: e.id, href:g.createLink(controller:'execution',action:'follow',id:e.id,absolute:true)){
status(null==e.dateCompleted?'running':e.status)
user(e.user)
started(epoch:e.dateStarted.time,e.dateStarted.toString())
if(e.scheduledExecution && results.jobs[e.scheduledExecution.id.toString()]){
job(id:e.scheduledExecution.id){
name(e.scheduledExecution.jobName)
group(e.scheduledExecution.groupPath?:'')
description(e.scheduledExecution.description)
}
}else{
description(e.toString())
}
}
}
}
}
}
}

80 changes: 80 additions & 0 deletions test/api/test-executions-running.sh
@@ -0,0 +1,80 @@
#!/bin/bash

#test output from /api/executions/running

errorMsg() {
echo "$*" 1>&2
}

DIR=$(cd `dirname $0` && pwd)

# accept url argument on commandline, if '-' use default
url="$1"
if [ "-" == "$1" ] ; then
url='http://localhost:4440'
fi
apiurl="${url}/api"
VERSHEADER="X-RUNDECK-API-VERSION: 1.2"

# curl opts to use a cookie jar, and follow redirects, showing only errors
CURLOPTS="-s -S -L -c $DIR/cookies -b $DIR/cookies"
CURL="curl $CURLOPTS"


XMLSTARLET=xml

# now submit req
runurl="${apiurl}/executions/running"
proj=$2
if [ "" == "$2" ] ; then
proj="test"
fi

echo "TEST: /api/executions/running for project ${proj}..."

params="project=${proj}"

# get listing
$CURL --header "$VERSHEADER" ${runurl}?${params} > $DIR/curl.out
if [ 0 != $? ] ; then
errorMsg "ERROR: failed query request"
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /joblist element
$XMLSTARLET el $DIR/curl.out | grep -e '^result' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi

# job list query doesn't wrap result in common result wrapper
#If <result error="true"> then an error occured.
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" $DIR/curl.out)
if [ "true" == "$waserror" ] ; then
errorMsg "Server reported an error: "
$XMLSTARLET sel -T -t -v "/result/error/message" -n $DIR/curl.out
exit 2
fi

#Check projects list
itemcount=$($XMLSTARLET sel -T -t -v "/result/executions/@count" $DIR/curl.out)
echo "$itemcount executions"
if [ "" == "$itemcount" ] ; then
errorMsg "FAIL: executions count was not valid"
exit 2
fi
echo "OK"




#rm $DIR/curl.out

0 comments on commit d221197

Please sign in to comment.