Index  | Recent Threads  | Unanswered Threads  | Who's Active  | Guidelines  | Search
 

Quick Go »
No member browsing this thread
Thread Status: Active
Total posts in this thread: 65
Posts: 65   Pages: 7   [ Previous Page | 1 2 3 4 5 6 7 | Next Page ]
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 13414 times and has 64 replies Next Thread
KerSamson
Master Cruncher
Switzerland
Joined: Jan 29, 2007
Post Count: 1684
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Something weird with the XML API, [new question]

I try to fetch result status in json format using the API.
If I place the request using wget or curl, whatever I give as option for limit and offset, I always received the first 25 results (ResultsReturned": "25", "Offset": "0").
However, if I perform exactly the same request interactively in Firefox, the returned json file is correct in terms of ResultsReturned (e.g. 250) and Offset (e.g. 750).
I experience exactly the same behaviour for xml format.
I've just spent a couple of hours trying to understand what is going wrong but I still do not have any clue.
Help and support is welcome !
Cheers,
Yves
----------------------------------------
----------------------------------------
[Edit 1 times, last edit by KerSamson at Nov 21, 2016 10:34:10 AM]
[Nov 21, 2016 10:33:26 AM]   Link   Report threatening or abusive post: please login first  Go to top 
adriverhoef
Master Cruncher
The Netherlands
Joined: Apr 3, 2009
Post Count: 2346
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Something weird with the XML API, [new question]

That's odd, Yves, because it works for me. If you fill out the values for $MEMBER and $VERIFY and run
MEMBER="crunchingaccountname" # The name of your account with which you're crunching
VERIFY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Your verification code on 'My Profile'
wget "https://secure.worldcommunitygrid.org/api/mem...ERIFY&Limit=250"
what do you get?

Adri
[Nov 21, 2016 4:54:48 PM]   Link   Report threatening or abusive post: please login first  Go to top 
KerSamson
Master Cruncher
Switzerland
Joined: Jan 29, 2007
Post Count: 1684
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Something weird with the XML API, [Resolved]

Hi Adri,
it is very odd since the request is conform to the API description and works fine in Firefox address bar and it delivers the correct content according to the defined Limit and Offset.
However, if the identical request is performed using wget or curl, the Limit and Offset arguments seem to be ignored.

I found the cause for the trouble !!!
wget "...."
curl "...."
Warm thanks Adri ! Since you help me to identify the missing quotes !!!
I'm probably too tired !!!
Cheers,
Yves
----------------------------------------
[Nov 21, 2016 5:49:26 PM]   Link   Report threatening or abusive post: please login first  Go to top 
adriverhoef
Master Cruncher
The Netherlands
Joined: Apr 3, 2009
Post Count: 2346
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Something weird with the XML API, [Resolved]

Good to hear that your problem has been resolved now, Yves. Are you writing a script or some such perhaps? raised eyebrow
[Nov 21, 2016 10:42:57 PM]   Link   Report threatening or abusive post: please login first  Go to top 
KerSamson
Master Cruncher
Switzerland
Joined: Jan 29, 2007
Post Count: 1684
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Something weird with the XML API, [Resolved]

Yes ! The first draft (PoC) is running for gathering the result files (json).
The next step will be to read out the json to put the information into a database.
The following step will to grab some additional html pages for gathering a couple of statistics like projects, team, etc.
Cheers,
Yves
----------------------------------------
[Nov 22, 2016 6:44:36 AM]   Link   Report threatening or abusive post: please login first  Go to top 
adriverhoef
Master Cruncher
The Netherlands
Joined: Apr 3, 2009
Post Count: 2346
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Something weird with the XML API, [Resolved]

That's what I did, too, by using a flat file instead of a database. My script is called 'wcgresults' and it runs every hour from crontab: "xx * * * * bin/wcgresults -df misc/WCG.log". Maybe it's of some use to you (if you save it to a file, don't forget to 'chmod +x' it wink ).

EDIT: updated version of the script here: https://secure.worldcommunitygrid.org/forums/wcg/viewpostinthread?post=536034
----------------------------------------
[Edit 4 times, last edit by adriverhoef at Dec 10, 2016 1:40:46 AM]
[Nov 22, 2016 9:19:12 AM]   Link   Report threatening or abusive post: please login first  Go to top 
KerSamson
Master Cruncher
Switzerland
Joined: Jan 29, 2007
Post Count: 1684
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Something weird with the XML API, [Resolved]

Hi Adri,
I thank you for the input, I will read it carefully.
My result collection script is much more limited. I will post it here as soon as I will consolidate it.
The PoC is written in Unix shell (bash) but the objective is to have the most part of the application written in Python.
I plan to use SQLite for storing the collected information.
If you are interested with the concept, please send me an e-mail and I will send you more details.
Cheers,
Yves
---
PS: You can find a valid e-mail address over my company web site.
----------------------------------------
[Nov 22, 2016 9:43:21 AM]   Link   Report threatening or abusive post: please login first  Go to top 
Former Member
Cruncher
Joined: May 22, 2018
Post Count: 0
Status: Offline
Reply to this Post  Reply with Quote 
Re: Something weird with the XML API, [Resolved]

HI adriverhoef ;
I tried this commands
MEMBER="blabla"
mint@mint ~ $ VERIFY="blabla"
mint@mint ~ $ wget "https://secure.worldcommunitygrid.org/api/mem...ERIFY&Limit=250"
/api/mem...ERIFY&Limit=250

like you said before but i got this results

Resolving secure.worldcommunitygrid.org (secure.worldcommunitygrid.org)... 198.20.8.246
Connecting to secure.worldcommunitygrid.org (secure.worldcommunitygrid.org)|198.20.8.246|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2016-12-09 10:41:05 ERROR 403: Forbidden.

could you please tell me if i have to add something else to get my results in xml file
[Dec 9, 2016 10:51:03 AM]   Link   Report threatening or abusive post: please login first  Go to top 
adriverhoef
Master Cruncher
The Netherlands
Joined: Apr 3, 2009
Post Count: 2346
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Something weird with the XML API, [Resolved]

K.BENZAOUI,
You're on the right track.
You need to look at the source of my posting to copy a useful URL, presented here in two parts to prevent the website's forum software from interpreting it:

https://secure.worldcommunitygrid.org/
api/members/"$MEMBER"/results?code=$VERIFY&format=xml&Limit=250

If you join the two lines https... and api/... together (...grid.org/api/members/...), you should be more succesful.
----------------------------------------
[Edit 2 times, last edit by adriverhoef at Dec 9, 2016 6:22:51 PM]
[Dec 9, 2016 6:20:19 PM]   Link   Report threatening or abusive post: please login first  Go to top 
adriverhoef
Master Cruncher
The Netherlands
Joined: Apr 3, 2009
Post Count: 2346
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Something weird with the XML API, [Resolved]

Since using a long URL is causing trouble, I'm using the variable $URLBASE now in this new version of my script.
EDIT: changing 'secure' to 'www' in the URLBASE.
---8< --- SNIP SNIP SNIP --- CUT HERE ---8<
#!/bin/sh
#
# wcgresults - use WCG's API to get a list of recent results
# https://www.worldcommunitygrid.org/help/viewTopic.do?shortName=api
#
# VERSION: 1.8.3
# Author: Adri Verhoef

Prog=${0##*/}

#############
# CONFIGURE #
#############
TMPDIR=/var/tmp # Directory for storing temporary files
URLBASE=https://www.worldcommunitygrid.org # Don't change this, unless you know what you're doing
MEMBER="youraccountname" # The name of your account with which you're crunching
VERIFY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # Your verification code on 'My Profile'
MEMBER1="anotheraccount"
VERIFY1="11111111111111111111111111111111"
########################
# END OF CONFIGURATION #
########################

usage () {
printf "%s\n" \
"Usage: $Prog [options] [-d | file ...]" \
" Options:" \
" -b sortby sort results by the value of ’sortby’" \
" (0 = DeviceId, 1 = SentTime, 2 = ReportDeadline, 3 = ReceivedTime (default), 4 = CpuTime)" \
" -d download a new status file before calculating averages" \
" -f logfile record results that went through the validator to file ’logfile’" \
" -l limit define the number of results to download (default: 250)" \
" -o offset define the number of results to skip when downloading (default: 0)" \
" -s state only select results with ”ValidateState” value ’state’" \
" (0 = pending validation, 1 = valid, 2 = invalid," \
" 4 = pending verification, 5 = results failed to validate within given deadline)" \
" -u user the name of your account on World Community Grid (default: you; ’user’ = 1 ... for other account(s))" \
" -w only select results that are still 'in progress'" \
;
}

# Options
OPTS=hb:df:l:o:s:u:w
export opt_b=3 # latest received
export opt_d=0
export opt_f=""
export opt_l=250
export opt_o=0
export opt_s=""
export opt_u=""
export opt_w=0
while getopts $OPTS opt; do
case $opt in
h) usage; exit 0;;
[dw]) eval let opt_$opt++;;
[a-zA-Z0-9]) eval opt_$opt='$OPTARG';;
?) usage; exit 1;;
esac
done
shift $(($OPTIND - 1))

