File: oarapi_examples.txt

package info (click to toggle)
oar 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,700 kB
  • sloc: perl: 34,517; sh: 6,041; ruby: 5,840; sql: 3,390; cpp: 2,277; makefile: 402; php: 365; ansic: 335; python: 275; exp: 23
file content (78 lines) | stat: -rw-r--r-- 3,263 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
### Examples using ruby restclient ###
> gem install rest-client
> export PATH=$PATH:/var/lib/gems/1.8/bin
> restclient http://kameleon:kameleon@localhost/oarapi-priv

# Getting resources infos
  # in JSON
irb(main):004:0> puts get('/resources.json')
  # in YAML
irb(main):005:0> puts get('/resources.yaml')
  # Same thing
irb(main):050:0> puts get('/resources', :accept=>"text/yaml")
  # Specifying the "oar" data structure
irb(main):050:0> puts get('/resources.json?structure=oar')
  # Specifying the "simple" data structure
irb(main):050:0> puts get('/resources.json?structure=simple')
  # Details about a resource
irb(main):008:0> puts get('/resources/1.yaml')
  # Details and resources of a node
irb(main):007:0> puts get('/resources/nodes/liza-1.yaml')
  # Details of all the resources (expansion)
irb(main):007:0> puts get('/resources/all.yaml')

# Getting jobs infos
irb(main):006:0> puts get('/jobs.yaml')
irb(main):009:0> puts get('/jobs/12.yaml')

# Submiting a job (using JSON format)
irb(main):010:0> require 'json'
irb(main):012:0> j={ 'resource' => '/nodes=2/cpu=1', 'command' => '/usr/bin/id' }
irb(main):015:0> job=post('/jobs' , j.to_json , :content_type => 'application/json')

# Getting details about the previously submited job
irb(main):035:0> uri=JSON.parse(job)['links'].find { |l| l["rel"]=="self" }["href"]
irb(main):035:0> puts get(uri+"yaml")

# Submitting a job using JSON format, but requiring the result in YAML
irb(main):037:0> job=post('/jobs.yaml' , j.to_json , :content_type => 'application/json')

# Submitting a job with a provided inline script
irb(main):024:0> script="#!/bin/bash
irb(main):025:0" #OAR --name test
irb(main):025:0" echo \"Hello world\"
irb(main):026:0" whoami
irb(main):027:0" sleep 300
irb(main):028:0" "
irb(main):029:0> j={ 'resource' => '/nodes=2/cpu=1', 'script' => script , 'scanscript' ==> 1, 'workdir' => '~kameleon'}
irb(main):030:0> job=post('/jobs' , j.to_json , :content_type => 'application/json')

# Deleting a job
irb(main):111:0> delete("/jobs/#{JSON.parse(job)['id']}.yaml")

# Send the checkpoint signal to a job
irb(main):102:0> puts post('/jobs/2911/checkpoints/new','',:content_type => "application/json")

# Suspending/resuming a job
irb(main):102:0> puts post('/jobs/2911/holds/new','',:content_type => "application/json")
irb(main):102:0> puts post('/jobs/2911/resumptions/new','',:content_type => "application/json")

# Adding new resources (oar user only)
irb(main):078:0> r=[{ 'network_address' => 'test1', 'besteffort'=>'NO' , 'cpu' => '10' },
                    { 'network_address' => 'test2', 'besteffort'=>'NO' , 'cpu' => '11' }]
irb(main):078:0> puts post('/resources', r.to_json , :content_type => 'application/json')

# Changing the state of a resource
irb(main):079:0> puts post('/resources/11/state','{"state":"Dead"}',:content_type => 'application/json')

# Deleting a resource by id (oar user only)
irb(main):079:0> puts delete('/resources/11.yaml')

# Deleting a resource by node/cpuset (oar user only)
irb(main):080:0> puts delete('/resources/test2-p/1')


### Example using curl ###

curl -i -X POST http://www/oarapi/jobs.json -H'Content-Type: application/json' -d '{"resource":"/nodes=1,walltime=00:10:00", "script_path":"\"sleep 600\"", "type":"inner=986078"}'