Sample Client to Use CI Service Sample

Tested on Python 2.7.9.


In [1]:
!ifconfig


eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:99  
          inet addr:172.17.0.153  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:99/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1375 errors:0 dropped:2 overruns:0 frame:0
          TX packets:392 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:187331 (187.3 KB)  TX bytes:2362686 (2.3 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:234 errors:0 dropped:0 overruns:0 frame:0
          TX packets:234 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:25814 (25.8 KB)  TX bytes:25814 (25.8 KB)


In [1]:
import requests
import json
import py2cytoscape.util as cy
import networkx as nx

BASE = 'http://192.168.99.100/v1/'
HEADERS = {'Content-Type': 'application/json'}

# Generate a scale-free graph with 3000 nodes (with NetworkX)
g = nx.scale_free_graph(3000)

# Convert to Cytoscape.js JSON
cyg = cy.from_networkx(g)

In [2]:
# Hello service
url_hello = BASE + 'hello'


for i in range(3):
    post_data = {
    'name' : 'John Doe ' + str(i)
}
    res = requests.post(url_hello, data=json.dumps(post_data), headers=HEADERS)
    print(res.content)


{
    "job_id": "2837b0fd-84a8-478c-a342-c30c3249b15d", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/2837b0fd-84a8-478c-a342-c30c3249b15d"
}

{
    "job_id": "b26754c6-3ee9-4343-a6f4-784e5276e1c9", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/b26754c6-3ee9-4343-a6f4-784e5276e1c9"
}

{
    "job_id": "54870a02-b787-40bf-aa8a-bd0411f08e23", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/54870a02-b787-40bf-aa8a-bd0411f08e23"
}


In [3]:
url_algorithms = BASE + 'algorithms'
print(url_algorithms)

url_btw = BASE + 'algorithms/pagerank'

for i in range(12):
    res = requests.post(url_btw, data=json.dumps(cyg), headers=HEADERS)
    print(res.content)


http://192.168.99.100/v1/algorithms
{
    "job_id": "22d0aac0-1216-4018-a811-46c0800795cc", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/22d0aac0-1216-4018-a811-46c0800795cc"
}

{
    "job_id": "be36cfa1-2e39-4f8a-b261-ab525b8cdffb", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/be36cfa1-2e39-4f8a-b261-ab525b8cdffb"
}

{
    "job_id": "c881e0df-590b-42c8-9fff-0321aee6b5f5", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/c881e0df-590b-42c8-9fff-0321aee6b5f5"
}

{
    "job_id": "eb26fdb7-79ef-42b1-840f-bbac48770106", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/eb26fdb7-79ef-42b1-840f-bbac48770106"
}

{
    "job_id": "7aeeb9ce-542c-401b-b6f1-5974ad6cce0d", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/7aeeb9ce-542c-401b-b6f1-5974ad6cce0d"
}

{
    "job_id": "e01600e0-50fd-4e9a-8b51-d7150ae76a9c", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/e01600e0-50fd-4e9a-8b51-d7150ae76a9c"
}

{
    "job_id": "6d9ce5dd-ed4e-41bc-9005-a9fc5759af87", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/6d9ce5dd-ed4e-41bc-9005-a9fc5759af87"
}

{
    "job_id": "c6f70c80-82ba-4b73-8e32-ae60be5fc44e", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/c6f70c80-82ba-4b73-8e32-ae60be5fc44e"
}

{
    "job_id": "31558f6e-0eed-4436-84e0-bf3e8f77a9bd", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/31558f6e-0eed-4436-84e0-bf3e8f77a9bd"
}

{
    "job_id": "c65a4993-e83a-4344-9fd1-03c265448ae2", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/c65a4993-e83a-4344-9fd1-03c265448ae2"
}

{
    "job_id": "1ad63ea6-538a-4daa-a8aa-a12b367b4f2c", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/1ad63ea6-538a-4daa-a8aa-a12b367b4f2c"
}

{
    "job_id": "69695277-2b7d-4203-a54d-00a454bf5e32", 
    "result_type": "memory", 
    "status": "queued", 
    "url": "queue/69695277-2b7d-4203-a54d-00a454bf5e32"
}


In [4]:
# Apply layout URL:

url_apply = BASE + 'generators/scalefree'
post_data = {
    'num_nodes': 1000
}

for i in range(5):
    res = requests.post(url_apply, data=json.dumps(post_data), headers=HEADERS)
    print(res.content)


{
    "job_id": "cace0dbb-b1ca-45d4-85a4-19535a2be8f0", 
    "result_type": "file", 
    "status": "queued", 
    "url": "queue/cace0dbb-b1ca-45d4-85a4-19535a2be8f0"
}

{
    "job_id": "1bbd547a-8f49-45e4-a41b-be3415f3b471", 
    "result_type": "file", 
    "status": "queued", 
    "url": "queue/1bbd547a-8f49-45e4-a41b-be3415f3b471"
}

{
    "job_id": "3012143f-c254-4eed-8f2f-cd3973631bc5", 
    "result_type": "file", 
    "status": "queued", 
    "url": "queue/3012143f-c254-4eed-8f2f-cd3973631bc5"
}

{
    "job_id": "043ad136-9f74-4a82-9d66-ed1f4a511e0b", 
    "result_type": "file", 
    "status": "queued", 
    "url": "queue/043ad136-9f74-4a82-9d66-ed1f4a511e0b"
}

{
    "job_id": "d4bc7b2d-10a5-48bb-85ed-6fd826c19598", 
    "result_type": "file", 
    "status": "queued", 
    "url": "queue/d4bc7b2d-10a5-48bb-85ed-6fd826c19598"
}


In [5]:
# Job Status
url_jobs =  BASE + 'jobs'
print(url_jobs)

res = requests.get(url_jobs)
jobs = res.json()

print('Number of jobs = ' + str(len(jobs)))


http://192.168.99.100/v1/jobs
Number of jobs = 20

In [6]:
# Delete the first job
res = requests.delete(url_jobs + '/' + jobs[0]['job_id'])
print(json.dumps(res.json(), indent=4))


{
    "message": "Job 2837b0fd-84a8-478c-a342-c30c3249b15d removed."
}

In [7]:
# res = requests.delete(url_jobs)
# print(json.dumps(res.json(), indent=4))