case $opt_b in [01234]) case $opt_b in 0) opt_b=DeviceId;; 1) opt_b=SentTime;; 2) opt_b=ReportDeadline;; 3) opt_b=ReceivedTime;; 4) opt_b=CpuTime;; esac; SortBy="&SortBy=$opt_b";; *) SortBy="";; esac
case $opt_o in 0) Offset="";; *) Offset="&Offset=$opt_o";; esac
case $opt_s in [01245]) ValidateState="&ValidateState=$opt_s";; *) ValidateState="";; esac
case $opt_u in "") ;; *) eval MEMBER=\$MEMBER$opt_u; eval VERIFY=\$VERIFY$opt_u;; esac
case $opt_w in 0) ServerState=5;; *) ServerState=4;; esac

TMPFILE=$TMPDIR/$Prog.`date +%Y-%m-%dT%H:%M:%S`

PRINT_LONG_FORMAT='
printf "%-20s %6d", $str_ValidateState[$ValidateState], $combi_DeviceName_AppName_ValidateState_count{$DeviceName}{$AppName}{$ValidateState};
printf " %6.1f", $cc=($combi_DeviceName_AppName_ValidateState_ClaimedCredit{$DeviceName}{$AppName}{$ValidateState} / $combi_DeviceName_AppName_ValidateState_count{$DeviceName}{$AppName}{$ValidateState});
printf "/%-6.1f", $g=($combi_DeviceName_AppName_ValidateState_GrantedCredit{$DeviceName}{$AppName}{$ValidateState} / $combi_DeviceName_AppName_ValidateState_count{$DeviceName}{$AppName}{$ValidateState});
printf " %7.2f", $ct=($combi_DeviceName_AppName_ValidateState_CpuTime{$DeviceName}{$AppName}{$ValidateState} / $combi_DeviceName_AppName_ValidateState_count{$DeviceName}{$AppName}{$ValidateState});
printf "/%-7.2f", $combi_DeviceName_AppName_ValidateState_ElapsedTime{$DeviceName}{$AppName}{$ValidateState} / $combi_DeviceName_AppName_ValidateState_count{$DeviceName}{$AppName}{$ValidateState};
printf "\n";
'
ADDITIONAL_HEADER='(ValidationState) (Claim/Grant) (Cpu/Elapsed)'
PRINT_LONG_HEADER='
printf "%-16s %-6s %4d\t'"$ADDITIONAL_HEADER"'\n", $DeviceName, $AppName, $combi_DeviceName_AppName{$DeviceName}{$AppName};
'

calculate_or_record () {
perl -wne '
BEGIN {
if ($ENV{opt_f} ne "") {
if (open(LOGFILE, $ENV{opt_f})) {
while (<LOGFILE>) {
chomp;
@t = split(/\t/);
$workunit{$t[9]} = $t[15]; # Name and ValidateState
}
close(LOGFILE);
}
open(LOGFILE, ">>$ENV{opt_f}") || die "$ENV{Prog}: cannot open logfile ’$ENV{opt_f}’ for writing.\n";
}
$outcome_varies = 0;
$str_Outcome[0] = "(waiting)"; # in progress
$str_Outcome[1] = "success";
$str_Outcome[3] = "error";
$str_Outcome[4] = "no reply";
$str_Outcome[6] = "validation error";
$str_Outcome[7] = "abandoned";
$str_ValidateState[0] = "Pending validation";
$str_ValidateState[1] = "Valid";
$str_ValidateState[2] = "Invalid";
$str_ValidateState[3] = "In progress"; # originally undefined state, so it is now a user defined value
$str_ValidateState[4] = "Pending verification";
$str_ValidateState[5] = "Too late";
#str_ExitStatus[192] = "EXIT_STATEFILE_WRITE";
$txt_ExitStatus[192] = "The client will exit if it cannot write to the client_state.xml file. Make sure you have permission to write to the BOINC Data directory.";
#str_ExitStatus[193] = "EXIT_SIGNAL";
$txt_ExitStatus[193] = "The client, Manager and/or application will exit when getting the exit signal.";
#str_ExitStatus[194] = "EXIT_ABORTED_BY_CLIENT";
$txt_ExitStatus[194] = "Task was aborted by the BOINC client.";
#str_ExitStatus[195] = "EXIT_CHILD_FAILED";
$txt_ExitStatus[195] = "The science application running the task failed for unknown reasons.";
#str_ExitStatus[196] = "EXIT_DISK_LIMIT_EXCEEDED";
$txt_ExitStatus[196] = "The amount of disk space that the task could use was more than the limit set to the task.";
#str_ExitStatus[197] = "EXIT_TIME_LIMIT_EXCEEDED";
$txt_ExitStatus[197] = "The amount of time that the task can run was estimated to be far greater than the time limit set to the task.";
#str_ExitStatus[198] = "EXIT_MEM_LIMIT_EXCEEDED";
$txt_ExitStatus[198] = "The amount of memory that the task could use was greater than the limit set to the task.";
#str_ExitStatus[199] = "EXIT_CLIENT_EXITING";
$txt_ExitStatus[199] = "The task was ended when the client was exited.";
#str_ExitStatus[200] = "EXIT_UNSTARTED_LATE";
$txt_ExitStatus[200] = "Task was aborted due to it having not started and already past the deadline.";
#str_ExitStatus[201] = "EXIT_MISSING_COPROC";
$txt_ExitStatus[201] = "A coprocessor that was detected earlier went missing. Work for it is being aborted.";
#str_ExitStatus[202] = "EXIT_ABORTED_BY_PROJECT";
$txt_ExitStatus[202] = "Tasks on the computer were aborted by the project.";
#str_ExitStatus[203] = "EXIT_ABORTED_VIA_GUI";
$txt_ExitStatus[203] = "Applications exit with this code after you told them to abort.";
#str_ExitStatus[204] = "EXIT_UNKNOWN";
$txt_ExitStatus[204] = "Unknown exit.";
$results_available = 0;
}
chomp;
if (/"ResultsReturned": "([^"]+)",/) { print "Results returned: $1\n" unless $ENV{opt_f} ne ""; }
elsif (/"AppName": "([^"]+)",/) { $AppName = $1; }
elsif (/"ClaimedCredit": ([^,]+)/) { $ClaimedCredit = $1; }
elsif (/"CpuTime": ([^,]+)/) { $CpuTime = $1; }
elsif (/"ElapsedTime": ([^,]+)/) { $ElapsedTime = $1; }
elsif (/"ExitStatus": ([^,]+)/) { $ExitStatus = $1; }
elsif (/"GrantedCredit": ([^,]+)/) { $GrantedCredit = $1; }
elsif (/"DeviceId": ([^,]+)/) { $DeviceId = $1; } # only used for LOGFILE
elsif (/"DeviceName": "([^"]+)",/) { $DeviceName = $1; }
elsif (/"ModTime": ([^,]+)/) { $ModTime = $1; } # only used for LOGFILE
elsif (/"Name": "([^"]+)",/) { $Name = $1; }
elsif (/"Outcome": ([^,]+)/) { $Outcome = $1; }
elsif (/"ReceivedTime": "([^"]+)",/) { $ReceivedTime = $1; } # only used for LOGFILE
elsif (/"ReportDeadline": "([^"]+)",/) { $ReportDeadline = $1; } # only used for LOGFILE
elsif (/"SentTime": "([^"]+)",/) { $SentTime = $1; } # only used for LOGFILE
elsif (/"ServerState": ([^,]+)/) { $ServerState = $1; }
elsif (/"ValidateState": ([^,]+)/) { $ValidateState = $1; }
elsif (/"FileDeleteState": ([^,]+)/) { $FileDeleteState = $1; } # only used for LOGFILE
if (/"([^"]+)": ("([^"]+)"|[0-9]+(\.[0-9]+)?)$/) { # last item in record, line not ending in comma
if ($ENV{opt_f} ne "") {
# ServerState == 5: results that have already been reported back to the server
# ValidateState == 0: pending validation
# ValidateState == 4: pending verification
if ($ServerState == 5 && $ValidateState != 0 && $ValidateState != 4) {
if (exists $workunit{$Name}) {
if ($workunit{$Name} != $ValidateState) {
print STDERR "$Name has its ValidateState changed from $workunit{$Name} to $ValidateState\n"; # Hopefully changed from ”Too Late” into something better.
} else {
next; # already recorded in LOGFILE
}
}
next if $ClaimedCredit + $CpuTime + $ElapsedTime + $GrantedCredit == 0.0; # probably: 192 <= $ExitStatus <= 204
printf LOGFILE "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", $AppName, $ClaimedCredit, $CpuTime, $ElapsedTime, $ExitStatus, $GrantedCredit, $DeviceId, $DeviceName, $ModTime, $Name, $Outcome, $ReceivedTime, $ReportDeadline, $SentTime, $ServerState, $ValidateState, $FileDeleteState;
}
} else {
if ($Outcome != 1) {
if ($Outcome == 0) {
$ValidateState = 3; # In progress
$ExitStatus = "-";
} else {
$results_available = 1;
}
$fmt0 = "%-16s %-4s %-9s %-20s %-6s";
$fmt1 = "%s %s";
$fmt2 = "%6.1f/%-6.1f %7.2f/%-7.2f ";
$fmt3 = " %s\n";
printf "$fmt0 $fmt1$fmt3", "(DeviceName)", "App", "(Outcome)", "(ValidationState)", "(Exit)", "(Claim/Grant)", "(Cpu/Elapsed)", "(Name)" if ++$outcome_varies == 1;
if ($ExitStatus ne "-") {
if ($ExitStatus >= 192 && $ExitStatus <= 204) {
if (not exists $DidExitStatus[$ExitStatus]) {
$DidExitStatus[$ExitStatus] = 1;
printf "\tExitStatus $ExitStatus: $txt_ExitStatus[$ExitStatus]\n";
}
}
}
printf "$fmt0 $fmt2$fmt3", $DeviceName, $AppName, $str_Outcome[$Outcome], $str_ValidateState[$ValidateState], $ExitStatus, $ClaimedCredit, $GrantedCredit, $CpuTime, $ElapsedTime, $Name;
}
if ($ServerState == 5) {
$results_available = 1;
# results that have already been reported back to the server
$combi_DeviceName_AppName{$DeviceName}{$AppName}++;
$combi_DeviceName_AppName_ValidateState_count{$DeviceName}{$AppName}{$ValidateState}++; # number of validated results
$combi_DeviceName_AppName_ValidateState_ClaimedCredit{$DeviceName}{$AppName}{$ValidateState} += $ClaimedCredit;
$combi_DeviceName_AppName_ValidateState_CpuTime{$DeviceName}{$AppName}{$ValidateState} += $CpuTime;
$combi_DeviceName_AppName_ValidateState_ElapsedTime{$DeviceName}{$AppName}{$ValidateState} += $ElapsedTime;
$combi_DeviceName_AppName_ValidateState_GrantedCredit{$DeviceName}{$AppName}{$ValidateState} += $GrantedCredit;
}
}
}
END {
if ($results_available > 0) {
printf "%s %s %-6s %s %s\n", "=" x 16, " " x 4, " (Number)", " " x 20, "(Number)" if $outcome_varies > 0;
foreach $DeviceName (keys %combi_DeviceName_AppName) {
#print "$DeviceName:\n";
foreach $AppName (keys %{$combi_DeviceName_AppName{$DeviceName}}) {
if ($ENV{opt_s} eq "") {
'"$PRINT_LONG_HEADER"'
foreach $ValidateState (keys %{$combi_DeviceName_AppName_ValidateState_count{$DeviceName}{$AppName}}) {
printf "\t\t\t\t";
'"$PRINT_LONG_FORMAT"'
}
} else {
foreach $ValidateState (keys %{$combi_DeviceName_AppName_ValidateState_count{$DeviceName}{$AppName}}) {
if ($ENV{opt_s} eq $ValidateState) {
printf "%-16s %-6s %4d\t", $DeviceName, $AppName, $combi_DeviceName_AppName{$DeviceName}{$AppName};
'"$PRINT_LONG_FORMAT"'
}
}
}
}
}
}
}
' "$@"
}

wcgget() {
[ -n "$opt_f" ] && Offset="&Offset=$skipm"
wget $QUIET -O $TMPFILE "$URLBASE/api/members/$MEMBER/results?code=$VERIFY&format=json&ServerState=$ServerState$ValidateState$SortBy$Offset&Limit=$opt_l" && [ -s $TMPFILE ] &&
calculate_or_record $TMPFILE
if [ -n "$opt_f" ]; then
mv $TMPFILE $TMPFILE.$skipm
[ -s $TMPFILE.$skipm ] || exit 1
fi
}

wcgget_cumulative() {
SortBy="&SortBy=CpuTime" # CpuTime is rather unique for each WU, in order to prevent fetching duplicate WU-entries from the database (resulting from overlap in two or more fetches) using other key selections such as SentTime.
# (https://www.worldcommunitygrid.org/help/viewTopic.do?shortName=api says "Default is SentTime.")
wcgget
let avail=`perl -wne 'print if s/\s+"ResultsAvailable": "([^"]+)",\s+/$1/' $TMPFILE.$skipm` # "ResultsAvailable": "395",
let toget=$avail-$opt_l
while [ $toget -gt 0 ]; do let skipm=$skipm+$opt_l; wcgget; let toget=$toget-$opt_l; done
}

if [ $opt_d = 0 ]; then
calculate_or_record "$@"
else
let skipm=0 # offset
if [ -n "$opt_f" ]
then
QUIET=-q
wcgget_cumulative
else
QUIET=""
wcgget
fi
fi

----------------------------------------
[Edit 3 times, last edit by adriverhoef at Dec 28, 2016 11:58:17 AM]
[Dec 10, 2016 1:38:39 AM]   Link   Report threatening or abusive post: please login first  Go to top 
Posts: 65   Pages: 7   [ Previous Page | 1 2 3 4 5 6 7 | Next Page ]
[ Jump to Last Post ]
Post new Thread